Use do_run_from_file() for test_mmap
This commit is contained in:
Родитель
98bb3dd7d7
Коммит
179da486f9
|
@ -0,0 +1,38 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <assert.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int* map = (int*)mmap(0, 5000, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED | MAP_ANON, -1, 0);
|
||||
/* TODO: Should we align to 4k?
|
||||
assert(((int)map) % 4096 == 0); // aligned
|
||||
*/
|
||||
assert(munmap(map, 5000) == 0);
|
||||
}
|
||||
|
||||
const int NUM_BYTES = 8 * 1024 * 1024;
|
||||
const int NUM_INTS = NUM_BYTES / sizeof(int);
|
||||
|
||||
int* map = (int*)mmap(0, NUM_BYTES, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED | MAP_ANON, -1, 0);
|
||||
assert(map != MAP_FAILED);
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NUM_INTS; i++) {
|
||||
map[i] = i;
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_INTS; i++) {
|
||||
assert(map[i] == i);
|
||||
}
|
||||
|
||||
assert(munmap(map, NUM_BYTES) == 0);
|
||||
|
||||
printf("hello,world");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
hello,world
|
|
@ -4486,46 +4486,11 @@ return malloc(size);
|
|||
|
||||
Settings.TOTAL_MEMORY = 128*1024*1024
|
||||
|
||||
src = '''
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <assert.h>
|
||||
test_path = path_from_root('tests', 'core', 'test_mmap')
|
||||
src, output = (test_path + s for s in ('.in', '.out'))
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int* map = (int*)mmap(0, 5000, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED | MAP_ANON, -1, 0);
|
||||
/* TODO: Should we align to 4k?
|
||||
assert(((int)map) % 4096 == 0); // aligned
|
||||
*/
|
||||
assert(munmap(map, 5000) == 0);
|
||||
}
|
||||
|
||||
const int NUM_BYTES = 8 * 1024 * 1024;
|
||||
const int NUM_INTS = NUM_BYTES / sizeof(int);
|
||||
|
||||
int* map = (int*)mmap(0, NUM_BYTES, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED | MAP_ANON, -1, 0);
|
||||
assert(map != MAP_FAILED);
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NUM_INTS; i++) {
|
||||
map[i] = i;
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_INTS; i++) {
|
||||
assert(map[i] == i);
|
||||
}
|
||||
|
||||
assert(munmap(map, NUM_BYTES) == 0);
|
||||
|
||||
printf("hello,world");
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
self.do_run(src, 'hello,world')
|
||||
self.do_run(src, 'hello,world', force_c=True)
|
||||
self.do_run_from_file(src, output)
|
||||
self.do_run_from_file(src, output, force_c=True)
|
||||
|
||||
def test_mmap_file(self):
|
||||
if self.emcc_args is None: return self.skip('requires emcc')
|
||||
|
|
Загрузка…
Ссылка в новой задаче