2017-11-25 13:56:57 +00:00
|
|
|
// Copyright 2016 Dolphin Emulator Project / 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-08-07 23:24:39 +00:00
|
|
|
#include <catch2/catch.hpp>
|
2017-11-25 13:56:57 +00:00
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <bitset>
|
|
|
|
#include <string>
|
|
|
|
#include "common/file_util.h"
|
|
|
|
#include "core/core.h"
|
|
|
|
#include "core/core_timing.h"
|
|
|
|
|
|
|
|
// Numbers are chosen randomly to make sure the correct one is given.
|
|
|
|
static constexpr std::array<u64, 5> CB_IDS{{42, 144, 93, 1026, UINT64_C(0xFFFF7FFFF7FFFF)}};
|
|
|
|
static constexpr int MAX_SLICE_LENGTH = 20000; // Copied from CoreTiming internals
|
|
|
|
|
|
|
|
static std::bitset<CB_IDS.size()> callbacks_ran_flags;
|
|
|
|
static u64 expected_callback = 0;
|
|
|
|
static s64 lateness = 0;
|
|
|
|
|
|
|
|
template <unsigned int IDX>
|
|
|
|
void CallbackTemplate(u64 userdata, s64 cycles_late) {
|
|
|
|
static_assert(IDX < CB_IDS.size(), "IDX out of range");
|
|
|
|
callbacks_ran_flags.set(IDX);
|
|
|
|
REQUIRE(CB_IDS[IDX] == userdata);
|
|
|
|
REQUIRE(CB_IDS[IDX] == expected_callback);
|
|
|
|
REQUIRE(lateness == cycles_late);
|
|
|
|
}
|
|
|
|
|
2019-02-14 17:42:58 +00:00
|
|
|
struct ScopeInit final {
|
2017-11-25 13:56:57 +00:00
|
|
|
ScopeInit() {
|
2019-02-14 17:42:58 +00:00
|
|
|
core_timing.Initialize();
|
2017-11-25 13:56:57 +00:00
|
|
|
}
|
|
|
|
~ScopeInit() {
|
2019-02-14 17:42:58 +00:00
|
|
|
core_timing.Shutdown();
|
2017-11-25 13:56:57 +00:00
|
|
|
}
|
2019-02-14 17:42:58 +00:00
|
|
|
|
|
|
|
Core::Timing::CoreTiming core_timing;
|
2017-11-25 13:56:57 +00:00
|
|
|
};
|
|
|
|
|
2019-02-14 17:42:58 +00:00
|
|
|
static void AdvanceAndCheck(Core::Timing::CoreTiming& core_timing, u32 idx, int downcount,
|
|
|
|
int expected_lateness = 0, int cpu_downcount = 0) {
|
2017-11-25 13:56:57 +00:00
|
|
|
callbacks_ran_flags = 0;
|
|
|
|
expected_callback = CB_IDS[idx];
|
|
|
|
lateness = expected_lateness;
|
|
|
|
|
2019-02-12 17:32:15 +00:00
|
|
|
// Pretend we executed X cycles of instructions.
|
2019-02-14 17:42:58 +00:00
|
|
|
core_timing.AddTicks(core_timing.GetDowncount() - cpu_downcount);
|
|
|
|
core_timing.Advance();
|
2017-11-25 13:56:57 +00:00
|
|
|
|
|
|
|
REQUIRE(decltype(callbacks_ran_flags)().set(idx) == callbacks_ran_flags);
|
2019-02-14 17:42:58 +00:00
|
|
|
REQUIRE(downcount == core_timing.GetDowncount());
|
2017-11-25 13:56:57 +00:00
|
|
|
}
|