diff options
| author | J08nY | 2018-01-18 22:07:34 +0100 |
|---|---|---|
| committer | J08nY | 2018-01-18 23:38:40 +0100 |
| commit | 77a4a7c2af7aad72e699018fcda8e4cb52d377e6 (patch) | |
| tree | 8755e6b3d1c0e856252dfc8fe37b1c727606a812 | |
| parent | b03007db7612a6d9ab70cd0e698de565a9687ddf (diff) | |
| download | ecgen-77a4a7c2af7aad72e699018fcda8e4cb52d377e6.tar.gz ecgen-77a4a7c2af7aad72e699018fcda8e4cb52d377e6.tar.zst ecgen-77a4a7c2af7aad72e699018fcda8e4cb52d377e6.zip | |
| -rwxr-xr-x | test/ecgen.sh | 7 | ||||
| -rw-r--r-- | test/src/gen/test_curve.c | 36 | ||||
| -rw-r--r-- | test/src/gen/test_point.c | 22 | ||||
| -rw-r--r-- | test/src/gen/test_seed.c | 36 | ||||
| -rw-r--r-- | test/src/io/test_cli.c | 20 | ||||
| -rw-r--r-- | test/src/util/test_random.c | 18 | ||||
| -rw-r--r-- | test/src/util/test_timeout.c | 36 |
7 files changed, 174 insertions, 1 deletions
diff --git a/test/ecgen.sh b/test/ecgen.sh index 006025e..145c3a4 100755 --- a/test/ecgen.sh +++ b/test/ecgen.sh @@ -122,6 +122,11 @@ function cli() { assert_raises "${ecgen} --seed=some" 64 assert_raises "${ecgen} 1 2 3" 64 assert_raises "${ecgen} --fp --f2m 1" 1 + assert_raises "${ecgen} --brainpool --anomalous --fp 10" 1 + assert_raises "${ecgen} --brainpool=01234 --fp 10" 1 + assert_raises "${ecgen} --brainpool-rfc=01234 --fp 10" 1 + assert_raises "${ecgen} --ansi=01234 --fp 10" 1 + assert_raises "${ecgen} --hex-check=not_hex --fp 10" 1 } function hex() { @@ -142,4 +147,4 @@ invalid twist cli hex -end_suite ecgen
\ No newline at end of file +end_suite ecgen diff --git a/test/src/gen/test_curve.c b/test/src/gen/test_curve.c new file mode 100644 index 0000000..3fe4801 --- /dev/null +++ b/test/src/gen/test_curve.c @@ -0,0 +1,36 @@ +/* + * ecgen, tool for generating Elliptic curve domain parameters + * Copyright (C) 2017 J08nY + */ +#include <criterion/criterion.h> +#include "gen/curve.h" +#include "test/default.h" + +TestSuite(curve, .init = default_setup, .fini = default_teardown); + +Test(curve, test_curve_new) { + curve_t *curve = curve_new(); + cr_assert_not_null(curve, ); + curve_free(&curve); + cr_assert_null(curve, ); +} + +Test(curve, test_curve_copy) { + curve_t *curve = curve_new(); + curve_t *other = curve_new_copy(curve); + cr_assert_not_null(other, ); + curve_copy(curve, other); + cr_assert_not_null(other, ); + curve_free(&curve); + curve_free(&other); +} + +Test(curve, test_curve_clone) { + curve_t *curve = curve_new(); + curve_t *other = curve_new_clone(curve); + cr_assert_not_null(other, ); + curve_clone(curve, other); + cr_assert_not_null(other, ); + curve_free(&curve); + curve_free(&other); +}
\ No newline at end of file diff --git a/test/src/gen/test_point.c b/test/src/gen/test_point.c index 19869c5..ca23ba6 100644 --- a/test/src/gen/test_point.c +++ b/test/src/gen/test_point.c @@ -9,6 +9,28 @@ TestSuite(point, .init = io_setup, .fini = io_teardown); +Test(point, test_point_clone) { + point_t *one = point_new(); + point_t *other = point_new_clone(one); + cr_assert_not_null(other, ); + point_clone(one, other); + cr_assert_not_null(other, ); + point_free(&one); + point_free(&other); +} + +Test(point, test_points_clone) { + point_t *one = point_new(); + point_t **points = points_new(1); + points[0] = one; + point_t **others = points_new_clone(points, 1); + cr_assert_not_null(others, ); + points_clone(points, others, 1); + cr_assert_not_null(others, ); + points_free_deep(&points, 1); + points_free_deep(&others, 1); +} + Test(point, test_point_random) { // curve = ellinit([1, 3], 23), order = 27 GEN e = ellinit(mkvec2s(1, 3), stoi(23), -1); diff --git a/test/src/gen/test_seed.c b/test/src/gen/test_seed.c new file mode 100644 index 0000000..807db31 --- /dev/null +++ b/test/src/gen/test_seed.c @@ -0,0 +1,36 @@ +/* + * ecgen, tool for generating Elliptic seed domain parameters + * Copyright (C) 2017 J08nY + */ +#include <criterion/criterion.h> +#include "gen/seed.h" +#include "test/default.h" + +TestSuite(seed, .init = default_setup, .fini = default_teardown); + +Test(seed, test_seed_new) { + seed_t *seed = seed_new(); + cr_assert_not_null(seed, ); + seed_free(&seed); + cr_assert_null(seed, ); +} + +Test(seed, test_seed_copy) { + seed_t *seed = seed_new(); + seed_t *other = seed_new_copy(seed); + cr_assert_not_null(other, ); + seed_copy(seed, other); + cr_assert_not_null(other, ); + seed_free(&seed); + seed_free(&other); +} + +Test(seed, test_seed_clone) { + seed_t *seed = seed_new(); + seed_t *other = seed_new_clone(seed); + cr_assert_not_null(other, ); + seed_clone(seed, other); + cr_assert_not_null(other, ); + seed_free(&seed); + seed_free(&other); +}
\ No newline at end of file diff --git a/test/src/io/test_cli.c b/test/src/io/test_cli.c index 1701a4e..77d8672 100644 --- a/test/src/io/test_cli.c +++ b/test/src/io/test_cli.c @@ -20,6 +20,16 @@ Test(cli, test_memory) { int ret = argp_parse(&test_argp, argc, argv, 0, 0, cfg); cr_assert_eq(ret, 0, ); cr_assert_eq(cfg->memory, 2000, ); + + char *argx[] = {"ecgen", "--memory=2m", "--fp", "1"}; + ret = argp_parse(&test_argp, argc, argx, 0, 0, cfg); + cr_assert_eq(ret, 0, ); + cr_assert_eq(cfg->memory, 2000000, ); + + char *argy[] = {"ecgen", "--memory=2g", "--fp", "1"}; + ret = argp_parse(&test_argp, argc, argy, 0, 0, cfg); + cr_assert_eq(ret, 0, ); + cr_assert_eq(cfg->memory, 2000000000, ); } Test(cli, test_thread_memory) { @@ -52,4 +62,14 @@ Test(cli, test_timeout) { int ret = argp_parse(&test_argp, argc, argv, 0, 0, cfg); cr_assert_eq(ret, 0, ); cr_assert_eq(cfg->timeout, 600, ); + + char *argx[] = {"ecgen", "--timeout=1h", "--fp", "1"}; + ret = argp_parse(&test_argp, argc, argx, 0, 0, cfg); + cr_assert_eq(ret, 0, ); + cr_assert_eq(cfg->timeout, 3600, ); + + char *argy[] = {"ecgen", "--timeout=1d", "--fp", "1"}; + ret = argp_parse(&test_argp, argc, argy, 0, 0, cfg); + cr_assert_eq(ret, 0, ); + cr_assert_eq(cfg->timeout, 86400, ); }
\ No newline at end of file diff --git a/test/src/util/test_random.c b/test/src/util/test_random.c index bb632a6..be45f95 100644 --- a/test/src/util/test_random.c +++ b/test/src/util/test_random.c @@ -4,6 +4,7 @@ */ #include <criterion/criterion.h> +#include "math/poly.h" #include "test/default.h" #include "util/random.h" @@ -30,3 +31,20 @@ Test(random, test_random_int) { cr_assert_geq(cmpii(j, int2n(9)), 0, ); } } + +Test(random, test_random_field_element_fp) { + GEN fp = random_int(25); + for (size_t i = 0; i < 100; ++i) { + GEN j = random_field_element(fp); + cr_assert_geq(cmpii(j, gen_0), 0, ); + cr_assert_lt(cmpii(j, fp), 0, ); + } +} + +Test(random, test_random_field_element_f2m) { + GEN f2m = poly_find_gen(23); + for (size_t i = 0; i < 100; ++i) { + GEN j = random_field_element(f2m); + cr_assert_not_null(j, ); + } +}
\ No newline at end of file diff --git a/test/src/util/test_timeout.c b/test/src/util/test_timeout.c new file mode 100644 index 0000000..307c3a8 --- /dev/null +++ b/test/src/util/test_timeout.c @@ -0,0 +1,36 @@ +/* + * ecgen, tool for generating Elliptic curve domain parameters + * Copyright (C) 2017 J08nY + */ + +#include <criterion/criterion.h> +#include "util/timeout.h" +#include "test/default.h" + +void timeout_setup(void) { + default_setup(); + timeout_init(); +} + +TestSuite(timeout, .init = timeout_setup, .fini = default_teardown); + +Test(timeout, test_timeout_stop) { + bool done = false; + timeout_start(5) { + cr_assert_fail(); + } else { + done = true; + } + timeout_stop(); + cr_assert(done, ); +} + +Test(timeout, test_timeout_handle) { + bool done = false; + timeout_start(1) { + done = true; + } else { + sleep(2); + } + cr_assert(done, ); +}
\ No newline at end of file |
