From 9d41ac2f7b54a33298372bf5873eb15973da4f09 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Tue, 9 Jul 2024 17:42:46 +0800 Subject: [PATCH] build: add more tests to build system --- .gitignore | 2 +- CMakeLists.txt | 17 +++++++------- benchmarks/microbench/CMakeLists.txt | 3 +++ benchmarks/microbench/src/CMakeLists.txt | 23 +++++++++++++++++++ kernels/CMakeLists.txt | 2 ++ kernels/demo/CMakeLists.txt | 1 + kernels/demo/include/io.h | 2 +- kernels/demo/src/CMakeLists.txt | 20 ++++++++++++++++ kernels/hello/CMakeLists.txt | 14 ++++++++++++ tests/alu-tests/CMakeLists.txt | 29 ++++++++++++++++++++++++ tests/alu-tests/gen_alu_test.c | 2 +- tests/cpu-tests/tests/CMakeLists.txt | 9 +++----- 12 files changed, 107 insertions(+), 17 deletions(-) create mode 100644 benchmarks/microbench/CMakeLists.txt create mode 100644 benchmarks/microbench/src/CMakeLists.txt create mode 100644 kernels/CMakeLists.txt create mode 100644 kernels/demo/CMakeLists.txt create mode 100644 kernels/demo/src/CMakeLists.txt create mode 100644 kernels/hello/CMakeLists.txt create mode 100644 tests/alu-tests/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 5170a12..fe30a49 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -* !*/ !*.h !*.c @@ -13,3 +12,4 @@ _* *~ build/ !.gitignore +out/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 61f185a..78d91c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,14 +3,15 @@ cmake_minimum_required(VERSION 3.22) project(am-kernels) set(CMAKE_C_STANDARD 11) enable_language(C ASM) - include(CheckPIESupported) +include(GNUInstallDirs) + +find_package(am-${ARCH}) +find_package(klib) + check_pie_supported() -if(${PLATFORM} MATCHES "native") -set(ARCH "native") -else() -set(ARCH ${ISA}-${PLATFORM}) -endif() - -add_subdirectory(tests/cpu-tests) \ No newline at end of file +add_subdirectory(tests/cpu-tests) +# add_subdirectory(tests/alu-tests) +add_subdirectory(benchmarks/microbench) +add_subdirectory(kernels) diff --git a/benchmarks/microbench/CMakeLists.txt b/benchmarks/microbench/CMakeLists.txt new file mode 100644 index 0000000..0b2b255 --- /dev/null +++ b/benchmarks/microbench/CMakeLists.txt @@ -0,0 +1,3 @@ +include_directories(include) + +add_subdirectory(src) diff --git a/benchmarks/microbench/src/CMakeLists.txt b/benchmarks/microbench/src/CMakeLists.txt new file mode 100644 index 0000000..349cc5c --- /dev/null +++ b/benchmarks/microbench/src/CMakeLists.txt @@ -0,0 +1,23 @@ +add_executable(bench + qsort/qsort.c + ssort/ssort.cc + queen/queen.c + sieve/sieve.c + bf/bf.c + 15pz/15pz.cc + dinic/dinic.cc + lzip/lzip.c + lzip/quicklz.c + md5/md5.c + bench.c + fib/fib.c +) + +target_link_libraries(bench am-${ARCH} klib npcgcc) + +# -- Extract binary file from ELF +add_custom_command(TARGET bench + COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary bench bench.bin) + +install(TARGETS bench RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/bench.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) diff --git a/kernels/CMakeLists.txt b/kernels/CMakeLists.txt new file mode 100644 index 0000000..aed5366 --- /dev/null +++ b/kernels/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(hello) +add_subdirectory(demo) diff --git a/kernels/demo/CMakeLists.txt b/kernels/demo/CMakeLists.txt new file mode 100644 index 0000000..febd4f0 --- /dev/null +++ b/kernels/demo/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(src) diff --git a/kernels/demo/include/io.h b/kernels/demo/include/io.h index 9ed6b50..b2c7c61 100644 --- a/kernels/demo/include/io.h +++ b/kernels/demo/include/io.h @@ -1,6 +1,6 @@ #ifndef __DRAW_H__ -#define HAS_GUI +// #define HAS_GUI #include #include diff --git a/kernels/demo/src/CMakeLists.txt b/kernels/demo/src/CMakeLists.txt new file mode 100644 index 0000000..b58503b --- /dev/null +++ b/kernels/demo/src/CMakeLists.txt @@ -0,0 +1,20 @@ +add_executable(demo + aclock/aclock.c + ant/ant.c + bf/bf.c + cmatrix/cmatrix.c + donut/donut.c + galton/galton.c + hanoi/hanoi.c + life/life.c + main.c +) +target_include_directories(demo PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) +target_link_libraries(demo PRIVATE am-${ARCH} klib npcgcc) + +# -- Extract binary file from ELF +add_custom_command(TARGET demo + COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary demo demo.bin) + +install(TARGETS demo RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/demo.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) diff --git a/kernels/hello/CMakeLists.txt b/kernels/hello/CMakeLists.txt new file mode 100644 index 0000000..0afa490 --- /dev/null +++ b/kernels/hello/CMakeLists.txt @@ -0,0 +1,14 @@ +add_executable(hello + hello.c +) +target_include_directories(hello PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) +target_link_libraries(hello PRIVATE am-${ARCH} klib npcgcc) +target_compile_options(hello PRIVATE -nostdlib -nodefaultlibs) +target_link_options(hello PRIVATE -nostdlib -nodefaultlibs) + +# -- Extract binary file from ELF +add_custom_command(TARGET hello + COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary hello hello.bin) + +install(TARGETS hello RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/hello.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) diff --git a/tests/alu-tests/CMakeLists.txt b/tests/alu-tests/CMakeLists.txt new file mode 100644 index 0000000..4fb0bd4 --- /dev/null +++ b/tests/alu-tests/CMakeLists.txt @@ -0,0 +1,29 @@ +# TODO: CMake does not support multiple toolchain in one run. We need a seperate +# project for native binary compilation + +# cmake_minimum_required(VERSION 3.22) + +# project(alu-tests) +# set(CMAKE_C_STANDARD 11) +# enable_language(C ASM) +# include(GNUInstallDirs) + +# add_executable(gen_alu_test gen_alu_test.c) + +# add_custom_command(TARGET gen_alu_test POST_BUILD +# BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/alu_test.c +# COMMAND $ > alu_test.c) + +add_executable(alu_test alu_test.c) + +target_include_directories(alu_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) +target_link_libraries(alu_test PRIVATE am-${ARCH} klib npcgcc) +target_compile_options(alu_test PRIVATE -nostdlib -nodefaultlibs) +target_link_options(alu_test PRIVATE -nostdlib -nodefaultlibs) + +# -- Extract binary file from ELF +add_custom_command(TARGET alu_test + COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary alu_test alu_test.bin) + +install(TARGETS alu_test RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/alu_test.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) diff --git a/tests/alu-tests/gen_alu_test.c b/tests/alu-tests/gen_alu_test.c index 9ae5009..5e16e56 100644 --- a/tests/alu-tests/gen_alu_test.c +++ b/tests/alu-tests/gen_alu_test.c @@ -114,7 +114,7 @@ int exclude(type t, char* op, int x, int y) int main(void) { printf("#include \n"); - printf("int main(void) {\n"); + printf("int main(const char *) {\n"); printf(" int exit_code = 0;\n"); FOR_SET_ALL(signed int, vsi); diff --git a/tests/cpu-tests/tests/CMakeLists.txt b/tests/cpu-tests/tests/CMakeLists.txt index 3e1bb7a..c03254b 100644 --- a/tests/cpu-tests/tests/CMakeLists.txt +++ b/tests/cpu-tests/tests/CMakeLists.txt @@ -1,6 +1,3 @@ -find_package(am-${ARCH}) -find_package(klib) - set(SOURCES add.c add-longlong.c @@ -42,12 +39,12 @@ foreach(SOURCE IN LISTS SOURCES) get_filename_component(SOURCE_NAME ${SOURCE} NAME_WLE) add_executable(${SOURCE_NAME} ${SOURCE}) - target_link_libraries(${SOURCE_NAME} PRIVATE am-${ARCH}) + target_link_libraries(${SOURCE_NAME} PRIVATE am-${ARCH} klib) # -- Extract binary file from ELF add_custom_command(TARGET ${SOURCE_NAME} COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary ${SOURCE_NAME} ${SOURCE_NAME}.bin) - install(TARGETS ${SOURCE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_DATADIR}/elf) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SOURCE_NAME}.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/binary) + install(TARGETS ${SOURCE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SOURCE_NAME}.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) endforeach()