From bd8376e231c2c00f2836825f5a1325aeb21d78fa Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sat, 25 May 2013 05:20:28 -0700 Subject: [PATCH] Making xenia-test run on Windows. --- src/xenia/cpu/processor.cc | 2 +- src/xenia/cpu/x64/x64_jit.cc | 5 ++- tools/xenia-test/xenia-test.cc | 70 +++++++++++++++++++++++++++++----- 3 files changed, 64 insertions(+), 13 deletions(-) diff --git a/src/xenia/cpu/processor.cc b/src/xenia/cpu/processor.cc index e6cc5d7d7..ec6a69f7e 100644 --- a/src/xenia/cpu/processor.cc +++ b/src/xenia/cpu/processor.cc @@ -100,7 +100,7 @@ int Processor::Setup() { int Processor::LoadRawBinary(const xechar_t* path, uint32_t start_address) { ExecModule* exec_module = NULL; - const xechar_t* name = xestrrchr(path, '/') + 1; + const xechar_t* name = xestrrchr(path, XE_PATH_SEPARATOR) + 1; // TODO(benvanik): map file from filesystem API, not via platform API. xe_mmap_ref mmap = xe_mmap_open(kXEFileModeRead, path, 0, 0); diff --git a/src/xenia/cpu/x64/x64_jit.cc b/src/xenia/cpu/x64/x64_jit.cc index facf0103c..9f373a52f 100644 --- a/src/xenia/cpu/x64/x64_jit.cc +++ b/src/xenia/cpu/x64/x64_jit.cc @@ -36,8 +36,6 @@ X64JIT::~X64JIT() { int X64JIT::Setup() { int result_code = 1; - XELOGCPU("Initializing x64 JIT backend..."); - // Check processor for support. result_code = CheckProcessor(); if (result_code) { @@ -97,6 +95,8 @@ static const BitDescription x86Features[] = { int X64JIT::CheckProcessor() { const CpuInfo* cpu = CpuInfo::getGlobal(); const X86CpuInfo* x86Cpu = static_cast(cpu); + +#if 0 XELOGCPU("Processor Info:"); XELOGCPU(" Vendor string : %s", cpu->getVendorString()); XELOGCPU(" Brand string : %s", cpu->getBrandString()); @@ -118,6 +118,7 @@ int X64JIT::CheckProcessor() { XELOGCPU(" %s", d->description); } } +#endif // TODO(benvanik): ensure features we want are supported. diff --git a/tools/xenia-test/xenia-test.cc b/tools/xenia-test/xenia-test.cc index c20a5da2e..5611580db 100644 --- a/tools/xenia-test/xenia-test.cc +++ b/tools/xenia-test/xenia-test.cc @@ -9,7 +9,9 @@ #include +#if !XE_LIKE(WIN32) #include +#endif // !WIN32 #include @@ -19,8 +21,13 @@ using namespace xe::cpu; using namespace xe::kernel; +#if XE_LIKE(WIN32) +DEFINE_string(test_path, "test\\codegen\\", + "Directory scanned for test files."); +#else DEFINE_string(test_path, "test/codegen/", "Directory scanned for test files."); +#endif // WIN32 typedef vector > annotations_list_t; @@ -115,12 +122,13 @@ int run_test(string& src_file_path) { XEEXPECTZERO(read_annotations(src_file_path, annotations)); - xe_memory_options_t memory_options; - xe_zero_struct(&memory_options, sizeof(memory_options)); - memory = xe_memory_create(memory_options); - XEEXPECTNOTNULL(memory); + while (!memory) { + xe_memory_options_t memory_options; + xe_zero_struct(&memory_options, sizeof(memory_options)); + memory = xe_memory_create(memory_options); + } - backend_ = shared_ptr(new xe::cpu::x64::X64Backend()); + backend = shared_ptr(new xe::cpu::x64::X64Backend()); processor = shared_ptr(new Processor(memory, backend)); XEEXPECTZERO(processor->Setup()); @@ -128,7 +136,14 @@ int run_test(string& src_file_path) { runtime = shared_ptr(new Runtime(processor, XT(""))); // Load the binary module. - XEEXPECTZERO(processor->LoadRawBinary(bin_file_path.c_str(), 0x82010000)); +#if XE_WCHAR + xechar_t bin_file_path_str[XE_MAX_PATH]; + XEEXPECTTRUE(xestrwiden(bin_file_path_str, XECOUNT(bin_file_path_str), + bin_file_path.c_str())); +#else + const xechar_t* bin_file_path_str = bin_file_path.c_str(); +#endif // XE_CHAR + XEEXPECTZERO(processor->LoadRawBinary(bin_file_path_str, 0x82010000)); // Simulate a thread. thread_state = processor->AllocThread(256 * 1024, 0); @@ -157,7 +172,29 @@ XECLEANUP: int discover_tests(string& test_path, vector& test_files) { - // TODO(benvanik): use PAL instead of this + // TODO(benvanik): use PAL instead of this. +#if XE_LIKE(WIN32) + string search_path = test_path; + search_path.append("\\*.s"); + WIN32_FIND_DATAA ffd; + HANDLE hFind = FindFirstFileA(search_path.c_str(), &ffd); + if (hFind == INVALID_HANDLE_VALUE) { + XELOGE("Unable to find test path %s", test_path.c_str()); + return 1; + } + do { + if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { + string file_name = string(ffd.cFileName); + string file_path = test_path; + if (*(test_path.end() - 1) != '\\') { + file_path += "\\"; + } + file_path += file_name; + test_files.push_back(file_path); + } + } while (FindNextFileA(hFind, &ffd)); + FindClose(hFind); +#else DIR* d = opendir(test_path.c_str()); if (!d) { XELOGE("Unable to find test path %s", test_path.c_str()); @@ -179,10 +216,11 @@ int discover_tests(string& test_path, } } closedir(d); +#endif // WIN32 return 0; } -int run_tests(const xechar_t* test_name) { +int run_tests(std::string& test_name) { int result_code = 1; int failed_count = 0; int passed_count = 0; @@ -203,7 +241,7 @@ int run_tests(const xechar_t* test_name) { for (vector::iterator it = test_files.begin(); it != test_files.end(); ++it) { - if (test_name && *it != test_name) { + if (test_name.length() && *it != test_name) { continue; } @@ -235,8 +273,20 @@ int xenia_test(int argc, xechar_t **argv) { if (argc >= 2) { test_name = argv[1]; } + + string test_name_str; + if (test_name) { +#if XE_WCHAR + char test_name_buffer[XE_MAX_PATH]; + XEIGNORE(xestrnarrow(test_name_buffer, XECOUNT(test_name_buffer), + test_name)); + test_name_str = test_name_buffer; +#else + test_name_str = test_name; +#endif // XE_WCHAR + } - result_code = run_tests(test_name); + result_code = run_tests(test_name_str); return result_code; }