CMake: Support windows for tests

This commit is contained in:
TellowKrinkle 2021-08-13 00:39:40 -05:00 committed by refractionpcsx2
parent 04df2824cf
commit 4d8b9aee2a
6 changed files with 93 additions and 29 deletions

View File

@ -50,6 +50,7 @@ add_subdirectory(pcsx2)
# tests # tests
if(ACTUALLY_ENABLE_TESTS) if(ACTUALLY_ENABLE_TESTS)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory(3rdparty/gtest EXCLUDE_FROM_ALL) add_subdirectory(3rdparty/gtest EXCLUDE_FROM_ALL)
add_subdirectory(tests/ctest) add_subdirectory(tests/ctest)
endif() endif()

View File

@ -1,17 +1,27 @@
option(ENABLE_UNSUPPORTED_TESTS "Include tests that require instructions not supported by this computer" OFF) option(ENABLE_UNSUPPORTED_TESTS "Include tests that require instructions not supported by this computer" OFF)
set(avxdetect_code " set(avxdetect_code "
int main() #ifdef __GNUC__
{ #include <cpuid.h>
#if defined(__AVX2__) void cpuid(int result[4], int leaf, int subleaf) {
return 51; __cpuid_count(leaf, subleaf, result[0], result[1], result[2], result[3]);
#elif defined(__AVX__) }
return 50;
#elif defined(__SSE4_1__)
return 41;
#else #else
return 0; #include <intrin.h>
#define cpuid __cpuidex
#endif #endif
int test(int leaf, int subleaf, int reg, int bit) {
int res[4];
cpuid(res, 0, 0);
if (res[0] < leaf) { return 0; }
cpuid(res, leaf, subleaf);
return !!(res[reg] & (1 << bit));
}
int main() {
if (test(7, 0, 1, 5) /* AVX2 */) return 51;
if (test(1, 0, 2, 28) /* AVX */) return 50;
if (test(1, 0, 2, 19) /* SSE41 */) return 41;
return 0;
} }
") ")
@ -27,11 +37,27 @@ else()
compile_result_unused compile_result_unused
"${CMAKE_BINARY_DIR}" "${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/avxdetect.c" "${CMAKE_BINARY_DIR}/avxdetect.c"
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS:STRING=-march=native"
) )
set(CMAKE_CROSSCOMPILING ${cc_backup}) set(CMAKE_CROSSCOMPILING ${cc_backup})
endif() endif()
if (MSVC)
if(_M_X86_32)
set(compile_options_sse4 /arch:SSE2)
endif()
set(compile_options_avx /arch:AVX)
set(compile_options_avx2 /arch:AVX2)
set(definitions_sse4 _M_SSE=0x401)
set(definitions_avx _M_SSE=0x500)
set(definitions_avx2 _M_SSE=0x501)
else()
set(compile_options_sse4 -msse4.1)
set(compile_options_avx -mavx)
set(compile_options_avx2 -mavx2 -mbmi -mbmi2)
endif()
set(isa_number_sse4 41)
set(isa_number_avx 50)
set(isa_number_avx2 51)
enable_testing() enable_testing()
add_custom_target(unittests) add_custom_target(unittests)

View File

@ -1,15 +1,14 @@
foreach(isa "sse4" "avx" "avx2") foreach(isa "sse4" "avx" "avx2")
set(GSDir ${CMAKE_SOURCE_DIR}/pcsx2/GS) set(GSDir ${CMAKE_SOURCE_DIR}/pcsx2/GS)
if((${isa} STREQUAL "sse4" AND ${native_vector_isa} LESS 41) if(${native_vector_isa} LESS ${isa_number_${isa}})
OR (${isa} STREQUAL "avx" AND ${native_vector_isa} LESS 50)
OR (${isa} STREQUAL "avx2" AND ${native_vector_isa} LESS 51))
# Skip unsupported tests # Skip unsupported tests
continue() continue()
endif() endif()
add_pcsx2_test(swizzle_test_${isa} add_pcsx2_test(swizzle_test_${isa}
swizzle_test_main.cpp swizzle_test_main.cpp
swizzle_test_nops.cpp
${GSDir}/GSBlock.cpp ${GSDir}/GSBlock.cpp
${GSDir}/GSBlock.h ${GSDir}/GSBlock.h
${GSDir}/GSClut.cpp ${GSDir}/GSClut.cpp
@ -18,20 +17,10 @@ foreach(isa "sse4" "avx" "avx2")
${GSDir}/GSTables.h) ${GSDir}/GSTables.h)
target_include_directories(swizzle_test_${isa} PRIVATE ${GSDir} ${CMAKE_SOURCE_DIR}/pcsx2/ ${CMAKE_SOURCE_DIR}/pcsx2/gui) target_include_directories(swizzle_test_${isa} PRIVATE ${GSDir} ${CMAKE_SOURCE_DIR}/pcsx2/ ${CMAKE_SOURCE_DIR}/pcsx2/gui)
if(WIN32)
# Prevent linker errors for functions in e.g. GSClut that we don't actually use depending on things we didn't include target_include_directories(swizzle_test_${isa} PRIVATE ${CMAKE_SOURCE_DIR}/3rdparty)
if(UNIX AND NOT APPLE)
target_compile_options(swizzle_test_${isa} PRIVATE -ffunction-sections)
target_link_options(swizzle_test_${isa} PRIVATE -Wl,-gc-sections)
elseif(APPLE)
target_link_options(swizzle_test_${isa} PRIVATE -Wl,-dead_strip)
endif() endif()
if(${isa} STREQUAL "avx2") target_compile_options(swizzle_test_${isa} PRIVATE ${compile_options_${isa}})
target_compile_options(swizzle_test_${isa} PRIVATE -mavx2 -mbmi -mbmi2) target_compile_definitions(swizzle_test_${isa} PRIVATE ${definitions_${isa}})
elseif(${isa} STREQUAL "avx")
target_compile_options(swizzle_test_${isa} PRIVATE -mavx)
else()
target_compile_options(swizzle_test_${isa} PRIVATE -msse4.1)
endif()
endforeach() endforeach()

View File

@ -0,0 +1,37 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2021 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 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 PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
// This file defines functions that are linked to by files used in swizzle tests but not actually used in swizzle tests, in order to make linkers happy
#include "PrecompiledHeader.h"
#include "GSBlock.h"
#include "GSClut.h"
#include "GSLocalMemory.h"
GSLocalMemory::psm_t GSLocalMemory::m_psm[64];
GSOffset* GSLocalMemory::GetOffset(uint32 bp, uint32 bw, uint32 psm)
{
abort();
}
void* vmalloc(size_t size, bool code)
{
abort();
}
void vmfree(void* ptr, size_t size)
{
abort();
}

View File

@ -13,20 +13,29 @@
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "codegen_tests.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <x86emitter/x86emitter.h> #include <x86emitter/x86emitter.h>
#include <Utilities/Assertions.h>
using namespace x86Emitter; using namespace x86Emitter;
thread_local const char *currentTest; thread_local const char *currentTest;
void pxOnAssert(const DiagnosticOrigin &origin, const wxString &msg) { static void assertHandlerInternal(const DiagnosticOrigin& origin, const wxChar* msg) {
FAIL() << "Assertion failed: " << msg FAIL() << "Assertion failed: " << wxString(msg)
<< "\n at " << origin.srcfile << ":" << origin.line << "" << "\n at " << origin.srcfile << ":" << origin.line << ""
<< "\n when trying to assemble " << currentTest; << "\n when trying to assemble " << currentTest;
} }
static bool assertHandler(const DiagnosticOrigin& origin, const wxChar* msg) {
assertHandlerInternal(origin, msg);
return false;
}
void runCodegenTest(void (*exec)(void *base), const char* description, const char* expected) { void runCodegenTest(void (*exec)(void *base), const char* description, const char* expected) {
pxDoAssert = assertHandler;
u8 code[4096]; u8 code[4096];
memset(code, 0xcc, sizeof(code)); memset(code, 0xcc, sizeof(code));
char str[4096] = {0}; char str[4096] = {0};

View File

@ -13,6 +13,8 @@
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "Utilities/Dependencies.h"
void runCodegenTest(void (*exec)(void *base), const char* description, const char* expected); void runCodegenTest(void (*exec)(void *base), const char* description, const char* expected);
// Use null to skip, empty string to expect no output // Use null to skip, empty string to expect no output