Skip to content

Commit ef2988b

Browse files
committed
add test for robust(windows)
1 parent 6746e1a commit ef2988b

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

test/test_pthread.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11

22
#include <thread>
3+
#include <iostream>
34

45
#include "test.h"
56

6-
#ifdef __linux__
7+
#if defined(__linux__) || defined(__linux)
78
#include <pthread.h>
89
#include <time.h>
910

@@ -21,13 +22,28 @@ TEST(PThread, Robust) {
2122

2223
struct timespec tout;
2324
clock_gettime(CLOCK_REALTIME, &tout);
24-
struct tm *tmp = localtime(&tout.tv_sec);
25-
tout.tv_sec += 1; /* 1 seconds from now */
2625
int r = pthread_mutex_timedlock(&mutex, &tout);
2726
EXPECT_EQ(r, EOWNERDEAD);
2827

2928
pthread_mutex_consistent(&mutex);
3029
pthread_mutex_unlock(&mutex);
3130
pthread_mutex_destroy(&mutex);
3231
}
33-
#endif // __linux__
32+
#elif defined(WIN64) || defined(_WIN64) || defined(__WIN64__) || \
33+
defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
34+
#include <Windows.h>
35+
#include <tchar.h>
36+
37+
TEST(PThread, Robust) {
38+
HANDLE lock = CreateMutex(NULL, FALSE, _T("test-robust"));
39+
std::thread{[] {
40+
HANDLE lock = CreateMutex(NULL, FALSE, _T("test-robust"));
41+
WaitForSingleObject(lock, 0);
42+
}}.join();
43+
44+
DWORD r = WaitForSingleObject(lock, 0);
45+
EXPECT_EQ(r, WAIT_ABANDONED);
46+
47+
CloseHandle(lock);
48+
}
49+
#endif // !__linux__

0 commit comments

Comments
 (0)