Skip to content

Commit 32e1daf

Browse files
authored
Cleanup some core tests. NFC. (emscripten-core#23331)
1 parent 8046a49 commit 32e1daf

10 files changed

+73
-95
lines changed

test/core/emmalloc_memalign_corruption.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include <stdio.h>
1010
#include <stdlib.h>
1111

12-
extern "C" {
13-
1412
EM_JS(void, log_started, (), {
1513
out("foo_start");
1614
})
@@ -33,8 +31,6 @@ void foo_end(int n) {
3331
if (n > 30000) foo_end(n - 5);
3432
}
3533

36-
} // extern "C"
37-
3834
int main(int argc, char** argv) {
3935
int x = atoi(argv[1]);
4036
foo_start(x);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
* found in the LICENSE file.
66
*/
77

8+
#include <stdbool.h>
89
#include <stdio.h>
910
#include <assert.h>
11+
1012
int main() {
1113
assert(1 == true); // pass
1214
assert(1 == false); // fail

test/core/test_em_asm_2.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
#include <emscripten.h>
77
#include <stdio.h>
88

9-
int main()
10-
{
9+
int main() {
1110
printf("EM_ASM: Simple expression without trailing semicolon\n");
1211
EM_ASM(out('1. expression without trailing semicolon'));
1312
EM_ASM("out('2. expression without trailing semicolon')");
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <emscripten/emmalloc.h>
2+
#include <stdio.h>
3+
#include <string.h>
4+
5+
int main() {
6+
void *ptr = malloc(20);
7+
void *ptr2 = malloc(30);
8+
memset(ptr2, 0xFF, 30);
9+
free(ptr2);
10+
printf("%d %d\n", ptr != 0, emmalloc_validate_memory_regions());
11+
ptr2 = memalign(32, 20);
12+
printf("%d %d\n", ptr2 != 0, emmalloc_validate_memory_regions());
13+
free(ptr2);
14+
printf("%d\n", emmalloc_validate_memory_regions());
15+
free(ptr);
16+
printf("%d\n", emmalloc_validate_memory_regions());
17+
}
File renamed without changes.

test/core/test_emmalloc_trim.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <stdio.h>
2+
#include <unistd.h>
3+
#include <emscripten/emmalloc.h>
4+
#include <emscripten/heap.h>
5+
6+
size_t round_to_4k(size_t val){
7+
return (val + 4095) & ~4095;
8+
}
9+
10+
void print_stats(int cnt) {
11+
printf("dynamic heap %d: %zu\n", cnt, round_to_4k(emmalloc_dynamic_heap_size()));
12+
printf("free dynamic memory %d: %zu\n", cnt, round_to_4k(emmalloc_free_dynamic_memory()));
13+
printf("unclaimed heap memory %d: %zu\n", cnt, round_to_4k(emmalloc_unclaimed_heap_memory()));
14+
printf("sbrk %d: %#zx\n", cnt, round_to_4k((size_t)sbrk(0)));
15+
}
16+
17+
int main() {
18+
printf("heap size: %zu\n", emscripten_get_heap_size());
19+
print_stats(0);
20+
21+
void *ptr = malloc(32*1024*1024);
22+
void *ptr2 = malloc(4*1024*1024);
23+
printf("%d\n", (int)(ptr && ptr2));
24+
print_stats(1);
25+
26+
int success = emmalloc_trim(0);
27+
printf("1st trim: %d\n", success);
28+
print_stats(1);
29+
30+
success = emmalloc_trim(0);
31+
printf("2nd trim: %d\n", success);
32+
print_stats(2);
33+
free(ptr2);
34+
35+
success = emmalloc_trim(100000);
36+
printf("3rd trim: %d\n", success);
37+
print_stats(3);
38+
39+
success = emmalloc_trim(100000);
40+
printf("4th trim: %d\n", success);
41+
print_stats(4);
42+
43+
success = emmalloc_trim(0);
44+
printf("5th trim: %d\n", success);
45+
print_stats(5);
46+
}

test/core/test_emmalloc_trim.cpp

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
#include <stdio.h>
99
#include "emscripten.h"
1010

11-
extern "C" {
1211
void save_me_aimee() { printf("mann\n"); }
13-
}
1412

1513
int main() {
1614
// EMSCRIPTEN_COMMENT("hello from the source");

test/test_core.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -825,16 +825,16 @@ def test_emmalloc_trim(self):
825825
self.set_setting('MALLOC', 'emmalloc')
826826
self.emcc_args += ['-sINITIAL_MEMORY=128MB', '-sALLOW_MEMORY_GROWTH', '-sMAXIMUM_MEMORY=2147418112']
827827

828-
self.do_core_test('test_emmalloc_trim.cpp')
828+
self.do_core_test('test_emmalloc_trim.c')
829829

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

835835
@also_with_standalone_wasm()
836836
def test_assert(self):
837-
self.do_core_test('test_assert.cpp', assert_returncode=NON_ZERO)
837+
self.do_core_test('test_assert.c', assert_returncode=NON_ZERO)
838838

839839
@crossplatform
840840
@also_with_standalone_wasm(impure=True)
@@ -1719,15 +1719,15 @@ def test_set_align(self):
17191719

17201720
def test_emscripten_api(self):
17211721
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_save_me_aimee'])
1722-
self.do_core_test('test_emscripten_api.cpp')
1722+
self.do_core_test('test_emscripten_api.c')
17231723

17241724
# Sanitizers are not compatible with LINKABLE (dynamic linking.
17251725
if not is_sanitizing(self.emcc_args) and not self.is_wasm64():
17261726
# test EXPORT_ALL
17271727
self.clear_setting('EXPORTED_FUNCTIONS')
17281728
self.set_setting('EXPORT_ALL')
17291729
self.set_setting('LINKABLE')
1730-
self.do_core_test('test_emscripten_api.cpp')
1730+
self.do_core_test('test_emscripten_api.c')
17311731

17321732
def test_emscripten_run_script_string_int(self):
17331733
src = r'''
@@ -8267,8 +8267,8 @@ def test_pthread_join_and_asyncify(self):
82678267
@no_asan('asyncify stack operations confuse asan')
82688268
@no_wasm2js('TODO: lazy loading in wasm2js')
82698269
@parameterized({
8270+
'': (False,),
82708271
'conditional': (True,),
8271-
'unconditional': (False,),
82728272
})
82738273
def test_emscripten_lazy_load_code(self, conditional):
82748274
if self.get_setting('STACK_OVERFLOW_CHECK'):
@@ -8279,7 +8279,7 @@ def test_emscripten_lazy_load_code(self, conditional):
82798279
self.emcc_args += ['--profiling-funcs'] # so that we can find the functions for the changes below
82808280
if conditional:
82818281
self.emcc_args += ['-DCONDITIONAL']
8282-
self.do_core_test('emscripten_lazy_load_code.cpp', args=['0'])
8282+
self.do_core_test('emscripten_lazy_load_code.c', args=['0'])
82838283

82848284
first_size = os.path.getsize('emscripten_lazy_load_code.wasm')
82858285
second_size = os.path.getsize('emscripten_lazy_load_code.wasm.lazy.wasm')

0 commit comments

Comments
 (0)