aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorJ08nY2020-03-07 21:42:03 +0100
committerJ08nY2020-03-07 21:42:03 +0100
commit38d04f0d19059b2d8c6ad8fc46a9eec67946fffe (patch)
treed1c59ce418cd244f548dc07729e0a8157ffef850 /test
parent8b8389ce6177cff95865280c9476569dd1abb7c7 (diff)
downloadpyecsca-38d04f0d19059b2d8c6ad8fc46a9eec67946fffe.tar.gz
pyecsca-38d04f0d19059b2d8c6ad8fc46a9eec67946fffe.tar.zst
pyecsca-38d04f0d19059b2d8c6ad8fc46a9eec67946fffe.zip
Remove Trace title and data attributes, use meta attr.
Diffstat (limited to 'test')
-rw-r--r--test/ec/test_configuration.py5
-rw-r--r--test/sca/test_align.py26
-rw-r--r--test/sca/test_combine.py8
-rw-r--r--test/sca/test_edit.py2
-rw-r--r--test/sca/test_filter.py2
-rw-r--r--test/sca/test_match.py10
-rw-r--r--test/sca/test_plot.py4
-rw-r--r--test/sca/test_process.py2
-rw-r--r--test/sca/test_sampling.py4
-rw-r--r--test/sca/test_test.py25
-rw-r--r--test/sca/test_trace.py2
-rw-r--r--test/sca/test_traceset.py8
12 files changed, 47 insertions, 51 deletions
diff --git a/test/ec/test_configuration.py b/test/ec/test_configuration.py
index 54e4827..9c8e361 100644
--- a/test/ec/test_configuration.py
+++ b/test/ec/test_configuration.py
@@ -1,7 +1,7 @@
from unittest import TestCase
from pyecsca.ec.configuration import (all_configurations, HashType, RandomMod, Multiplication,
- Squaring, Reduction)
+ Squaring, Reduction, Inversion)
from pyecsca.ec.model import ShortWeierstrassModel
from pyecsca.ec.mult import LTRMultiplier
from .utils import slow
@@ -15,7 +15,8 @@ class ConfigurationTests(TestCase):
"mod_rand": RandomMod.SAMPLE,
"mult": Multiplication.BASE,
"sqr": Squaring.BASE,
- "red": Reduction.BASE
+ "red": Reduction.BASE,
+ "inv": Inversion.GCD
}
@slow
diff --git a/test/sca/test_align.py b/test/sca/test_align.py
index f446f17..8aa489b 100644
--- a/test/sca/test_align.py
+++ b/test/sca/test_align.py
@@ -12,9 +12,9 @@ class AlignTests(Plottable):
first_arr = np.array([10, 64, 120, 64, 10, 10, 10, 10, 10], dtype=np.dtype("i1"))
second_arr = np.array([10, 10, 10, 10, 50, 80, 50, 20, 10], dtype=np.dtype("i1"))
third_arr = np.array([70, 30, 42, 35, 28, 21, 15, 10, 5], dtype=np.dtype("i1"))
- a = Trace(first_arr, None, None)
- b = Trace(second_arr, None, None)
- c = Trace(third_arr, None, None)
+ a = Trace(first_arr)
+ b = Trace(second_arr)
+ c = Trace(third_arr)
result = align_correlation(a, b, c, reference_offset=1, reference_length=3, max_offset=4, min_correlation=0.65)
self.assertIsNotNone(result)
self.assertEqual(len(result), 2)
@@ -36,16 +36,16 @@ class AlignTests(Plottable):
def test_peak_align(self):
first_arr = np.array([10, 64, 14, 120, 15, 30, 10, 15, 20, 15, 15, 10, 10], dtype=np.dtype("i1"))
second_arr = np.array([10, 10, 10, 10, 90, 40, 50, 20, 10, 17, 16, 10, 10], dtype=np.dtype("i1"))
- a = Trace(first_arr, None, None)
- b = Trace(second_arr, None, None)
+ a = Trace(first_arr)
+ b = Trace(second_arr)
result = align_peaks(a, b, reference_offset=2, reference_length=5, max_offset=3)
self.assertEqual(np.argmax(result[0].samples), np.argmax(result[1].samples))
def test_sad_align(self):
first_arr = np.array([10, 64, 14, 120, 15, 30, 10, 15, 20, 15, 15, 10, 10], dtype=np.dtype("i1"))
second_arr = np.array([10, 10, 10, 10, 90, 40, 50, 20, 10, 17, 16, 10, 10], dtype=np.dtype("i1"))
- a = Trace(first_arr, None, None)
- b = Trace(second_arr, None, None)
+ a = Trace(first_arr)
+ b = Trace(second_arr)
result = align_sad(a, b, reference_offset=2, reference_length=5, max_offset=3)
self.assertEqual(len(result), 2)
@@ -53,9 +53,9 @@ class AlignTests(Plottable):
first_arr = np.array([10, 64, 14, 120, 15, 30, 10, 15, 20, 15, 15, 10, 10, 8, 10, 12, 10, 13, 9], dtype=np.dtype("i1"))
second_arr = np.array([10, 10, 10, 10, 60, 40, 90, 20, 10, 17, 16, 10, 10, 10, 10, 10, 17, 12, 10], dtype=np.dtype("i1"))
third_arr = np.array([10, 30, 20, 21, 15, 8, 10, 37, 21, 77, 20, 28, 25, 10, 9, 10, 15, 9, 10], dtype=np.dtype("i1"))
- a = Trace(first_arr, None, None)
- b = Trace(second_arr, None, None)
- c = Trace(third_arr, None, None)
+ a = Trace(first_arr)
+ b = Trace(second_arr)
+ c = Trace(third_arr)
result = align_dtw_scale(a, b, c)
self.assertEqual(np.argmax(result[0].samples), np.argmax(result[1].samples))
@@ -66,9 +66,9 @@ class AlignTests(Plottable):
first_arr = np.array([10, 64, 14, 120, 15, 30, 10, 15, 20, 15, 15, 10, 10, 8, 10, 12, 10, 13, 9], dtype=np.dtype("i1"))
second_arr = np.array([10, 10, 10, 10, 60, 40, 90, 20, 10, 17, 16, 10, 10, 10, 10, 10, 17, 12, 10], dtype=np.dtype("i1"))
third_arr = np.array([10, 30, 20, 21, 15, 8, 10, 47, 21, 77, 20, 28, 25, 10, 9, 10, 15, 9, 10], dtype=np.dtype("i1"))
- a = Trace(first_arr, None, None)
- b = Trace(second_arr, None, None)
- c = Trace(third_arr, None, None)
+ a = Trace(first_arr)
+ b = Trace(second_arr)
+ c = Trace(third_arr)
result = align_dtw(a, b, c)
self.assertEqual(np.argmax(result[0].samples), np.argmax(result[1].samples))
diff --git a/test/sca/test_combine.py b/test/sca/test_combine.py
index 41df9fb..a35772b 100644
--- a/test/sca/test_combine.py
+++ b/test/sca/test_combine.py
@@ -7,9 +7,9 @@ from pyecsca.sca import Trace, CombinedTrace, average, conditional_average, stan
class CombineTests(TestCase):
def setUp(self):
- self.a = Trace(np.array([20, 80], dtype=np.dtype("i1")), None, b"\xff", None)
- self.b = Trace(np.array([30, 42], dtype=np.dtype("i1")), None, b"\xff", None)
- self.c = Trace(np.array([78, 56], dtype=np.dtype("i1")), None, b"\x00", None)
+ self.a = Trace(np.array([20, 80], dtype=np.dtype("i1")), {"data": b"\xff"})
+ self.b = Trace(np.array([30, 42], dtype=np.dtype("i1")), {"data": b"\xff"})
+ self.c = Trace(np.array([78, 56], dtype=np.dtype("i1")), {"data": b"\x00"})
def test_average(self):
self.assertIsNone(average())
@@ -22,7 +22,7 @@ class CombineTests(TestCase):
def test_conditional_average(self):
result = conditional_average(self.a, self.b, self.c,
- condition=lambda trace: trace.data[0] == 0xff)
+ condition=lambda trace: trace.meta["data"] == b"\xff")
self.assertIsInstance(result, CombinedTrace)
self.assertEqual(len(result.samples), 2)
self.assertEqual(result.samples[0], 25)
diff --git a/test/sca/test_edit.py b/test/sca/test_edit.py
index f5b529e..f701d83 100644
--- a/test/sca/test_edit.py
+++ b/test/sca/test_edit.py
@@ -8,7 +8,7 @@ from pyecsca.sca import Trace, trim, reverse, pad
class EditTests(TestCase):
def setUp(self):
- self._trace = Trace(np.array([10, 20, 30, 40, 50], dtype=np.dtype("i1")), None, None, None)
+ self._trace = Trace(np.array([10, 20, 30, 40, 50], dtype=np.dtype("i1")))
def test_trim(self):
result = trim(self._trace, 2)
diff --git a/test/sca/test_filter.py b/test/sca/test_filter.py
index fda5626..1c9e9ca 100644
--- a/test/sca/test_filter.py
+++ b/test/sca/test_filter.py
@@ -10,7 +10,7 @@ class FilterTests(Plottable):
def setUp(self):
self._trace = Trace(
np.array([5, 12, 15, 13, 15, 11, 7, 2, -4, -8, -10, -8, -13, -9, -11, -8, -5],
- dtype=np.dtype("i1")), None, None, None)
+ dtype=np.dtype("i1")), None)
def test_lowpass(self):
result = filter_lowpass(self._trace, 100, 20)
diff --git a/test/sca/test_match.py b/test/sca/test_match.py
index 1781d9d..cd0b780 100644
--- a/test/sca/test_match.py
+++ b/test/sca/test_match.py
@@ -9,22 +9,20 @@ from .utils import Plottable
class MatchingTests(Plottable):
def test_simple_match(self):
- pattern = Trace(np.array([1, 15, 12, -10, 0, 13, 17, -1, 0], dtype=np.dtype("i1")), None,
- None, None)
+ pattern = Trace(np.array([1, 15, 12, -10, 0, 13, 17, -1, 0], dtype=np.dtype("i1")), None)
base = Trace(np.array(
[0, 1, 3, 1, 2, -2, -3, 1, 15, 12, -10, 0, 13, 17, -1, 0, 3, 1],
- dtype=np.dtype("i1")), None, None, None)
+ dtype=np.dtype("i1")), None)
filtered = match_part(base, 7, 9)
self.assertListEqual(filtered, [7])
self.plot(base=base, pattern=pad(pattern, (filtered[0], 0)))
def test_multiple_match(self):
- pattern = Trace(np.array([1, 15, 12, -10, 0, 13, 17, -1, 0], dtype=np.dtype("i1")), None,
- None, None)
+ pattern = Trace(np.array([1, 15, 12, -10, 0, 13, 17, -1, 0], dtype=np.dtype("i1")), None)
base = Trace(np.array(
[0, 1, 3, 1, 2, -2, -3, 1, 18, 10, -5, 0, 13, 17, -1, 0, 3, 1, 2, 5, 13, 8, -8, 1,
11, 15, 0, 1, 5, 2, 4],
- dtype=np.dtype("i1")), None, None, None)
+ dtype=np.dtype("i1")), None)
filtered = match_pattern(base, pattern, 0.9)
self.assertListEqual(filtered, [7, 19])
self.plot(base=base, pattern1=pad(pattern, (filtered[0], 0)), pattern2=pad(pattern, (filtered[1], 0)))
diff --git a/test/sca/test_plot.py b/test/sca/test_plot.py
index 9158e5c..5b65c87 100644
--- a/test/sca/test_plot.py
+++ b/test/sca/test_plot.py
@@ -11,8 +11,8 @@ from .utils import Plottable
class PlotTests(Plottable):
def setUp(self) -> None:
- self.trace1 = Trace(np.array([6, 7, 3, -2, 5, 1], dtype=np.dtype("i1")), None, None)
- self.trace2 = Trace(np.array([2, 3, 7, 0, -1, 0], dtype=np.dtype("i1")), None, None)
+ self.trace1 = Trace(np.array([6, 7, 3, -2, 5, 1], dtype=np.dtype("i1")))
+ self.trace2 = Trace(np.array([2, 3, 7, 0, -1, 0], dtype=np.dtype("i1")))
def test_html(self):
if getenv("PYECSCA_TEST_PLOTS") is None:
diff --git a/test/sca/test_process.py b/test/sca/test_process.py
index 49d520f..d1bbddb 100644
--- a/test/sca/test_process.py
+++ b/test/sca/test_process.py
@@ -7,7 +7,7 @@ from pyecsca.sca import Trace, absolute, invert, threshold, rolling_mean, offset
class ProcessTests(TestCase):
def setUp(self):
- self._trace = Trace(np.array([30, -60, 145, 247], dtype=np.dtype("i2")), None, None, None)
+ self._trace = Trace(np.array([30, -60, 145, 247], dtype=np.dtype("i2")), None)
def test_absolute(self):
result = absolute(self._trace)
diff --git a/test/sca/test_sampling.py b/test/sca/test_sampling.py
index 1af1579..79f55b4 100644
--- a/test/sca/test_sampling.py
+++ b/test/sca/test_sampling.py
@@ -8,7 +8,7 @@ from .utils import Plottable
class SamplingTests(Plottable):
def setUp(self):
- self._trace = Trace(np.array([20, 40, 50, 50, 10], dtype=np.dtype("i1")), None, None)
+ self._trace = Trace(np.array([20, 40, 50, 50, 10], dtype=np.dtype("i1")))
def test_downsample_average(self):
result = downsample_average(self._trace, 2)
@@ -29,7 +29,7 @@ class SamplingTests(Plottable):
def test_downsample_decimate(self):
trace = Trace(np.array([20, 30, 55, 18, 15, 10, 35, 24, 21, 15, 10, 8, -10, -5,
-8, -12, -15, -18, -34, -21, -17, -10, -5, -12, -6, -2,
- 4, 8, 21, 28], dtype=np.dtype("i1")), None, None, None)
+ 4, 8, 21, 28], dtype=np.dtype("i1")))
result = downsample_decimate(trace, 2)
self.assertIsNotNone(result)
self.assertIsInstance(result, Trace)
diff --git a/test/sca/test_test.py b/test/sca/test_test.py
index f012f7f..e2b3969 100644
--- a/test/sca/test_test.py
+++ b/test/sca/test_test.py
@@ -8,19 +8,16 @@ from pyecsca.sca import Trace, welch_ttest, student_ttest, ks_test
class TTestTests(TestCase):
def setUp(self):
- self.a = Trace(np.array([20, 80], dtype=np.dtype("i1")), None, b"\xff", None)
- self.b = Trace(np.array([30, 42], dtype=np.dtype("i1")), None, b"\xff", None)
- self.c = Trace(np.array([78, 56], dtype=np.dtype("i1")), None, b"\x00", None)
- self.d = Trace(np.array([98, 36], dtype=np.dtype("i1")), None, b"\x00", None)
+ self.a = Trace(np.array([20, 80], dtype=np.dtype("i1")))
+ self.b = Trace(np.array([30, 42], dtype=np.dtype("i1")))
+ self.c = Trace(np.array([78, 56], dtype=np.dtype("i1")))
+ self.d = Trace(np.array([98, 36], dtype=np.dtype("i1")))
def test_welch_ttest(self):
self.assertIsNotNone(welch_ttest([self.a, self.b], [self.c, self.d]))
- a = Trace(np.array([19.8, 20.4, 19.6, 17.8, 18.5, 18.9, 18.3, 18.9, 19.5, 22.0]), None,
- None, None)
- b = Trace(np.array([28.2, 26.6, 20.1, 23.3, 25.2, 22.1, 17.7, 27.6, 20.6, 13.7]), None,
- None, None)
- c = Trace(np.array([20.2, 21.6, 27.1, 13.3, 24.2, 20.1, 11.7, 25.6, 26.6, 21.4]), None,
- None, None)
+ a = Trace(np.array([19.8, 20.4, 19.6, 17.8, 18.5, 18.9, 18.3, 18.9, 19.5, 22.0]))
+ b = Trace(np.array([28.2, 26.6, 20.1, 23.3, 25.2, 22.1, 17.7, 27.6, 20.6, 13.7]))
+ c = Trace(np.array([20.2, 21.6, 27.1, 13.3, 24.2, 20.1, 11.7, 25.6, 26.6, 21.4]))
result = welch_ttest([a, b], [b, c])
self.assertIsNotNone(result)
@@ -35,8 +32,8 @@ class KolmogorovSmirnovTests(TestCase):
def test_ks_test(self):
self.assertIsNone(ks_test([], []))
- a = Trace(np.array([20, 80], dtype=np.dtype("i1")), None, b"\xff", None)
- b = Trace(np.array([30, 42], dtype=np.dtype("i1")), None, b"\xff", None)
- c = Trace(np.array([78, 56], dtype=np.dtype("i1")), None, b"\x00", None)
- d = Trace(np.array([98, 36], dtype=np.dtype("i1")), None, b"\x00", None)
+ a = Trace(np.array([20, 80], dtype=np.dtype("i1")))
+ b = Trace(np.array([30, 42], dtype=np.dtype("i1")))
+ c = Trace(np.array([78, 56], dtype=np.dtype("i1")))
+ d = Trace(np.array([98, 36], dtype=np.dtype("i1")))
self.assertIsNotNone(ks_test([a, b], [c, d]))
diff --git a/test/sca/test_trace.py b/test/sca/test_trace.py
index d09c4f5..91b640d 100644
--- a/test/sca/test_trace.py
+++ b/test/sca/test_trace.py
@@ -6,7 +6,7 @@ from pyecsca.sca import Trace
class TraceTests(TestCase):
def test_basic(self):
- trace = Trace(np.array([10, 15, 24], dtype=np.dtype("i1")), "Name", b"\xff\xaa", None)
+ trace = Trace(np.array([10, 15, 24], dtype=np.dtype("i1")))
self.assertIsNotNone(trace)
self.assertIn("Trace", str(trace))
self.assertIsNone(trace.trace_set)
diff --git a/test/sca/test_traceset.py b/test/sca/test_traceset.py
index 72eac47..351f025 100644
--- a/test/sca/test_traceset.py
+++ b/test/sca/test_traceset.py
@@ -9,9 +9,9 @@ import numpy as np
from pyecsca.sca import (TraceSet, InspectorTraceSet, ChipWhispererTraceSet, PickleTraceSet,
HDF5TraceSet, Trace)
-EXAMPLE_TRACES = [Trace(np.array([20, 40, 50, 50, 10], dtype=np.dtype("i1")), None, None),
- Trace(np.array([1, 2, 3, 4, 5], dtype=np.dtype("i1")), None, None),
- Trace(np.array([6, 7, 8, 9, 10], dtype=np.dtype("i1")), None, None)]
+EXAMPLE_TRACES = [Trace(np.array([20, 40, 50, 50, 10], dtype=np.dtype("i1"))),
+ Trace(np.array([1, 2, 3, 4, 5], dtype=np.dtype("i1"))),
+ Trace(np.array([6, 7, 8, 9, 10], dtype=np.dtype("i1")))]
EXAMPLE_KWARGS = {"num_traces": 3, "thingy": "abc"}
@@ -97,7 +97,7 @@ class HDF5TraceSetTests(TestCase):
shutil.copy("test/data/test.h5", path)
trace_set = HDF5TraceSet.inplace(path)
self.assertIsNotNone(trace_set)
- test_trace = Trace(np.array([6, 7], dtype=np.dtype("i1")), None, None, meta={"thing": "ring"})
+ test_trace = Trace(np.array([6, 7], dtype=np.dtype("i1")), meta={"thing": "ring"})
trace_set[0] = deepcopy(test_trace)
trace_set.save()
trace_set.close()