half-sample 0.1.27__tar.gz → 0.1.29__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- half_sample-0.1.29/MANIFEST.in +2 -0
- half_sample-0.1.29/PKG-INFO +17 -0
- {half_sample-0.1.27 → half_sample-0.1.29}/README.md +26 -1
- half_sample-0.1.29/half_sample.egg-info/PKG-INFO +17 -0
- half_sample-0.1.29/half_sample.egg-info/SOURCES.txt +23 -0
- half_sample-0.1.29/half_sample.egg-info/not-zip-safe +1 -0
- half_sample-0.1.29/pyproject.toml +3 -0
- half_sample-0.1.29/sample/sample.exe +0 -0
- {half_sample-0.1.27 → half_sample-0.1.29}/sample/sample.py +5 -0
- half_sample-0.1.29/setup.py +85 -0
- half_sample-0.1.29/tests/test_0819_cycle_regression.py +222 -0
- half_sample-0.1.29/tests/test_commander.py +22 -0
- half_sample-0.1.29/tests/test_estimate.py +111 -0
- half_sample-0.1.29/tests/test_measure.py +1305 -0
- half_sample-0.1.29/tests/test_protocol.py +146 -0
- half_sample-0.1.29/tests/test_release_pipeline.py +121 -0
- half_sample-0.1.29/tests/test_release_runtime.py +98 -0
- half_sample-0.1.29/tests/test_sampler.py +44 -0
- half_sample-0.1.27/PKG-INFO +0 -15
- half_sample-0.1.27/cpp_build/sample.exe +0 -0
- half_sample-0.1.27/half_sample.egg-info/PKG-INFO +0 -15
- half_sample-0.1.27/half_sample.egg-info/SOURCES.txt +0 -12
- half_sample-0.1.27/setup.py +0 -18
- {half_sample-0.1.27 → half_sample-0.1.29}/half_sample.egg-info/dependency_links.txt +0 -0
- {half_sample-0.1.27 → half_sample-0.1.29}/half_sample.egg-info/top_level.txt +0 -0
- {half_sample-0.1.27 → half_sample-0.1.29}/sample/__init__.py +0 -0
- {half_sample-0.1.27 → half_sample-0.1.29}/sample/process.py +0 -0
- {half_sample-0.1.27 → half_sample-0.1.29}/sample/protocol.py +0 -0
- {half_sample-0.1.27 → half_sample-0.1.29}/sample/result.py +0 -0
- {half_sample-0.1.27 → half_sample-0.1.29}/setup.cfg +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: half_sample
|
|
3
|
+
Version: 0.1.29
|
|
4
|
+
Summary: sample data and analysis
|
|
5
|
+
Home-page: https://github.com/KD-Group/Half.Sample
|
|
6
|
+
Author: kunde
|
|
7
|
+
Author-email: gzkunde@163.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Dynamic: author
|
|
13
|
+
Dynamic: author-email
|
|
14
|
+
Dynamic: classifier
|
|
15
|
+
Dynamic: home-page
|
|
16
|
+
Dynamic: requires-python
|
|
17
|
+
Dynamic: summary
|
|
@@ -2,7 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://ci.appveyor.com/project/Wingsgo/half-sample)
|
|
4
4
|
|
|
5
|
-
Half.Sample
|
|
5
|
+
Half.Sample 提供 Windows x64 采集程序、Python 包和 Rust crate。两种客户端通过独立的 `sample.exe` 完成采集及波形拟合,也可以在没有采集卡的机器上显式选择模拟采集。仓库另有独立的 PCI-1714U DAQ 能力验证程序。
|
|
6
|
+
|
|
7
|
+
## 使用发行包
|
|
8
|
+
|
|
9
|
+
Python 项目通过 `pip install half-sample` 安装,沿用 `from sample import Sampler`。Rust 客户端首次公开发布后,在项目中执行 `cargo add half-sample`,将[模拟采集示例](rust/examples/mock.rs)放入 `src/main.rs` 并执行 `cargo run`。示例显式选择模拟模式,使用包内的程序输出实测及拟合波形。真机使用匹配的厂商驱动。[Rust 使用说明](rust/README.md)
|
|
10
|
+
|
|
11
|
+
需要在安装程序中单独分发运行时时,从相应版本的 GitHub Release 获取 `half-sample-<版本>-windows-x86_64.zip` 及其 `.sha256` 文件,校验后将 `sample.exe` 放入应用安装目录。Rust 客户端支持显式指定此绝对路径。
|
|
12
|
+
|
|
13
|
+
## AppVeyor 发布
|
|
14
|
+
|
|
15
|
+
普通提交构建原生程序、Python wheel、sdist、Rust crate 和独立运行时附件,在打好的包上执行模拟采集。版本标签采用 `v<版本>`,例如 `v0.1.28`,并与 `setup.py`、`rust/Cargo.toml` 中的版本一致。标签任务通过测试后分别向 GitHub Releases、PyPI 和 crates.io 发布,并从 crates.io 安装精确版本进行回读验证。
|
|
16
|
+
|
|
17
|
+
维护者在 AppVeyor 项目的加密环境变量中配置 PyPI 的 `PYPIPASSWORD`、用于本仓库发布附件的 `GITHUB_TOKEN` 和允许发布 `half-sample` 的 `CARGO_REGISTRY_TOKEN`。如果一个渠道已成功、另一个失败,可重试同一版本;流水线比对已发布文件的 SHA-256,发现内容冲突时报告文件名并停止。
|
|
18
|
+
|
|
19
|
+
从 Windows x64 源码检出构建运行时和分发包时,在仓库根目录执行:
|
|
20
|
+
|
|
21
|
+
```powershell
|
|
22
|
+
scons -Q -j4 RELEASE=1 sample.exe
|
|
23
|
+
python scripts/prepare_runtime.py
|
|
24
|
+
python setup.py sdist bdist_wheel
|
|
25
|
+
cargo package --locked --allow-dirty --manifest-path rust/Cargo.toml
|
|
26
|
+
Copy-Item rust/target/package/*.crate artifacts/
|
|
27
|
+
python -m scripts.check_packages inspect
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
从源码开发 Rust 客户端前先执行前两步,使本地 `rust/runtime/windows-x86_64/sample.exe` 与 Python 包使用同一份构建产物。
|
|
6
31
|
|
|
7
32
|
## 构建环境
|
|
8
33
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: half_sample
|
|
3
|
+
Version: 0.1.29
|
|
4
|
+
Summary: sample data and analysis
|
|
5
|
+
Home-page: https://github.com/KD-Group/Half.Sample
|
|
6
|
+
Author: kunde
|
|
7
|
+
Author-email: gzkunde@163.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Dynamic: author
|
|
13
|
+
Dynamic: author-email
|
|
14
|
+
Dynamic: classifier
|
|
15
|
+
Dynamic: home-page
|
|
16
|
+
Dynamic: requires-python
|
|
17
|
+
Dynamic: summary
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MANIFEST.in
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
half_sample.egg-info/PKG-INFO
|
|
6
|
+
half_sample.egg-info/SOURCES.txt
|
|
7
|
+
half_sample.egg-info/dependency_links.txt
|
|
8
|
+
half_sample.egg-info/not-zip-safe
|
|
9
|
+
half_sample.egg-info/top_level.txt
|
|
10
|
+
sample/__init__.py
|
|
11
|
+
sample/process.py
|
|
12
|
+
sample/protocol.py
|
|
13
|
+
sample/result.py
|
|
14
|
+
sample/sample.exe
|
|
15
|
+
sample/sample.py
|
|
16
|
+
tests/test_0819_cycle_regression.py
|
|
17
|
+
tests/test_commander.py
|
|
18
|
+
tests/test_estimate.py
|
|
19
|
+
tests/test_measure.py
|
|
20
|
+
tests/test_protocol.py
|
|
21
|
+
tests/test_release_pipeline.py
|
|
22
|
+
tests/test_release_runtime.py
|
|
23
|
+
tests/test_sampler.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
Binary file
|
|
@@ -57,6 +57,11 @@ class Sampler:
|
|
|
57
57
|
if execution_path:
|
|
58
58
|
return execution_path
|
|
59
59
|
|
|
60
|
+
# Installed releases keep the matching runtime inside the Python package.
|
|
61
|
+
execution_path = _existing_file(_SOURCE_ROOT, 'sample', 'sample.exe')
|
|
62
|
+
if execution_path:
|
|
63
|
+
return execution_path
|
|
64
|
+
|
|
60
65
|
# try the Python/frozen executable directory
|
|
61
66
|
try:
|
|
62
67
|
executable_directory = Path(sys.executable).parent
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import gzip
|
|
2
|
+
import os
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import tarfile
|
|
5
|
+
|
|
6
|
+
from setuptools import Distribution, setup
|
|
7
|
+
from setuptools.command.build_py import build_py
|
|
8
|
+
from setuptools.command.sdist import sdist
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
from setuptools.command.bdist_wheel import bdist_wheel
|
|
12
|
+
except ImportError: # setuptools versions supporting Python 3.6
|
|
13
|
+
from wheel.bdist_wheel import bdist_wheel
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def require_runtime():
|
|
17
|
+
if not Path('sample/sample.exe').is_file():
|
|
18
|
+
raise SystemExit('Missing sample/sample.exe. Run scripts/prepare_runtime.py after the release build.')
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class BuildPython(build_py):
|
|
22
|
+
def run(self):
|
|
23
|
+
require_runtime()
|
|
24
|
+
# Legacy wheel reuses build/lib; timestamps there may belong to an earlier release.
|
|
25
|
+
self.force = True
|
|
26
|
+
super().run()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class SourceDistribution(sdist):
|
|
30
|
+
def run(self):
|
|
31
|
+
require_runtime()
|
|
32
|
+
super().run()
|
|
33
|
+
|
|
34
|
+
def make_archive(self, base_name, format, root_dir=None, base_dir=None, **kwargs):
|
|
35
|
+
# Retried builds of the same tag must match already published artifacts.
|
|
36
|
+
if format != 'gztar' or 'SOURCE_DATE_EPOCH' not in os.environ:
|
|
37
|
+
return super().make_archive(base_name, format, root_dir, base_dir, **kwargs)
|
|
38
|
+
timestamp = int(os.environ['SOURCE_DATE_EPOCH'])
|
|
39
|
+
output = Path(base_name + '.tar.gz')
|
|
40
|
+
output.parent.mkdir(parents=True, exist_ok=True)
|
|
41
|
+
|
|
42
|
+
def set_metadata(info):
|
|
43
|
+
info.mtime = timestamp
|
|
44
|
+
info.uid = info.gid = 0
|
|
45
|
+
info.uname = info.gname = ''
|
|
46
|
+
return info
|
|
47
|
+
|
|
48
|
+
with output.open('wb') as stream:
|
|
49
|
+
with gzip.GzipFile(filename='', mode='wb', fileobj=stream, mtime=timestamp) as compressed:
|
|
50
|
+
with tarfile.open(fileobj=compressed, mode='w', format=tarfile.GNU_FORMAT) as archive:
|
|
51
|
+
archive.add(str(Path(root_dir or '.') / base_dir), arcname=base_dir, filter=set_metadata)
|
|
52
|
+
return str(output)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class WindowsDistribution(Distribution):
|
|
56
|
+
def has_ext_modules(self):
|
|
57
|
+
# Place the installed package in platlib along with its x64 subprocess.
|
|
58
|
+
return True
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class WindowsWheel(bdist_wheel):
|
|
62
|
+
def get_tag(self):
|
|
63
|
+
# The subprocess has no Python ABI dependency.
|
|
64
|
+
return 'py3', 'none', 'win_amd64'
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
setup(
|
|
68
|
+
name='half_sample',
|
|
69
|
+
version='0.1.29',
|
|
70
|
+
author='kunde',
|
|
71
|
+
author_email='gzkunde@163.com',
|
|
72
|
+
description='sample data and analysis',
|
|
73
|
+
url='https://github.com/KD-Group/Half.Sample',
|
|
74
|
+
packages=['sample'],
|
|
75
|
+
classifiers=[
|
|
76
|
+
'Programming Language :: Python :: 3',
|
|
77
|
+
'License :: OSI Approved :: MIT License',
|
|
78
|
+
'Operating System :: Microsoft :: Windows',
|
|
79
|
+
],
|
|
80
|
+
python_requires='>=3.6',
|
|
81
|
+
package_data={'sample': ['sample.exe']},
|
|
82
|
+
distclass=WindowsDistribution,
|
|
83
|
+
cmdclass={'build_py': BuildPython, 'sdist': SourceDistribution, 'bdist_wheel': WindowsWheel},
|
|
84
|
+
zip_safe=False,
|
|
85
|
+
)
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import os
|
|
3
|
+
import subprocess
|
|
4
|
+
import time
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from sample.protocol import parse_assignments
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
SOURCE_ROOT = Path(__file__).resolve().parents[1]
|
|
13
|
+
SAMPLE_EXE = SOURCE_ROOT / "cpp_build" / "sample.exe"
|
|
14
|
+
DEFAULT_REGRESSION_DIR = Path(r"D:\kunde\code\KDM3000\Sample采集数据-20280819")
|
|
15
|
+
REGRESSION_CASES = (
|
|
16
|
+
(1, 1, 65),
|
|
17
|
+
(2, 16, 65),
|
|
18
|
+
(3, 32, 65),
|
|
19
|
+
(4, 1, 62),
|
|
20
|
+
(5, 16, 62),
|
|
21
|
+
(6, 32, 62),
|
|
22
|
+
(7, 32, 72),
|
|
23
|
+
(8, 16, 72),
|
|
24
|
+
(9, 1, 72),
|
|
25
|
+
(10, 32, 72),
|
|
26
|
+
(11, 32, 60),
|
|
27
|
+
(12, 16, 60),
|
|
28
|
+
(13, 1, 60),
|
|
29
|
+
)
|
|
30
|
+
FINITE_SCALARS = (
|
|
31
|
+
"maximum",
|
|
32
|
+
"minimum",
|
|
33
|
+
"sampling_interval",
|
|
34
|
+
"wave_interval",
|
|
35
|
+
"tau",
|
|
36
|
+
"w",
|
|
37
|
+
"b",
|
|
38
|
+
"loss",
|
|
39
|
+
"v_inf",
|
|
40
|
+
"cycle_maximum",
|
|
41
|
+
"cycle_minimum",
|
|
42
|
+
"cycle_vmax",
|
|
43
|
+
"cycle_vmin",
|
|
44
|
+
"cycle_vpp",
|
|
45
|
+
"cycle_vtop",
|
|
46
|
+
"cycle_vbase",
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _build_sample_executable(executable=SAMPLE_EXE):
|
|
51
|
+
command = ["scons", "-Q", "sample.exe"]
|
|
52
|
+
try:
|
|
53
|
+
completed = subprocess.run(
|
|
54
|
+
command,
|
|
55
|
+
cwd=str(SOURCE_ROOT),
|
|
56
|
+
check=True,
|
|
57
|
+
stdout=subprocess.PIPE,
|
|
58
|
+
stderr=subprocess.PIPE,
|
|
59
|
+
universal_newlines=True,
|
|
60
|
+
errors="replace",
|
|
61
|
+
)
|
|
62
|
+
except subprocess.CalledProcessError as error:
|
|
63
|
+
raise RuntimeError(
|
|
64
|
+
"sample.exe build failed with exit {}\nstdout:\n{}\nstderr:\n{}".format(
|
|
65
|
+
error.returncode, error.output or "", error.stderr or ""
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
if not executable.is_file():
|
|
69
|
+
raise RuntimeError(
|
|
70
|
+
"sample.exe build succeeded without creating {}\nstdout:\n{}\nstderr:\n{}".format(
|
|
71
|
+
executable, completed.stdout, completed.stderr
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
return executable
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_build_sample_executable_runs_scons_with_python36_compatible_io(monkeypatch, tmp_path):
|
|
78
|
+
built_executable = tmp_path / "sample.exe"
|
|
79
|
+
built_executable.touch()
|
|
80
|
+
observed = {}
|
|
81
|
+
|
|
82
|
+
def run(command, **kwargs):
|
|
83
|
+
observed["command"] = command
|
|
84
|
+
observed["kwargs"] = kwargs
|
|
85
|
+
return subprocess.CompletedProcess(command, 0, stdout="build stdout", stderr="")
|
|
86
|
+
|
|
87
|
+
monkeypatch.setattr(subprocess, "run", run)
|
|
88
|
+
|
|
89
|
+
assert _build_sample_executable(built_executable) == built_executable
|
|
90
|
+
assert observed["command"] == ["scons", "-Q", "sample.exe"]
|
|
91
|
+
assert observed["kwargs"] == {
|
|
92
|
+
"cwd": str(SOURCE_ROOT),
|
|
93
|
+
"check": True,
|
|
94
|
+
"stdout": subprocess.PIPE,
|
|
95
|
+
"stderr": subprocess.PIPE,
|
|
96
|
+
"universal_newlines": True,
|
|
97
|
+
"errors": "replace",
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def test_build_sample_executable_reports_scons_output(monkeypatch, tmp_path):
|
|
102
|
+
def run(command, **kwargs):
|
|
103
|
+
del kwargs
|
|
104
|
+
raise subprocess.CalledProcessError(
|
|
105
|
+
2, command, output="build stdout", stderr="build stderr"
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
monkeypatch.setattr(subprocess, "run", run)
|
|
109
|
+
|
|
110
|
+
with pytest.raises(RuntimeError) as raised:
|
|
111
|
+
_build_sample_executable(tmp_path / "sample.exe")
|
|
112
|
+
|
|
113
|
+
assert "build stdout" in str(raised.value)
|
|
114
|
+
assert "build stderr" in str(raised.value)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@pytest.fixture(scope="module")
|
|
118
|
+
def regression_dir():
|
|
119
|
+
configured = os.environ.get("HALF_SAMPLE_0819_REGRESSION_DIR")
|
|
120
|
+
directory = Path(configured) if configured else DEFAULT_REGRESSION_DIR
|
|
121
|
+
if not directory.is_dir():
|
|
122
|
+
pytest.skip("0819 regression data directory not found: {}".format(directory))
|
|
123
|
+
return directory
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
@pytest.fixture(scope="module")
|
|
127
|
+
def sample_executable(regression_dir):
|
|
128
|
+
del regression_dir
|
|
129
|
+
return _build_sample_executable()
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _split_protocol_responses(stdout):
|
|
133
|
+
responses = []
|
|
134
|
+
current = []
|
|
135
|
+
for line in stdout.splitlines():
|
|
136
|
+
if line.strip() == "EOF":
|
|
137
|
+
responses.append("\n".join(current))
|
|
138
|
+
current = []
|
|
139
|
+
else:
|
|
140
|
+
current.append(line)
|
|
141
|
+
assert not current, "sample.exe output did not end with EOF: {!r}".format(current)
|
|
142
|
+
assert len(responses) == 3, "expected three protocol responses, got {}: {!r}".format(
|
|
143
|
+
len(responses), stdout
|
|
144
|
+
)
|
|
145
|
+
return responses
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _run_protocol_case(executable, directory, case_number, waveforms):
|
|
149
|
+
filename = "0819-{}.txt".format(case_number)
|
|
150
|
+
assert (directory / filename).is_file(), "missing regression input: {}".format(directory / filename)
|
|
151
|
+
commands = "\n".join((
|
|
152
|
+
"to_config {} 50 False 0 100 10 independent_cycle".format(waveforms),
|
|
153
|
+
"to_process {} independent_cycle".format(filename),
|
|
154
|
+
"to_query",
|
|
155
|
+
"",
|
|
156
|
+
))
|
|
157
|
+
started = time.perf_counter()
|
|
158
|
+
completed = subprocess.run(
|
|
159
|
+
[str(executable)],
|
|
160
|
+
input=commands,
|
|
161
|
+
cwd=str(directory),
|
|
162
|
+
stdout=subprocess.PIPE,
|
|
163
|
+
stderr=subprocess.PIPE,
|
|
164
|
+
universal_newlines=True,
|
|
165
|
+
timeout=180,
|
|
166
|
+
check=False,
|
|
167
|
+
)
|
|
168
|
+
elapsed = time.perf_counter() - started
|
|
169
|
+
assert completed.returncode == 0, (
|
|
170
|
+
"sample.exe exited {} for case {}\nstdout:\n{}\nstderr:\n{}".format(
|
|
171
|
+
completed.returncode, case_number, completed.stdout, completed.stderr
|
|
172
|
+
)
|
|
173
|
+
)
|
|
174
|
+
responses = _split_protocol_responses(completed.stdout)
|
|
175
|
+
parsed = [parse_assignments(response) if response.strip() else {} for response in responses]
|
|
176
|
+
for command, response in zip(("to_config", "to_process", "to_query"), parsed):
|
|
177
|
+
assert response.get("error") is not True, "{} failed for case {}: {}".format(
|
|
178
|
+
command, case_number, response
|
|
179
|
+
)
|
|
180
|
+
return parsed[-1], elapsed
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
@pytest.mark.parametrize(
|
|
184
|
+
"case_number,waveforms,nominal_mv",
|
|
185
|
+
REGRESSION_CASES,
|
|
186
|
+
ids=["0819-{}-n{}-{}mv".format(*case) for case in REGRESSION_CASES],
|
|
187
|
+
)
|
|
188
|
+
def test_0819_independent_cycle_regression(
|
|
189
|
+
regression_dir, sample_executable, case_number, waveforms, nominal_mv):
|
|
190
|
+
result, elapsed = _run_protocol_case(sample_executable, regression_dir, case_number, waveforms)
|
|
191
|
+
|
|
192
|
+
assert result["success"] is True
|
|
193
|
+
assert result["waveform_processing_mode"] == "independent_cycle"
|
|
194
|
+
assert result["complete_waveforms"] == waveforms
|
|
195
|
+
assert result["v_inf_valid"] is True
|
|
196
|
+
for field in FINITE_SCALARS:
|
|
197
|
+
assert math.isfinite(result[field]), "{} is not finite: {!r}".format(field, result[field])
|
|
198
|
+
assert result["cycle_vpp"] == pytest.approx(
|
|
199
|
+
result["cycle_vmax"] - result["cycle_vmin"], abs=2e-6
|
|
200
|
+
)
|
|
201
|
+
assert result["v_inf"] == pytest.approx(
|
|
202
|
+
result["cycle_vtop"] - result["cycle_vbase"], abs=2e-6
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
nominal_voltage = nominal_mv / 1000.0
|
|
206
|
+
assert abs(result["v_inf"] - nominal_voltage) <= max(0.015, nominal_voltage * 0.25)
|
|
207
|
+
assert 50.0 <= result["tau"] <= 500.0
|
|
208
|
+
assert result["loss"] >= 0.0
|
|
209
|
+
assert math.sqrt(result["loss"]) / result["v_inf"] < 0.15
|
|
210
|
+
assert len(result["wave"]) >= 3
|
|
211
|
+
assert all(math.isfinite(value) for value in result["wave"])
|
|
212
|
+
|
|
213
|
+
print(
|
|
214
|
+
"0819-{} PASS n={} v_inf={:.6f} tau={:.6f} normalized_rmse={:.6f} elapsed={:.3f}s".format(
|
|
215
|
+
case_number,
|
|
216
|
+
waveforms,
|
|
217
|
+
result["v_inf"],
|
|
218
|
+
result["tau"],
|
|
219
|
+
math.sqrt(result["loss"]) / result["v_inf"],
|
|
220
|
+
elapsed,
|
|
221
|
+
)
|
|
222
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from sample import protocol, sampler
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class MyTestCase(unittest.TestCase):
|
|
6
|
+
def test_protocol_parser_accepts_cpp_escape_contract(self):
|
|
7
|
+
response = 'message = "plain \\"quote\\" \\\\ slash\\rline\\nnext\\ttab"\n'
|
|
8
|
+
expected = 'plain "quote" \\ slash\rline\nnext\ttab'
|
|
9
|
+
self.assertEqual(protocol.parse_assignments(response), {'message': expected})
|
|
10
|
+
|
|
11
|
+
def test_commander_frame(self):
|
|
12
|
+
result = sampler.communicate("simple_test")
|
|
13
|
+
self.assertTrue(result.success)
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
result = sampler.communicate("unknown_command")
|
|
17
|
+
except sampler.Error as e:
|
|
18
|
+
self.assertTrue(str(e).startswith("command_not_found"))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
if __name__ == '__main__':
|
|
22
|
+
unittest.main()
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import time
|
|
2
|
+
import unittest
|
|
3
|
+
from sample import sampler
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MyTestCase(unittest.TestCase):
|
|
7
|
+
def test_estimate(self):
|
|
8
|
+
sampler.set_sampler(sampler_name="mock_sampler")
|
|
9
|
+
|
|
10
|
+
for mock_tau in [50, 100, 200]: # us
|
|
11
|
+
sampler.set_sampler_value("mock_tau", mock_tau)
|
|
12
|
+
|
|
13
|
+
sampler.measure(number_of_waveforms=2, emitting_frequency=200)
|
|
14
|
+
|
|
15
|
+
while sampler.is_measuring:
|
|
16
|
+
time.sleep(0.1)
|
|
17
|
+
|
|
18
|
+
result = sampler.query()
|
|
19
|
+
self.assertEqual(result.success, True)
|
|
20
|
+
|
|
21
|
+
tau = result.tau
|
|
22
|
+
print(tau)
|
|
23
|
+
# self.assertTrue(abs(tau - mock_tau) < 2.0)
|
|
24
|
+
|
|
25
|
+
def test_auto_mode(self):
|
|
26
|
+
sampler.set_sampler(sampler_name="mock_sampler")
|
|
27
|
+
|
|
28
|
+
mock_taus = [1, 10, 100, 1000, 10000] # us
|
|
29
|
+
for mock_tau in mock_taus:
|
|
30
|
+
sampler.set_sampler_value("mock_tau", mock_tau)
|
|
31
|
+
sampler.measure(number_of_waveforms=4, emitting_frequency=10, auto_mode=True)
|
|
32
|
+
while sampler.is_measuring:
|
|
33
|
+
time.sleep(0.1)
|
|
34
|
+
result = sampler.query()
|
|
35
|
+
diff_ratio = abs(result.tau - mock_tau) / mock_tau
|
|
36
|
+
|
|
37
|
+
self.assertTrue(diff_ratio <= 0.1 or diff_ratio < 0.5)
|
|
38
|
+
|
|
39
|
+
def test_low_frequency(self):
|
|
40
|
+
sampler.set_sampler(sampler_name="mock_sampler")
|
|
41
|
+
|
|
42
|
+
mock_taus = [20000, 40000, 80000, 100000] # us
|
|
43
|
+
for mock_tau in mock_taus:
|
|
44
|
+
sampler.set_sampler_value("mock_tau", mock_tau)
|
|
45
|
+
|
|
46
|
+
sampler.measure(number_of_waveforms=4, emitting_frequency=10, auto_mode=True)
|
|
47
|
+
while sampler.is_measuring:
|
|
48
|
+
time.sleep(0.1)
|
|
49
|
+
result = sampler.query()
|
|
50
|
+
self.assertTrue(result.tau >= 10000)
|
|
51
|
+
|
|
52
|
+
sampler.measure(number_of_waveforms=4, emitting_frequency=0.5, auto_mode=True)
|
|
53
|
+
while sampler.is_measuring:
|
|
54
|
+
time.sleep(0.1)
|
|
55
|
+
result = sampler.query()
|
|
56
|
+
diff_ratio = abs(result.tau - mock_tau) / mock_tau
|
|
57
|
+
self.assertTrue(diff_ratio <= 0.01) # less than 1%
|
|
58
|
+
|
|
59
|
+
def test_low_voltage_margin(self):
|
|
60
|
+
sampler.set_sampler(sampler_name="mock_sampler")
|
|
61
|
+
sampler.set_sampler_value("mock_noise", 0)
|
|
62
|
+
|
|
63
|
+
for mock_v0, mock_v_inf in [[1, 2], [2, 3]]:
|
|
64
|
+
sampler.set_sampler_value("mock_v0", mock_v0)
|
|
65
|
+
sampler.set_sampler_value("mock_v_inf", mock_v_inf)
|
|
66
|
+
|
|
67
|
+
mock_taus = [1, 10, 100, 1000, 10000] # us
|
|
68
|
+
for mock_tau in mock_taus:
|
|
69
|
+
sampler.set_sampler_value("mock_tau", mock_tau)
|
|
70
|
+
|
|
71
|
+
sampler.measure(number_of_waveforms=4, emitting_frequency=10, auto_mode=True)
|
|
72
|
+
while sampler.is_measuring:
|
|
73
|
+
time.sleep(0.1)
|
|
74
|
+
result = sampler.query()
|
|
75
|
+
|
|
76
|
+
diff = abs(mock_tau - result.tau)
|
|
77
|
+
diff_ratio = diff / mock_tau
|
|
78
|
+
self.assertTrue(diff_ratio <= 0.2 or diff < 0.5)
|
|
79
|
+
self.assertTrue(abs(mock_v0 - result.v0) <= 0.5)
|
|
80
|
+
self.assertTrue(abs(mock_v_inf - result.v_inf) <= 0.5)
|
|
81
|
+
|
|
82
|
+
def test_wave_is_going_down(self):
|
|
83
|
+
sampler.set_sampler(sampler_name="mock_sampler")
|
|
84
|
+
mock_noise = 0.5
|
|
85
|
+
sampler.set_sampler_value('mock_noise', mock_noise)
|
|
86
|
+
|
|
87
|
+
mock_tau = 100000
|
|
88
|
+
sampler.set_sampler_value('mock_tau', mock_tau)
|
|
89
|
+
|
|
90
|
+
sampler.set_sampler_value('mock_is_going_down', 1.0)
|
|
91
|
+
|
|
92
|
+
mock_v0, mock_v_inf = 1.0, 2.0
|
|
93
|
+
sampler.set_sampler_value('mock_v0', mock_v0)
|
|
94
|
+
sampler.set_sampler_value('mock_v_inf', mock_v_inf)
|
|
95
|
+
|
|
96
|
+
sampler.measure(number_of_waveforms=4, emitting_frequency=0.5, auto_mode=False)
|
|
97
|
+
while sampler.is_measuring:
|
|
98
|
+
time.sleep(0.1)
|
|
99
|
+
result = sampler.query()
|
|
100
|
+
self.assertTrue(result.wave_interval >= 1000) # us
|
|
101
|
+
|
|
102
|
+
sampler.measure(number_of_waveforms=4, emitting_frequency=0.5, auto_mode=True)
|
|
103
|
+
while sampler.is_measuring:
|
|
104
|
+
time.sleep(0.1)
|
|
105
|
+
result = sampler.query()
|
|
106
|
+
print(result.wave_interval)
|
|
107
|
+
self.assertTrue(500 <= result.wave_interval < 600) # us
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if __name__ == '__main__':
|
|
111
|
+
unittest.main()
|