|
@@ -20,9 +20,9 @@ static int run(void*) {
|
|
static void testStart() {
|
|
static void testStart() {
|
|
runDone = 0;
|
|
runDone = 0;
|
|
Core::Thread t;
|
|
Core::Thread t;
|
|
- CORE_TEST_ERROR(t.start(run, nullptr));
|
|
+ CORE_TEST_FALSE(t.start(run, nullptr));
|
|
int returnValue = 0;
|
|
int returnValue = 0;
|
|
- CORE_TEST_ERROR(t.join(&returnValue));
|
|
+ CORE_TEST_FALSE(t.join(&returnValue));
|
|
CORE_TEST_EQUAL(1, runDone);
|
|
CORE_TEST_EQUAL(1, runDone);
|
|
CORE_TEST_EQUAL(7, returnValue);
|
|
CORE_TEST_EQUAL(7, returnValue);
|
|
}
|
|
}
|
|
@@ -30,54 +30,54 @@ static void testStart() {
|
|
static void testLambda() {
|
|
static void testLambda() {
|
|
IntHolder i(0);
|
|
IntHolder i(0);
|
|
Core::Thread t;
|
|
Core::Thread t;
|
|
- CORE_TEST_ERROR(t.start(
|
|
+ CORE_TEST_FALSE(t.start(
|
|
[](void* p) {
|
|
[](void* p) {
|
|
IntHolder* ip = static_cast<IntHolder*>(p);
|
|
IntHolder* ip = static_cast<IntHolder*>(p);
|
|
ip->value = 2;
|
|
ip->value = 2;
|
|
return 0;
|
|
return 0;
|
|
},
|
|
},
|
|
&i));
|
|
&i));
|
|
- CORE_TEST_ERROR(t.join(nullptr));
|
|
+ CORE_TEST_FALSE(t.join(nullptr));
|
|
CORE_TEST_EQUAL(2, i.value);
|
|
CORE_TEST_EQUAL(2, i.value);
|
|
}
|
|
}
|
|
|
|
|
|
static void testJoinWithoutStart() {
|
|
static void testJoinWithoutStart() {
|
|
Core::Thread t;
|
|
Core::Thread t;
|
|
- CORE_TEST_EQUAL(Core::ErrorCode::THREAD_ERROR, t.join(nullptr));
|
|
+ CORE_TEST_TRUE(t.join(nullptr));
|
|
}
|
|
}
|
|
|
|
|
|
static void testAutoJoin() {
|
|
static void testAutoJoin() {
|
|
Core::Thread t;
|
|
Core::Thread t;
|
|
- CORE_TEST_ERROR(t.start([](void*) { return 0; }, nullptr));
|
|
+ CORE_TEST_FALSE(t.start([](void*) { return 0; }, nullptr));
|
|
}
|
|
}
|
|
|
|
|
|
static void testMove() {
|
|
static void testMove() {
|
|
Core::Thread t;
|
|
Core::Thread t;
|
|
- CORE_TEST_ERROR(t.start([](void*) { return 0; }, nullptr));
|
|
+ CORE_TEST_FALSE(t.start([](void*) { return 0; }, nullptr));
|
|
Core::Thread m = Core::move(t);
|
|
Core::Thread m = Core::move(t);
|
|
- CORE_TEST_ERROR(m.join());
|
|
+ CORE_TEST_FALSE(m.join());
|
|
}
|
|
}
|
|
|
|
|
|
static void testMoveAssignment() {
|
|
static void testMoveAssignment() {
|
|
Core::Thread t;
|
|
Core::Thread t;
|
|
- CORE_TEST_ERROR(t.start([](void*) { return 0; }, nullptr));
|
|
+ CORE_TEST_FALSE(t.start([](void*) { return 0; }, nullptr));
|
|
Core::Thread m;
|
|
Core::Thread m;
|
|
m = Core::move(t);
|
|
m = Core::move(t);
|
|
- CORE_TEST_ERROR(m.join());
|
|
+ CORE_TEST_FALSE(m.join());
|
|
}
|
|
}
|
|
|
|
|
|
static void testMoveIntoActive() {
|
|
static void testMoveIntoActive() {
|
|
Core::Thread t;
|
|
Core::Thread t;
|
|
- CORE_TEST_ERROR(t.start([](void*) { return 0; }, nullptr));
|
|
+ CORE_TEST_FALSE(t.start([](void*) { return 0; }, nullptr));
|
|
Core::Thread m;
|
|
Core::Thread m;
|
|
t = Core::move(m);
|
|
t = Core::move(m);
|
|
}
|
|
}
|
|
|
|
|
|
static void testDoubleJoin() {
|
|
static void testDoubleJoin() {
|
|
Core::Thread t;
|
|
Core::Thread t;
|
|
- CORE_TEST_ERROR(t.start([](void*) { return 0; }, nullptr));
|
|
+ CORE_TEST_FALSE(t.start([](void*) { return 0; }, nullptr));
|
|
- CORE_TEST_ERROR(t.join(nullptr));
|
|
+ CORE_TEST_FALSE(t.join(nullptr));
|
|
- CORE_TEST_EQUAL(Core::ErrorCode::THREAD_ERROR, t.join(nullptr));
|
|
+ CORE_TEST_TRUE(t.join(nullptr));
|
|
}
|
|
}
|
|
|
|
|
|
struct MutexCounter {
|
|
struct MutexCounter {
|
|
@@ -100,12 +100,12 @@ static void testMutex() {
|
|
CORE_TEST_ERROR(Core::Clock::getNanos(n));
|
|
CORE_TEST_ERROR(Core::Clock::getNanos(n));
|
|
|
|
|
|
MutexCounter mc;
|
|
MutexCounter mc;
|
|
- CORE_TEST_ERROR(mc.m.init());
|
|
+ CORE_TEST_FALSE(mc.m.init());
|
|
Core::Thread t[2];
|
|
Core::Thread t[2];
|
|
- CORE_TEST_ERROR(t[0].start(incrementMutexCounter, &mc));
|
|
+ CORE_TEST_FALSE(t[0].start(incrementMutexCounter, &mc));
|
|
- CORE_TEST_ERROR(t[1].start(incrementMutexCounter, &mc));
|
|
+ CORE_TEST_FALSE(t[1].start(incrementMutexCounter, &mc));
|
|
- CORE_TEST_ERROR(t[0].join(nullptr));
|
|
+ CORE_TEST_FALSE(t[0].join(nullptr));
|
|
- CORE_TEST_ERROR(t[1].join(nullptr));
|
|
+ CORE_TEST_FALSE(t[1].join(nullptr));
|
|
CORE_TEST_EQUAL(20000, mc.counter);
|
|
CORE_TEST_EQUAL(20000, mc.counter);
|
|
|
|
|
|
Core::Clock::Nanos n2;
|
|
Core::Clock::Nanos n2;
|
|
@@ -135,10 +135,10 @@ static void testSpinLock() {
|
|
|
|
|
|
SpinLockCounter sc;
|
|
SpinLockCounter sc;
|
|
Core::Thread t[2];
|
|
Core::Thread t[2];
|
|
- CORE_TEST_ERROR(t[0].start(incrementSpinLockCounter, &sc));
|
|
+ CORE_TEST_FALSE(t[0].start(incrementSpinLockCounter, &sc));
|
|
- CORE_TEST_ERROR(t[1].start(incrementSpinLockCounter, &sc));
|
|
+ CORE_TEST_FALSE(t[1].start(incrementSpinLockCounter, &sc));
|
|
- CORE_TEST_ERROR(t[0].join(nullptr));
|
|
+ CORE_TEST_FALSE(t[0].join(nullptr));
|
|
- CORE_TEST_ERROR(t[1].join(nullptr));
|
|
+ CORE_TEST_FALSE(t[1].join(nullptr));
|
|
CORE_TEST_EQUAL(20000, sc.counter);
|
|
CORE_TEST_EQUAL(20000, sc.counter);
|
|
|
|
|
|
Core::Clock::Nanos n2;
|
|
Core::Clock::Nanos n2;
|
|
@@ -147,6 +147,12 @@ static void testSpinLock() {
|
|
s.append(n2 - n).append("ns SpinLock").printLine();
|
|
s.append(n2 - n).append("ns SpinLock").printLine();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static void testDoubleStart() {
|
|
|
|
+ Core::Thread t;
|
|
|
|
+ CORE_TEST_FALSE(t.start([](void*) { return 0; }, nullptr));
|
|
|
|
+ CORE_TEST_TRUE(t.start([](void*) { return 0; }, nullptr));
|
|
|
|
+}
|
|
|
|
+
|
|
void Core::testThread() {
|
|
void Core::testThread() {
|
|
testStart();
|
|
testStart();
|
|
testLambda();
|
|
testLambda();
|
|
@@ -158,4 +164,5 @@ void Core::testThread() {
|
|
testDoubleJoin();
|
|
testDoubleJoin();
|
|
testMutex();
|
|
testMutex();
|
|
testSpinLock();
|
|
testSpinLock();
|
|
|
|
+ testDoubleStart();
|
|
}
|
|
}
|