aboutsummaryrefslogtreecommitdiff
path: root/test/sca/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/sca/utils.py')
-rw-r--r--test/sca/utils.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/sca/utils.py b/test/sca/utils.py
new file mode 100644
index 0000000..1083b87
--- /dev/null
+++ b/test/sca/utils.py
@@ -0,0 +1,24 @@
+import matplotlib.pyplot as plt
+from unittest import TestCase
+from pyecsca.sca import Trace
+from os.path import join, exists
+from os import mkdir, getenv
+
+
+def slow(func):
+ func.slow = 1
+ return func
+
+
+def plot(case: TestCase, *traces: Trace):
+ if getenv("PYECSCA_TEST_PLOTS") is None:
+ return
+ fig = plt.figure()
+ ax = fig.add_subplot(111)
+ for i, trace in enumerate(traces):
+ ax.plot(trace.samples, label=str(i))
+ ax.legend(loc="best")
+ directory = join("test", "plots")
+ if not exists(directory):
+ mkdir(directory)
+ plt.savefig(join(directory, case.id() + ".png"))