Skip to content

Commit

Permalink
WIP: Update coremark build scirpt and move executables to a different
Browse files Browse the repository at this point in the history
folder

Signed-off-by: Ádám László Kulcsár <[email protected]>
  • Loading branch information
kulcsaradam committed Dec 4, 2024
1 parent 0f40ad3 commit d149148
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 16 deletions.
100 changes: 97 additions & 3 deletions test/programs/build_programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,124 @@

import argparse
import os
from subprocess import PIPE, Popen

from os.path import abspath, dirname, join

PROGRAMS_SOURCE_DIR = dirname(abspath(__file__))

PROGRAMS_EXECUTABLE_DIR = join(dirname(abspath(__file__)), "executables")

COREMARK_SOURCES = join(PROGRAMS_SOURCE_DIR, "coremark")

clang = False
emcc = False
clang_path = '/opt/wasi-sdk/bin/clang'
emcc_path = '/usr/lib/emscripten/emcc'

def compile_coremark():
global emcc, emcc_path, clang, clang_path

if clang:
if os.system(clang_path + " --version >/dev/null") != 0:
print("Could not find wasi-clang for building coremark.")
exit(1)

proc = Popen([clang_path,
'-O3',
'-I'+COREMARK_SOURCES+'/posix', '-I'+COREMARK_SOURCES,
'-DFLAGS_STR="-O3 -DPERFORMANCE_RUN=1"',
'-Wl,--export=main',
'-DITERATIONS=400000',
'-DSEED_METHOD=SEED_VOLATILE',
'-DPERFORMANCE_RUN=1',
'-Wl,--allow-undefined',
COREMARK_SOURCES + '/core_list_join.c',
COREMARK_SOURCES + '/core_main.c',
COREMARK_SOURCES + '/core_matrix.c',
COREMARK_SOURCES + '/core_state.c',
COREMARK_SOURCES + '/core_util.c',
COREMARK_SOURCES + '/posix/core_portme.c',
'-o'+ PROGRAMS_EXECUTABLE_DIR +'/coremark_clang.wasm'
])

out, _ = proc.communicate()

if proc.returncode != 0:
print("Error with clang compilation! Stopping.")
exit(1)


if emcc:
if os.system(emcc_path + " --version >/dev/null") != 0:
print("Could not find emcc for building coremark.")
exit(1)

proc = Popen([emcc_path,
'-O3',
'-I'+COREMARK_SOURCES, '-I',COREMARK_SOURCES+'/posix',
'-DFLAGS_STR="-O3 -DPERFORMANCE_RUN=1"',
'-Wl,--allow-undefined',
'-DITERATIONS=400000',
'-DSEED_METHOD=SEED_VOLATILE',
'-DPERFORMANCE_RUN=1',
'-Wl,--export=main',
'-sWASM=1',
'-sEXPORTED_FUNCTIONS=_main',
'-sEXPORTED_RUNTIME_METHODS=ccal,cwrap',
COREMARK_SOURCES + '/core_list_join.c',
COREMARK_SOURCES + '/core_main.c',
COREMARK_SOURCES + '/core_matrix.c',
COREMARK_SOURCES + '/core_state.c',
COREMARK_SOURCES + '/core_util.c',
COREMARK_SOURCES + '/posix/core_portme.c',
'-o'+ PROGRAMS_EXECUTABLE_DIR +'/coremark_emcc.wasm'
])

out, _ = proc.communicate()

if proc.returncode != 0:
print("Error with emscripten compilation! Stopping.")
exit(1)

return


def parse_args():
global emcc, emcc_path, clang, clang_path

parser = argparse.ArgumentParser()
parser.add_argument("--all", help="compile all programs", action="store_true", default=True)
parser.add_argument("--coremark", help="compile coremark", action="store_true")
parser.add_argument("--summary", help="Generate summary", action="store_true", default=False)
parser.add_argument("--emcc", help="Compile with emscripten. If there is no system emcc then follow the argument with a path to the emcc executeable.", nargs="?", default="")
parser.add_argument("--clang", help="Compile with clang. If there is no system emcc then follow the argument with a path to the emcc executeable.", nargs="?", default="")
args = parser.parse_args()

args.orig_results = args.results.copy()
if args.emcc != "" and args.emcc is not None:
emcc_path = args.emcc
emcc = True
elif args.emcc != "":
emcc = True

if args.clang != "" and args.clang is not None:
clang_path = args.clang
clang = True
elif args.clang != "":
clang = True

if not clang and not emcc:
print("Please define which compilers to use with --emcc, --clang!")
exit(1)

return args

def main():
args = parse_args()

if args.all:
compile_coremark()

print("All programs compiled succesfully!")
return

Expand Down
Binary file added test/programs/executables/coremark_clang.wasm
Binary file not shown.
Binary file added test/programs/executables/coremark_emcc.wasm
Binary file not shown.
Binary file added test/programs/executables/coremark_emcc2.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added test/programs/executables/dhrystone_emcc.wasm
Binary file not shown.
26 changes: 13 additions & 13 deletions tools/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _run_wast_tests(engine, files, is_fail):
fails = 0
for file in files:
if jit:
filename = os.path.basename(file)
filename = os.path.basename(file)
if filename in JIT_EXCLUDE_FILES:
continue

Expand Down Expand Up @@ -185,18 +185,18 @@ def run_extended_tests(engine):
continue

test_paths = sum(
[glob(join(TEST_DIR, 'regression', f'issue-{id}', '*.wasm'), recursive=False) for id in test_case['ids']],
[])
[glob(join(TEST_DIR, 'regression', f'issue-{id}', '*.wasm'), recursive=False) for id in test_case['ids']],
[])

if not test_paths:
test_paths = sum(
[glob(join(TEST_DIR, 'regression', f'issue-{id}', f"{test_case['file']}"), recursive=False) for id in
test_case['ids']],
[])
[glob(join(TEST_DIR, 'regression', f'issue-{id}', f"{test_case['file']}"), recursive=False) for id in
test_case['ids']],
[])

if ('expected return' not in test_case and test_case['compile_options']['expected return']['ret code'] == 0) \
or test_case['expected return']['ret code'] == 0:
test_list_pass.extend(test_paths)
test_list_pass.extend(test_paths)
else:
test_list_fail.extend(test_paths)

Expand Down Expand Up @@ -268,12 +268,12 @@ def run_wamr_compiler_tests(engine):
if fail_total > 0:
raise Exception("other wamr-compiler tests failed")

@runner('dhrystone', default=True)
def run_dhrystone_tests(engine):
TEST_DIR = join(PROJECT_SOURCE_DIR, 'test', 'programs', 'dhrystone')
@runner('programs', default=True)
def run_program_tests(engine):
TEST_DIR = join(PROJECT_SOURCE_DIR, 'test', 'programs', 'executables')

print('Running dhrystone tests:')
xpass = glob(join(TEST_DIR, '**/*.wasm'), recursive=True)
print('Running program tests:')
xpass = glob(join(TEST_DIR, '*.wasm'), recursive=True)
xpass_result = _run_wast_tests(engine, xpass, False)

tests_total = len(xpass)
Expand All @@ -283,7 +283,7 @@ def run_dhrystone_tests(engine):
print('%sFAIL : %d%s' % (COLOR_RED, fail_total, COLOR_RESET))

if fail_total > 0:
raise Exception("dhrystone tests failed")
raise Exception("program tests failed")

def main():
parser = ArgumentParser(description='Walrus Test Suite Runner')
Expand Down

0 comments on commit d149148

Please sign in to comment.