Skip to content

Commit

Permalink
Run all browser tests in 2gb mode (#21268)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 authored Feb 13, 2024
1 parent 0cb21d5 commit fa57899
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 91 deletions.
14 changes: 1 addition & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -811,19 +811,7 @@ jobs:
steps:
- run-tests-chrome:
title: "browser_2gb"
test_targets: "
browser_2gb.test_gles2_uniform_arrays
browser_2gb.test_fetch_to_memory
browser_2gb.test_emscripten_animate_canvas_element_size_manual_css
browser_2gb.test_fulles2_sdlproc
browser_2gb.test_cubegeom*
browser_2gb.test_html5_webgl_create_context*
browser_2gb.test_main_thread_async_em_asm
browser_2gb.test_webgl2_*
browser_2gb.test_webgl_*
browser_2gb.test_sdl_image
browser_2gb.test_wasm_worker*
"
test_targets: "browser_2gb"
test-browser-chrome-wasm64-4gb:
executor: bionic
steps:
Expand Down
4 changes: 3 additions & 1 deletion src/library_html5_webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ var LibraryHtml5WebGL = {
var len = arr.length;
var writeLength = dstLength < len ? dstLength : len;
var heap = heapType ? HEAPF32 : HEAP32;
// Works because HEAPF32 and HEAP32 have the same bytes-per-element
dst = {{{ getHeapOffset('dst', 'float') }}};
for (var i = 0; i < writeLength; ++i) {
heap[(dst >> 2) + i] = arr[i];
heap[dst + i] = arr[i];
}
return len;
},
Expand Down
55 changes: 24 additions & 31 deletions test/browser/emmalloc_memgrowth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,30 @@
uint64_t nextAllocationSize = 16*1024*1024;
bool allocHasFailed = false;

void grow_memory()
{
uint8_t *ptr = (uint8_t*)malloc((size_t)nextAllocationSize);
EM_ASM({}, ptr); // Pass ptr out to confuse LLVM that it is used, so it won't optimize it away in -O1 and higher.
size_t heapSize = emscripten_get_heap_size();
printf("Allocated %zu: %d. Heap size: %zu\n", (size_t)nextAllocationSize, ptr ? 1 : 0, heapSize);
if (ptr)
{
if (!allocHasFailed)
{
nextAllocationSize *= 2;
// Make sure we don't overflow, and also exercise malloc(-1) to gracefully return 0 in ABORTING_MALLOC=0 mode.
if (nextAllocationSize > 0xFFFFFFFFULL)
nextAllocationSize = 0xFFFFFFFFULL;
}
}
else
{
nextAllocationSize /= 2;
allocHasFailed = true;
}
void grow_memory() {
uint8_t *ptr = (uint8_t*)malloc((size_t)nextAllocationSize);
EM_ASM({}, ptr); // Pass ptr out to confuse LLVM that it is used, so it won't optimize it away in -O1 and higher.
size_t heapSize = emscripten_get_heap_size();
printf("Allocated %zu: %d. Heap size: %zu\n", (size_t)nextAllocationSize, ptr ? 1 : 0, heapSize);
if (ptr) {
if (!allocHasFailed) {
nextAllocationSize *= 2;
// Make sure we don't overflow, and also exercise malloc(-1) to gracefully return 0 in ABORTING_MALLOC=0 mode.
if (nextAllocationSize > 0xFFFFFFFFULL)
nextAllocationSize = 0xFFFFFFFFULL;
}
} else {
nextAllocationSize /= 2;
allocHasFailed = true;
}
}

int main()
{
// Exhaust all available memory.
for(int i = 0; i < 50; ++i)
grow_memory();
// If we get this far without crashing on OOM, we are ok!
printf("Test finished!\n");
#ifdef REPORT_RESULT
REPORT_RESULT(0);
#endif
int main() {
// Exhaust all available memory.
for(int i = 0; i < 50; ++i) {
grow_memory();
}
// If we get this far without crashing on OOM, we are ok!
printf("Test finished!\n");
return 0;
}
47 changes: 18 additions & 29 deletions test/fs/test_idbfs_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@

int result = 1;

void success()
{
void success() {
REPORT_RESULT(result);
#ifdef FORCE_EXIT
emscripten_force_exit(0);
#endif
}

void test() {

int fd;
struct stat st;

#if FIRST

// for each file, we first make sure it doesn't currently exist
Expand All @@ -49,22 +47,20 @@ void test() {
fd = open("/working1/waka.txt", O_RDWR | O_CREAT, 0666);
if (fd == -1)
result = -5000 - errno;
else
{
else {
if (write(fd,"az",2) != 2)
result = -6000 - errno;
if (close(fd) != 0)
result = -7000 - errno;
}

// a file whose contents are random-ish string set by the test_browser.py file
if ((stat("/working1/moar.txt", &st) != -1) || (errno != ENOENT))
result = -8000 - errno;
fd = open("/working1/moar.txt", O_RDWR | O_CREAT, 0666);
if (fd == -1)
result = -9000 - errno;
else
{
else {
if (write(fd, SECRET, strlen(SECRET)) != strlen(SECRET))
result = -10000 - errno;
if (close(fd) != 0)
Expand Down Expand Up @@ -92,8 +88,7 @@ void test() {
fd = open("/working1/waka.txt", O_RDONLY);
if (fd == -1)
result = -17000 - errno;
else
{
else {
char bf[4];
int bytes_read = read(fd,&bf[0],sizeof(bf));
if (bytes_read != 2)
Expand All @@ -105,19 +100,17 @@ void test() {
if (unlink("/working1/waka.txt") != 0)
result = -21000 - errno;
}

// does the random-ish file exist and does it contain SECRET?
fd = open("/working1/moar.txt", O_RDONLY);
if (fd == -1)
if (fd == -1) {
result = -22000 - errno;
else
{
} else {
char bf[256];
int bytes_read = read(fd,&bf[0],sizeof(bf));
if (bytes_read != strlen(SECRET))
if (bytes_read != strlen(SECRET)) {
result = -23000;
else
{
} else {
bf[strlen(SECRET)] = 0;
if (strcmp(bf,SECRET) != 0)
result = -24000;
Expand All @@ -129,14 +122,13 @@ void test() {
}

// does the directory exist?
if (stat("/working1/dir", &st) != 0)
if (stat("/working1/dir", &st) != 0) {
result = -27000 - errno;
else
{
} else {
if (!S_ISDIR(st.st_mode))
result = -28000;
if (rmdir("/working1/dir") != 0)
result = -29000 - errno;
if (rmdir("/working1/dir") != 0)
result = -29000 - errno;
}

#endif
Expand Down Expand Up @@ -164,20 +156,18 @@ void test() {
ccall('success', 'v');
});
);

}

int main() {

EM_ASM(
FS.mkdir('/working1');
FS.mount(IDBFS, {}, '/working1');

#if !FIRST
// syncfs(true, f) should not break on already-existing directories:
FS.mkdir('/working1/dir');
// syncfs(true, f) should not break on already-existing directories:
FS.mkdir('/working1/dir');
#endif

// sync from persisted state into memory and then
// run the 'test' function
FS.syncfs(true, function (err) {
Expand All @@ -187,6 +177,5 @@ int main() {
);

emscripten_exit_with_live_runtime();

return 0;
}
Loading

0 comments on commit fa57899

Please sign in to comment.