early-access version 1255
This commit is contained in:
145
src/tests/core/arm/arm_test_common.cpp
Executable file
145
src/tests/core/arm/arm_test_common.cpp
Executable file
@@ -0,0 +1,145 @@
|
||||
// Copyright 2016 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "common/page_table.h"
|
||||
#include "core/core.h"
|
||||
#include "core/hle/kernel/memory/page_table.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
#include "core/memory.h"
|
||||
#include "tests/core/arm/arm_test_common.h"
|
||||
|
||||
namespace ArmTests {
|
||||
|
||||
TestEnvironment::TestEnvironment(bool mutable_memory_)
|
||||
: mutable_memory(mutable_memory_),
|
||||
test_memory(std::make_shared<TestMemory>(this)), kernel{Core::System::GetInstance()} {
|
||||
auto& system = Core::System::GetInstance();
|
||||
|
||||
auto process = Kernel::Process::Create(system, "", Kernel::Process::ProcessType::Userland);
|
||||
page_table = &process->PageTable().PageTableImpl();
|
||||
|
||||
system.Memory().MapIoRegion(*page_table, 0x00000000, 0x80000000, test_memory);
|
||||
system.Memory().MapIoRegion(*page_table, 0x80000000, 0x80000000, test_memory);
|
||||
|
||||
kernel.MakeCurrentProcess(process.get());
|
||||
}
|
||||
|
||||
TestEnvironment::~TestEnvironment() {
|
||||
auto& system = Core::System::GetInstance();
|
||||
system.Memory().UnmapRegion(*page_table, 0x80000000, 0x80000000);
|
||||
system.Memory().UnmapRegion(*page_table, 0x00000000, 0x80000000);
|
||||
}
|
||||
|
||||
void TestEnvironment::SetMemory64(VAddr vaddr, u64 value) {
|
||||
SetMemory32(vaddr + 0, static_cast<u32>(value));
|
||||
SetMemory32(vaddr + 4, static_cast<u32>(value >> 32));
|
||||
}
|
||||
|
||||
void TestEnvironment::SetMemory32(VAddr vaddr, u32 value) {
|
||||
SetMemory16(vaddr + 0, static_cast<u16>(value));
|
||||
SetMemory16(vaddr + 2, static_cast<u16>(value >> 16));
|
||||
}
|
||||
|
||||
void TestEnvironment::SetMemory16(VAddr vaddr, u16 value) {
|
||||
SetMemory8(vaddr + 0, static_cast<u8>(value));
|
||||
SetMemory8(vaddr + 1, static_cast<u8>(value >> 8));
|
||||
}
|
||||
|
||||
void TestEnvironment::SetMemory8(VAddr vaddr, u8 value) {
|
||||
test_memory->data[vaddr] = value;
|
||||
}
|
||||
|
||||
std::vector<WriteRecord> TestEnvironment::GetWriteRecords() const {
|
||||
return write_records;
|
||||
}
|
||||
|
||||
void TestEnvironment::ClearWriteRecords() {
|
||||
write_records.clear();
|
||||
}
|
||||
|
||||
TestEnvironment::TestMemory::~TestMemory() {}
|
||||
|
||||
std::optional<bool> TestEnvironment::TestMemory::IsValidAddress(VAddr addr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<u8> TestEnvironment::TestMemory::Read8(VAddr addr) {
|
||||
const auto iter = data.find(addr);
|
||||
|
||||
if (iter == data.end()) {
|
||||
// Some arbitrary data
|
||||
return static_cast<u8>(addr);
|
||||
}
|
||||
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
std::optional<u16> TestEnvironment::TestMemory::Read16(VAddr addr) {
|
||||
return *Read8(addr) | static_cast<u16>(*Read8(addr + 1)) << 8;
|
||||
}
|
||||
|
||||
std::optional<u32> TestEnvironment::TestMemory::Read32(VAddr addr) {
|
||||
return *Read16(addr) | static_cast<u32>(*Read16(addr + 2)) << 16;
|
||||
}
|
||||
|
||||
std::optional<u64> TestEnvironment::TestMemory::Read64(VAddr addr) {
|
||||
return *Read32(addr) | static_cast<u64>(*Read32(addr + 4)) << 32;
|
||||
}
|
||||
|
||||
bool TestEnvironment::TestMemory::ReadBlock(VAddr src_addr, void* dest_buffer, std::size_t size) {
|
||||
VAddr addr = src_addr;
|
||||
u8* data = static_cast<u8*>(dest_buffer);
|
||||
|
||||
for (std::size_t i = 0; i < size; i++, addr++, data++) {
|
||||
*data = *Read8(addr);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestEnvironment::TestMemory::Write8(VAddr addr, u8 data) {
|
||||
env->write_records.emplace_back(8, addr, data);
|
||||
if (env->mutable_memory)
|
||||
env->SetMemory8(addr, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestEnvironment::TestMemory::Write16(VAddr addr, u16 data) {
|
||||
env->write_records.emplace_back(16, addr, data);
|
||||
if (env->mutable_memory)
|
||||
env->SetMemory16(addr, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestEnvironment::TestMemory::Write32(VAddr addr, u32 data) {
|
||||
env->write_records.emplace_back(32, addr, data);
|
||||
if (env->mutable_memory)
|
||||
env->SetMemory32(addr, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestEnvironment::TestMemory::Write64(VAddr addr, u64 data) {
|
||||
env->write_records.emplace_back(64, addr, data);
|
||||
if (env->mutable_memory)
|
||||
env->SetMemory64(addr, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestEnvironment::TestMemory::WriteBlock(VAddr dest_addr, const void* src_buffer,
|
||||
std::size_t size) {
|
||||
VAddr addr = dest_addr;
|
||||
const u8* data = static_cast<const u8*>(src_buffer);
|
||||
|
||||
for (std::size_t i = 0; i < size; i++, addr++, data++) {
|
||||
env->write_records.emplace_back(8, addr, *data);
|
||||
if (env->mutable_memory)
|
||||
env->SetMemory8(addr, *data);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace ArmTests
|
93
src/tests/core/arm/arm_test_common.h
Executable file
93
src/tests/core/arm/arm_test_common.h
Executable file
@@ -0,0 +1,93 @@
|
||||
// Copyright 2016 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/memory_hook.h"
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
|
||||
namespace Common {
|
||||
struct PageTable;
|
||||
}
|
||||
|
||||
namespace ArmTests {
|
||||
|
||||
struct WriteRecord {
|
||||
WriteRecord(std::size_t size, VAddr addr, u64 data) : size(size), addr(addr), data(data) {}
|
||||
std::size_t size;
|
||||
VAddr addr;
|
||||
u64 data;
|
||||
bool operator==(const WriteRecord& o) const {
|
||||
return std::tie(size, addr, data) == std::tie(o.size, o.addr, o.data);
|
||||
}
|
||||
};
|
||||
|
||||
class TestEnvironment final {
|
||||
public:
|
||||
/*
|
||||
* Inititalise test environment
|
||||
* @param mutable_memory If false, writes to memory can never be read back.
|
||||
* (Memory is immutable.)
|
||||
*/
|
||||
explicit TestEnvironment(bool mutable_memory = false);
|
||||
|
||||
/// Shutdown test environment
|
||||
~TestEnvironment();
|
||||
|
||||
/// Sets value at memory location vaddr.
|
||||
void SetMemory8(VAddr vaddr, u8 value);
|
||||
void SetMemory16(VAddr vaddr, u16 value);
|
||||
void SetMemory32(VAddr vaddr, u32 value);
|
||||
void SetMemory64(VAddr vaddr, u64 value);
|
||||
|
||||
/**
|
||||
* Whenever Memory::Write{8,16,32,64} is called within the test environment,
|
||||
* a new write-record is made.
|
||||
* @returns A vector of write records made since they were last cleared.
|
||||
*/
|
||||
std::vector<WriteRecord> GetWriteRecords() const;
|
||||
|
||||
/// Empties the internal write-record store.
|
||||
void ClearWriteRecords();
|
||||
|
||||
private:
|
||||
friend struct TestMemory;
|
||||
struct TestMemory final : Common::MemoryHook {
|
||||
explicit TestMemory(TestEnvironment* env_) : env(env_) {}
|
||||
TestEnvironment* env;
|
||||
|
||||
~TestMemory() override;
|
||||
|
||||
std::optional<bool> IsValidAddress(VAddr addr) override;
|
||||
|
||||
std::optional<u8> Read8(VAddr addr) override;
|
||||
std::optional<u16> Read16(VAddr addr) override;
|
||||
std::optional<u32> Read32(VAddr addr) override;
|
||||
std::optional<u64> Read64(VAddr addr) override;
|
||||
|
||||
bool ReadBlock(VAddr src_addr, void* dest_buffer, std::size_t size) override;
|
||||
|
||||
bool Write8(VAddr addr, u8 data) override;
|
||||
bool Write16(VAddr addr, u16 data) override;
|
||||
bool Write32(VAddr addr, u32 data) override;
|
||||
bool Write64(VAddr addr, u64 data) override;
|
||||
|
||||
bool WriteBlock(VAddr dest_addr, const void* src_buffer, std::size_t size) override;
|
||||
|
||||
std::unordered_map<VAddr, u8> data;
|
||||
};
|
||||
|
||||
bool mutable_memory;
|
||||
std::shared_ptr<TestMemory> test_memory;
|
||||
std::vector<WriteRecord> write_records;
|
||||
Common::PageTable* page_table = nullptr;
|
||||
Kernel::KernelCore kernel;
|
||||
};
|
||||
|
||||
} // namespace ArmTests
|
147
src/tests/core/core_timing.cpp
Executable file
147
src/tests/core/core_timing.cpp
Executable file
@@ -0,0 +1,147 @@
|
||||
// Copyright 2016 Dolphin Emulator Project / 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <bitset>
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "common/file_util.h"
|
||||
#include "core/core.h"
|
||||
#include "core/core_timing.h"
|
||||
|
||||
namespace {
|
||||
// Numbers are chosen randomly to make sure the correct one is given.
|
||||
constexpr std::array<u64, 5> CB_IDS{{42, 144, 93, 1026, UINT64_C(0xFFFF7FFFF7FFFF)}};
|
||||
constexpr std::array<u64, 5> calls_order{{2, 0, 1, 4, 3}};
|
||||
std::array<s64, 5> delays{};
|
||||
|
||||
std::bitset<CB_IDS.size()> callbacks_ran_flags;
|
||||
u64 expected_callback = 0;
|
||||
|
||||
template <unsigned int IDX>
|
||||
void HostCallbackTemplate(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) {
|
||||
static_assert(IDX < CB_IDS.size(), "IDX out of range");
|
||||
callbacks_ran_flags.set(IDX);
|
||||
REQUIRE(CB_IDS[IDX] == user_data);
|
||||
REQUIRE(CB_IDS[IDX] == CB_IDS[calls_order[expected_callback]]);
|
||||
delays[IDX] = ns_late.count();
|
||||
++expected_callback;
|
||||
}
|
||||
|
||||
struct ScopeInit final {
|
||||
ScopeInit() {
|
||||
core_timing.SetMulticore(true);
|
||||
core_timing.Initialize([]() {});
|
||||
}
|
||||
~ScopeInit() {
|
||||
core_timing.Shutdown();
|
||||
}
|
||||
|
||||
Core::Timing::CoreTiming core_timing;
|
||||
};
|
||||
|
||||
u64 TestTimerSpeed(Core::Timing::CoreTiming& core_timing) {
|
||||
const u64 start = core_timing.GetGlobalTimeNs().count();
|
||||
volatile u64 placebo = 0;
|
||||
for (std::size_t i = 0; i < 1000; i++) {
|
||||
placebo = placebo + core_timing.GetGlobalTimeNs().count();
|
||||
}
|
||||
const u64 end = core_timing.GetGlobalTimeNs().count();
|
||||
return end - start;
|
||||
}
|
||||
|
||||
} // Anonymous namespace
|
||||
|
||||
TEST_CASE("CoreTiming[BasicOrder]", "[core]") {
|
||||
ScopeInit guard;
|
||||
auto& core_timing = guard.core_timing;
|
||||
std::vector<std::shared_ptr<Core::Timing::EventType>> events{
|
||||
Core::Timing::CreateEvent("callbackA", HostCallbackTemplate<0>),
|
||||
Core::Timing::CreateEvent("callbackB", HostCallbackTemplate<1>),
|
||||
Core::Timing::CreateEvent("callbackC", HostCallbackTemplate<2>),
|
||||
Core::Timing::CreateEvent("callbackD", HostCallbackTemplate<3>),
|
||||
Core::Timing::CreateEvent("callbackE", HostCallbackTemplate<4>),
|
||||
};
|
||||
|
||||
expected_callback = 0;
|
||||
|
||||
core_timing.SyncPause(true);
|
||||
|
||||
const u64 one_micro = 1000U;
|
||||
for (std::size_t i = 0; i < events.size(); i++) {
|
||||
const u64 order = calls_order[i];
|
||||
const auto future_ns = std::chrono::nanoseconds{static_cast<s64>(i * one_micro + 100)};
|
||||
|
||||
core_timing.ScheduleEvent(future_ns, events[order], CB_IDS[order]);
|
||||
}
|
||||
/// test pause
|
||||
REQUIRE(callbacks_ran_flags.none());
|
||||
|
||||
core_timing.Pause(false); // No need to sync
|
||||
|
||||
while (core_timing.HasPendingEvents())
|
||||
;
|
||||
|
||||
REQUIRE(callbacks_ran_flags.all());
|
||||
|
||||
for (std::size_t i = 0; i < delays.size(); i++) {
|
||||
const double delay = static_cast<double>(delays[i]);
|
||||
const double micro = delay / 1000.0f;
|
||||
const double mili = micro / 1000.0f;
|
||||
printf("HostTimer Pausing Delay[%zu]: %.3f %.6f\n", i, micro, mili);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("CoreTiming[BasicOrderNoPausing]", "[core]") {
|
||||
ScopeInit guard;
|
||||
auto& core_timing = guard.core_timing;
|
||||
std::vector<std::shared_ptr<Core::Timing::EventType>> events{
|
||||
Core::Timing::CreateEvent("callbackA", HostCallbackTemplate<0>),
|
||||
Core::Timing::CreateEvent("callbackB", HostCallbackTemplate<1>),
|
||||
Core::Timing::CreateEvent("callbackC", HostCallbackTemplate<2>),
|
||||
Core::Timing::CreateEvent("callbackD", HostCallbackTemplate<3>),
|
||||
Core::Timing::CreateEvent("callbackE", HostCallbackTemplate<4>),
|
||||
};
|
||||
|
||||
core_timing.SyncPause(true);
|
||||
core_timing.SyncPause(false);
|
||||
|
||||
expected_callback = 0;
|
||||
|
||||
const u64 start = core_timing.GetGlobalTimeNs().count();
|
||||
const u64 one_micro = 1000U;
|
||||
|
||||
for (std::size_t i = 0; i < events.size(); i++) {
|
||||
const u64 order = calls_order[i];
|
||||
const auto future_ns = std::chrono::nanoseconds{static_cast<s64>(i * one_micro + 100)};
|
||||
core_timing.ScheduleEvent(future_ns, events[order], CB_IDS[order]);
|
||||
}
|
||||
|
||||
const u64 end = core_timing.GetGlobalTimeNs().count();
|
||||
const double scheduling_time = static_cast<double>(end - start);
|
||||
const double timer_time = static_cast<double>(TestTimerSpeed(core_timing));
|
||||
|
||||
while (core_timing.HasPendingEvents())
|
||||
;
|
||||
|
||||
REQUIRE(callbacks_ran_flags.all());
|
||||
|
||||
for (std::size_t i = 0; i < delays.size(); i++) {
|
||||
const double delay = static_cast<double>(delays[i]);
|
||||
const double micro = delay / 1000.0f;
|
||||
const double mili = micro / 1000.0f;
|
||||
printf("HostTimer No Pausing Delay[%zu]: %.3f %.6f\n", i, micro, mili);
|
||||
}
|
||||
|
||||
const double micro = scheduling_time / 1000.0f;
|
||||
const double mili = micro / 1000.0f;
|
||||
printf("HostTimer No Pausing Scheduling Time: %.3f %.6f\n", micro, mili);
|
||||
printf("HostTimer No Pausing Timer Time: %.3f %.6f\n", timer_time / 1000.f,
|
||||
timer_time / 1000000.f);
|
||||
}
|
Reference in New Issue
Block a user