summaryrefslogtreecommitdiff
path: root/src/tests/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/common')
-rw-r--r--src/tests/common/bit_utils.cpp23
-rw-r--r--src/tests/common/cityhash.cpp22
-rw-r--r--src/tests/common/fibers.cpp28
-rw-r--r--src/tests/common/ring_buffer.cpp10
4 files changed, 41 insertions, 42 deletions
diff --git a/src/tests/common/bit_utils.cpp b/src/tests/common/bit_utils.cpp
deleted file mode 100644
index 479b5995a..000000000
--- a/src/tests/common/bit_utils.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2017 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#include <catch2/catch.hpp>
-#include <math.h>
-#include "common/bit_util.h"
-
-namespace Common {
-
-TEST_CASE("BitUtils::CountTrailingZeroes", "[common]") {
- REQUIRE(Common::CountTrailingZeroes32(0) == 32);
- REQUIRE(Common::CountTrailingZeroes64(0) == 64);
- REQUIRE(Common::CountTrailingZeroes32(9) == 0);
- REQUIRE(Common::CountTrailingZeroes32(8) == 3);
- REQUIRE(Common::CountTrailingZeroes32(0x801000) == 12);
- REQUIRE(Common::CountTrailingZeroes64(9) == 0);
- REQUIRE(Common::CountTrailingZeroes64(8) == 3);
- REQUIRE(Common::CountTrailingZeroes64(0x801000) == 12);
- REQUIRE(Common::CountTrailingZeroes64(0x801000000000UL) == 36);
-}
-
-} // namespace Common
diff --git a/src/tests/common/cityhash.cpp b/src/tests/common/cityhash.cpp
new file mode 100644
index 000000000..7a40b6c4a
--- /dev/null
+++ b/src/tests/common/cityhash.cpp
@@ -0,0 +1,22 @@
+// Copyright 2021 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include <catch2/catch.hpp>
+
+#include "common/cityhash.h"
+
+constexpr char msg[] = "The blue frogs are singing under the crimson sky.\n"
+ "It is time to run, Robert.";
+
+using namespace Common;
+
+TEST_CASE("CityHash", "[common]") {
+ // These test results were built against a known good version.
+ REQUIRE(CityHash64(msg, sizeof(msg)) == 0x92d5c2e9cbfbbc01);
+ REQUIRE(CityHash64WithSeed(msg, sizeof(msg), 0xdead) == 0xbfbe93f21a2820dd);
+ REQUIRE(CityHash64WithSeeds(msg, sizeof(msg), 0xbeef, 0xcafe) == 0xb343317955fc8a06);
+ REQUIRE(CityHash128(msg, sizeof(msg)) == u128{0x98e60d0423747eaa, 0xd8694c5b6fcaede9});
+ REQUIRE(CityHash128WithSeed(msg, sizeof(msg), {0xdead, 0xbeef}) ==
+ u128{0xf0307dba81199ebe, 0xd77764e0c4a9eb74});
+}
diff --git a/src/tests/common/fibers.cpp b/src/tests/common/fibers.cpp
index d94492fc6..751cbe196 100644
--- a/src/tests/common/fibers.cpp
+++ b/src/tests/common/fibers.cpp
@@ -67,7 +67,7 @@ void TestControl1::DoWork() {
value++;
}
results[id] = value;
- Fiber::YieldTo(work_fibers[id], thread_fibers[id]);
+ Fiber::YieldTo(work_fibers[id], *thread_fibers[id]);
}
void TestControl1::ExecuteThread(u32 id) {
@@ -76,7 +76,7 @@ void TestControl1::ExecuteThread(u32 id) {
thread_fibers[id] = thread_fiber;
work_fibers[id] = std::make_shared<Fiber>(std::function<void(void*)>{WorkControl1}, this);
items[id] = rand() % 256;
- Fiber::YieldTo(thread_fibers[id], work_fibers[id]);
+ Fiber::YieldTo(thread_fibers[id], *work_fibers[id]);
thread_fibers[id]->Exit();
}
@@ -117,11 +117,11 @@ public:
for (u32 i = 0; i < 12000; i++) {
value1 += i;
}
- Fiber::YieldTo(fiber1, fiber3);
+ Fiber::YieldTo(fiber1, *fiber3);
const u32 id = thread_ids.Get();
assert1 = id == 1;
value2 += 5000;
- Fiber::YieldTo(fiber1, thread_fibers[id]);
+ Fiber::YieldTo(fiber1, *thread_fibers[id]);
}
void DoWork2() {
@@ -129,7 +129,7 @@ public:
;
value2 = 2000;
trap = false;
- Fiber::YieldTo(fiber2, fiber1);
+ Fiber::YieldTo(fiber2, *fiber1);
assert3 = false;
}
@@ -137,19 +137,19 @@ public:
const u32 id = thread_ids.Get();
assert2 = id == 0;
value1 += 1000;
- Fiber::YieldTo(fiber3, thread_fibers[id]);
+ Fiber::YieldTo(fiber3, *thread_fibers[id]);
}
void ExecuteThread(u32 id);
void CallFiber1() {
const u32 id = thread_ids.Get();
- Fiber::YieldTo(thread_fibers[id], fiber1);
+ Fiber::YieldTo(thread_fibers[id], *fiber1);
}
void CallFiber2() {
const u32 id = thread_ids.Get();
- Fiber::YieldTo(thread_fibers[id], fiber2);
+ Fiber::YieldTo(thread_fibers[id], *fiber2);
}
void Exit();
@@ -241,23 +241,23 @@ public:
void DoWork1() {
value1 += 1;
- Fiber::YieldTo(fiber1, fiber2);
+ Fiber::YieldTo(fiber1, *fiber2);
const u32 id = thread_ids.Get();
value3 += 1;
- Fiber::YieldTo(fiber1, thread_fibers[id]);
+ Fiber::YieldTo(fiber1, *thread_fibers[id]);
}
void DoWork2() {
value2 += 1;
const u32 id = thread_ids.Get();
- Fiber::YieldTo(fiber2, thread_fibers[id]);
+ Fiber::YieldTo(fiber2, *thread_fibers[id]);
}
void ExecuteThread(u32 id);
void CallFiber1() {
const u32 id = thread_ids.Get();
- Fiber::YieldTo(thread_fibers[id], fiber1);
+ Fiber::YieldTo(thread_fibers[id], *fiber1);
}
void Exit();
@@ -332,7 +332,7 @@ public:
void Execute() {
thread_fiber = Fiber::ThreadToFiber();
- Fiber::YieldTo(thread_fiber, fiber1);
+ Fiber::YieldTo(thread_fiber, *fiber1);
thread_fiber->Exit();
}
@@ -340,7 +340,7 @@ public:
fiber1->SetRewindPoint(std::function<void(void*)>{WorkControl4}, this);
if (rewinded) {
goal_reached = true;
- Fiber::YieldTo(fiber1, thread_fiber);
+ Fiber::YieldTo(fiber1, *thread_fiber);
}
rewinded = true;
fiber1->Rewind();
diff --git a/src/tests/common/ring_buffer.cpp b/src/tests/common/ring_buffer.cpp
index 54def22da..903626e4b 100644
--- a/src/tests/common/ring_buffer.cpp
+++ b/src/tests/common/ring_buffer.cpp
@@ -14,7 +14,7 @@
namespace Common {
TEST_CASE("RingBuffer: Basic Tests", "[common]") {
- RingBuffer<char, 4, 1> buf;
+ RingBuffer<char, 4> buf;
// Pushing values into a ring buffer with space should succeed.
for (std::size_t i = 0; i < 4; i++) {
@@ -77,7 +77,7 @@ TEST_CASE("RingBuffer: Basic Tests", "[common]") {
}
TEST_CASE("RingBuffer: Threaded Test", "[common]") {
- RingBuffer<char, 4, 2> buf;
+ RingBuffer<char, 8> buf;
const char seed = 42;
const std::size_t count = 1000000;
std::size_t full = 0;
@@ -92,8 +92,8 @@ TEST_CASE("RingBuffer: Threaded Test", "[common]") {
std::array<char, 2> value = {seed, seed};
std::size_t i = 0;
while (i < count) {
- if (const std::size_t c = buf.Push(&value[0], 1); c > 0) {
- REQUIRE(c == 1U);
+ if (const std::size_t c = buf.Push(&value[0], 2); c > 0) {
+ REQUIRE(c == 2U);
i++;
next_value(value);
} else {
@@ -107,7 +107,7 @@ TEST_CASE("RingBuffer: Threaded Test", "[common]") {
std::array<char, 2> value = {seed, seed};
std::size_t i = 0;
while (i < count) {
- if (const std::vector<char> v = buf.Pop(1); v.size() > 0) {
+ if (const std::vector<char> v = buf.Pop(2); v.size() > 0) {
REQUIRE(v.size() == 2U);
REQUIRE(v[0] == value[0]);
REQUIRE(v[1] == value[1]);