2023-09-08 11:35:18 +02:00
|
|
|
/* Main Unit Test entry point.
|
2017-11-21 21:31:08 +01:00
|
|
|
*
|
2023-01-07 17:20:15 +01:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
2023-01-07 17:32:48 +01:00
|
|
|
* SPDX-FileCopyrightText: 2017 Steffen Vogel <post@steffenvogel.de>
|
2023-01-07 17:20:15 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2023-09-08 11:35:18 +02:00
|
|
|
*/
|
2017-11-21 21:31:08 +01:00
|
|
|
|
|
|
|
#include <criterion/criterion.h>
|
2018-01-31 15:11:13 +01:00
|
|
|
#include <criterion/hooks.h>
|
|
|
|
#include <criterion/internal/ordered-set.h>
|
2024-02-29 19:34:27 +01:00
|
|
|
#include <criterion/options.h>
|
2017-11-21 21:31:08 +01:00
|
|
|
|
2017-12-19 19:06:30 +01:00
|
|
|
#include <villas/log.hpp>
|
2017-12-06 17:37:15 +01:00
|
|
|
|
2018-01-10 15:26:52 +01:00
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
|
2022-08-30 12:01:47 -04:00
|
|
|
// Returns true if there is at least one enabled test in this suite
|
2024-02-29 19:34:27 +01:00
|
|
|
static bool suite_enabled(struct criterion_test_set *tests, const char *name) {
|
|
|
|
FOREACH_SET(void *suite_ptr, tests->suites) {
|
|
|
|
struct criterion_suite_set *suite = (struct criterion_suite_set *)suite_ptr;
|
2018-01-30 15:08:28 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
if (!strcmp(suite->suite.name, name)) {
|
|
|
|
FOREACH_SET(void *test_ptr, suite->tests) {
|
|
|
|
struct criterion_test *test = (struct criterion_test *)test_ptr;
|
2018-01-31 15:12:19 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
if (!test->data->disabled)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-30 12:01:47 -04:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
return false;
|
2018-01-31 15:12:19 +01:00
|
|
|
}
|
|
|
|
|
2022-08-30 12:01:47 -04:00
|
|
|
// Limit number of parallel jobs to 1 in case we use the FPGA
|
2024-02-29 19:34:27 +01:00
|
|
|
ReportHook(PRE_ALL)(struct criterion_test_set *tests) {
|
|
|
|
if (suite_enabled(tests, "fpga")) {
|
|
|
|
auto logger = villas::logging.get("unittest");
|
2018-01-31 15:12:19 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
logger->info("FPGA tests enabled. Only 1 job is executed in parallel!.");
|
|
|
|
criterion_options.jobs = 1;
|
|
|
|
}
|
2018-01-31 15:12:19 +01:00
|
|
|
}
|
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
int ret;
|
2018-02-13 15:39:03 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
spdlog::set_level(spdlog::level::debug);
|
|
|
|
spdlog::set_pattern("[%T] [%l] [%n] %v");
|
2018-02-13 15:39:03 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
// Run criterion tests
|
|
|
|
auto tests = criterion_initialize();
|
2018-01-31 15:12:19 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
ret = criterion_handle_args(argc, argv, true);
|
|
|
|
if (ret)
|
|
|
|
ret = !criterion_run_all_tests(tests);
|
2018-01-31 15:12:19 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
criterion_finalize(tests);
|
2018-01-31 15:12:19 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
return ret;
|
2018-01-31 15:12:19 +01:00
|
|
|
}
|