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 /test/src | |
| parent | bc643ab1903239d039f6b9527cb21029a886561d (diff) | |
| download | ecgen-8d2422ced21f204215a904e1a2f6bfbc143bc894.tar.gz ecgen-8d2422ced21f204215a904e1a2f6bfbc143bc894.tar.zst ecgen-8d2422ced21f204215a904e1a2f6bfbc143bc894.zip | |
Add tests for cli parsing.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/io/test_cli.c | 56 |
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 |
