2021-12-17 15:43:58 -06:00
|
|
|
#include "storm/Thread.hpp"
|
2025-03-31 14:19:47 -04:00
|
|
|
#include <bc/Memory.hpp>
|
2021-12-17 15:43:58 -06:00
|
|
|
#include "test/Test.hpp"
|
|
|
|
|
|
2022-12-28 20:03:31 -06:00
|
|
|
uint32_t threadProc(void* param) {
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-26 23:07:48 -05:00
|
|
|
TEST_CASE("CCritSect::Enter", "[thread]") {
|
|
|
|
|
SECTION("locks critical section") {
|
|
|
|
|
CCritSect critSect;
|
|
|
|
|
critSect.Enter();
|
|
|
|
|
SUCCEED();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("CCritSect::Leave", "[thread]") {
|
|
|
|
|
SECTION("unlocks critical section") {
|
|
|
|
|
CCritSect critSect;
|
|
|
|
|
critSect.Enter();
|
|
|
|
|
critSect.Leave();
|
|
|
|
|
SUCCEED();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-17 15:43:58 -06:00
|
|
|
TEST_CASE("SGetCurrentThreadId", "[thread]") {
|
|
|
|
|
SECTION("returns thread id") {
|
|
|
|
|
uintptr_t threadId = SGetCurrentThreadId();
|
|
|
|
|
CHECK(threadId > 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-28 15:43:57 -06:00
|
|
|
|
|
|
|
|
TEST_CASE("SCritSect::Enter", "[thread]") {
|
|
|
|
|
SECTION("locks critical section") {
|
|
|
|
|
SCritSect critSect;
|
|
|
|
|
critSect.Enter();
|
|
|
|
|
SUCCEED();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("SCritSect::Leave", "[thread]") {
|
|
|
|
|
SECTION("unlocks critical section") {
|
|
|
|
|
SCritSect critSect;
|
|
|
|
|
critSect.Enter();
|
|
|
|
|
critSect.Leave();
|
|
|
|
|
SUCCEED();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-28 20:03:31 -06:00
|
|
|
|
|
|
|
|
TEST_CASE("SThread::Create", "[thread]") {
|
|
|
|
|
SECTION("creates new thread") {
|
|
|
|
|
SThread thread;
|
2022-12-28 22:52:14 -06:00
|
|
|
auto threadName = const_cast<char*>("TestThread");
|
|
|
|
|
auto threadParam = SMemAlloc(16, nullptr, 0, 0x0);
|
|
|
|
|
REQUIRE(SThread::Create(threadProc, threadParam, thread, threadName, 0) != 0);
|
2024-02-20 18:52:22 -05:00
|
|
|
thread.Wait(100);
|
2022-12-28 20:03:31 -06:00
|
|
|
}
|
|
|
|
|
}
|