Skip to content

Commit

Permalink
First crack at a test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTG committed Dec 6, 2023
1 parent 090627b commit 549cd4a
Show file tree
Hide file tree
Showing 11 changed files with 564 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,12 @@ add_subdirectory(src)
if (BUILD_QT_SDL)
add_subdirectory(src/frontend/qt_sdl)
endif()

option(MELONDS_BUILD_TESTS "Build the melonDS test suite." OFF)

if (MELONDS_BUILD_TESTS)
include(CTest)
message(STATUS "Enabling melonDS test suite.")
enable_testing()
add_subdirectory(test)
endif()
65 changes: 65 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
cmake_policy(SET CMP0110 NEW)

if (NOT NDS_ROM)
message(WARNING "NDS_ROM must be set to the path of an NDS ROM; tests that require one won't run.")
set(NDS_ROM "NDS_ROM-NOTFOUND" CACHE FILEPATH "Path to an NDS ROM" FORCE)
else()
message(DEBUG "NDS_ROM: ${NDS_ROM}")
endif()

include(CMakePrintHelpers)

function(add_melonds_test)
set(options WILL_FAIL ARM7_BIOS ARM9_BIOS ARM7_DSI_BIOS ARM9_DSI_BIOS NDS_FIRMWARE DSI_FIRMWARE DSI_NAND DISABLED)
set(oneValueArgs TARGET NAME ROM)
set(multiValueArgs ARGS LABEL)
cmake_parse_arguments(PARSE_ARGV 0 MELONDS_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}")

cmake_print_variables(MELONDS_TEST_TARGET MELONDS_TEST_NAME MELONDS_TEST_ROM MELONDS_TEST_ARGS MELONDS_TEST_LABEL MELONDS_TEST_WILL_FAIL MELONDS_TEST_DISABLED)
add_test(
NAME "${MELONDS_TEST_NAME}"
COMMAND "${MELONDS_TEST_TARGET}"
${MELONDS_TEST_ARGS}
COMMAND_EXPAND_LISTS
)

if (MELONDS_TEST_ROM)
list(APPEND REQUIRED_FILES "${MELONDS_TEST_ROM}")
endif()

macro(expose_system_file SYSFILE)
if (MELONDS_TEST_${SYSFILE})
list(APPEND REQUIRED_FILES "${${SYSFILE}}")
list(APPEND ENVIRONMENT "${SYSFILE}=${${SYSFILE}}")
endif()
endmacro()

expose_system_file(ARM7_BIOS)
expose_system_file(ARM9_BIOS)
expose_system_file(ARM7_DSI_BIOS)
expose_system_file(ARM9_DSI_BIOS)
expose_system_file(NDS_FIRMWARE)
expose_system_file(DSI_FIRMWARE)
expose_system_file(DSI_NAND)

set_tests_properties("${MELONDS_TEST_NAME}" PROPERTIES LABELS "${MELONDS_TEST_LABEL}") # This is already a list
set_tests_properties("${MELONDS_TEST_NAME}" PROPERTIES ENVIRONMENT "${ENVIRONMENT}")
set_tests_properties("${MELONDS_TEST_NAME}" PROPERTIES REQUIRED_FILES "${REQUIRED_FILES}")

if (MELONDS_TEST_WILL_FAIL)
set_tests_properties("${MELONDS_TEST_NAME}" PROPERTIES WILL_FAIL TRUE)
endif()

if (MELONDS_TEST_DISABLED)
set_tests_properties("${MELONDS_TEST_NAME}" PROPERTIES DISABLED TRUE)
endif()
endfunction()

function(add_test_executable TEST_PROGRAM)
add_executable("${TEST_PROGRAM}" "${TEST_PROGRAM}.cpp")
target_link_libraries("${TEST_PROGRAM}" PRIVATE core melonDS-tests-common)
target_include_directories("${TEST_PROGRAM}" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../src")
endfunction()

add_subdirectory(common)
add_subdirectory(cases)
1 change: 1 addition & 0 deletions test/cases/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(basic)
22 changes: 22 additions & 0 deletions test/cases/basic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Test executables must be defined separately from the actual tests,
# as the same test executable might be used for multiple tests
# (with different parameters each time).

add_test_executable(NDSCreated)
add_test_executable(MultipleNDSCreated)
add_test_executable(MultipleNDSCreatedInDifferentOrder)

add_melonds_test(
NAME "NDS is created and destroyed"
TARGET NDSCreated
)

add_melonds_test(
NAME "Multiple NDS systems are created and destroyed"
TARGET MultipleNDSCreated
)

add_melonds_test(
NAME "Multiple NDS systems are created and destroyed in different orders"
TARGET MultipleNDSCreatedInDifferentOrder
)
28 changes: 28 additions & 0 deletions test/cases/basic/MultipleNDSCreated.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2016-2023 melonDS team
This file is part of melonDS.
melonDS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with melonDS. If not, see http://www.gnu.org/licenses/.
*/

#include "NDS.h"

int main()
{
// volatile so it's not optimized out
volatile auto nds1 = std::make_unique<melonDS::NDS>();
volatile auto nds2 = std::make_unique<melonDS::NDS>();
volatile auto nds3 = std::make_unique<melonDS::NDS>();
volatile auto nds4 = std::make_unique<melonDS::NDS>();
}
34 changes: 34 additions & 0 deletions test/cases/basic/MultipleNDSCreatedInDifferentOrder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2016-2023 melonDS team
This file is part of melonDS.
melonDS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with melonDS. If not, see http://www.gnu.org/licenses/.
*/

#include <memory>
#include "NDS.h"

int main()
{
// volatile so it's not optimized out
auto nds1 = std::make_unique<volatile melonDS::NDS>();
auto nds2 = std::make_unique<volatile melonDS::NDS>();
auto nds3 = std::make_unique<volatile melonDS::NDS>();
auto nds4 = std::make_unique<volatile melonDS::NDS>();

nds3 = nullptr;
nds1 = nullptr;
nds4 = nullptr;
nds2 = nullptr;
}
28 changes: 28 additions & 0 deletions test/cases/basic/NDSCreated.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2016-2023 melonDS team
This file is part of melonDS.
melonDS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with melonDS. If not, see http://www.gnu.org/licenses/.
*/

#include <memory>
#include "NDS.h"

int main()
{
// volatile so it's not optimized out
volatile auto nds = std::make_unique<melonDS::NDS>();

// NDS is probably waaaay too big for the stack
}
13 changes: 13 additions & 0 deletions test/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
include(FixInterfaceIncludes)

add_library(melonDS-tests-common STATIC
Platform.cpp
TestCommon.cpp
TestCommon.h
)

# The test program is built with C++20 so we can use std::counting_semaphore
set_target_properties(melonDS-tests-common PROPERTIES CXX_STANDARD 20)

target_link_libraries(melonDS-tests-common PRIVATE core)
target_include_directories(melonDS-tests-common PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../../src")
Loading

0 comments on commit 549cd4a

Please sign in to comment.