aboutsummaryrefslogtreecommitdiff
path: root/test/sca/utils.py
blob: 1083b87ba06783d6bc11574af8fd5b00459c05d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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"))