all repos — mgba @ bb6728558dfc477e9f7d2c608f3e01c8626d46f9

mGBA Game Boy Advance Emulator

Test: Restructure test suite into multiple executables
Vicki Pfau vi@endrift.com
Sat, 12 Aug 2017 16:48:48 -0700
commit

bb6728558dfc477e9f7d2c608f3e01c8626d46f9

parent

66d5106e0b613857bc8aa9b5c8dc42b59b9d12de

11 files changed, 12 insertions(+), 128 deletions(-)

jump to
M CHANGESCHANGES

@@ -40,6 +40,7 @@ - All: Make FIXED_ROM_BUFFER an option instead of 3DS-only

- Qt: Don't rebuild library view if style hasn't changed - Qt: Redo GameController into multiple classes - SDL: Fix 2.0.5 build on macOS under some circumstances + - Test: Restructure test suite into multiple executables 0.6.0: (2017-07-16) Features:
M CMakeLists.txtCMakeLists.txt

@@ -861,10 +861,16 @@ enable_testing()

include_directories(AFTER ${CMOCKA_INCLUDE_DIRS}) link_directories(${CMOCKA_LIBRARY_DIRS}) - add_executable(${BINARY_NAME}-suite ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test/suite-main.c ${TEST_SRC}) - target_link_libraries(${BINARY_NAME}-suite ${BINARY_NAME} ${PLATFORM_LIBRARY} cmocka) - set_target_properties(${BINARY_NAME}-suite PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}") - add_test(${BINARY_NAME}-suite ${BINARY_NAME}-suite) + foreach(TEST IN LISTS TEST_SRC) + string(REPLACE "${CMAKE_SOURCE_DIR}/src/" "" TEST_NAME "${TEST}") + string(REPLACE "/" "-" TEST_NAME "${TEST_NAME}") + string(REPLACE "-test" "" TEST_NAME "${TEST_NAME}") + string(REPLACE ".c" "" TEST_NAME "${TEST_NAME}") + add_executable(test-${TEST_NAME} ${TEST}) + target_link_libraries(test-${TEST_NAME} ${BINARY_NAME} ${PLATFORM_LIBRARY} cmocka) + set_target_properties(test-${TEST_NAME} PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}") + add_test(${TEST_NAME} test-${TEST_NAME}) + endforeach() endif() if(BUILD_EXAMPLE)
M src/core/test/core.csrc/core/test/core.c

@@ -34,9 +34,3 @@ cmocka_unit_test(findNullPath),

#endif cmocka_unit_test(findNullVF), cmocka_unit_test(findEmpty)) - -int TestRunCore(void) { - int failures = 0; - failures += M_TEST_SUITE_RUN(mCore); - return failures; -}
D src/gb/test/gb.c

@@ -1,20 +0,0 @@

-/* Copyright (c) 2013-2016 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/test/suite.h" - -M_TEST_SUITE_DECLARE(GBCore); -M_TEST_SUITE_DECLARE(GBMBC); -M_TEST_SUITE_DECLARE(GBMemory); -M_TEST_SUITE_DECLARE(GBRTC); - -int TestRunGB(void) { - int failures = 0; - failures += M_TEST_SUITE_RUN(GBCore); - failures += M_TEST_SUITE_RUN(GBMBC); - failures += M_TEST_SUITE_RUN(GBMemory); - failures += M_TEST_SUITE_RUN(GBRTC); - return failures; -}
D src/gb/test/gb.h

@@ -1,12 +0,0 @@

-/* Copyright (c) 2013-2016 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef TEST_GB_H -#define TEST_GB_H -#include <mgba-util/common.h> - -int TestRunGB(void); - -#endif
D src/gba/test/gba.c

@@ -1,14 +0,0 @@

-/* Copyright (c) 2013-2016 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/test/suite.h" - -M_TEST_SUITE_DECLARE(GBACore); - -int TestRunGBA(void) { - int failures = 0; - failures += M_TEST_SUITE_RUN(GBACore); - return failures; -}
D src/gba/test/gba.h

@@ -1,12 +0,0 @@

-/* Copyright (c) 2013-2016 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef TEST_GBA_H -#define TEST_GBA_H -#include <mgba-util/common.h> - -int TestRunGBA(void); - -#endif
D src/platform/test/suite-main.c

@@ -1,27 +0,0 @@

-/* Copyright (c) 2013-2016 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/test/suite.h" - -#include "util/test/util.h" -#include "core/test/core.h" -#ifdef M_CORE_GBA -#include "gba/test/gba.h" -#endif -#ifdef M_CORE_GB -#include "gb/test/gb.h" -#endif - -int main() { - int failures = TestRunUtil(); - failures += TestRunCore(); -#ifdef M_CORE_GBA - failures += TestRunGBA(); -#endif -#ifdef M_CORE_GB - failures += TestRunGB(); -#endif - return failures != 0; -}
M src/util/test/suite.hsrc/util/test/suite.h

@@ -12,14 +12,12 @@ #include <cmocka.h>

#define M_TEST_DEFINE(NAME) static void NAME (void **state ATTRIBUTE_UNUSED) -#define M_TEST_SUITE(NAME) _testSuite_ ## NAME -#define M_TEST_SUITE_RUN(NAME) (printf("\nRunning suite %s\n", # NAME), M_TEST_SUITE(NAME)()) #define M_TEST_SUITE_DEFINE(NAME, ...) M_TEST_SUITE_DEFINE_EX(NAME, NULL, NULL, __VA_ARGS__) #define M_TEST_SUITE_DEFINE_SETUP(NAME, ...) M_TEST_SUITE_DEFINE_EX(NAME, _testSuite_setup_ ## NAME, NULL, __VA_ARGS__) #define M_TEST_SUITE_DEFINE_TEARDOWN(NAME, ...) M_TEST_SUITE_DEFINE_EX(NAME, NULL, _testSuite_teardown_ ## NAME, __VA_ARGS__) #define M_TEST_SUITE_DEFINE_SETUP_TEARDOWN(NAME, ...) M_TEST_SUITE_DEFINE_EX(NAME, _testSuite_setup_ ## NAME, _testSuite_teardown_ ## NAME, __VA_ARGS__) #define M_TEST_SUITE_DEFINE_EX(NAME, SETUP, TEARDOWN, ...) \ - int M_TEST_SUITE(NAME) (void) { \ + int main(void) { \ const static struct CMUnitTest tests[] = { \ __VA_ARGS__ \ }; \

@@ -28,7 +26,5 @@ }

#define M_TEST_SUITE_SETUP(NAME) static int _testSuite_setup_ ## NAME (void **state ATTRIBUTE_UNUSED) #define M_TEST_SUITE_TEARDOWN(NAME) static int _testSuite_teardown_ ## NAME (void **state ATTRIBUTE_UNUSED) - -#define M_TEST_SUITE_DECLARE(NAME) extern int M_TEST_SUITE(NAME) (void) #endif
D src/util/test/util.c

@@ -1,16 +0,0 @@

-/* Copyright (c) 2013-2016 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/test/suite.h" - -M_TEST_SUITE_DECLARE(TextCodec); -M_TEST_SUITE_DECLARE(VFS); - -int TestRunUtil(void) { - int failures = 0; - failures += M_TEST_SUITE_RUN(TextCodec); - failures += M_TEST_SUITE_RUN(VFS); - return failures; -}
D src/util/test/util.h

@@ -1,12 +0,0 @@

-/* Copyright (c) 2013-2016 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef TEST_UTIL_H -#define TEST_UTIL_H -#include <mgba-util/common.h> - -int TestRunUtil(void); - -#endif