From 3db8fe6f53f51f5c4f5e4dd4e09ac2537ce709ce Mon Sep 17 00:00:00 2001 From: Daniel Thornburgh Date: Wed, 26 Oct 2022 11:26:43 -0700 Subject: [PATCH] Refactor NES tests. --- test/{nes-mmc3 => }/mesen.lua | 0 test/nes-cnrom/CMakeLists.txt | 30 ++------------------ test/nes-cnrom/no-compile/CMakeLists.txt | 8 ++---- test/nes-mmc1/CMakeLists.txt | 35 ++---------------------- test/nes-mmc1/no-compile/CMakeLists.txt | 22 +++++++-------- test/nes-mmc3/CMakeLists.txt | 28 +------------------ test/nes-mmc3/test-lib.c | 9 ------ test/nes-nrom/CMakeLists.txt | 33 ++-------------------- test/nes-nrom/no-compile/CMakeLists.txt | 15 ++++------ test/{nes-nrom => }/test-lib.c | 0 test/test.cmake | 34 +++++++++++++++++++++++ 11 files changed, 60 insertions(+), 154 deletions(-) rename test/{nes-mmc3 => }/mesen.lua (100%) delete mode 100644 test/nes-mmc3/test-lib.c rename test/{nes-nrom => }/test-lib.c (100%) create mode 100644 test/test.cmake diff --git a/test/nes-mmc3/mesen.lua b/test/mesen.lua similarity index 100% rename from test/nes-mmc3/mesen.lua rename to test/mesen.lua diff --git a/test/nes-cnrom/CMakeLists.txt b/test/nes-cnrom/CMakeLists.txt index 317cb04f4..c858190d0 100644 --- a/test/nes-cnrom/CMakeLists.txt +++ b/test/nes-cnrom/CMakeLists.txt @@ -1,37 +1,11 @@ cmake_minimum_required(VERSION 3.18) project(test-nes-mmc1 LANGUAGES C) -include(CTest) -add_library(test-lib test-lib.c) - -function(add_mesen_test name) - add_executable(${name} ${name}.c) - target_link_libraries(${name} test-lib) - add_test(NAME test-${name} COMMAND ${MESEN_COMMAND} --testrunner - $ ${CMAKE_CURRENT_SOURCE_DIR}/mesen.lua) -endfunction() +include(../test.cmake) add_mesen_test(minimal) - add_mesen_test(chr-ram) add_mesen_test(chr-rom) -function(add_no_compile_test target) - add_test(NAME ${target}-no-compile COMMAND ${CMAKE_CTEST_COMMAND} - --build-and-test ${CMAKE_CURRENT_SOURCE_DIR}/no-compile - ${CMAKE_CURRENT_BINARY_DIR}/no-compile/${target} - --build-generator ${CMAKE_GENERATOR} - --build-makeprogram ${CMAKE_MAKE_PROGRAM} - --build-target ${target} - --build-options - -DLLVM_MOS=${LLVM_MOS} - -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} - -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} - ) - set_property(TEST ${target}-no-compile PROPERTY WILL_FAIL YES) -endfunction() - -add_no_compile_test(chr-rom-too-big) -add_no_compile_test(chr-rom-non-pow2) +add_subdirectory(no-compile) diff --git a/test/nes-cnrom/no-compile/CMakeLists.txt b/test/nes-cnrom/no-compile/CMakeLists.txt index 445a72c19..2bb2c26dd 100644 --- a/test/nes-cnrom/no-compile/CMakeLists.txt +++ b/test/nes-cnrom/no-compile/CMakeLists.txt @@ -1,6 +1,4 @@ -cmake_minimum_required(VERSION 3.18) +set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL ON) -project(test-nes-mmc1-nocompile LANGUAGES C) - -add_executable(chr-rom-too-big chr-rom-too-big.c) -add_executable(chr-rom-non-pow2 chr-rom-non-pow2.c) +add_no_compile_test(chr-rom-too-big) +add_no_compile_test(chr-rom-non-pow2) diff --git a/test/nes-mmc1/CMakeLists.txt b/test/nes-mmc1/CMakeLists.txt index dee7a35d6..bc4eba198 100644 --- a/test/nes-mmc1/CMakeLists.txt +++ b/test/nes-mmc1/CMakeLists.txt @@ -1,16 +1,8 @@ cmake_minimum_required(VERSION 3.18) project(test-nes-mmc1 LANGUAGES C) -include(CTest) -add_library(test-lib test-lib.c) - -function(add_mesen_test name) - add_executable(${name} ${name}.c) - target_link_libraries(${name} test-lib) - add_test(NAME test-${name} COMMAND ${MESEN_COMMAND} --testrunner - $ ${CMAKE_CURRENT_SOURCE_DIR}/mesen.lua) -endfunction() +include(../test.cmake) add_mesen_test(minimal) @@ -39,27 +31,4 @@ add_mesen_test(prg-ram) add_mesen_test(prg-ram-c) target_link_options(prg-ram-c PRIVATE -Tcommon.ld -Tprg-rom-128.ld -Tc-in-prg-ram-0.ld) -function(add_no_compile_test target) - add_test(NAME ${target}-no-compile COMMAND ${CMAKE_CTEST_COMMAND} - --build-and-test ${CMAKE_CURRENT_SOURCE_DIR}/no-compile - ${CMAKE_CURRENT_BINARY_DIR}/no-compile/${target} - --build-generator ${CMAKE_GENERATOR} - --build-makeprogram ${CMAKE_MAKE_PROGRAM} - --build-target ${target} - --build-options - -DLLVM_MOS=${LLVM_MOS} - -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} - -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} - ) - set_property(TEST ${target}-no-compile PROPERTY WILL_FAIL YES) -endfunction() - -add_no_compile_test(chr-rom-too-big) -add_no_compile_test(chr-rom-non-pow2) -add_no_compile_test(chr-ram-too-big) -add_no_compile_test(chr-ram-uneven-banks) -add_no_compile_test(chr-nvram-uneven-banks) -add_no_compile_test(prg-ram-too-big) -add_no_compile_test(prg-ram-uneven-banks) -add_no_compile_test(prg-nvram-uneven-banks) +add_subdirectory(no-compile) diff --git a/test/nes-mmc1/no-compile/CMakeLists.txt b/test/nes-mmc1/no-compile/CMakeLists.txt index c483bcd3f..9d5d70ee5 100644 --- a/test/nes-mmc1/no-compile/CMakeLists.txt +++ b/test/nes-mmc1/no-compile/CMakeLists.txt @@ -1,14 +1,12 @@ cmake_minimum_required(VERSION 3.18) -project(test-nes-mmc1-nocompile LANGUAGES C) - -add_executable(chr-rom-too-big chr-rom-too-big.c) -add_executable(chr-rom-non-pow2 chr-rom-non-pow2.c) - -add_executable(chr-ram-too-big chr-ram-too-big.c) -add_executable(chr-ram-uneven-banks chr-ram-uneven-banks.c) -add_executable(chr-nvram-uneven-banks chr-nvram-uneven-banks.c) - -add_executable(prg-ram-too-big prg-ram-too-big.c) -add_executable(prg-ram-uneven-banks prg-ram-uneven-banks.c) -add_executable(prg-nvram-uneven-banks prg-nvram-uneven-banks.c) +set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL ON) + +add_no_compile_test(chr-rom-too-big) +add_no_compile_test(chr-rom-non-pow2) +add_no_compile_test(chr-ram-too-big) +add_no_compile_test(chr-ram-uneven-banks) +add_no_compile_test(chr-nvram-uneven-banks) +add_no_compile_test(prg-ram-too-big) +add_no_compile_test(prg-ram-uneven-banks) +add_no_compile_test(prg-nvram-uneven-banks) diff --git a/test/nes-mmc3/CMakeLists.txt b/test/nes-mmc3/CMakeLists.txt index 151cb9eec..c3af0fb79 100644 --- a/test/nes-mmc3/CMakeLists.txt +++ b/test/nes-mmc3/CMakeLists.txt @@ -1,33 +1,7 @@ cmake_minimum_required(VERSION 3.18) project(test-nes-mmc3 LANGUAGES C) -include(CTest) -add_library(test-lib test-lib.c) - -function(add_mesen_test name) - add_executable(${name} ${name}.c) - target_link_libraries(${name} test-lib) - add_test(NAME test-${name} COMMAND ${MESEN_COMMAND} --testrunner - $ ${CMAKE_CURRENT_SOURCE_DIR}/mesen.lua) -endfunction() +include(../test.cmake) add_mesen_test(minimal) - -function(add_no_compile_test target) - add_test(NAME ${target}-no-compile COMMAND ${CMAKE_CTEST_COMMAND} - --build-and-test ${CMAKE_CURRENT_SOURCE_DIR}/no-compile - ${CMAKE_CURRENT_BINARY_DIR}/no-compile/${target} - --build-generator ${CMAKE_GENERATOR} - --build-makeprogram ${CMAKE_MAKE_PROGRAM} - --build-target ${target} - --build-options - -DLLVM_MOS=${LLVM_MOS} - -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} - -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} - ) - set_property(TEST ${target}-no-compile PROPERTY WILL_FAIL YES) -endfunction() - -#add_no_compile_test(chr-rom-too-big) diff --git a/test/nes-mmc3/test-lib.c b/test/nes-mmc3/test-lib.c deleted file mode 100644 index a7c1a218b..000000000 --- a/test/nes-mmc3/test-lib.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -__attribute__((noreturn)) void _exit(int status) { - // This is an unused APU test register, so it should be safe to use writing to - // this address to report the exit code to the controlling Mesen Lua script. - POKE(0x4018, status); - __builtin_unreachable(); -} - diff --git a/test/nes-nrom/CMakeLists.txt b/test/nes-nrom/CMakeLists.txt index 0fcbfee82..4522ea35d 100644 --- a/test/nes-nrom/CMakeLists.txt +++ b/test/nes-nrom/CMakeLists.txt @@ -1,16 +1,8 @@ cmake_minimum_required(VERSION 3.18) project(test-nes-mmc1 LANGUAGES C) -include(CTest) -add_library(test-lib test-lib.c) - -function(add_mesen_test name) - add_executable(${name} ${name}.c) - target_link_libraries(${name} test-lib) - add_test(NAME test-${name} COMMAND ${MESEN_COMMAND} --testrunner - $ ${CMAKE_CURRENT_SOURCE_DIR}/mesen.lua) -endfunction() +include(../test.cmake) add_mesen_test(minimal) @@ -26,25 +18,4 @@ target_link_options(prg-ram-c PRIVATE -Tcommon.ld -Tc-in-prg-ram.ld) add_mesen_test(zp-data) -function(add_no_compile_test target) - add_test(NAME ${target}-no-compile COMMAND ${CMAKE_CTEST_COMMAND} - --build-and-test ${CMAKE_CURRENT_SOURCE_DIR}/no-compile - ${CMAKE_CURRENT_BINARY_DIR}/no-compile/${target} - --build-generator ${CMAKE_GENERATOR} - --build-makeprogram ${CMAKE_MAKE_PROGRAM} - --build-target ${target} - --build-options - -DLLVM_MOS=${LLVM_MOS} - -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} - -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} - ) - set_property(TEST ${target}-no-compile PROPERTY WILL_FAIL YES) -endfunction() - -add_no_compile_test(chr-rom-too-big) -add_no_compile_test(chr-rom-non-pow2) -add_no_compile_test(chr-ram-too-big) - -add_no_compile_test(prg-rom-too-big) -add_no_compile_test(prg-ram-too-big) +add_subdirectory(no-compile) diff --git a/test/nes-nrom/no-compile/CMakeLists.txt b/test/nes-nrom/no-compile/CMakeLists.txt index 8eafe8da9..e0db51d63 100644 --- a/test/nes-nrom/no-compile/CMakeLists.txt +++ b/test/nes-nrom/no-compile/CMakeLists.txt @@ -1,10 +1,7 @@ -cmake_minimum_required(VERSION 3.18) +set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL ON) -project(test-nes-mmc1-nocompile LANGUAGES C) - -add_executable(chr-rom-too-big chr-rom-too-big.c) -add_executable(chr-rom-non-pow2 chr-rom-non-pow2.c) -add_executable(chr-ram-too-big chr-ram-too-big.c) - -add_executable(prg-rom-too-big prg-rom-too-big.c) -add_executable(prg-ram-too-big prg-ram-too-big.c) +add_no_compile_test(chr-ram-too-big) +add_no_compile_test(chr-rom-non-pow2) +add_no_compile_test(chr-rom-too-big) +add_no_compile_test(prg-rom-too-big) +add_no_compile_test(prg-ram-too-big) diff --git a/test/nes-nrom/test-lib.c b/test/test-lib.c similarity index 100% rename from test/nes-nrom/test-lib.c rename to test/test-lib.c diff --git a/test/test.cmake b/test/test.cmake new file mode 100644 index 000000000..42cc0968f --- /dev/null +++ b/test/test.cmake @@ -0,0 +1,34 @@ +include(CTest) + +add_library(test-lib ${CMAKE_CURRENT_SOURCE_DIR}/../test-lib.c) + +function(add_mesen_test name) + add_executable(${name} ${name}.c) + target_link_libraries(${name} test-lib) + add_test(NAME test-${name} COMMAND ${MESEN_COMMAND} --testrunner + $ ${CMAKE_CURRENT_SOURCE_DIR}/../mesen.lua) +endfunction() + +function(add_mesen_test name) + add_executable(${name} ${name}.c) + target_link_libraries(${name} test-lib) + add_test(NAME test-${name} COMMAND ${MESEN_COMMAND} --testrunner + $ ${CMAKE_CURRENT_SOURCE_DIR}/../mesen.lua) +endfunction() + +function(add_no_compile_test target) + add_executable(${target} ${target}.c) + add_test(NAME ${target}-no-compile COMMAND ${CMAKE_CTEST_COMMAND} + --build-and-test ${CMAKE_CURRENT_SOURCE_DIR}/.. + ${CMAKE_CURRENT_BINARY_DIR}/${target} + --build-generator ${CMAKE_GENERATOR} + --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-target ${target} + --build-options + -DLLVM_MOS=${LLVM_MOS} + -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} + -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} + -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} + ) + set_property(TEST ${target}-no-compile PROPERTY WILL_FAIL YES) +endfunction()