From 9e8b57d6e6c5cee76af12bce27efb81041676314 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 6 Dec 2020 19:13:54 +0100 Subject: added testing framework (check) --- LINKS | 1 + emu/CMakeLists.txt | 3 +++ emu/emul.c | 20 ++++++++++++------- emu/tests/CMakeLists.txt | 4 ++++ emu/tests/test_cpu_6502.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 emu/tests/CMakeLists.txt create mode 100644 emu/tests/test_cpu_6502.c diff --git a/LINKS b/LINKS index e5ec1ca..345b34e 100644 --- a/LINKS +++ b/LINKS @@ -139,3 +139,4 @@ http://nparker.llx.com/a2/opcodes.html testing: http://www.ucunit.org/_related__sites.html http://cunit.sourceforge.net/ +https://github.com/vndmtrx/check-cmake-example diff --git a/emu/CMakeLists.txt b/emu/CMakeLists.txt index 33f02f5..535802a 100644 --- a/emu/CMakeLists.txt +++ b/emu/CMakeLists.txt @@ -36,9 +36,12 @@ INCLUDE(FindPkgConfig) PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2) PKG_SEARCH_MODULE(SDL2_GFX REQUIRED SDL2_gfx) +PKG_SEARCH_MODULE(CHECK REQUIRED check) include_directories(${SDL2_INCLUDE_DIRS} ${SDL2_INCLUDE_DIRS}) add_executable(emu ${SRC}) target_link_libraries(emu ${SDL2_LIBRARIES} ${SDL2_GFX_LIBRARIES}) +enable_testing() +add_subdirectory(tests) diff --git a/emu/emul.c b/emu/emul.c index 0399d33..4d2c3f1 100644 --- a/emu/emul.c +++ b/emu/emul.c @@ -74,6 +74,18 @@ void emul_start( emul_t *emul ) } } +static void print_help( void ) +{ + fprintf( stderr, "CPU is paused, press\n" + "(s) for single step\n" + "(f) fini (continue to next rts)\n" + "(c) for continue running\n" + "(b) break to single stepping\n" + "(+) speed up\n" + "(-) speed down\n" + "(q) or (ESC) for shutting down\n" ); +} + void emul_run( emul_t *emul, int nof_steps ) { #ifdef WITH_GUI @@ -82,13 +94,7 @@ void emul_run( emul_t *emul, int nof_steps ) bool done = false; if( emul->paused ) { - fprintf( stderr, "CPU is paused, press\n" - "(s) for single step\n" - "(c) for continue running\n" - "(b) break to single stepping\n" - "(+) speed up\n" - "(-) speed down\n" - "(q) or (ESC) for shutting down\n" ); + print_help( ); } while( !done ) { diff --git a/emu/tests/CMakeLists.txt b/emu/tests/CMakeLists.txt new file mode 100644 index 0000000..5011371 --- /dev/null +++ b/emu/tests/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(test_cpu_6502 test_cpu_6502.c) +target_link_libraries(test_cpu_6502 ${CHECK_LIBRARIES} pthread) + +add_test(NAME test_cpu_6502 COMMAND test_cpu_6502 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests) diff --git a/emu/tests/test_cpu_6502.c b/emu/tests/test_cpu_6502.c new file mode 100644 index 0000000..0eb6a2b --- /dev/null +++ b/emu/tests/test_cpu_6502.c @@ -0,0 +1,50 @@ +#include +#include +#include + +void setup( void ) +{ +} + +void teardown( void ) +{ +} + +START_TEST( test_cpu_6502_nop ) +{ +} +END_TEST + +Suite *make_cpu_6502_testsuite( void ) +{ + Suite *suite; + TCase *tc_opcodes; + + suite = suite_create( "6502 CPU tests" ); + + tc_opcodes = tcase_create( "test opcodes" ); + + tcase_add_test( tc_opcodes, test_cpu_6502_nop ); + + suite_add_tcase( suite, tc_opcodes ); + + return suite; +} + +int main( void ) +{ + SRunner *runner; + int tests_failed = 0; + + runner = srunner_create( make_cpu_6502_testsuite( ) ); + srunner_set_fork_status( runner, CK_NOFORK ); + + srunner_set_log( runner, "test.log" ); + srunner_set_xml( runner, "test.xml" ); + srunner_run_all( runner, CK_VERBOSE ); + + tests_failed = srunner_ntests_failed( runner ); + srunner_free( runner ); + + exit( ( tests_failed == 0 ) ? EXIT_SUCCESS : EXIT_FAILURE ); +} -- cgit v1.2.3-54-g00ecf