aboutsummaryrefslogtreecommitdiff
path: root/test/src/io/test_cli.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/src/io/test_cli.c')
-rw-r--r--test/src/io/test_cli.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/src/io/test_cli.c b/test/src/io/test_cli.c
new file mode 100644
index 0000000..c90bbfa
--- /dev/null
+++ b/test/src/io/test_cli.c
@@ -0,0 +1,56 @@
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017 J08nY
+ */
+
+#include "test/utils.h"
+#include "io/cli.h"
+#include "io/config.h"
+#include <criterion/criterion.h>
+#include <unistd.h>
+
+static struct argp test_argp = {cli_options, cli_parse, cli_args_doc,
+ cli_doc, 0, cli_filter};
+
+TestSuite(cli, .init = default_setup, .fini = default_teardown);
+
+
+Test(cli, test_memory) {
+ int argc = 4;
+ char *argv[] = {"ecgen", "--memory=2k", "--fp", "1"};
+ config_t cfg;
+ memset(&cfg, 0, sizeof(cfg));
+ int ret = argp_parse(&test_argp, argc, argv, 0, 0, &cfg);
+ cr_assert_eq(ret, 0,);
+ cr_assert_eq(cfg.memory, 2000,);
+}
+
+Test(cli, test_thread_memory) {
+ int argc = 4;
+ char *argv[] = {"ecgen", "--thread-stack=2k", "--fp", "1"};
+ config_t cfg;
+ memset(&cfg, 0, sizeof(cfg));
+ int ret = argp_parse(&test_argp, argc, argv, 0, 0, &cfg);
+ cr_assert_eq(ret, 0,);
+ cr_assert_eq(cfg.thread_memory, 2000,);
+}
+
+Test(cli, test_threads) {
+ int argc = 4;
+ char *argv[] = {"ecgen", "--threads=2", "--fp", "1"};
+ config_t cfg;
+ memset(&cfg, 0, sizeof(cfg));
+ int ret = argp_parse(&test_argp, argc, argv, 0, 0, &cfg);
+ cr_assert_eq(ret, 0,);
+ cr_assert_eq(cfg.threads, 2,);
+}
+
+Test(cli, test_auto_threads) {
+ int argc = 4;
+ char *argv[] = {"ecgen", "--threads=auto", "--fp", "1"};
+ config_t cfg;
+ memset(&cfg, 0, sizeof(cfg));
+ int ret = argp_parse(&test_argp, argc, argv, 0, 0, &cfg);
+ cr_assert_eq(ret, 0,);
+ cr_assert_eq(cfg.threads, sysconf(_SC_NPROCESSORS_ONLN),);
+} \ No newline at end of file