Skip to content

Commit c782652

Browse files
author
Zachary Turner
committed
Get test executables compiling on Windows.
Many of the test executables use pthreads directly. This isn't portable on Windows, so this patch converts these test to use C++11 threads and mutexes. Since Windows' implementation of std::thread classes throw and catch from header files, this patch also disables exceptions when compiling with clang on Windows. Reviewed by: Todd Fiala, Ed Maste Differential Revision: http://reviews.llvm.org/D4816 llvm-svn: 215562
1 parent d3d657c commit c782652

File tree

31 files changed

+201
-138
lines changed

31 files changed

+201
-138
lines changed

lldb/test/api/multiple-debuggers/multi-process-driver.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
#include <lldb/API/SBDebugger.h>
3030
#endif
3131

32+
#include <chrono>
33+
#include <thread>
34+
3235
#define NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS 50
3336

3437
#define DEBUG 0
@@ -233,18 +236,18 @@ int main (int argc, char **argv)
233236
inferior_process_name = argv[1];
234237
}
235238

239+
std::thread threads[NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS];
236240
for (uint64_t i = 0; i< NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS; i++)
237241
{
238-
pthread_t thread;
239-
pthread_create (&thread, NULL, do_one_debugger, (void*) i);
242+
threads[i] = std::move(std::thread(do_one_debugger, (void*)i));
240243
}
241244

242245

243246
int max_time_to_wait = 20; // 20 iterations, or 60 seconds
244247
int iter = 0;
245248
while (1)
246249
{
247-
sleep (3);
250+
std::this_thread::sleep_for(std::chrono::seconds(3));
248251
bool all_done = true;
249252
int successful_threads = 0;
250253
int total_completed_threads = 0;

lldb/test/expression_command/call-restarts/TestCallThatRestarts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def test_with_dsym(self):
3030
@dwarf_test
3131
@skipIfLinux # llvm.org/pr19246: intermittent failure
3232
@skipIfDarwin # llvm.org/pr19246: intermittent failure
33+
@skipIfWindows # Test relies on signals, unsupported on Windows
3334
def test_with_dwarf(self):
3435
"""Test calling std::String member function."""
3536
self.buildDwarf()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
LEVEL = ../../make
22

3-
C_SOURCES := wait-a-while.c
3+
CXX_SOURCES := wait-a-while.cpp
44

55
include $(LEVEL)/Makefile.rules

lldb/test/expression_command/timeout/TestCallWithTimeout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def setUp(self):
1515
# Call super's setUp().
1616
TestBase.setUp(self)
1717

18-
self.main_source = "wait-a-while.c"
18+
self.main_source = "wait-a-while.cpp"
1919
self.main_source_spec = lldb.SBFileSpec (self.main_source)
2020

2121

lldb/test/expression_command/timeout/wait-a-while.c

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <stdio.h>
2+
#include <stdint.h>
3+
4+
#include <chrono>
5+
#include <thread>
6+
7+
8+
int
9+
wait_a_while (int microseconds)
10+
{
11+
int num_times = 0;
12+
13+
while (1)
14+
{
15+
num_times++;
16+
std::this_thread::sleep_for(std::chrono::microseconds(microseconds));
17+
break;
18+
}
19+
return num_times;
20+
}
21+
22+
int
23+
main (int argc, char **argv)
24+
{
25+
printf ("stop here in main.\n");
26+
int num_times = wait_a_while (argc * 1000);
27+
printf ("Done, took %d times.\n", num_times);
28+
29+
return 0;
30+
31+
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
LEVEL = ../../make
22

3-
C_SOURCES := main.c
4-
LD_EXTRAS := -lpthread
5-
3+
CXX_SOURCES := main.cpp
4+
ENABLE_THREADS := Yes
65
EXE := AttachResume
76

87
include $(LEVEL)/Makefile.rules

lldb/test/functionalities/attach_resume/TestAttachResume.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def wait_for_state(s, timeout=5):
7070
'Process not stopped after interrupt')
7171

7272
# check that this breakpoint is auto-cleared on detach (r204752)
73-
self.runCmd("br set -f main.c -l 12")
73+
self.runCmd("br set -f main.cpp -l 12")
7474

7575
self.runCmd("c")
7676
self.assertTrue(wait_for_state(lldb.eStateRunning),
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
#include <unistd.h>
21
#include <stdio.h>
32
#include <fcntl.h>
4-
#include <pthread.h>
3+
4+
#include <chrono>
5+
#include <thread>
56

67
void *start(void *data)
78
{
@@ -10,23 +11,21 @@ void *start(void *data)
1011
for (i=0; i<30; i++)
1112
{
1213
if ( idx == 0 )
13-
usleep(1);
14-
sleep(1);
14+
std::this_thread::sleep_for(std::chrono::microseconds(1));
15+
std::this_thread::sleep_for(std::chrono::seconds(1));
1516
}
1617
return 0;
1718
}
1819

1920
int main(int argc, char const *argv[])
2021
{
2122
static const size_t nthreads = 16;
22-
pthread_attr_t attr;
23-
pthread_t threads[nthreads];
23+
std::thread threads[nthreads];
2424
size_t i;
2525

26-
pthread_attr_init(&attr);
2726
for (i=0; i<nthreads; i++)
28-
pthread_create(&threads[i], &attr, &start, (void *)i);
27+
threads[i] = std::move(std::thread(start, (void*)i));
2928

3029
for (i=0; i<nthreads; i++)
31-
pthread_join(threads[i], 0);
30+
threads[i].join();
3231
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
LEVEL = ../../make
22

3-
CFLAGS_EXTRAS := -lpthread
43
C_SOURCES := locking.c
4+
ENABLE_THREADS := YES
55

66
include $(LEVEL)/Makefile.rules

0 commit comments

Comments
 (0)