From: Wolfgang Bangerth Date: Wed, 22 May 2024 03:24:20 +0000 (-0600) Subject: Add tests. X-Git-Tag: v9.6.0-rc1~144^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52c7d36d3e577726e9369a4dbc6551ac961b2860;p=dealii.git Add tests. --- diff --git a/tests/multithreading/task_result_01.cc b/tests/multithreading/task_result_01.cc new file mode 100644 index 0000000000..2f361e9849 --- /dev/null +++ b/tests/multithreading/task_result_01.cc @@ -0,0 +1,43 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2009 - 2020 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + +// A test for basic functionality of the TaskResult function + +#include + +#include "../tests.h" + + + +int +main() +{ + initlog(); + + // Create a background task that sleeps for a while and then + // issues its result. Associate this background task with + // a TaskResult object. + Threads::TaskResult t = Threads::new_task([]() { + std::this_thread::sleep_for(std::chrono::seconds(1)); + return 42; + }); + + // Wait for that background task to finish, then get its + // value: + deallog << t.value() << std::endl; + + // Ensure that we can continue to ask for the return value: + deallog << t.value() << std::endl; +} diff --git a/tests/multithreading/task_result_01.output b/tests/multithreading/task_result_01.output new file mode 100644 index 0000000000..85ecae61a0 --- /dev/null +++ b/tests/multithreading/task_result_01.output @@ -0,0 +1,3 @@ + +DEAL::42 +DEAL::42 diff --git a/tests/multithreading/task_result_02.cc b/tests/multithreading/task_result_02.cc new file mode 100644 index 0000000000..f3e7ed70e0 --- /dev/null +++ b/tests/multithreading/task_result_02.cc @@ -0,0 +1,47 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2009 - 2020 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + +// A test for basic functionality of the TaskResult function. This +// test checks the move constructor. + +#include + +#include "../tests.h" + + + +int +main() +{ + initlog(); + + // Create a background task that sleeps for a while and then + // issues its result. Associate this background task with + // a TaskResult object. + Threads::TaskResult t = Threads::new_task([]() { + std::this_thread::sleep_for(std::chrono::seconds(1)); + return 42; + }); + + // Move the task + Threads::TaskResult tt = std::move(t); + + // Wait for that background task to finish, then get its + // value: + deallog << tt.value() << std::endl; + + // Ensure that we can continue to ask for the return value: + deallog << tt.value() << std::endl; +} diff --git a/tests/multithreading/task_result_02.output b/tests/multithreading/task_result_02.output new file mode 100644 index 0000000000..85ecae61a0 --- /dev/null +++ b/tests/multithreading/task_result_02.output @@ -0,0 +1,3 @@ + +DEAL::42 +DEAL::42