aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/test_builder.py
diff options
context:
space:
mode:
authorJ08nY2023-09-28 17:31:33 +0200
committerJ08nY2023-09-28 17:31:33 +0200
commitf2a0476c778dd5f752bf522f28563ec7a01f186e (patch)
treece1566ffa0478131236cb603774f88222173f98b /test/test_builder.py
parentedae0ca0627926772045c105ae4551c18f872653 (diff)
downloadpyecsca-codegen-f2a0476c778dd5f752bf522f28563ec7a01f186e.tar.gz
pyecsca-codegen-f2a0476c778dd5f752bf522f28563ec7a01f186e.tar.zst
pyecsca-codegen-f2a0476c778dd5f752bf522f28563ec7a01f186e.zip
Move to pytest.
Diffstat (limited to 'test/test_builder.py')
-rw-r--r--test/test_builder.py266
1 files changed, 201 insertions, 65 deletions
diff --git a/test/test_builder.py b/test/test_builder.py
index f2760ea..0f931ef 100644
--- a/test/test_builder.py
+++ b/test/test_builder.py
@@ -1,71 +1,207 @@
-from unittest import TestCase
-
-from click.testing import CliRunner
+import pytest
from pyecsca.codegen.builder import build_impl, list_impl
-from parameterized import parameterized
-class BuilderTests(TestCase):
- @parameterized.expand([
- ("basic", ["--platform", "HOST", "shortw", "projective", "add-1998-cmo", "dbl-1998-cmo", "z", "ltr(complete=True)", "."]),
- ("karatsuba", ["--platform", "HOST", "--mul", "KARATSUBA", "shortw", "projective", "add-1998-cmo", "dbl-1998-cmo", "z", "ltr(complete=True)", "."]),
- ("strip", ["--platform", "HOST", "--strip", "--no-remove", "shortw", "projective", "add-1998-cmo", "dbl-1998-cmo", "z", "ltr(complete=True)", "."]),
- ("montgom", ["--platform", "HOST", "--no-ecdsa", "montgom", "xz", "ladd-1987-m", "dbl-1987-m", "scale", "ldr()", "."]),
- ("jacobian", ["--platform", "HOST", "--no-ecdsa", "shortw", "jacobian", "add-2007-bl", "dbl-2007-bl", "rtl()", "."])
- ])
- def test_cli_build(self, name, args):
- runner = CliRunner()
- with runner.isolated_filesystem():
- result = runner.invoke(build_impl, args)
- self.assertEqual(result.exit_code, 0)
+@pytest.mark.parametrize(
+ "name,args",
+ [
+ (
+ "basic",
+ [
+ "--platform",
+ "HOST",
+ "shortw",
+ "projective",
+ "add-1998-cmo",
+ "dbl-1998-cmo",
+ "z",
+ "ltr(complete=True)",
+ ".",
+ ],
+ ),
+ (
+ "karatsuba",
+ [
+ "--platform",
+ "HOST",
+ "--mul",
+ "KARATSUBA",
+ "shortw",
+ "projective",
+ "add-1998-cmo",
+ "dbl-1998-cmo",
+ "z",
+ "ltr(complete=True)",
+ ".",
+ ],
+ ),
+ (
+ "strip",
+ [
+ "--platform",
+ "HOST",
+ "--strip",
+ "--no-remove",
+ "shortw",
+ "projective",
+ "add-1998-cmo",
+ "dbl-1998-cmo",
+ "z",
+ "ltr(complete=True)",
+ ".",
+ ],
+ ),
+ (
+ "montgom",
+ [
+ "--platform",
+ "HOST",
+ "--no-ecdsa",
+ "montgom",
+ "xz",
+ "ladd-1987-m",
+ "dbl-1987-m",
+ "scale",
+ "ldr()",
+ ".",
+ ],
+ ),
+ (
+ "jacobian",
+ [
+ "--platform",
+ "HOST",
+ "--no-ecdsa",
+ "shortw",
+ "jacobian",
+ "add-2007-bl",
+ "dbl-2007-bl",
+ "rtl()",
+ ".",
+ ],
+ ),
+ ],
+)
+def test_cli_build(name, args, isolated_cli_runner):
+ result = isolated_cli_runner.invoke(build_impl, args)
+ assert result.exit_code == 0
+
+
+def test_cli_build_fails(isolated_cli_runner):
+ # unknown model
+ result = isolated_cli_runner.invoke(
+ build_impl,
+ [
+ "--platform",
+ "HOST",
+ "missing",
+ "projective",
+ "add-1998-cmo",
+ "dbl-1998-cmo",
+ "z",
+ "ltr(complete=True)",
+ ".",
+ ],
+ )
+ assert result.exit_code == 2
+ result = isolated_cli_runner.invoke(
+ build_impl,
+ [
+ "--platform",
+ "HOST",
+ "shortw",
+ "missing",
+ "add-1998-cmo",
+ "dbl-1998-cmo",
+ "z",
+ "ltr(complete=True)",
+ ".",
+ ],
+ )
+ assert result.exit_code == 2
+ result = isolated_cli_runner.invoke(
+ build_impl,
+ [
+ "--platform",
+ "HOST",
+ "shortw",
+ "projective",
+ "missing",
+ "dbl-1998-cmo",
+ "z",
+ "ltr(complete=True)",
+ ".",
+ ],
+ )
+ assert result.exit_code == 2
+ result = isolated_cli_runner.invoke(
+ build_impl,
+ [
+ "--platform",
+ "HOST",
+ "shortw",
+ "projective",
+ "add-1998-cmo",
+ "dbl-1998-cmo",
+ "z",
+ "missing",
+ ".",
+ ],
+ )
+ assert result.exit_code == 2
+ result = isolated_cli_runner.invoke(
+ build_impl,
+ [
+ "--platform",
+ "HOST",
+ "shortw",
+ "projective",
+ "add-1998-cmo",
+ "dbl-1998-cmo",
+ "z",
+ "missing()",
+ ".",
+ ],
+ )
+ assert result.exit_code == 2
+ result = isolated_cli_runner.invoke(
+ build_impl,
+ [
+ "--platform",
+ "HOST",
+ "shortw",
+ "projective",
+ "add-1998-cmo",
+ "z",
+ "ltr(complete=True)",
+ ".",
+ ],
+ )
+ assert result.exit_code == 2
+ result = isolated_cli_runner.invoke(
+ build_impl,
+ [
+ "--platform",
+ "HOST",
+ "shortw",
+ "projective",
+ "add-1998-cmo",
+ "add-1998-cmo",
+ "z",
+ "ltr(complete=True)",
+ ".",
+ ],
+ )
+ assert result.exit_code == 2
- def test_cli_build_fails(self):
- runner = CliRunner()
- with runner.isolated_filesystem():
- # unknown model
- result = runner.invoke(build_impl,
- ["--platform", "HOST", "missing", "projective", "add-1998-cmo",
- "dbl-1998-cmo", "z", "ltr(complete=True)", "."])
- self.assertEqual(result.exit_code, 2)
- # unknown coordinates
- result = runner.invoke(build_impl,
- ["--platform", "HOST", "shortw", "missing", "add-1998-cmo",
- "dbl-1998-cmo", "z", "ltr(complete=True)", "."])
- self.assertEqual(result.exit_code, 2)
- # unknown formula
- result = runner.invoke(build_impl,
- ["--platform", "HOST", "shortw", "projective", "missing",
- "dbl-1998-cmo", "z", "ltr(complete=True)", "."])
- self.assertEqual(result.exit_code, 2)
- # bad formatted mult spec
- result = runner.invoke(build_impl,
- ["--platform", "HOST", "shortw", "projective", "add-1998-cmo",
- "dbl-1998-cmo", "z", "missing", "."])
- self.assertEqual(result.exit_code, 2)
- # unknown mult
- result = runner.invoke(build_impl,
- ["--platform", "HOST", "shortw", "projective", "add-1998-cmo",
- "dbl-1998-cmo", "z", "missing()", "."])
- self.assertEqual(result.exit_code, 2)
- # missing required formulas to mult
- result = runner.invoke(build_impl,
- ["--platform", "HOST", "shortw", "projective", "add-1998-cmo",
- "z", "ltr(complete=True)", "."])
- self.assertEqual(result.exit_code, 2)
- # duplicate formulas
- result = runner.invoke(build_impl,
- ["--platform", "HOST", "shortw", "projective", "add-1998-cmo",
- "add-1998-cmo", "z", "ltr(complete=True)", "."])
- self.assertEqual(result.exit_code, 2)
- def test_cli_list(self):
- runner = CliRunner()
- result = runner.invoke(list_impl, [])
- self.assertEqual(result.exit_code, 0)
- result = runner.invoke(list_impl, ["montgom"])
- self.assertEqual(result.exit_code, 0)
- result = runner.invoke(list_impl, ["montgom", "xz"])
- self.assertEqual(result.exit_code, 0)
- result = runner.invoke(list_impl, ["montgom", "xz", "ladd-1987-m"])
- self.assertEqual(result.exit_code, 0)
+def test_cli_list(cli_runner):
+ result = cli_runner.invoke(list_impl, [])
+ assert result.exit_code == 0
+ result = cli_runner.invoke(list_impl, ["montgom"])
+ assert result.exit_code == 0
+ result = cli_runner.invoke(list_impl, ["montgom", "xz"])
+ assert result.exit_code == 0
+ result = cli_runner.invoke(list_impl, ["montgom", "xz", "ladd-1987-m"])
+ assert result.exit_code == 0