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
if(ACTUALLY_ENABLE_TESTS)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory(3rdparty/gtest EXCLUDE_FROM_ALL)
add_subdirectory(tests/ctest)
endif()

View File

@ -1,17 +1,27 @@
option(ENABLE_UNSUPPORTED_TESTS "Include tests that require instructions not supported by this computer" OFF)
set(avxdetect_code "
int main()
{
#if defined(__AVX2__)
return 51;
#elif defined(__AVX__)
return 50;
#elif defined(__SSE4_1__)
return 41;
#ifdef __GNUC__
#include <cpuid.h>
void cpuid(int result[4], int leaf, int subleaf) {
__cpuid_count(leaf, subleaf, result[0], result[1], result[2], result[3]);
}
#else
return 0;
#include <intrin.h>
#define cpuid __cpuidex
#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
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/avxdetect.c"
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS:STRING=-march=native"
)
set(CMAKE_CROSSCOMPILING ${cc_backup})
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()
add_custom_target(unittests)

View File

@ -1,15 +1,14 @@
foreach(isa "sse4" "avx" "avx2")
set(GSDir ${CMAKE_SOURCE_DIR}/pcsx2/GS)
if((${isa} STREQUAL "sse4" AND ${native_vector_isa} LESS 41)
OR (${isa} STREQUAL "avx" AND ${native_vector_isa} LESS 50)
OR (${isa} STREQUAL "avx2" AND ${native_vector_isa} LESS 51))
if(${native_vector_isa} LESS ${isa_number_${isa}})
# Skip unsupported tests
continue()
endif()
add_pcsx2_test(swizzle_test_${isa}
swizzle_test_main.cpp
swizzle_test_nops.cpp
${GSDir}/GSBlock.cpp
${GSDir}/GSBlock.h
${GSDir}/GSClut.cpp
@ -18,20 +17,10 @@ foreach(isa "sse4" "avx" "avx2")
${GSDir}/GSTables.h)
target_include_directories(swizzle_test_${isa} PRIVATE ${GSDir} ${CMAKE_SOURCE_DIR}/pcsx2/ ${CMAKE_SOURCE_DIR}/pcsx2/gui)
# Prevent linker errors for functions in e.g. GSClut that we don't actually use depending on things we didn't include
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)
if(WIN32)
target_include_directories(swizzle_test_${isa} PRIVATE ${CMAKE_SOURCE_DIR}/3rdparty)
endif()
if(${isa} STREQUAL "avx2")
target_compile_options(swizzle_test_${isa} PRIVATE -mavx2 -mbmi -mbmi2)
elseif(${isa} STREQUAL "avx")
target_compile_options(swizzle_test_${isa} PRIVATE -mavx)
else()
target_compile_options(swizzle_test_${isa} PRIVATE -msse4.1)
endif()
target_compile_options(swizzle_test_${isa} PRIVATE ${compile_options_${isa}})
target_compile_definitions(swizzle_test_${isa} PRIVATE ${definitions_${isa}})
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/>.
*/
#include "codegen_tests.h"
#include <gtest/gtest.h>
#include <x86emitter/x86emitter.h>
#include <Utilities/Assertions.h>
using namespace x86Emitter;
thread_local const char *currentTest;
void pxOnAssert(const DiagnosticOrigin &origin, const wxString &msg) {
FAIL() << "Assertion failed: " << msg
static void assertHandlerInternal(const DiagnosticOrigin& origin, const wxChar* msg) {
FAIL() << "Assertion failed: " << wxString(msg)
<< "\n at " << origin.srcfile << ":" << origin.line << ""
<< "\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) {
pxDoAssert = assertHandler;
u8 code[4096];
memset(code, 0xcc, sizeof(code));
char str[4096] = {0};

View File

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