From ea22643b2217921df74ea14df47d7c83987d5761 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 9 Dec 2016 17:29:27 +0200 Subject: Initial parallel scheduler implementation, use to run testscrips --- unit-tests/buildfile | 2 +- unit-tests/scheduler/buildfile | 14 +++++ unit-tests/scheduler/driver.cxx | 94 ++++++++++++++++++++++++++++++ unit-tests/test/script/lexer/variable.test | 14 ++--- unit-tests/test/script/parser/buildfile | 5 +- unit-tests/test/script/parser/driver.cxx | 2 + 6 files changed, 119 insertions(+), 12 deletions(-) create mode 100644 unit-tests/scheduler/buildfile create mode 100644 unit-tests/scheduler/driver.cxx (limited to 'unit-tests') diff --git a/unit-tests/buildfile b/unit-tests/buildfile index f8cfb9d..feebda6 100644 --- a/unit-tests/buildfile +++ b/unit-tests/buildfile @@ -2,6 +2,6 @@ # copyright : Copyright (c) 2014-2016 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -d = function/ lexer/ test/script/ +d = function/ lexer/ scheduler/ test/script/ ./: $d include $d diff --git a/unit-tests/scheduler/buildfile b/unit-tests/scheduler/buildfile new file mode 100644 index 0000000..cfcd3cb --- /dev/null +++ b/unit-tests/scheduler/buildfile @@ -0,0 +1,14 @@ +# file : unit-tests/scheduler/buildfile +# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +#@@ Temporary until we get utility library support. +# +if ($cxx.target.class != "windows") + cxx.libs += -lpthread +import libs = libbutl%lib{butl} +src = scheduler diagnostics utility variable name b-options types-parsers + +exe{driver}: cxx{driver} ../../build2/cxx{$src} $libs + +include ../../build2/ diff --git a/unit-tests/scheduler/driver.cxx b/unit-tests/scheduler/driver.cxx new file mode 100644 index 0000000..65ba5e5 --- /dev/null +++ b/unit-tests/scheduler/driver.cxx @@ -0,0 +1,94 @@ +// file : unit-tests/scheduler/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include +#include + +#include +#include + +#include + +using namespace std; + +namespace build2 +{ + int + main () + { + //scheduler s (1); + scheduler s (scheduler::hardware_concurrency ()); + + auto inner = [] (size_t x, size_t y, size_t& out) + { + out = x + y; + this_thread::sleep_for (chrono::microseconds (out * 10)); + }; + + auto outer = [&s, &inner] (size_t n, size_t& out) + { + vector result (2 * n, 0); + scheduler::atomic_count task_count (0); + + for (size_t i (0); i != 2 * n; ++i) + { + s.async (task_count, + inner, + i, + i, + std::ref (result[i])); + } + + s.wait (task_count); + assert (task_count == 0); + + for (size_t i (0); i != n; ++i) + out += result[i]; + + this_thread::sleep_for (chrono::microseconds (out * 10)); + }; + + const size_t tasks (50); + + vector result (tasks, 0); + scheduler::atomic_count task_count (0); + + for (size_t i (0); i != tasks; ++i) + { + s.async (task_count, + outer, + i, + std::ref (result[i])); + } + + s.wait (task_count); + assert (task_count == 0); + + scheduler::stat st (s.shutdown ()); + + /* + cerr << "thread_max_active " << st.thread_max_active << endl + << "thread_max_total " << st.thread_max_total << endl + << "thread_helpers " << st.thread_helpers << endl + << "thread_max_waiting " << st.thread_max_waiting << endl + << endl + << "task_queue_depth " << st.task_queue_depth << endl + << "task_queue_full " << st.task_queue_full << endl + << endl + << "wait_queue_slots " << st.wait_queue_slots << endl + << "wait_queue_collisions " << st.wait_queue_collisions << endl; + */ + + return 0; + } +} + +int +main () +{ + return build2::main (); +} diff --git a/unit-tests/test/script/lexer/variable.test b/unit-tests/test/script/lexer/variable.test index 6478fea..302a8b1 100644 --- a/unit-tests/test/script/lexer/variable.test +++ b/unit-tests/test/script/lexer/variable.test @@ -29,18 +29,12 @@ $* <"0" >>EOO EOO -$* <"10" >>EOO -'10' - -EOO - -$* <"101" >>EOO -'101' - -EOO - $* <"1abc" >>EOO '1' 'abc' EOO + +$* <"10" 2>>EOE != 0 +stdin:1:1: error: multi-digit special variable name +EOE diff --git a/unit-tests/test/script/parser/buildfile b/unit-tests/test/script/parser/buildfile index b570901..ad32494 100644 --- a/unit-tests/test/script/parser/buildfile +++ b/unit-tests/test/script/parser/buildfile @@ -4,12 +4,15 @@ #@@ Temporary until we get utility library support. # +if ($cxx.target.class != "windows") + cxx.libs += -lpthread import libs = libbutl%lib{butl} src = token lexer parser diagnostics utility variable name context target \ scope prerequisite file module operation rule b-options algorithm search \ filesystem function functions-builtin functions-path functions-process-path \ functions-string config/{utility init operation} dump types-parsers \ -test/{target script/{token lexer parser script}} +test/{target script/{token lexer parser script}} \ +scheduler exe{driver}: cxx{driver} ../../../../build2/cxx{$src} $libs \ test{cleanup command-if command-re-parse description exit expansion \ diff --git a/unit-tests/test/script/parser/driver.cxx b/unit-tests/test/script/parser/driver.cxx index 83160cb..c116680 100644 --- a/unit-tests/test/script/parser/driver.cxx +++ b/unit-tests/test/script/parser/driver.cxx @@ -10,6 +10,7 @@ #include #include +#include #include @@ -136,6 +137,7 @@ namespace build2 tracer trace ("main"); init (argv[0], 1); // Fake build system driver, default verbosity. + sched.startup (1); // Serial execution. reset (strings ()); // No command line variables. bool scope (false); -- cgit v1.1