Skip to content

Commit

Permalink
unit tests mtie,tdev for ts2phc
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunyez committed Sep 28, 2023
1 parent a2cbcb2 commit 504f181
Show file tree
Hide file tree
Showing 5 changed files with 621 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/vse_sync_pp/analyzers/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def __init__(self, config):
# samples in the initial transient period are ignored
self._transient = config.parameter('transient-period/s')
# minimum test duration for a valid test
self._duration = config.parameter('min-test-duration/s')
self._duration_min = config.parameter('min-test-duration/s')
# limit initial tau observation windows from 1 to 10k taus
taus_below_10k = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90,
100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 2000, 3000,
Expand Down Expand Up @@ -365,19 +365,20 @@ def prepare(self, rows):
def calculate_rate(data):
# calculate sample rate using 100 samples
cumdelta = 0
for i in range(1, 100):

for i in range(1, 100 if len(data) > 100 else len(data)):
cumdelta = cumdelta + data.iloc[i].timestamp - data.iloc[i - 1].timestamp
return round((1 / (cumdelta / 100)))

def _test_common(self, data):
if len(data) == 0:
return (False, "no data")
return ("error", "no data")
if frozenset(data.state.unique()).difference(self.locked):
return (False, "loss of lock")
if len(data) - 1 < self._duration:
return (False, "short test samples")
if data.iloc[-1].timestamp - data.iloc[0].timestamp < self._duration:
if data.iloc[-1].timestamp - data.iloc[0].timestamp < self._duration_min:
return (False, "short test duration")
if len(data) - 1 < self._duration_min:
return (False, "short test samples")
if self._rate is None:
self._rate = self.calculate_rate(data)
if self._lpf_signal is None:
Expand Down
92 changes: 91 additions & 1 deletion tests/vse_sync_pp/analyzers/test_gnss.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import math

from vse_sync_pp.analyzers.gnss import (
TimeErrorAnalyzer
TimeErrorAnalyzer,
TimeDeviationAnalyzer,
MaxTimeIntervalErrorAnalyzer
)

from .test_analyzer import AnalyzerTestBuilder
Expand Down Expand Up @@ -215,3 +217,91 @@ class TestTimeErrorAnalyzer(TestCase, metaclass=AnalyzerTestBuilder):
},
},
)


class TestMaxTimeIntervalErrorAnalyzer(TestCase, metaclass=AnalyzerTestBuilder):
"""Test cases for vse_sync_pp.analyzers.gnss.MaxTimeIntervalErrorAnalyzer"""
constructor = MaxTimeIntervalErrorAnalyzer
id_ = 'gnss/mtie'
parser = 'gnss/time-error'
expect = (
{
'requirements': 'G.8272/PRTC-A',
'parameters': {
'maximum-time-interval-error-limit/%': 100,
'transient-period/s': 1,
'min-test-duration/s': 1,
},
'rows': (),
'result': "error",
'reason': "no data",
'timestamp': None,
'duration': None,
'analysis': {},
},
{
'requirements': 'G.8272/PRTC-A',
'parameters': {
'maximum-time-interval-error-limit/%': 100,
'transient-period/s': 6,
'min-test-duration/s': 1,
},
'rows': (
TERR(Decimal(0), 0, 5),
TERR(Decimal(1), 0, 5),
TERR(Decimal(2), 0, 5),
TERR(Decimal(3), 0, 5),
TERR(Decimal(4), 0, 5),
TERR(Decimal(5), 0, 5),
),
'result': "error",
'reason': "no data",
'timestamp': None,
'duration': None,
'analysis': {},
}
)


class TestTimeDeviationAnalyzer(TestCase, metaclass=AnalyzerTestBuilder):
"""Test cases for vse_sync_pp.analyzers.gnss.TimeDeviationAnalyzer"""
constructor = TimeDeviationAnalyzer
id_ = 'gnss/time-deviation'
parser = 'gnss/time-error'
expect = (
{
'requirements': 'G.8272/PRTC-A',
'parameters': {
'time-deviation-limit/%': 100,
'transient-period/s': 1,
'min-test-duration/s': 1,
},
'rows': (),
'result': "error",
'reason': "no data",
'timestamp': None,
'duration': None,
'analysis': {},
},
{
'requirements': 'G.8272/PRTC-A',
'parameters': {
'time-deviation-limit/%': 100,
'transient-period/s': 6,
'min-test-duration/s': 1,
},
'rows': (
TERR(Decimal(0), 0, 5),
TERR(Decimal(1), 0, 5),
TERR(Decimal(2), 0, 5),
TERR(Decimal(3), 0, 5),
TERR(Decimal(4), 0, 5),
TERR(Decimal(5), 0, 5),
),
'result': "error",
'reason': "no data",
'timestamp': None,
'duration': None,
'analysis': {},
}
)
4 changes: 3 additions & 1 deletion tests/vse_sync_pp/analyzers/test_phc2sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from decimal import Decimal
import math

from vse_sync_pp.analyzers.phc2sys import TimeErrorAnalyzer
from vse_sync_pp.analyzers.phc2sys import (
TimeErrorAnalyzer
)

from .test_analyzer import AnalyzerTestBuilder

Expand Down
86 changes: 85 additions & 1 deletion tests/vse_sync_pp/analyzers/test_ppsdpll.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from decimal import Decimal

from vse_sync_pp.analyzers.ppsdpll import (
TimeErrorAnalyzer
TimeErrorAnalyzer,
TimeDeviationAnalyzer,
MaxTimeIntervalErrorAnalyzer
)

from .test_analyzer import AnalyzerTestBuilder
Expand Down Expand Up @@ -232,3 +234,85 @@ class TestTimeErrorAnalyzer(TestCase, metaclass=AnalyzerTestBuilder):
},
},
)


class TestMaxTimeIntervalErrorAnalyzer(TestCase, metaclass=AnalyzerTestBuilder):
"""Test cases for vse_sync_pp.analyzers.ppsdpll.MaxTimeIntervalErrorAnalyzer"""
constructor = MaxTimeIntervalErrorAnalyzer
id_ = 'ppsdpll/mtie'
parser = 'dpll/time-error'
expect = (
{
'requirements': 'G.8272/PRTC-B',
'parameters': {
'maximum-time-interval-error-limit/%': 100,
'transient-period/s': 1,
'min-test-duration/s': 3,
},
'rows': (),
'result': "error",
'reason': "no data",
'timestamp': None,
'duration': None,
'analysis': {},
},
{
'requirements': 'G.8272/PRTC-B',
'parameters': {
'maximum-time-interval-error-limit/%': 100,
'transient-period/s': 3,
'min-test-duration/s': 1,
},
'rows': (
DPLLS(Decimal('1876878.28'), 3, 3, Decimal(1)),
DPLLS(Decimal('1876879.28'), 3, 3, Decimal(1)),
DPLLS(Decimal('1876880.28'), 3, 3, Decimal(1)),
),
'result': "error",
'reason': "no data",
'timestamp': None,
'duration': None,
'analysis': {},
}
)


class TestTimeDeviationAnalyzer(TestCase, metaclass=AnalyzerTestBuilder):
"""Test cases for vse_sync_pp.analyzers.ppsdpll.TimeDeviationAnalyzer"""
constructor = TimeDeviationAnalyzer
id_ = 'ppsdpll/time-deviation'
parser = 'dpll/time-error'
expect = (
{
'requirements': 'G.8272/PRTC-B',
'parameters': {
'time-deviation-limit/%': 100,
'transient-period/s': 1,
'min-test-duration/s': 3,
},
'rows': (),
'result': "error",
'reason': "no data",
'timestamp': None,
'duration': None,
'analysis': {},
},
{
'requirements': 'G.8272/PRTC-B',
'parameters': {
'time-deviation-limit/%': 100,
'transient-period/s': 3,
'min-test-duration/s': 1,
},
'rows': (
DPLLS(Decimal('1876878.28'), 3, 3, Decimal(1)),
DPLLS(Decimal('1876879.28'), 3, 3, Decimal(1)),
DPLLS(Decimal('1876880.28'), 3, 3, Decimal(1)),
),
'result': "error",
'reason': "no data",
'timestamp': None,
'duration': None,
'analysis': {},
}
)
Loading

0 comments on commit 504f181

Please sign in to comment.