diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-03-15 11:39:31 +0100 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-03-15 11:39:31 +0100 |
commit | 68a6e9658047aa04f16870dbc48ba79a2963a650 (patch) | |
tree | ce8c206d0e2da384362a8dd805881d5bfb250663 /modules/async | |
parent | e69e7b542f9a0aa3101cc5a13e2be30975e6a301 (diff) |
async: Introducing minor tests for immediate conveyors
Diffstat (limited to 'modules/async')
-rw-r--r-- | modules/async/.nix/derivation.nix | 8 | ||||
-rw-r--r-- | modules/async/SConstruct | 1 | ||||
-rw-r--r-- | modules/async/c++/SConscript | 8 | ||||
-rw-r--r-- | modules/async/c++/async.hpp | 3 | ||||
-rw-r--r-- | modules/async/tests/SConscript | 31 | ||||
-rw-r--r-- | modules/async/tests/immediate.cpp | 52 |
6 files changed, 98 insertions, 5 deletions
diff --git a/modules/async/.nix/derivation.nix b/modules/async/.nix/derivation.nix index aad258f..3992ea1 100644 --- a/modules/async/.nix/derivation.nix +++ b/modules/async/.nix/derivation.nix @@ -22,7 +22,13 @@ in stdenv.mkDerivation { buildInputs = [ forstio.core - ]; + ]; + + doCheck = true; + checkPhase = '' + scons test + ./bin/tests + ''; outputs = ["out" "dev"]; } diff --git a/modules/async/SConstruct b/modules/async/SConstruct index def568e..f71db5a 100644 --- a/modules/async/SConstruct +++ b/modules/async/SConstruct @@ -58,6 +58,7 @@ env.targets = []; Export('env') SConscript('c++/SConscript') +SConscript('tests/SConscript') env.Alias('cdb', env.cdb); env.Alias('all', [env.targets]); diff --git a/modules/async/c++/SConscript b/modules/async/c++/SConscript index 57707c4..0363355 100644 --- a/modules/async/c++/SConscript +++ b/modules/async/c++/SConscript @@ -21,18 +21,18 @@ env.headers += async_env.headers; ## Shared lib objects_shared = [] async_env.add_source_files(objects_shared, async_env.sources, shared=True); -async_env.library_shared = async_env.SharedLibrary('#build/forstio-async', [objects_shared]); +env.library_shared = async_env.SharedLibrary('#build/forstio-async', [objects_shared]); ## Static lib objects_static = [] async_env.add_source_files(objects_static, async_env.sources, shared=False); -async_env.library_static = async_env.StaticLibrary('#build/forstio-async', [objects_static]); +env.library_static = async_env.StaticLibrary('#build/forstio-async', [objects_static]); # Set Alias -env.Alias('library_async', [async_env.library_shared, async_env.library_static]); +env.Alias('library_async', [env.library_shared, env.library_static]); env.targets += ['library_async']; # Install -env.Install('$prefix/lib/', [async_env.library_shared, async_env.library_static]); +env.Install('$prefix/lib/', [env.library_shared, env.library_static]); env.Install('$prefix/include/forstio/async/', [async_env.headers]); diff --git a/modules/async/c++/async.hpp b/modules/async/c++/async.hpp index d116499..257fbd7 100644 --- a/modules/async/c++/async.hpp +++ b/modules/async/c++/async.hpp @@ -829,6 +829,9 @@ public: } }; +/** + * An immediately fulfilled node either containing a value or an error. + */ class immediate_conveyor_node_base : public conveyor_node, public conveyor_event_storage { private: diff --git a/modules/async/tests/SConscript b/modules/async/tests/SConscript new file mode 100644 index 0000000..f8ffc92 --- /dev/null +++ b/modules/async/tests/SConscript @@ -0,0 +1,31 @@ +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +test_cases_env = env.Clone(); + +test_cases_env.Append(LIBS=['forstio-test']); + +test_cases_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) +test_cases_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) + +env.sources += test_cases_env.sources; +env.headers += test_cases_env.headers; + +objects_static = [] +test_cases_env.add_source_files(objects_static, test_cases_env.sources, shared=False); +test_cases_env.program = test_cases_env.Program('#bin/tests', [objects_static, env.library_static]); + +# Set Alias +env.Alias('test', test_cases_env.program); +env.Alias('check', test_cases_env.program); + +env.targets += ['test','check']; diff --git a/modules/async/tests/immediate.cpp b/modules/async/tests/immediate.cpp new file mode 100644 index 0000000..a5d9b2f --- /dev/null +++ b/modules/async/tests/immediate.cpp @@ -0,0 +1,52 @@ +#include <forstio/test/suite.hpp> + +#include <forstio/templates.hpp> + +#include "../c++/async.hpp" + +namespace { +SAW_TEST("Immediate Conveyor"){ + using namespace saw; + + event_loop loop; + wait_scope wait{loop}; + + int val = 5; + conveyor<int> immediately_done{val}; + + int passed = 0; + auto res = immediately_done.then([&passed](int a) { + passed = a; + }).sink(); + + wait.poll(); + + SAW_EXPECT(passed == val, "Expected a 5 in passed value."); +} + +SAW_TEST("Immediate Conveyor Queueing"){ + using namespace saw; + + event_loop loop; + wait_scope wait{loop}; + + int val = 5; + conveyor<int> immediately_done{val}; + + int passed = 0; + auto res = immediately_done.then([&passed](int a) { + passed = a; + }).sink([](auto err){ + SAW_EXPECT(false, "No error should occur. This code path shouldn't be reachable."); + return err; + }); + + wait.poll(); + wait.poll(); + wait.poll(); + wait.poll(); + wait.poll(); + + SAW_EXPECT(passed == val, "Expected a 5 in passed value."); +} +} |