From ce1970da8f2fb506df1e58afd39bd3029898c47a Mon Sep 17 00:00:00 2001 From: Florian Fischer <florian.fl.fischer@fau.de> Date: Wed, 27 Jan 2021 14:05:29 +0100 Subject: [PATCH] [test] remove feature_flags from test and introduce io test runner To skip test if emper::IO is false the new io test runner in tests/test-runner is introduced which checks emper::IO and skips the test otherwise executes our normal testMain function. Fixes #10. --- tests/ConcurrentNetworkEchoTest.cpp | 5 +++ tests/fixtures/meson.build | 5 +-- tests/meson.build | 52 +++++++------------------ tests/test-runner/emper-test-runner.cpp | 31 +-------------- tests/test-runner/io-test-runner.cpp | 14 +++++++ tests/test-runner/meson.build | 24 ++++++++---- tests/test-runner/test-runner.cpp | 32 +++++++++++++++ tests/test-runner/test-runner.hpp | 8 ++++ 8 files changed, 93 insertions(+), 78 deletions(-) create mode 100644 tests/test-runner/io-test-runner.cpp create mode 100644 tests/test-runner/test-runner.cpp create mode 100644 tests/test-runner/test-runner.hpp diff --git a/tests/ConcurrentNetworkEchoTest.cpp b/tests/ConcurrentNetworkEchoTest.cpp index 864065c0..0ccfddab 100644 --- a/tests/ConcurrentNetworkEchoTest.cpp +++ b/tests/ConcurrentNetworkEchoTest.cpp @@ -6,6 +6,7 @@ #include <vector> #include "CountingPrivateSemaphore.hpp" +#include "Emper.hpp" #include "Fiber.hpp" #include "Runtime.hpp" #include "emper.hpp" @@ -16,6 +17,10 @@ #define BUF_SIZE 1024 auto main(int argc, char* argv[]) -> int { + if constexpr (!emper::IO) { + exit(77); + } + unsigned int client_count = 10; unsigned int echos = 1000; int port = PORT; diff --git a/tests/fixtures/meson.build b/tests/fixtures/meson.build index 9b3f3c13..37deaeff 100644 --- a/tests/fixtures/meson.build +++ b/tests/fixtures/meson.build @@ -1,9 +1,6 @@ test_fixtures_include_dir = include_directories('.') -test_fixtures_sources = [] -if get_option('io') - test_fixtures_sources += ['network.cpp'] -endif +test_fixtures_sources = ['network.cpp'] test_fixtures_lib = library( 'test-fixtures', diff --git a/tests/meson.build b/tests/meson.build index 264746c2..59ef9414 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -32,7 +32,7 @@ tests = { 'ReuseBpsTest.cpp': { 'description': 'Test resetting of BPSs', - 'emper_test_runner': true, + 'test_runner': 'emper', }, 'SimpleActorTest.cpp': @@ -64,92 +64,82 @@ tests = { 'description': 'Simple test for PrivateSemaphore:signalFromAnywhere()', 'test_suite': 'smoke', # 'is_parallel': true, - 'emper_test_runner': true, + 'test_runner': 'emper', }, 'TellActorFromAnywhereTest.cpp': { 'description': 'Simple test for Actor:tellFromAnywhere()', 'test_suite': 'smoke', # 'is_parallel': true, - 'emper_test_runner': true, + 'test_runner': 'emper', }, 'IncrementalCompletionTest.cpp': { - 'feature_flags': ['io'], 'description': 'Test incremental completion for hugre reads/writes', 'test_suite': 'io', - 'emper_test_runner': true, + 'test_runner': 'io', }, 'ReuseFutureTest.cpp': { - 'feature_flags': ['io'], 'description': 'Test reusing Future objects', 'test_suite': 'io', - 'emper_test_runner': true, + 'test_runner': 'io', }, 'LinkFutureTest.cpp': { - 'feature_flags': ['io'], 'description': 'Test linking Future objects', 'test_suite': 'io', - 'emper_test_runner': true, + 'test_runner': 'io', }, 'TooLongFutureChain.cpp': { - 'feature_flags': ['io'], 'description': 'Test linking Future objects', 'test_suite': 'io', 'should_fail': true, - 'emper_test_runner': true, + 'test_runner': 'io', }, 'AlarmFutureTest.cpp': { - 'feature_flags': ['io'], 'description': 'Test AlarmFuture object based timeouts', 'test_suite': 'io', - 'emper_test_runner': true, + 'test_runner': 'io', }, 'TimeoutWrapperTest.cpp': { - 'feature_flags': ['io'], 'description': 'Test TimeoutWrapper object based IO request timeouts', 'test_suite': 'io', - 'emper_test_runner': true, + 'test_runner': 'io', }, 'CancelFutureTest.cpp': { - 'feature_flags': ['io'], 'description': 'Test Future cancellation', 'test_suite': 'io', - 'emper_test_runner': true, + 'test_runner': 'io', }, 'SimpleNetworkTest.cpp': { - 'feature_flags': ['io'], 'description': 'Simple network test', 'test_suite': 'io', - 'emper_test_runner': true, + 'test_runner': 'io', }, 'SimpleDiskAndNetworkTest.cpp': { - 'feature_flags': ['io'], 'description': 'Simple network and disk IO test', 'test_suite': 'io', - 'emper_test_runner': true, + 'test_runner': 'io', }, 'ConcurrentNetworkEchoTest.cpp': { - 'feature_flags': ['io'], 'description': 'Concurrent network echo test with 10 clients', 'test_suite': 'io', 'args': ['10', '10000'], @@ -170,20 +160,6 @@ test_env = environment( subdir('test-runner') foreach source, test_dict : tests - # check feature flags - if test_dict.has_key('feature_flags') - include_test = true - foreach flag : test_dict.get('feature_flags') - if not get_option(flag) - include_test = false - break - endif - endforeach - - if not include_test - continue - endif - endif # TODO: Use meson fs (filesystem) module once meson >= 0.53 is in # buster-backports, instead of split('.')[0] # test_name = fs.replace_suffix(source, '') @@ -195,8 +171,8 @@ foreach source, test_dict : tests test_deps += test_dict['dependencies'] endif - if test_dict.get('emper_test_runner', false) - test_deps += emper_test_runner_dep + if test_dict.has_key('test_runner') + test_deps += test_runners[test_dict['test_runner']] endif test_exe = executable(test_name, diff --git a/tests/test-runner/emper-test-runner.cpp b/tests/test-runner/emper-test-runner.cpp index 711e757f..b212119f 100644 --- a/tests/test-runner/emper-test-runner.cpp +++ b/tests/test-runner/emper-test-runner.cpp @@ -1,33 +1,6 @@ // SPDX-License-Identifier: LGPL-3.0-or-later // Copyright © 2020 Florian Schmaus -#include <cstdlib> -#include <iostream> - -#include "Fiber.hpp" -#include "Runtime.hpp" #include "emper-common.h" +#include "test-runner.hpp" -void emperTest() __attribute__((weak)); - -static void invokeTest() { - emperTest(); - - exit(EXIT_SUCCESS); -} - -auto main(UNUSED_ARG int argc, UNUSED_ARG char* argv[]) -> int { - if (!&emperTest) { - std::cerr << "ERROR: The emperTest() method is not defined."; - return EXIT_FAILURE; - } - - Runtime runtime; - - Fiber* alphaFiber = Fiber::from(&invokeTest); - - runtime.scheduleFromAnywhere(*alphaFiber); - - runtime.waitUntilFinished(); - - return EXIT_FAILURE; -} +auto main(UNUSED_ARG int argc, UNUSED_ARG char* argv[]) -> int { return testMain(); } diff --git a/tests/test-runner/io-test-runner.cpp b/tests/test-runner/io-test-runner.cpp new file mode 100644 index 00000000..ed4a4b68 --- /dev/null +++ b/tests/test-runner/io-test-runner.cpp @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright © 2020-2021 Florian Schmaus, Florian Fischer +#include <cstdlib> + +#include "Emper.hpp" +#include "emper-common.h" +#include "test-runner.hpp" + +auto main(UNUSED_ARG int argc, UNUSED_ARG char* argv[]) -> int { + if constexpr (!emper::IO) { + exit(77); + } + return testMain(); +} diff --git a/tests/test-runner/meson.build b/tests/test-runner/meson.build index 151b2cab..a949890e 100644 --- a/tests/test-runner/meson.build +++ b/tests/test-runner/meson.build @@ -1,8 +1,18 @@ -emper_test_runner_lib = library('emper-test-runner', - 'emper-test-runner.cpp', - dependencies: emper_dep - ) +test_runners = {} -emper_test_runner_dep = declare_dependency( - link_with : emper_test_runner_lib -) +avail_test_runners = { + 'emper': { + 'sources': ['emper-test-runner.cpp'], + }, + 'io': { + 'sources': ['io-test-runner.cpp'], + }, +} + +foreach runner, runner_dict : avail_test_runners + runner_lib = library(runner + '-test-runner', + ['test-runner.cpp'] + runner_dict['sources'], + dependencies: [emper_dep] + runner_dict.get('deps', [])) + + test_runners += {runner: declare_dependency(link_with: runner_lib)} +endforeach diff --git a/tests/test-runner/test-runner.cpp b/tests/test-runner/test-runner.cpp new file mode 100644 index 00000000..b78c7615 --- /dev/null +++ b/tests/test-runner/test-runner.cpp @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright © 2020-2021 Florian Schmaus, Florian Fischer +#include "test-runner.hpp" + +#include <cstdlib> +#include <iostream> + +#include "Fiber.hpp" +#include "Runtime.hpp" + +void invokeTest() { + emperTest(); + + exit(EXIT_SUCCESS); +} + +auto testMain() -> int { + if (!&emperTest) { + std::cerr << "ERROR: The emperTest() method is not defined."; + return EXIT_FAILURE; + } + + Runtime runtime; + + Fiber* alphaFiber = Fiber::from(&invokeTest); + + runtime.scheduleFromAnywhere(*alphaFiber); + + runtime.waitUntilFinished(); + + return EXIT_FAILURE; +} diff --git a/tests/test-runner/test-runner.hpp b/tests/test-runner/test-runner.hpp new file mode 100644 index 00000000..3819bafc --- /dev/null +++ b/tests/test-runner/test-runner.hpp @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright © 2020-2021 Florian Schmaus, Florian Fischer +#pragma once +void emperTest() __attribute__((weak)); + +void invokeTest(); + +auto testMain() -> int; -- GitLab