diff options
Diffstat (limited to 'src/tests/common')
| -rw-r--r-- | src/tests/common/bit_field.cpp | 5 | ||||
| -rw-r--r-- | src/tests/common/cityhash.cpp | 5 | ||||
| -rw-r--r-- | src/tests/common/fibers.cpp | 128 | ||||
| -rw-r--r-- | src/tests/common/host_memory.cpp | 5 | ||||
| -rw-r--r-- | src/tests/common/param_package.cpp | 5 | ||||
| -rw-r--r-- | src/tests/common/ring_buffer.cpp | 5 | ||||
| -rw-r--r-- | src/tests/common/unique_function.cpp | 5 |
7 files changed, 49 insertions, 109 deletions
diff --git a/src/tests/common/bit_field.cpp b/src/tests/common/bit_field.cpp index 182638000..0071ae52e 100644 --- a/src/tests/common/bit_field.cpp +++ b/src/tests/common/bit_field.cpp @@ -1,6 +1,5 @@ -// Copyright 2019 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. +// SPDX-FileCopyrightText: 2019 Citra Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later #include <array> #include <cstring> diff --git a/src/tests/common/cityhash.cpp b/src/tests/common/cityhash.cpp index 7a40b6c4a..05942eadb 100644 --- a/src/tests/common/cityhash.cpp +++ b/src/tests/common/cityhash.cpp @@ -1,6 +1,5 @@ -// Copyright 2021 yuzu Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. +// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later #include <catch2/catch.hpp> diff --git a/src/tests/common/fibers.cpp b/src/tests/common/fibers.cpp index 751cbe196..4e29f9199 100644 --- a/src/tests/common/fibers.cpp +++ b/src/tests/common/fibers.cpp @@ -1,6 +1,5 @@ -// Copyright 2020 yuzu Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. +// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later #include <atomic> #include <cstdlib> @@ -44,7 +43,15 @@ class TestControl1 { public: TestControl1() = default; - void DoWork(); + void DoWork() { + const u32 id = thread_ids.Get(); + u32 value = items[id]; + for (u32 i = 0; i < id; i++) { + value++; + } + results[id] = value; + Fiber::YieldTo(work_fibers[id], *thread_fibers[id]); + } void ExecuteThread(u32 id); @@ -55,35 +62,16 @@ public: std::vector<u32> results; }; -static void WorkControl1(void* control) { - auto* test_control = static_cast<TestControl1*>(control); - test_control->DoWork(); -} - -void TestControl1::DoWork() { - const u32 id = thread_ids.Get(); - u32 value = items[id]; - for (u32 i = 0; i < id; i++) { - value++; - } - results[id] = value; - Fiber::YieldTo(work_fibers[id], *thread_fibers[id]); -} - void TestControl1::ExecuteThread(u32 id) { thread_ids.Register(id); auto thread_fiber = Fiber::ThreadToFiber(); thread_fibers[id] = thread_fiber; - work_fibers[id] = std::make_shared<Fiber>(std::function<void(void*)>{WorkControl1}, this); + work_fibers[id] = std::make_shared<Fiber>([this] { DoWork(); }); items[id] = rand() % 256; Fiber::YieldTo(thread_fibers[id], *work_fibers[id]); thread_fibers[id]->Exit(); } -static void ThreadStart1(u32 id, TestControl1& test_control) { - test_control.ExecuteThread(id); -} - /** This test checks for fiber setup configuration and validates that fibers are * doing all the work required. */ @@ -96,7 +84,7 @@ TEST_CASE("Fibers::Setup", "[common]") { test_control.results.resize(num_threads, 0); std::vector<std::thread> threads; for (u32 i = 0; i < num_threads; i++) { - threads.emplace_back(ThreadStart1, i, std::ref(test_control)); + threads.emplace_back([&test_control, i] { test_control.ExecuteThread(i); }); } for (u32 i = 0; i < num_threads; i++) { threads[i].join(); @@ -168,21 +156,6 @@ public: std::shared_ptr<Common::Fiber> fiber3; }; -static void WorkControl2_1(void* control) { - auto* test_control = static_cast<TestControl2*>(control); - test_control->DoWork1(); -} - -static void WorkControl2_2(void* control) { - auto* test_control = static_cast<TestControl2*>(control); - test_control->DoWork2(); -} - -static void WorkControl2_3(void* control) { - auto* test_control = static_cast<TestControl2*>(control); - test_control->DoWork3(); -} - void TestControl2::ExecuteThread(u32 id) { thread_ids.Register(id); auto thread_fiber = Fiber::ThreadToFiber(); @@ -194,18 +167,6 @@ void TestControl2::Exit() { thread_fibers[id]->Exit(); } -static void ThreadStart2_1(u32 id, TestControl2& test_control) { - test_control.ExecuteThread(id); - test_control.CallFiber1(); - test_control.Exit(); -} - -static void ThreadStart2_2(u32 id, TestControl2& test_control) { - test_control.ExecuteThread(id); - test_control.CallFiber2(); - test_control.Exit(); -} - /** This test checks for fiber thread exchange configuration and validates that fibers are * that a fiber has been successfully transferred from one thread to another and that the TLS * region of the thread is kept while changing fibers. @@ -213,14 +174,19 @@ static void ThreadStart2_2(u32 id, TestControl2& test_control) { TEST_CASE("Fibers::InterExchange", "[common]") { TestControl2 test_control{}; test_control.thread_fibers.resize(2); - test_control.fiber1 = - std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_1}, &test_control); - test_control.fiber2 = - std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_2}, &test_control); - test_control.fiber3 = - std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_3}, &test_control); - std::thread thread1(ThreadStart2_1, 0, std::ref(test_control)); - std::thread thread2(ThreadStart2_2, 1, std::ref(test_control)); + test_control.fiber1 = std::make_shared<Fiber>([&test_control] { test_control.DoWork1(); }); + test_control.fiber2 = std::make_shared<Fiber>([&test_control] { test_control.DoWork2(); }); + test_control.fiber3 = std::make_shared<Fiber>([&test_control] { test_control.DoWork3(); }); + std::thread thread1{[&test_control] { + test_control.ExecuteThread(0); + test_control.CallFiber1(); + test_control.Exit(); + }}; + std::thread thread2{[&test_control] { + test_control.ExecuteThread(1); + test_control.CallFiber2(); + test_control.Exit(); + }}; thread1.join(); thread2.join(); REQUIRE(test_control.assert1); @@ -271,16 +237,6 @@ public: std::shared_ptr<Common::Fiber> fiber2; }; -static void WorkControl3_1(void* control) { - auto* test_control = static_cast<TestControl3*>(control); - test_control->DoWork1(); -} - -static void WorkControl3_2(void* control) { - auto* test_control = static_cast<TestControl3*>(control); - test_control->DoWork2(); -} - void TestControl3::ExecuteThread(u32 id) { thread_ids.Register(id); auto thread_fiber = Fiber::ThreadToFiber(); @@ -292,12 +248,6 @@ void TestControl3::Exit() { thread_fibers[id]->Exit(); } -static void ThreadStart3(u32 id, TestControl3& test_control) { - test_control.ExecuteThread(id); - test_control.CallFiber1(); - test_control.Exit(); -} - /** This test checks for one two threads racing for starting the same fiber. * It checks execution occurred in an ordered manner and by no time there were * two contexts at the same time. @@ -305,12 +255,15 @@ static void ThreadStart3(u32 id, TestControl3& test_control) { TEST_CASE("Fibers::StartRace", "[common]") { TestControl3 test_control{}; test_control.thread_fibers.resize(2); - test_control.fiber1 = - std::make_shared<Fiber>(std::function<void(void*)>{WorkControl3_1}, &test_control); - test_control.fiber2 = - std::make_shared<Fiber>(std::function<void(void*)>{WorkControl3_2}, &test_control); - std::thread thread1(ThreadStart3, 0, std::ref(test_control)); - std::thread thread2(ThreadStart3, 1, std::ref(test_control)); + test_control.fiber1 = std::make_shared<Fiber>([&test_control] { test_control.DoWork1(); }); + test_control.fiber2 = std::make_shared<Fiber>([&test_control] { test_control.DoWork2(); }); + const auto race_function{[&test_control](u32 id) { + test_control.ExecuteThread(id); + test_control.CallFiber1(); + test_control.Exit(); + }}; + std::thread thread1([&] { race_function(0); }); + std::thread thread2([&] { race_function(1); }); thread1.join(); thread2.join(); REQUIRE(test_control.value1 == 1); @@ -320,12 +273,10 @@ TEST_CASE("Fibers::StartRace", "[common]") { class TestControl4; -static void WorkControl4(void* control); - class TestControl4 { public: TestControl4() { - fiber1 = std::make_shared<Fiber>(std::function<void(void*)>{WorkControl4}, this); + fiber1 = std::make_shared<Fiber>([this] { DoWork(); }); goal_reached = false; rewinded = false; } @@ -337,7 +288,7 @@ public: } void DoWork() { - fiber1->SetRewindPoint(std::function<void(void*)>{WorkControl4}, this); + fiber1->SetRewindPoint([this] { DoWork(); }); if (rewinded) { goal_reached = true; Fiber::YieldTo(fiber1, *thread_fiber); @@ -352,11 +303,6 @@ public: bool rewinded; }; -static void WorkControl4(void* control) { - auto* test_control = static_cast<TestControl4*>(control); - test_control->DoWork(); -} - TEST_CASE("Fibers::Rewind", "[common]") { TestControl4 test_control{}; test_control.Execute(); diff --git a/src/tests/common/host_memory.cpp b/src/tests/common/host_memory.cpp index 2dc7b5d5e..e49d0a09f 100644 --- a/src/tests/common/host_memory.cpp +++ b/src/tests/common/host_memory.cpp @@ -1,6 +1,5 @@ -// Copyright 2021 yuzu emulator team -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. +// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later #include <catch2/catch.hpp> diff --git a/src/tests/common/param_package.cpp b/src/tests/common/param_package.cpp index e31ca3544..d036cc83a 100644 --- a/src/tests/common/param_package.cpp +++ b/src/tests/common/param_package.cpp @@ -1,6 +1,5 @@ -// Copyright 2017 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. +// SPDX-FileCopyrightText: 2017 Citra Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later #include <catch2/catch.hpp> #include <math.h> diff --git a/src/tests/common/ring_buffer.cpp b/src/tests/common/ring_buffer.cpp index 903626e4b..4f81b6e5e 100644 --- a/src/tests/common/ring_buffer.cpp +++ b/src/tests/common/ring_buffer.cpp @@ -1,6 +1,5 @@ -// Copyright 2018 yuzu emulator team -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. +// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later #include <algorithm> #include <array> diff --git a/src/tests/common/unique_function.cpp b/src/tests/common/unique_function.cpp index aa6e86593..311272506 100644 --- a/src/tests/common/unique_function.cpp +++ b/src/tests/common/unique_function.cpp @@ -1,6 +1,5 @@ -// Copyright 2021 yuzu Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. +// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later #include <string> |
