Add browser test for file IO in pthreads.
This commit is contained in:
Родитель
1dbac7aed5
Коммит
cd41b65e16
|
@ -0,0 +1,45 @@
|
|||
#include <pthread.h>
|
||||
#include <emscripten.h>
|
||||
#include <emscripten/threading.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void *thread1_start(void *arg)
|
||||
{
|
||||
EM_ASM(Module['print']('thread1_start!'););
|
||||
|
||||
FILE *handle = fopen("file1.txt", "r");
|
||||
assert(handle);
|
||||
char str[256] = {};
|
||||
fgets(str, 255, handle);
|
||||
fclose(handle);
|
||||
assert(!strcmp(str, "hello!"));
|
||||
|
||||
handle = fopen("file2.txt", "w");
|
||||
fputs("hello2!", handle);
|
||||
fclose(handle);
|
||||
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
FILE *handle = fopen("file1.txt", "w");
|
||||
fputs("hello!", handle);
|
||||
fclose(handle);
|
||||
pthread_t thr;
|
||||
pthread_create(&thr, NULL, thread1_start, 0);
|
||||
pthread_join(thr, 0);
|
||||
|
||||
handle = fopen("file2.txt", "r");
|
||||
char str[256] = {};
|
||||
fgets(str, 255, handle);
|
||||
fclose(handle);
|
||||
assert(!strcmp(str, "hello2!"));
|
||||
|
||||
#ifdef REPORT_RESULT
|
||||
int result = 0;
|
||||
REPORT_RESULT();
|
||||
#endif
|
||||
}
|
|
@ -2594,6 +2594,10 @@ window.close = function() {
|
|||
def test_pthread_setspecific_mainthread(self):
|
||||
self.btest(path_from_root('tests', 'pthread', 'test_pthread_setspecific_mainthread.cpp'), expected='0', args=['-lpthread'])
|
||||
|
||||
# Test that pthreads have access to filesystem.
|
||||
def test_pthread_file_io(self):
|
||||
self.btest(path_from_root('tests', 'pthread', 'test_pthread_file_io.cpp'), expected='0', args=['-lpthread', '-s', 'PTHREAD_POOL_SIZE=1'])
|
||||
|
||||
# Test that it is possible to send a signal via calling alarm(timeout), which in turn calls to the signal handler set by signal(SIGALRM, func);
|
||||
def test_sigalrm(self):
|
||||
self.btest(path_from_root('tests', 'sigalrm.cpp'), expected='0')
|
||||
|
|
Загрузка…
Ссылка в новой задаче