Skip to content

Commit 21657b7

Browse files
committed
Add a rudimentary testsuite.
This adds a very primitive test harness and tests relevant to the recent changes to how program startup works, as well as the upcoming changes to support LTO.
1 parent 2bfea0c commit 21657b7

28 files changed

Lines changed: 278 additions & 0 deletions

tests/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.observed
2+
*.wasm

tests/compile-only/addresses.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdio.h>
2+
#include <limits.h>
3+
4+
extern void __dso_handle;
5+
extern void __data_end;
6+
extern void __global_base;
7+
extern void __heap_base;
8+
9+
int main(int argc, char *argv[]) {
10+
printf("NULL=%p\n", NULL);
11+
printf("__dso_handle=%p\n", &__dso_handle);
12+
printf("__data_end=%p\n", &__data_end);
13+
printf("__global_base=%p\n", &__global_base);
14+
printf("__heap_base=%p\n", &__heap_base);
15+
printf("__builtin_frame_address(0)=%p\n", __builtin_frame_address(0));
16+
printf("__builtin_alloca(0)=%p\n", __builtin_alloca(0));
17+
printf("__builtin_wasm_memory_size(0)=%p\n", (void *)(__builtin_wasm_memory_size(0) * PAGE_SIZE));
18+
return 0;
19+
}

tests/compile-only/test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int main(){}

tests/empty-expected.wat

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(module
2+
(type (;0;) (func))
3+
(type (;1;) (func (result i32)))
4+
(func $__wasm_call_ctors (type 0))
5+
(func $_start (type 0)
6+
call $__wasm_call_ctors)
7+
(func $__main_void (type 1) (result i32)
8+
i32.const 0)
9+
(table (;0;) 1 1 funcref)
10+
(memory (;0;) 2)
11+
(global (;0;) (mut i32) (i32.const 66560))
12+
(export "memory" (memory 0))
13+
(export "_start" (func $_start)))

tests/exit_status_zero

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0

tests/general/argc_argv_main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
3+
int main(int argc, char *argv[]) {
4+
puts("hello from argc argv main!");
5+
return 0;
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello from argc argv main!

tests/general/argc_argv_main.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
3+
int main(int argc, char *argv[]) {
4+
puts("hello from C++ argc argv main!");
5+
return 0;
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello from C++ argc argv main!

tests/general/ctors_dtors.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <assert.h>
4+
#include <errno.h>
5+
extern char **environ;
6+
7+
static void from_atexit(void) {
8+
printf("hello from_atexit\n");
9+
}
10+
11+
static void another_from_atexit(void) {
12+
printf("hello another_from_atexit\n");
13+
}
14+
15+
__attribute__((constructor)) static void from_constructor(void) {
16+
printf("hello from_constructor\n");
17+
}
18+
19+
__attribute__((constructor(101))) static void from_constructor_101(void) {
20+
assert(errno == 0);
21+
printf("hello from_constructor101\n");
22+
23+
assert(environ && "environment should be initialized by this point");
24+
}
25+
26+
__attribute__((constructor(65535))) static void from_constructor_65535(void) {
27+
printf("hello from_constructor65535\n");
28+
}
29+
30+
__attribute__((destructor)) static void from_destructor(void) {
31+
printf("hello from_destructor\n");
32+
}
33+
34+
__attribute__((destructor(101))) static void from_destructor101(void) {
35+
printf("hello from_destructor101\n");
36+
}
37+
38+
__attribute__((destructor(65535))) static void from_destructor65535(void) {
39+
printf("hello from_destructor65535\n");
40+
}
41+
42+
int main(int argc, char *argv[]) {
43+
printf("hello main\n");
44+
assert(argc != 0);
45+
assert(argv != NULL);
46+
assert(argv[argc] == NULL);
47+
48+
atexit(from_atexit);
49+
atexit(another_from_atexit);
50+
printf("goodbye main\n");
51+
return 0;
52+
}

0 commit comments

Comments
 (0)