forked from machinekit/machinekit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/pll_correction: fix integer overflow error; desensitize
A MK [Jenkins build for an unrelated PR][1] failed in this test, meaning that this test's parameters are too restrictive, even for non-RT POSIX threads. This commit: - Fixes an integer overflow that caused it to fail on systems with very high jitter - Desensitizes the test by only requiring most of the final samples to be within 1% of the total phase offset Other changes: - Add README.md - Parameterize PERIOD & NUMSAMPS [1]: https://jenkins.machinekit.io/job/machinekit-PR-builder/68/console
- Loading branch information
Showing
6 changed files
with
84 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
This tests @sittner's [add-task-pll-functions.patch][1] as ported to | ||
Machinekit in [PR #1373][2]. | ||
|
||
The test .hal file starts the custom `pll_correction` component, and a | ||
`halsampler` takes `numsamps*4` samples (`numsamps` configured in | ||
`params.py.sh`). | ||
|
||
The `pll_correction.comp` HAL component sets the phase to ten times | ||
the period. The first `numsamps*3` samples should be enough time to | ||
lock the phase, and the final `numsamps` samples are counted to see | ||
how many are within 1% of the expected phase difference. | ||
|
||
Finally, the python `checkresult` script parses the `halsampler` | ||
output, checking the final sample. Most of the samples' PLL phase | ||
error must be within 1% of the total phase shift, or the test is | ||
deemed to have failed. (This is set very loosely in order to succeed | ||
even on systems with pathological jitter.) | ||
|
||
[1]: https://github.com/sittner/linuxcnc-ethercat/blob/c84a868b/patches/add-task-pll-functions.patch | ||
[2]: https://github.com/machinekit/machinekit/pull/1373 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,32 @@ | ||
#!/usr/bin/python | ||
|
||
import sys | ||
import os | ||
import sys, os | ||
|
||
# Params from test.hal | ||
period = 1000000 | ||
# Source params.py.sh | ||
execfile(os.path.join(os.path.dirname(__file__), "params.py.sh")) | ||
# Params from pll_correction.hal | ||
period = int(PERIOD) | ||
# Params from pll_correction.comp | ||
numsamps = 1000 | ||
numsamps = int(NUMSAMPS) | ||
# Number of periods in the future to lock onto | ||
pll_periods = int(PLL_PERIODS) | ||
|
||
os.chdir(os.path.dirname(os.path.realpath(__file__))) | ||
|
||
# Read last line of file | ||
with open("result", 'r') as f: | ||
with open("stderr", 'a') as log: | ||
for line in f: | ||
line = line.rstrip('[ \n]') | ||
(cycle_count, period_actual, pll_err, samp_avg, phase_diff) = ( | ||
[int(s) for s in line.split(' ')]) | ||
for line in f: | ||
line = line.rstrip('[ \n]') | ||
|
||
(cycle_count, period_actual, pll_err, samp_avg, phase_diff, mode) = ( | ||
[int(s) for s in line.split(' ')]) | ||
|
||
if cycle_count == 2*numsamps: | ||
log.write("%s\n" % line) | ||
if abs(samp_avg) > period/100: | ||
log.write("0 PLL didn't converge: abs(%d) > %d/100\n" % ( | ||
samp_avg, period)) | ||
sys.exit(-1) | ||
else: | ||
log.write("0 PLL converged: abs(%d) <= %d/100\n" % ( | ||
samp_avg, period)) | ||
if cycle_count == 4*numsamps: | ||
log.write("%s\n" % line) | ||
if abs(samp_avg) > period/100: | ||
log.write("10 PLL didn't converge: abs(%d) > %d/100\n" % ( | ||
samp_avg, period)) | ||
sys.exit(-1) | ||
else: | ||
log.write("10 PLL converged: abs(%d) <= %d/100\n" % ( | ||
samp_avg, period)) | ||
target = period * pll_periods | ||
if mode < 500: | ||
sys.stderr.write( | ||
"PLL didn't converge: samples w/ <1%% error = %d/%d\n" % | ||
(mode,numsamps)) | ||
with open("result", "r") as f: # Dump results to stderr | ||
for line in f: | ||
sys.stderr.write(line) | ||
sys.exit(-1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file is sourced both by test.sh and checkresult (python)!!! | ||
|
||
# Period | ||
PERIOD=1000000 | ||
|
||
# Number of samples; max 1000 (or adjust `samps` in `pll_correction.comp`) | ||
NUMSAMPS=1000 | ||
|
||
# Number of periods in the future to lock onto | ||
PLL_PERIODS=10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters