diff options
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | src/tests/common/bit_field.cpp | 5 | ||||
| -rw-r--r-- | src/tests/common/fibers.cpp | 123 | ||||
| -rw-r--r-- | src/tests/common/param_package.cpp | 5 | ||||
| -rw-r--r-- | src/tests/core/core_timing.cpp | 5 | ||||
| -rw-r--r-- | src/tests/core/internal_network/network.cpp (renamed from src/tests/core/network/network.cpp) | 4 | ||||
| -rw-r--r-- | src/tests/tests.cpp | 5 | 
7 files changed, 51 insertions, 101 deletions
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index a69ccb264..43ad2c7ff 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2018 yuzu Emulator Project +# SPDX-License-Identifier: GPL-2.0-or-later +  add_executable(tests      common/bit_field.cpp      common/cityhash.cpp @@ -7,7 +10,7 @@ add_executable(tests      common/ring_buffer.cpp      common/unique_function.cpp      core/core_timing.cpp -    core/network/network.cpp +    core/internal_network/network.cpp      tests.cpp      video_core/buffer_base.cpp      input_common/calibration_configuration_job.cpp 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/fibers.cpp b/src/tests/common/fibers.cpp index cfc84d423..4e29f9199 100644 --- a/src/tests/common/fibers.cpp +++ b/src/tests/common/fibers.cpp @@ -43,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); @@ -54,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.   */ @@ -95,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(); @@ -167,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(); @@ -193,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. @@ -212,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); @@ -270,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(); @@ -291,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. @@ -304,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); @@ -319,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;      } @@ -336,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); @@ -351,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/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/core/core_timing.cpp b/src/tests/core/core_timing.cpp index 8358d36b5..7c432a63c 100644 --- a/src/tests/core/core_timing.cpp +++ b/src/tests/core/core_timing.cpp @@ -8,6 +8,7 @@  #include <chrono>  #include <cstdlib>  #include <memory> +#include <optional>  #include <string>  #include "core/core.h" @@ -23,13 +24,15 @@ std::bitset<CB_IDS.size()> callbacks_ran_flags;  u64 expected_callback = 0;  template <unsigned int IDX> -void HostCallbackTemplate(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { +std::optional<std::chrono::nanoseconds> HostCallbackTemplate(std::uintptr_t user_data, s64 time, +                                                             std::chrono::nanoseconds ns_late) {      static_assert(IDX < CB_IDS.size(), "IDX out of range");      callbacks_ran_flags.set(IDX);      REQUIRE(CB_IDS[IDX] == user_data);      REQUIRE(CB_IDS[IDX] == CB_IDS[calls_order[expected_callback]]);      delays[IDX] = ns_late.count();      ++expected_callback; +    return std::nullopt;  }  struct ScopeInit final { diff --git a/src/tests/core/network/network.cpp b/src/tests/core/internal_network/network.cpp index 1bbb8372f..164b0ff24 100644 --- a/src/tests/core/network/network.cpp +++ b/src/tests/core/internal_network/network.cpp @@ -3,8 +3,8 @@  #include <catch2/catch.hpp> -#include "core/network/network.h" -#include "core/network/sockets.h" +#include "core/internal_network/network.h" +#include "core/internal_network/sockets.h"  TEST_CASE("Network::Errors", "[core]") {      Network::NetworkInstance network_instance; // initialize network diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index 275b430d9..3f905c05c 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -1,6 +1,5 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. +// SPDX-FileCopyrightText: 2016 Citra Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later  #define CATCH_CONFIG_MAIN  #include <catch2/catch.hpp>  | 
