MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / RunTest

Function RunTest

test/pthread/test_pthread_atomics.c:102–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100pthread_t thread[NUM_THREADS];
101
102void RunTest(int test)
103{
104 pthread_attr_t attr;
105 pthread_attr_init(&attr);
106 pthread_attr_setstacksize(&attr, 4*1024);
107
108 emscripten_outf("Main thread has thread ID %ld\n", (intptr_t)pthread_self());
109 assert(pthread_self() != 0);
110
111 switch(test)
112 {
113 case 2: memset(sharedData, 0xFF, sizeof(sharedData)); break;
114 case 5: memset(sharedData, 0x10, sizeof(sharedData)); break;
115 default: memset(sharedData, 0, sizeof(sharedData)); break;
116 }
117
118 emscripten_outf("Main: Starting test %d", test);
119
120 for(int i = 0; i < NUM_THREADS; ++i)
121 {
122 t[i].op = test;
123 t[i].threadId = i;
124 int rc = pthread_create(&thread[i], &attr, ThreadMain, &t[i]);
125 assert(rc == 0);
126 }
127
128 pthread_attr_destroy(&attr);
129
130 for(int i = 0; i < NUM_THREADS; ++i)
131 {
132 intptr_t status = 1;
133 int rc = pthread_join(thread[i], (void**)&status);
134 assert(rc == 0);
135 assert(status == 0);
136 }
137
138 int val = sharedData[0];
139 emscripten_outf("Main: Test %d finished. Result: %d", test, val);
140 if (test != 6)
141 {
142 for(int i = 1; i < N; ++i)
143 assert(sharedData[i] == sharedData[0]);
144 }
145}
146
147int main()
148{

Callers 1

mainFunction · 0.70

Calls 6

pthread_attr_initFunction · 0.85
memsetFunction · 0.85
pthread_attr_destroyFunction · 0.85
emscripten_outfFunction · 0.70
assertFunction · 0.50

Tested by

no test coverage detected