Skip to content

Commit

Permalink
Cleanup some core tests. NFC. (#23331)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 authored Jan 7, 2025
1 parent 8046a49 commit 32e1daf
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 95 deletions.
18 changes: 0 additions & 18 deletions test/core/emmalloc_memalign_corruption.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <stdio.h>
#include <stdlib.h>

extern "C" {

EM_JS(void, log_started, (), {
out("foo_start");
})
Expand All @@ -33,8 +31,6 @@ void foo_end(int n) {
if (n > 30000) foo_end(n - 5);
}

} // extern "C"

int main(int argc, char** argv) {
int x = atoi(argv[1]);
foo_start(x);
Expand Down
2 changes: 2 additions & 0 deletions test/core/test_assert.cpp → test/core/test_assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* found in the LICENSE file.
*/

#include <stdbool.h>
#include <stdio.h>
#include <assert.h>

int main() {
assert(1 == true); // pass
assert(1 == false); // fail
Expand Down
3 changes: 1 addition & 2 deletions test/core/test_em_asm_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#include <emscripten.h>
#include <stdio.h>

int main()
{
int main() {
printf("EM_ASM: Simple expression without trailing semicolon\n");
EM_ASM(out('1. expression without trailing semicolon'));
EM_ASM("out('2. expression without trailing semicolon')");
Expand Down
17 changes: 17 additions & 0 deletions test/core/test_emmalloc_memalign_corruption.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <emscripten/emmalloc.h>
#include <stdio.h>
#include <string.h>

int main() {
void *ptr = malloc(20);
void *ptr2 = malloc(30);
memset(ptr2, 0xFF, 30);
free(ptr2);
printf("%d %d\n", ptr != 0, emmalloc_validate_memory_regions());
ptr2 = memalign(32, 20);
printf("%d %d\n", ptr2 != 0, emmalloc_validate_memory_regions());
free(ptr2);
printf("%d\n", emmalloc_validate_memory_regions());
free(ptr);
printf("%d\n", emmalloc_validate_memory_regions());
}
File renamed without changes.
46 changes: 46 additions & 0 deletions test/core/test_emmalloc_trim.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <stdio.h>
#include <unistd.h>
#include <emscripten/emmalloc.h>
#include <emscripten/heap.h>

size_t round_to_4k(size_t val){
return (val + 4095) & ~4095;
}

void print_stats(int cnt) {
printf("dynamic heap %d: %zu\n", cnt, round_to_4k(emmalloc_dynamic_heap_size()));
printf("free dynamic memory %d: %zu\n", cnt, round_to_4k(emmalloc_free_dynamic_memory()));
printf("unclaimed heap memory %d: %zu\n", cnt, round_to_4k(emmalloc_unclaimed_heap_memory()));
printf("sbrk %d: %#zx\n", cnt, round_to_4k((size_t)sbrk(0)));
}

int main() {
printf("heap size: %zu\n", emscripten_get_heap_size());
print_stats(0);

void *ptr = malloc(32*1024*1024);
void *ptr2 = malloc(4*1024*1024);
printf("%d\n", (int)(ptr && ptr2));
print_stats(1);

int success = emmalloc_trim(0);
printf("1st trim: %d\n", success);
print_stats(1);

success = emmalloc_trim(0);
printf("2nd trim: %d\n", success);
print_stats(2);
free(ptr2);

success = emmalloc_trim(100000);
printf("3rd trim: %d\n", success);
print_stats(3);

success = emmalloc_trim(100000);
printf("4th trim: %d\n", success);
print_stats(4);

success = emmalloc_trim(0);
printf("5th trim: %d\n", success);
print_stats(5);
}
62 changes: 0 additions & 62 deletions test/core/test_emmalloc_trim.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#include <stdio.h>
#include "emscripten.h"

extern "C" {
void save_me_aimee() { printf("mann\n"); }
}

int main() {
// EMSCRIPTEN_COMMENT("hello from the source");
Expand Down
14 changes: 7 additions & 7 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,16 +825,16 @@ def test_emmalloc_trim(self):
self.set_setting('MALLOC', 'emmalloc')
self.emcc_args += ['-sINITIAL_MEMORY=128MB', '-sALLOW_MEMORY_GROWTH', '-sMAXIMUM_MEMORY=2147418112']

self.do_core_test('test_emmalloc_trim.cpp')
self.do_core_test('test_emmalloc_trim.c')

# Test case against https://github.com/emscripten-core/emscripten/issues/10363
def test_emmalloc_memalign_corruption(self, *args):
self.set_setting('MALLOC', 'emmalloc')
self.do_core_test('emmalloc_memalign_corruption.cpp')
self.do_core_test('test_emmalloc_memalign_corruption.c')

@also_with_standalone_wasm()
def test_assert(self):
self.do_core_test('test_assert.cpp', assert_returncode=NON_ZERO)
self.do_core_test('test_assert.c', assert_returncode=NON_ZERO)

@crossplatform
@also_with_standalone_wasm(impure=True)
Expand Down Expand Up @@ -1719,15 +1719,15 @@ def test_set_align(self):

def test_emscripten_api(self):
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_save_me_aimee'])
self.do_core_test('test_emscripten_api.cpp')
self.do_core_test('test_emscripten_api.c')

# Sanitizers are not compatible with LINKABLE (dynamic linking.
if not is_sanitizing(self.emcc_args) and not self.is_wasm64():
# test EXPORT_ALL
self.clear_setting('EXPORTED_FUNCTIONS')
self.set_setting('EXPORT_ALL')
self.set_setting('LINKABLE')
self.do_core_test('test_emscripten_api.cpp')
self.do_core_test('test_emscripten_api.c')

def test_emscripten_run_script_string_int(self):
src = r'''
Expand Down Expand Up @@ -8267,8 +8267,8 @@ def test_pthread_join_and_asyncify(self):
@no_asan('asyncify stack operations confuse asan')
@no_wasm2js('TODO: lazy loading in wasm2js')
@parameterized({
'': (False,),
'conditional': (True,),
'unconditional': (False,),
})
def test_emscripten_lazy_load_code(self, conditional):
if self.get_setting('STACK_OVERFLOW_CHECK'):
Expand All @@ -8279,7 +8279,7 @@ def test_emscripten_lazy_load_code(self, conditional):
self.emcc_args += ['--profiling-funcs'] # so that we can find the functions for the changes below
if conditional:
self.emcc_args += ['-DCONDITIONAL']
self.do_core_test('emscripten_lazy_load_code.cpp', args=['0'])
self.do_core_test('emscripten_lazy_load_code.c', args=['0'])

first_size = os.path.getsize('emscripten_lazy_load_code.wasm')
second_size = os.path.getsize('emscripten_lazy_load_code.wasm.lazy.wasm')
Expand Down

0 comments on commit 32e1daf

Please sign in to comment.