]> jfr.im git - irc/atheme/atheme.git/commitdiff
libathemecore/atheme.c: move digest tests to crypto benchmark utility
authorAaron Jones <redacted>
Tue, 18 Feb 2020 01:26:08 +0000 (01:26 +0000)
committerAaron Jones <redacted>
Tue, 18 Feb 2020 01:27:57 +0000 (01:27 +0000)
This removes the -t and -T command-line options from atheme-services and
adds a -T option to the crypto benchmark utility. Atheme proper now un-
conditionally requires the digest testsuite to pass (because libathemecore
itself uses the Digest API), with no option to skip it. CI builds can now
invoke the testsuite from the crypto benchmarking utility.

libathemecore/atheme.c
scripts/ci-build.sh
src/crypto-benchmark/Makefile
src/crypto-benchmark/benchmark.h
src/crypto-benchmark/main.c
src/crypto-benchmark/selftests.c [new file with mode: 0644]
src/crypto-benchmark/selftests.h [new file with mode: 0644]

index 73b2889bc72e55d499951d45345179f820a3d16d..c75fe3eaa9195076017d33ed35f896b0e484fcfe 100644 (file)
@@ -65,7 +65,7 @@ void (*db_load) (const char *name) = NULL;
 static void
 print_help(void)
 {
-       printf("usage: atheme [-dhnvr] [-c conf] [-l logfile] [-p pidfile]\n\n"
+       printf("usage: atheme-services [-dhnvr] [-c conf] [-l logfile] [-p pidfile]\n\n"
               "-c <file>    Specify the config file\n"
               "-d           Start in debugging mode\n"
               "-h           Print this message and exit\n"
@@ -74,8 +74,6 @@ print_help(void)
               "-n           Don't fork into the background (log screen + log file)\n"
               "-p <file>    Specify the pid file (will be overwritten)\n"
               "-D <dir>     Specify the data directory\n"
-              "-t           Don't run the integrated digest test suite\n"
-              "-T           Exit after running the integrated digest test suite\n"
               "-v           Print version information and exit\n");
 }
 /* *INDENT-ON* */
@@ -338,8 +336,6 @@ int
 atheme_main(int argc, char *argv[])
 {
        int daemonize_pipe[2] = { -1, -1 };
-       bool run_testsuite = true;
-       bool exit_after_testsuite = false;
        bool have_conf = false;
        bool have_log = false;
        bool have_datadir = false;
@@ -361,7 +357,7 @@ atheme_main(int argc, char *argv[])
        atheme_bootstrap();
 
        /* do command-line options */
-       while ((r = mowgli_getopt_long(argc, argv, "c:bdhrtTl:np:D:v", long_opts, NULL)) != -1)
+       while ((r = mowgli_getopt_long(argc, argv, "c:bdhrl:np:D:v", long_opts, NULL)) != -1)
        {
                switch (r)
                {
@@ -388,12 +384,6 @@ atheme_main(int argc, char *argv[])
                  case 'n':
                          runflags |= RF_LIVE;
                          break;
-                 case 't':
-                         run_testsuite = false;
-                         break;
-                 case 'T':
-                         exit_after_testsuite = true;
-                         break;
                  case 'p':
                          pidfilename = mowgli_optarg;
                          break;
@@ -405,17 +395,11 @@ atheme_main(int argc, char *argv[])
                          print_version();
                          exit(EXIT_SUCCESS);
                  default:
-                         fprintf(stderr, "usage: atheme [-bdhnvr] [-t|-T] [-c conf] [-l logfile] [-p pidfile]\n");
+                         fprintf(stderr, "usage: atheme-services [-bdhnvr] [-c conf] [-l logfile] [-p pidfile]\n");
                          exit(EXIT_FAILURE);
                }
        }
 
-       if (! run_testsuite && exit_after_testsuite)
-       {
-               fprintf(stderr, "Error: specify exactly one of -t / -T\n");
-               exit(EXIT_FAILURE);
-       }
-
        if (!have_conf)
                config_file = sstrdup(SYSCONFDIR "/atheme.conf");
 
@@ -432,8 +416,6 @@ atheme_main(int argc, char *argv[])
        atheme_init(argv[0], log_p);
 
        slog(LG_INFO, "%s is starting up...", PACKAGE_STRING);
-       slog(LG_INFO, "Using Digest API frontend: %s", digest_get_frontend_info());
-       slog(LG_INFO, "Using Random API frontend: %s", random_get_frontend_info());
 
        /* check for pid file */
 #ifndef MOWGLI_OS_WIN
@@ -454,26 +436,18 @@ atheme_main(int argc, char *argv[])
        }
 #endif
 
-       if (run_testsuite)
-       {
-               (void) slog(LG_INFO, "running digest testsuite...");
+       (void) slog(LG_INFO, "Using Digest API frontend: %s", digest_get_frontend_info());
+       (void) slog(LG_INFO, "Using Random API frontend: %s", random_get_frontend_info());
 
-               if (! digest_testsuite_run())
-               {
-                       (void) slog(LG_ERROR, "digest testsuite failed");
-                       exit(EXIT_FAILURE);
-               }
-
-               (void) slog(LG_INFO, "digest testsuite passed");
+       (void) slog(LG_INFO, "running digest testsuite...");
 
-               if (exit_after_testsuite)
-               {
-                       (void) slog(LG_INFO, "exiting due to -T");
-                       exit(EXIT_SUCCESS);
-               }
+       if (! digest_testsuite_run())
+       {
+               (void) slog(LG_ERROR, "digest testsuite failed");
+               exit(EXIT_FAILURE);
        }
-       else
-               (void) slog(LG_INFO, "digest testsuite skipped due to -t");
+
+       (void) slog(LG_INFO, "digest testsuite passed");
 
        if (!(runflags & RF_LIVE))
                daemonize(daemonize_pipe);
index cee88303ba85b487733244828a85f70ec43d7832..3ab270bf6b12f9074dc22d1b75f83666a3c0746d 100755 (executable)
@@ -50,6 +50,5 @@ esac
 "${MAKE}"
 "${MAKE}" install
 
-"${ATHEME_PREFIX}"/bin/atheme-services -dnT
-"${ATHEME_PREFIX}"/bin/atheme-crypto-benchmark -io
+"${ATHEME_PREFIX}"/bin/atheme-crypto-benchmark -T
 "${ATHEME_PREFIX}"/bin/atheme-ecdh-x25519-tool -T
index ec66c40c0c4a116817d7bdf7921d9935991c83cd..9d9f20fa177bf8d47646d8e77a38fc8dfdfc09b5 100644 (file)
@@ -6,7 +6,7 @@
 include ../../extra.mk
 
 PROG = ${PACKAGE_TARNAME}-crypto-benchmark${PROG_SUFFIX}
-SRCS = benchmark.c main.c optimal.c
+SRCS = benchmark.c main.c optimal.c selftests.c
 
 include ../../buildsys.mk
 
index 84bbfb19a4f02b4ec2b3c62fe74a9a5539ec9cc1..53d40b9c2e005e53c772dd74ceb2e03d48b4af41 100644 (file)
 #define BENCH_MIN(a, b)             (((a) <= (b)) ? (a) : (b))
 
 #define BENCH_RUN_OPTIONS_NONE      0x0000U
-#define BENCH_RUN_OPTIONS_OPTIMAL   0x0001U
-#define BENCH_RUN_OPTIONS_ARGON2    0x0002U
-#define BENCH_RUN_OPTIONS_SCRYPT    0x0004U
-#define BENCH_RUN_OPTIONS_PBKDF2    0x0008U
+#define BENCH_RUN_OPTIONS_TESTONLY  0x0001U
+#define BENCH_RUN_OPTIONS_OPTIMAL   0x0002U
+#define BENCH_RUN_OPTIONS_ARGON2    0x0004U
+#define BENCH_RUN_OPTIONS_SCRYPT    0x0008U
+#define BENCH_RUN_OPTIONS_PBKDF2    0x0010U
 
 #if defined(HAVE_LIBARGON2) || defined(HAVE_LIBSODIUM_SCRYPT)
 #  define HAVE_ANY_MEMORY_HARD_ALGORITHM 1
index d1d24d306aebc7a4e4d8d45f7f02c89c2c86003e..cdc8c99122ce4c98c6648ad1e3d4e2ad9a3fb1b1 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "benchmark.h"              // (everything else)
 #include "optimal.h"                // do_optimal_benchmarks()
+#include "selftests.h"              // do_crypto_selftests()
 
 #define BENCH_ARRAY_SIZE(x)         ((sizeof((x))) / (sizeof((x)[0])))
 
@@ -85,6 +86,7 @@ static const mowgli_getopt_option_t bench_long_opts[] = {
 
        {                     "help",       no_argument, NULL, 'h', 0 },
        {                  "version",       no_argument, NULL, 'v', 0 },
+       {       "run-selftests-only",       no_argument, NULL, 'T', 0 },
 
        {   "run-optimal-benchmarks",       no_argument, NULL, 'o', 0 },
        {      "optimal-clock-limit", required_argument, NULL, 'g', 0 },
@@ -127,6 +129,7 @@ print_usage(void)
                "\n"
                "  -h/--help                    Display this help information and exit\n"
                "  -v/--version                 Display program version and exit\n"
+               "  -T/--run-selftests-only      Exit after testing all supported algorithms\n"
                "\n"
                "  -o/--run-optimal-benchmarks  Perform an automatic parameter tuning benchmark:\n"
                "  -g/--optimal-clock-limit       Wall clock time limit for optimal benchmarks\n"
@@ -234,6 +237,10 @@ process_options(int argc, char *argv[])
                                // Version string was already printed at program startup
                                exit(EXIT_SUCCESS);
 
+                       case 'T':
+                               run_options |= BENCH_RUN_OPTIONS_TESTONLY;
+                               break;
+
                        case 'o':
                                run_options |= BENCH_RUN_OPTIONS_OPTIMAL;
                                break;
@@ -492,6 +499,7 @@ do_argon2_benchmarks(void)
        (void) bench_print("");
        (void) bench_print("");
        (void) bench_print(_("Beginning customizable Argon2 benchmark ..."));
+
        (void) argon2_print_colheaders();
 
        for (size_t b_argon2_type = 0; b_argon2_type < b_argon2_types_count; b_argon2_type++)
@@ -516,6 +524,7 @@ do_scrypt_benchmarks(void)
        (void) bench_print("");
        (void) bench_print("");
        (void) bench_print(_("Beginning customizable scrypt benchmark ..."));
+
        (void) scrypt_print_colheaders();
 
        for (size_t b_scrypt_memlimit = 0; b_scrypt_memlimit < b_scrypt_memlimits_count; b_scrypt_memlimit++)
@@ -578,6 +587,16 @@ main(int argc, char *argv[])
        (void) bench_print("");
        (void) bench_print(_("Using digest frontend: %s"), digest_get_frontend_info());
 
+       if (! do_crypto_selftests())
+       {
+               (void) bench_print("");
+               (void) bench_print(_("One or more self-tests FAILED (BUG!). Exiting now..."));
+               return EXIT_FAILURE;
+       }
+
+       if ((run_options & BENCH_RUN_OPTIONS_TESTONLY))
+               return EXIT_SUCCESS;
+
        if ((run_options & BENCH_RUN_OPTIONS_OPTIMAL) &&
            ! do_optimal_benchmarks(optimal_clocklimit, optimal_memlimit, optimal_memlimit_given, with_sasl_scram))
                // This function logs error messages on failure
diff --git a/src/crypto-benchmark/selftests.c b/src/crypto-benchmark/selftests.c
new file mode 100644 (file)
index 0000000..59d4395
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * SPDX-License-Identifier: ISC
+ * SPDX-URL: https://spdx.org/licenses/ISC.html
+ *
+ * Copyright (C) 2020 Aaron M. D. Jones <aaronmdjones@gmail.com>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+
+#include <atheme/attributes.h>      // ATHEME_FATTR_WUR
+#include <atheme/digest.h>          // digest_testsuite_run()
+#include <atheme/i18n.h>            // _() (gettext)
+#include <atheme/stdheaders.h>      // (everything else)
+
+#include "benchmark.h"              // bench_print()
+#include "selftests.h"              // self-declarations
+
+bool ATHEME_FATTR_WUR
+do_crypto_selftests(void)
+{
+       bool retval = true;
+
+       if (! digest_testsuite_run())
+       {
+               (void) bench_print(_("The Digest API testsuite FAILED!"));
+               retval = false;
+       }
+       else
+               (void) bench_print(_("The Digest API testsuite passed."));
+
+       return retval;
+}
diff --git a/src/crypto-benchmark/selftests.h b/src/crypto-benchmark/selftests.h
new file mode 100644 (file)
index 0000000..a79a515
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * SPDX-License-Identifier: ISC
+ * SPDX-URL: https://spdx.org/licenses/ISC.html
+ *
+ * Copyright (C) 2020 Aaron M. D. Jones <aaronmdjones@gmail.com>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+
+#ifndef ATHEME_SRC_CRYPTO_BENCHMARK_SELFTESTS_H
+#define ATHEME_SRC_CRYPTO_BENCHMARK_SELFTESTS_H 1
+
+#include <atheme/attributes.h>      // ATHEME_FATTR_WUR
+#include <atheme/stdheaders.h>      // bool
+
+bool do_crypto_selftests(void) ATHEME_FATTR_WUR;
+
+#endif /* !ATHEME_SRC_CRYPTO_BENCHMARK_SELFTESTS_H */