diff options
| author | J08nY | 2017-08-30 15:59:06 +0200 |
|---|---|---|
| committer | J08nY | 2017-08-30 15:59:06 +0200 |
| commit | 8d2422ced21f204215a904e1a2f6bfbc143bc894 (patch) | |
| tree | 9173722cabbb1523bee1191120cde46a01db1d9e | |
| parent | bc643ab1903239d039f6b9527cb21029a886561d (diff) | |
| download | ecgen-8d2422ced21f204215a904e1a2f6bfbc143bc894.tar.gz ecgen-8d2422ced21f204215a904e1a2f6bfbc143bc894.tar.zst ecgen-8d2422ced21f204215a904e1a2f6bfbc143bc894.zip | |
| -rw-r--r-- | src/io/cli.c | 2 | ||||
| -rw-r--r-- | test/common.sh | 1 | ||||
| -rwxr-xr-x | test/ecgen.sh | 16 | ||||
| -rwxr-xr-x | test/econvert.sh | 3 | ||||
| -rw-r--r-- | test/src/io/test_cli.c | 56 |
5 files changed, 73 insertions, 5 deletions
diff --git a/src/io/cli.c b/src/io/cli.c index 54dfb55..1cbf3b9 100644 --- a/src/io/cli.c +++ b/src/io/cli.c @@ -229,7 +229,7 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) { case ARGP_KEY_END: // validate all option states here. // Only one field - if (!cfg->prime_field && !cfg->binary_field) { + if (cfg->prime_field == cfg->binary_field) { argp_failure(state, 1, 0, "Specify field type, prime or binary, with --fp / " "--f2m (but not both)."); diff --git a/test/common.sh b/test/common.sh index 04f520e..5e2cb38 100644 --- a/test/common.sh +++ b/test/common.sh @@ -18,6 +18,7 @@ start_suite() { } end_suite() { + assert_end $1 echo "######################################################################" echo } diff --git a/test/ecgen.sh b/test/ecgen.sh index c1cbc07..5ec9ccd 100755 --- a/test/ecgen.sh +++ b/test/ecgen.sh @@ -91,6 +91,18 @@ function invalid() { assert_raises "${ecgen} --f2m --threads=2 -r -i -u 10" } +function cli() { + start_test + assert_raises "${ecgen} --threads=a" 1 + assert_raises "${ecgen} --format=something" 1 + assert_raises "${ecgen} --koblitz=2" 1 + assert_raises "${ecgen} --points=something" 1 + assert_raises "${ecgen} --seed=some" 1 + assert_raises "${ecgen} 1 2 3" 64 + assert_raises "${ecgen} --fp --f2m 1" 1 +} + + . ${ASSERT} -v start_suite runs @@ -99,5 +111,5 @@ json exhaustive anomalous invalid -assert_end ecgen -end_suite
\ No newline at end of file +cli +end_suite ecgen
\ No newline at end of file diff --git a/test/econvert.sh b/test/econvert.sh index 6bed3d4..ed1943c 100755 --- a/test/econvert.sh +++ b/test/econvert.sh @@ -17,5 +17,4 @@ function runs() { . ${ASSERT} -v start_suite runs -assert_end econvert -end_suite
\ No newline at end of file +end_suite econvert
\ No newline at end of file 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 |
