build: add more tests to build system

This commit is contained in:
xinyangli 2024-07-09 17:42:46 +08:00
parent 2f559823a6
commit 9d41ac2f7b
Signed by: xin
SSH key fingerprint: SHA256:qZ/tzd8lYRtUFSrfBDBMcUqV4GHKxqeqRA3huItgvbk
12 changed files with 107 additions and 17 deletions

2
.gitignore vendored
View file

@ -1,4 +1,3 @@
*
!*/ !*/
!*.h !*.h
!*.c !*.c
@ -13,3 +12,4 @@ _*
*~ *~
build/ build/
!.gitignore !.gitignore
out/

View file

@ -3,14 +3,15 @@ cmake_minimum_required(VERSION 3.22)
project(am-kernels) project(am-kernels)
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
enable_language(C ASM) enable_language(C ASM)
include(CheckPIESupported) include(CheckPIESupported)
include(GNUInstallDirs)
find_package(am-${ARCH})
find_package(klib)
check_pie_supported() check_pie_supported()
if(${PLATFORM} MATCHES "native")
set(ARCH "native")
else()
set(ARCH ${ISA}-${PLATFORM})
endif()
add_subdirectory(tests/cpu-tests) add_subdirectory(tests/cpu-tests)
# add_subdirectory(tests/alu-tests)
add_subdirectory(benchmarks/microbench)
add_subdirectory(kernels)

View file

@ -0,0 +1,3 @@
include_directories(include)
add_subdirectory(src)

View file

@ -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)

2
kernels/CMakeLists.txt Normal file
View file

@ -0,0 +1,2 @@
add_subdirectory(hello)
add_subdirectory(demo)

View file

@ -0,0 +1 @@
add_subdirectory(src)

View file

@ -1,6 +1,6 @@
#ifndef __DRAW_H__ #ifndef __DRAW_H__
#define HAS_GUI // #define HAS_GUI
#include <stdio.h> #include <stdio.h>
#include <am.h> #include <am.h>

View file

@ -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)

View file

@ -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)

View file

@ -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 $<TARGET_FILE:gen_alu_test> > 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)

View file

@ -114,7 +114,7 @@ int exclude(type t, char* op, int x, int y)
int main(void) int main(void)
{ {
printf("#include <stdio.h>\n"); printf("#include <stdio.h>\n");
printf("int main(void) {\n"); printf("int main(const char *) {\n");
printf(" int exit_code = 0;\n"); printf(" int exit_code = 0;\n");
FOR_SET_ALL(signed int, vsi); FOR_SET_ALL(signed int, vsi);

View file

@ -1,6 +1,3 @@
find_package(am-${ARCH})
find_package(klib)
set(SOURCES set(SOURCES
add.c add.c
add-longlong.c add-longlong.c
@ -42,12 +39,12 @@ foreach(SOURCE IN LISTS SOURCES)
get_filename_component(SOURCE_NAME ${SOURCE} NAME_WLE) get_filename_component(SOURCE_NAME ${SOURCE} NAME_WLE)
add_executable(${SOURCE_NAME} add_executable(${SOURCE_NAME}
${SOURCE}) ${SOURCE})
target_link_libraries(${SOURCE_NAME} PRIVATE am-${ARCH}) target_link_libraries(${SOURCE_NAME} PRIVATE am-${ARCH} klib)
# -- Extract binary file from ELF # -- Extract binary file from ELF
add_custom_command(TARGET ${SOURCE_NAME} add_custom_command(TARGET ${SOURCE_NAME}
COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary ${SOURCE_NAME} ${SOURCE_NAME}.bin) 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(TARGETS ${SOURCE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SOURCE_NAME}.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/binary) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SOURCE_NAME}.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels)
endforeach() endforeach()