Skip to content

Commit 5617421

Browse files
committed
Add a testcase for #12243 #12244 #12245 [ci skip]
1 parent daf783a commit 5617421

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include <errno.h>
2+
#include <stdlib.h>
3+
#include <fcntl.h>
4+
#include <unistd.h>
5+
#include <emscripten.h>
6+
#include <stdio.h>
7+
8+
class random_device
9+
{
10+
int __f_;
11+
public:
12+
// constructors
13+
explicit random_device();
14+
~random_device();
15+
16+
// generating functions
17+
unsigned operator()();
18+
};
19+
20+
random_device::random_device()
21+
: __f_(open("/dev/urandom", O_RDONLY))
22+
{
23+
if (__f_ < 0) abort();
24+
}
25+
26+
random_device::~random_device()
27+
{
28+
close(__f_);
29+
}
30+
31+
unsigned
32+
random_device::operator()()
33+
{
34+
unsigned r;
35+
size_t n = sizeof(r);
36+
char* p = reinterpret_cast<char*>(&r);
37+
while (n > 0)
38+
{
39+
ssize_t s = read(__f_, p, 1);
40+
if (s == 0) abort();
41+
if (s == -1)
42+
{
43+
if (errno != EINTR) abort();
44+
continue;
45+
}
46+
n -= static_cast<size_t>(s);
47+
p += static_cast<size_t>(s);
48+
}
49+
return r;
50+
}
51+
52+
void* ptr;
53+
54+
int main() {
55+
int total = 0;
56+
for (int i = 0; i < 128; i++) {
57+
EM_ASM({ out($0, $1) }, i, total);
58+
for (int j = 0; j < 128; j++) {
59+
auto* rd = new random_device;
60+
total += (*rd)();
61+
ptr = (void*)rd; // make sure the optimizer doesn't remove the allocation
62+
delete rd;
63+
}
64+
}
65+
EM_ASM({ out("done") });
66+
#ifdef REPORT_RESULT
67+
REPORT_RESULT(0);
68+
#endif
69+
return 0;
70+
}
71+

tests/test_browser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4509,6 +4509,10 @@ def run(emcc_args=[]):
45094509
def test_pthread_reltime(self):
45104510
self.btest(path_from_root('tests', 'pthread', 'test_pthread_reltime.cpp'), expected='3', args=['-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_POOL_SIZE=1'])
45114511

4512+
@requires_threads
4513+
def test_pthread_proxy_hammer(self):
4514+
self.btest(path_from_root('tests', 'pthread', 'test_pthread_proxy_hammer.cpp'), expected='0', args=['-s', 'USE_PTHREADS=1', '-O2', '-s', 'PROXY_TO_PTHREAD'])
4515+
45124516
# Tests that it is possible to load the main .js file of the application manually via a Blob URL, and still use pthreads.
45134517
@requires_threads
45144518
@no_wasm_backend("WASM2JS does not yet support pthreads")

0 commit comments

Comments
 (0)