Skip to content

Commit 6116553

Browse files
authored
Improve testing on Windows (WebAssembly#3142)
This PR contains: - Changes that enable/disable tests on Windows to allow for better local testing. - Also changes many abort() into Fatal() when it is really just exiting on error. This is because abort() generates a dialog window on Windows which is not great in automated scripts. - Improvements to CMake to better work with the project in IDEs (VS).
1 parent 9f7a053 commit 6116553

16 files changed

Lines changed: 55 additions & 57 deletions

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ if(MSVC)
145145
add_compile_flag("/wd4244")
146146
# 4722 warns that destructors never return, even with WASM_NORETURN.
147147
add_compile_flag("/wd4722")
148+
# "destructor was implicitly defined as deleted" caused by LLVM headers.
149+
add_compile_flag("/wd4624")
148150
add_compile_flag("/WX-")
149151
add_debug_compile_flag("/Od")
150152
add_nondebug_compile_flag("/O2")
@@ -156,6 +158,9 @@ if(MSVC)
156158
# Don't warn about using "strdup" as a reserved name.
157159
add_compile_flag("/D_CRT_NONSTDC_NO_DEPRECATE")
158160

161+
# multi-core build.
162+
add_compile_flag("/MP")
163+
159164
if(BYN_ENABLE_ASSERTIONS)
160165
# On non-Debug builds cmake automatically defines NDEBUG, so we
161166
# explicitly undefine it:
@@ -294,8 +299,10 @@ ENDIF()
294299

295300
# Sources.
296301

302+
file(GLOB binaryen_HEADERS src/*.h)
297303
set(binaryen_SOURCES
298304
src/binaryen-c.cpp
305+
${binaryen_HEADERS}
299306
)
300307
if(BUILD_STATIC_LIB)
301308
message(STATUS "Building libbinaryen as statically linked library.")
@@ -342,6 +349,7 @@ binaryen_add_executable(wasm-reduce src/tools/wasm-reduce.cpp)
342349
if(EMSCRIPTEN)
343350
set(binaryen_emscripten_SOURCES
344351
src/binaryen-c.cpp
352+
${binaryen_HEADERS}
345353
)
346354

347355
# binaryen.js WebAssembly variant

auto_update_tests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def update_example_tests():
5050
expected = os.path.splitext(t)[0] + '.txt'
5151
if not src.endswith(('.c', '.cpp')):
5252
continue
53+
# windows + gcc will need some work
54+
if shared.skip_if_on_windows('gcc'):
55+
return
5356
# build the C file separately
5457
extra = [os.environ.get('CC') or 'gcc',
5558
src, '-c', '-o', 'example.o',
@@ -120,8 +123,6 @@ def update_metadce_tests():
120123

121124

122125
def update_reduce_tests():
123-
if not shared.has_shell_timeout():
124-
return
125126
print('\n[ checking wasm-reduce ]\n')
126127
for t in shared.get_tests(shared.get_test_dir('reduce'), ['.wast']):
127128
print('..', os.path.basename(t))

check.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,6 @@ def run_gcc_tests():
338338
def run_unittest():
339339
print('\n[ checking unit tests...]\n')
340340

341-
# windows has some failures that need to be investigated
342-
if shared.skip_if_on_windows('unit'):
343-
return
344-
345341
# equivalent to `python -m unittest discover -s ./test -v`
346342
suite = unittest.defaultTestLoader.discover(os.path.dirname(shared.options.binaryen_test))
347343
result = unittest.TextTestRunner(verbosity=2, failfast=shared.options.abort_on_first_failure).run(suite)

scripts/fuzz_opt.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,12 @@ def randomize_opt_flags():
916916
mean = float(total_input_size) / counter
917917
mean_of_squares = float(total_input_size_squares) / counter
918918
stddev = math.sqrt(mean_of_squares - (mean ** 2))
919-
print('ITERATION:', counter, 'seed:', seed, 'size:', input_size, '(mean:', str(mean) + ', stddev:', str(stddev) + ')', 'speed:', counter / (time.time() - start_time), 'iters/sec, ', total_wasm_size / (time.time() - start_time), 'wasm_bytes/sec\n')
919+
elapsed = max(0.000001, time.time() - start_time)
920+
print('ITERATION:', counter, 'seed:', seed, 'size:', input_size,
921+
'(mean:', str(mean) + ', stddev:', str(stddev) + ')',
922+
'speed:', counter / elapsed,
923+
'iters/sec, ', total_wasm_size / elapsed,
924+
'wasm_bytes/sec\n')
920925
with open(raw_input_data, 'wb') as f:
921926
f.write(bytes([random.randint(0, 255) for x in range(input_size)]))
922927
assert os.path.getsize(raw_input_data) == input_size

scripts/test/wasm_opt.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ def update_wasm_opt_tests():
159159
print('\n[ checking wasm-opt passes... ]\n')
160160
for t in shared.get_tests(shared.get_test_dir('passes'), ['.wast', '.wasm']):
161161
print('..', os.path.basename(t))
162+
# windows has some failures that need to be investigated:
163+
# * ttf tests have different outputs - order of execution of params?
164+
# * dwarf tests print windows slashes instead of unix
165+
if ('translate-to-fuzz' in t or 'dwarf' in t) and \
166+
shared.skip_if_on_windows('fuzz translation tests'):
167+
continue
162168
binary = t.endswith('.wasm')
163169
base = os.path.basename(t).replace('.wast', '').replace('.wasm', '')
164170
passname = base

src/passes/ExtractFunction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ struct ExtractFunction : public Pass {
4242
}
4343
}
4444
if (!found) {
45-
std::cerr << "could not find the function to extract\n";
46-
abort();
45+
Fatal() << "could not find the function to extract\n";
4746
}
4847
// clear data
4948
module->memory.segments.clear();

src/passes/pass.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -591,16 +591,15 @@ void PassRunner::run() {
591591
if (!WasmValidator().validate(*wasm, validationFlags)) {
592592
WasmPrinter::printModule(wasm);
593593
if (passDebug >= 2) {
594-
std::cerr << "Last pass (" << pass->name
595-
<< ") broke validation. Here is the module before: \n"
596-
<< moduleBefore.str() << "\n";
594+
Fatal() << "Last pass (" << pass->name
595+
<< ") broke validation. Here is the module before: \n"
596+
<< moduleBefore.str() << "\n";
597597
} else {
598-
std::cerr << "Last pass (" << pass->name
599-
<< ") broke validation. Run with BINARYEN_PASS_DEBUG=2 "
600-
"in the env to see the earlier state, or 3 to dump "
601-
"byn-* files for each pass\n";
598+
Fatal() << "Last pass (" << pass->name
599+
<< ") broke validation. Run with BINARYEN_PASS_DEBUG=2 "
600+
"in the env to see the earlier state, or 3 to dump "
601+
"byn-* files for each pass\n";
602602
}
603-
abort();
604603
}
605604
}
606605
if (passDebug >= 3) {
@@ -613,8 +612,7 @@ void PassRunner::run() {
613612
std::cerr << "[PassRunner] (final validation)\n";
614613
if (!WasmValidator().validate(*wasm, validationFlags)) {
615614
WasmPrinter::printModule(wasm);
616-
std::cerr << "final module does not validate\n";
617-
abort();
615+
Fatal() << "final module does not validate\n";
618616
}
619617
}
620618
} else {

src/tools/execution-results.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ struct ExecutionResults {
9999
optimizedResults.get(wasm);
100100
if (optimizedResults != *this) {
101101
std::cout << "[fuzz-exec] optimization passes changed execution results";
102-
abort();
102+
exit(1);
103103
}
104104
}
105105

src/tools/wasm-as.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ int main(int argc, const char* argv[]) {
5454
Options::Arguments::One,
5555
[](Options* o, const std::string& argument) {
5656
if (argument != "web" && argument != "none" && argument != "wasm") {
57-
std::cerr << "Valid arguments for --validate flag are 'wasm', "
58-
"'web', and 'none'.\n";
59-
exit(1);
57+
Fatal() << "Valid arguments for --validate flag are 'wasm', "
58+
"'web', and 'none'.\n";
6059
}
6160
o->extra["validate"] = argument;
6261
})

src/tools/wasm-opt.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,7 @@ int main(int argc, const char* argv[]) {
377377
auto secondOutput = runCommand(extraFuzzCommand);
378378
std::cout << "[extra-fuzz-command second output:]\n" << firstOutput << '\n';
379379
if (firstOutput != secondOutput) {
380-
std::cerr << "extra fuzz command output differs\n";
381-
abort();
380+
Fatal() << "extra fuzz command output differs\n";
382381
}
383382
}
384383
return 0;

0 commit comments

Comments
 (0)