aboutsummaryrefslogtreecommitdiff
path: root/test/src/util
diff options
context:
space:
mode:
authorJ08nY2018-01-18 22:07:34 +0100
committerJ08nY2018-01-18 23:38:40 +0100
commit77a4a7c2af7aad72e699018fcda8e4cb52d377e6 (patch)
tree8755e6b3d1c0e856252dfc8fe37b1c727606a812 /test/src/util
parentb03007db7612a6d9ab70cd0e698de565a9687ddf (diff)
downloadecgen-77a4a7c2af7aad72e699018fcda8e4cb52d377e6.tar.gz
ecgen-77a4a7c2af7aad72e699018fcda8e4cb52d377e6.tar.zst
ecgen-77a4a7c2af7aad72e699018fcda8e4cb52d377e6.zip
Add some more basic tests for coverage.
Diffstat (limited to 'test/src/util')
-rw-r--r--test/src/util/test_random.c18
-rw-r--r--test/src/util/test_timeout.c36
2 files changed, 54 insertions, 0 deletions
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