From d00db8c5258e2565bbf506a6fe47bbca3d3ce9b2 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Wed, 23 Mar 2016 01:06:49 +0000 Subject: [PATCH] fixup! tests/JitX64: Address comments --- src/tests/CMakeLists.txt | 1 + .../arm/jit_x64/fuzz_arm_data_processing.cpp | 37 ++++++++----------- src/tests/core/arm/jit_x64/rand_int.h | 15 ++++++++ 3 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 src/tests/core/arm/jit_x64/rand_int.h diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 16d379b53..10fc10884 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -7,6 +7,7 @@ set(HEADERS if(ARCHITECTURE_x86_64) set(SRCS ${SRCS} + core/arm/jit_x64/rand_int.h core/arm/jit_x64/fuzz_arm_data_processing.cpp ) endif() diff --git a/src/tests/core/arm/jit_x64/fuzz_arm_data_processing.cpp b/src/tests/core/arm/jit_x64/fuzz_arm_data_processing.cpp index 5fec98107..906f88232 100644 --- a/src/tests/core/arm/jit_x64/fuzz_arm_data_processing.cpp +++ b/src/tests/core/arm/jit_x64/fuzz_arm_data_processing.cpp @@ -4,7 +4,6 @@ #include #include -#include #include @@ -17,6 +16,8 @@ #include "core/core.h" #include "core/memory_setup.h" +#include "tests/core/arm/jit_x64/rand_int.h" + std::pair FromBitString(const char* str) { REQUIRE(strlen(str) == 32); @@ -40,13 +41,6 @@ std::pair FromBitString(const char* str) { return { bits, mask }; } -u32 RandInt(u32 min, u32 max) { - static std::random_device rd; - static std::mt19937 mt(rd()); - std::uniform_int_distribution rand(min, max); - return rand(mt); -} - void FuzzJit(const int instruction_count, const int run_count, const std::function instruction_generator) { // Init core Core::Init(); @@ -54,8 +48,7 @@ void FuzzJit(const int instruction_count, const int run_count, const std::functi // Prepare memory constexpr size_t MEMORY_SIZE = 4096 * 2; - std::array test_mem; - std::memset(test_mem.data(), 0, MEMORY_SIZE); + std::array test_mem{}; Memory::MapMemoryRegion(0, MEMORY_SIZE, test_mem.data()); SCOPE_EXIT({ Memory::UnmapRegion(0, MEMORY_SIZE); }); @@ -73,7 +66,7 @@ void FuzzJit(const int instruction_count, const int run_count, const std::functi u32 initial_regs[15]; for (int i = 0; i < 15; i++) { - u32 val = RandInt(0, 0xFFFFFFFF); + u32 val = RandInt(0, 0xFFFFFFFF); interp.SetReg(i, val); jit.SetReg(i, val); initial_regs[i] = val; @@ -200,18 +193,18 @@ TEST_CASE("Fuzz ARM data processing instructions", "[JitX64]") { }}; auto instruction_select_without_R15 = [&]() -> u32 { - size_t inst_index = RandInt(0, instructions.size() - 1); + size_t inst_index = RandInt(0, instructions.size() - 1); u32 cond = 0xE; // Have a one-in-twenty-five chance of actually having a cond. if (RandInt(1, 25) == 1) { - cond = RandInt(0x0, 0xD); + cond = RandInt(0x0, 0xD); } - u32 Rn = RandInt(0, 15); - u32 Rd = RandInt(0, 14); - u32 S = RandInt(0, 1); - u32 shifter_operand = RandInt(0, 0xFFF); + u32 Rn = RandInt(0, 15); + u32 Rd = RandInt(0, 14); + u32 S = RandInt(0, 1); + u32 shifter_operand = RandInt(0, 0xFFF); u32 assemble_randoms = (shifter_operand << 0) | (Rd << 12) | (Rn << 16) | (S << 20) | (cond << 28); @@ -223,22 +216,22 @@ TEST_CASE("Fuzz ARM data processing instructions", "[JitX64]") { } SECTION("long blocks") { - FuzzJit(1024, 50, instruction_select_without_R15); + FuzzJit(1024, 15, instruction_select_without_R15); } auto instruction_select_only_R15 = [&]() -> u32 { - size_t inst_index = RandInt(0, instructions.size() - 1); + size_t inst_index = RandInt(0, instructions.size() - 1); u32 cond = 0xE; // Have a one-in-twenty-five chance of actually having a cond. if (RandInt(1, 25) == 1) { - cond = RandInt(0x0, 0xD); + cond = RandInt(0x0, 0xD); } - u32 Rn = RandInt(0, 15); + u32 Rn = RandInt(0, 15); u32 Rd = 15; u32 S = 0; - u32 shifter_operand = RandInt(0, 0xFFF); + u32 shifter_operand = RandInt(0, 0xFFF); u32 assemble_randoms = (shifter_operand << 0) | (Rd << 12) | (Rn << 16) | (S << 20) | (cond << 28); diff --git a/src/tests/core/arm/jit_x64/rand_int.h b/src/tests/core/arm/jit_x64/rand_int.h new file mode 100644 index 000000000..4612b8c9c --- /dev/null +++ b/src/tests/core/arm/jit_x64/rand_int.h @@ -0,0 +1,15 @@ +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include + +template +T RandInt(T min, T max) { + static std::random_device rd; + static std::mt19937 mt(rd()); + std::uniform_int_distribution rand(min, max); + return rand(mt); +}