From e54772fead056618fa39a7b3743a51749ec54f81 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Fri, 21 Oct 2016 18:28:18 -0700 Subject: [PATCH] Test: Refactor test framework --- CMakeLists.txt | 26 ++++++++++++++++--- .../test/suite/common => core/test}/core.c | 10 +++++-- .../common/common.h => core/test/core.h} | 8 +++--- src/platform/test/suite-main.c | 9 ++++--- src/platform/test/suite/CMakeLists.txt | 4 --- .../test/suite => util/test}/suite.h | 0 .../common/common.c => util/test/util.c} | 6 ++--- src/util/test/util.h | 12 +++++++++ .../test/suite/common => util/test}/vfs.c | 2 +- 9 files changed, 55 insertions(+), 22 deletions(-) rename src/{platform/test/suite/common => core/test}/core.c (84%) rename src/{platform/test/suite/common/common.h => core/test/core.h} (77%) delete mode 100644 src/platform/test/suite/CMakeLists.txt rename src/{platform/test/suite => util/test}/suite.h (100%) rename src/{platform/test/suite/common/common.c => util/test/util.c} (72%) create mode 100644 src/util/test/util.h rename src/{platform/test/suite/common => util/test}/vfs.c (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index c39f06551..3804de52e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,13 +35,20 @@ set(BUILD_GLES2 OFF CACHE STRING "Build with OpenGL|ES 2") set(USE_EPOXY ON CACHE STRING "Build with libepoxy") set(DISABLE_DEPS OFF CACHE BOOL "Build without dependencies") file(GLOB ARM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/arm/*.c) +file(GLOB ARM_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/arm/test/*.c) file(GLOB LR35902_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/*.c) +file(GLOB LR35902_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/test/*.c) file(GLOB GBA_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/*.c) +file(GLOB GBA_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/test/*.c) file(GLOB GB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/*.c) +file(GLOB GB_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/test/*.c) file(GLOB GBA_CHEATS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/cheats/*.c) file(GLOB GBA_RR_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/rr/*.c) file(GLOB GBA_EXTRA_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/extra/*.c) -file(GLOB UTIL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/*.[cSs] ${CMAKE_CURRENT_SOURCE_DIR}/src/core/*.c) +file(GLOB CORE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/core/*.c) +file(GLOB CORE_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/core/test/*.c) +file(GLOB UTIL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/*.[cSs]) +file(GLOB UTIL_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/test/*.c) file(GLOB GUI_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/gui/*.c ${CMAKE_CURRENT_SOURCE_DIR}/src/feature/gui/*.c) file(GLOB GBA_RENDERER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/renderers/*.c) file(GLOB SIO_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/sio/lockstep.c) @@ -533,7 +540,7 @@ foreach(FEATURE IN LISTS FEATURES) list(APPEND FEATURE_DEFINES "USE_${FEATURE}") endforeach() -set(CORE_SRC) +set(TEST_SRC ${CORE_TEST_SRC}) if(M_CORE_GB) add_definitions(-DM_CORE_GB) list(APPEND CORE_SRC @@ -541,6 +548,9 @@ if(M_CORE_GB) ${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/debugger/debugger.c ${GB_SRC} ${GB_RENDERER_SRC}) + list(APPEND TEST_SRC + ${LR35902_TEST_SRC} + ${GB_TEST_SRC}) endif() if(M_CORE_GBA) @@ -552,6 +562,9 @@ if(M_CORE_GBA) ${GBA_SRC} ${GBA_CHEATS_SRC} ${GBA_RENDERER_SRC}) + list(APPEND TEST_SRC + ${ARM_TEST_SRC} + ${GBA_TEST_SRC}) if(NOT M_CORE_GB) list(APPEND CORE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/audio.c) endif() @@ -581,6 +594,7 @@ list(APPEND CORE_SRC ${DEBUGGER_SRC} ${OS_SRC} ${THIRD_PARTY_SRC}) +list(APPEND TEST_SRC ${UTIL_TEST_SRC}) set(SRC ${CORE_SRC} ${VFS_SRC}) if(NOT MINIMAL_CORE) @@ -708,11 +722,15 @@ endif() if(NOT USE_CMOCKA) set(BUILD_SUITE OFF) endif() -if(USE_CMOCKA) +if(BUILD_SUITE) enable_testing() include_directories(AFTER ${CMOCKA_INCLUDE_DIRS}) link_directories(${CMOCKA_LIBRARY_DIRS}) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test/suite ${CMAKE_CURRENT_BINARY_DIR}/suite) + + 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) endif() if(BUILD_EXAMPLE) diff --git a/src/platform/test/suite/common/core.c b/src/core/test/core.c similarity index 84% rename from src/platform/test/suite/common/core.c rename to src/core/test/core.c index df008079b..12f67a900 100644 --- a/src/platform/test/suite/common/core.c +++ b/src/core/test/core.c @@ -3,7 +3,7 @@ * 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 "platform/test/suite/suite.h" +#include "util/test/suite.h" #include "core/core.h" #include "util/vfs.h" @@ -33,4 +33,10 @@ M_TEST_SUITE_DEFINE(mCore, cmocka_unit_test(findNullPath), #endif cmocka_unit_test(findNullVF), - cmocka_unit_test(findEmpty)) \ No newline at end of file + cmocka_unit_test(findEmpty)) + +int TestRunCore(void) { + int failures = 0; + failures += M_TEST_SUITE_RUN(mCore); + return failures; +} diff --git a/src/platform/test/suite/common/common.h b/src/core/test/core.h similarity index 77% rename from src/platform/test/suite/common/common.h rename to src/core/test/core.h index 19453c156..f5cbd16a0 100644 --- a/src/platform/test/suite/common/common.h +++ b/src/core/test/core.h @@ -3,10 +3,10 @@ * 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 SUITE_COMMON_H -#define SUITE_COMMON_H +#ifndef TEST_M_CORE_H +#define TEST_M_CORE_H #include "util/common.h" -int mTestRunCommon(void); +int TestRunCore(void); -#endif \ No newline at end of file +#endif diff --git a/src/platform/test/suite-main.c b/src/platform/test/suite-main.c index c655c4ab7..5d5419fc7 100644 --- a/src/platform/test/suite-main.c +++ b/src/platform/test/suite-main.c @@ -3,10 +3,13 @@ * 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 "platform/test/suite/suite.h" +#include "util/test/suite.h" -#include "platform/test/suite/common/common.h" +#include "util/test/util.h" +#include "core/test/core.h" int main() { - return mTestRunCommon() != 0; + int failures = TestRunUtil(); + failures += TestRunCore(); + return failures != 0; } diff --git a/src/platform/test/suite/CMakeLists.txt b/src/platform/test/suite/CMakeLists.txt deleted file mode 100644 index 05d7520b7..000000000 --- a/src/platform/test/suite/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -file(GLOB SUITE_COMMON_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/*.c) -add_executable(${BINARY_NAME}-suite ${SUITE_COMMON_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/../suite-main.c) -target_link_libraries(${BINARY_NAME}-suite ${BINARY_NAME} ${PLATFORM_LIBRARY} cmocka) -add_test(${BINARY_NAME}-suite ${BINARY_NAME}-suite) \ No newline at end of file diff --git a/src/platform/test/suite/suite.h b/src/util/test/suite.h similarity index 100% rename from src/platform/test/suite/suite.h rename to src/util/test/suite.h diff --git a/src/platform/test/suite/common/common.c b/src/util/test/util.c similarity index 72% rename from src/platform/test/suite/common/common.c rename to src/util/test/util.c index 3997dbb9d..df54d8000 100644 --- a/src/platform/test/suite/common/common.c +++ b/src/util/test/util.c @@ -3,14 +3,12 @@ * 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 "platform/test/suite/suite.h" +#include "util/test/suite.h" -M_TEST_SUITE_DECLARE(mCore); M_TEST_SUITE_DECLARE(VFS); -int mTestRunCommon(void) { +int TestRunUtil(void) { int failures = 0; - failures += M_TEST_SUITE_RUN(mCore); failures += M_TEST_SUITE_RUN(VFS); return failures; } diff --git a/src/util/test/util.h b/src/util/test/util.h new file mode 100644 index 000000000..e5a374554 --- /dev/null +++ b/src/util/test/util.h @@ -0,0 +1,12 @@ +/* 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 "util/common.h" + +int TestRunUtil(void); + +#endif diff --git a/src/platform/test/suite/common/vfs.c b/src/util/test/vfs.c similarity index 98% rename from src/platform/test/suite/common/vfs.c rename to src/util/test/vfs.c index 14122d01b..7e7707090 100644 --- a/src/platform/test/suite/common/vfs.c +++ b/src/util/test/vfs.c @@ -3,7 +3,7 @@ * 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 "platform/test/suite/suite.h" +#include "util/test/suite.h" #include "util/vfs.h"