Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1628,10 +1628,14 @@ if(BUILD_TESTING)
add_test(NAME run_tiny_bundled_load COMMAND ${CMAKE_COMMAND}
"-DLOADER=$<TARGET_FILE:gta6rt>" "-DGUEST=$<TARGET_FILE:tiny_bundled_load>"
"-DRUNNER=${CMAKE_CROSSCOMPILING_EMULATOR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/test/check_loaded_bundled.cmake")
# atexit handlers, static destructors and the ways out, compared with the same program run natively.
# atexit handlers, static destructors and the ways out, compared with the same program run natively. Under Wine
# the native runs already deviate (the guest CRT is the host's), so the script reports the skip; the property is
# what turns that into a ctest skip, for CMake versions that cannot exit 77 from a -P script.
add_test(NAME run_tiny_atexit COMMAND ${CMAKE_COMMAND}
"-DLOADER=$<TARGET_FILE:gta6rt>" "-DGUEST=$<TARGET_FILE:tiny_atexit>"
"-DRUNNER=${CMAKE_CROSSCOMPILING_EMULATOR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/test/check_atexit.cmake")
set_tests_properties(run_tiny_atexit PROPERTIES SKIP_RETURN_CODE 77
SKIP_REGULAR_EXPRESSION "SKIP: the guest CRT here is Wine's")
add_test(NAME run_tiny_game COMMAND gta6rt --run $<TARGET_FILE:tiny_game> -- hello 42)
add_test(NAME run_tiny_game_console_paths COMMAND ${CMAKE_COMMAND}
"-DLOADER=$<TARGET_FILE:gta6rt>" "-DGUEST=$<TARGET_FILE:tiny_game>"
Expand Down
22 changes: 18 additions & 4 deletions runtime/test/check_atexit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# sequence written below and end with its exit code. That is what the program does natively on Windows, and the
# native run is held to the same sequence, so the two cannot agree on a wrong answer. Under Wine both runs go through
# RUNNER, and Wine's own CRT differs in places (it drops a handler registered while handlers run, and its _exit does
# not wait for the exit lock), so there a native difference is reported without failing; --run is still held to the
# Windows sequence.
# not wait for the exit lock); in addition the guest runs on that same CRT through `--run`, and there no handler or
# destructor runs at all. When the native runs already differ, the sequence is not observable and the script reports a
# skip (77) instead of a gta6rt failure. On Windows the native runs match, so any difference there still fails.
get_filename_component(guest_dir "${GUEST}" DIRECTORY)
get_filename_component(guest_name "${GUEST}" NAME)

Expand Down Expand Up @@ -42,6 +43,7 @@ function(guest_lines output result)
endfunction()

set(failures "")
set(host_crt_differs FALSE) # the native runs above already deviate from Windows: the CRT here is not Windows'
foreach(mode return exit _exit quick_exit ExitProcess cexit c_exit concurrent_exit)
execute_process(COMMAND ${RUNNER} "${GUEST}" ${mode}
WORKING_DIRECTORY "${guest_dir}" TIMEOUT 60
Expand All @@ -55,6 +57,7 @@ foreach(mode return exit _exit quick_exit ExitProcess cexit c_exit concurrent_ex
string(CONCAT native_diff "[${mode}] native run differs from the expected sequence"
"\n expected (${code_${mode}}): ${expect_${mode}}\n native (${native_code}): ${native_lines}")
if(RUNNER)
set(host_crt_differs TRUE)
message(STATUS "${native_diff}\n (the host CRT differs from Windows; not a gta6rt failure)")
else()
string(APPEND failures "\n${native_diff}\n (the fixture or the host changed)")
Expand All @@ -65,7 +68,18 @@ foreach(mode return exit _exit quick_exit ExitProcess cexit c_exit concurrent_ex
"\n expected (${code_${mode}}): ${expect_${mode}}\n --run (${run_code}): ${run_lines}\n${run_err}")
endif()
endforeach()
if(failures)
if(failures AND RUNNER AND host_crt_differs)
# The guest runs on the host's CRT, not Windows' one: the native runs above already lose a handler registered while
# handlers run and truncate the concurrent exit, and through `--run` no handler and no destructor runs at all, the
# same code path that the native run takes. So the Windows sequence is not observable here whatever the loader
# does, and it is reported as a skip, not as a gta6rt failure. On Windows any difference still fails.
message(STATUS "SKIP: the guest CRT here is Wine's, which already differs from Windows in the native runs "
"(handlers and destructors dropped), so the --run sequence cannot be observed; not a gta6rt failure")
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.29)
cmake_language(EXIT 77) # the test's SKIP_RETURN_CODE; older CMake skips on the line above instead
endif()
elseif(failures)
message(FATAL_ERROR "atexit/termination differences:${failures}")
else()
message(STATUS "tiny_atexit: 8 termination paths match the Windows sequence")
endif()
message(STATUS "tiny_atexit: 8 termination paths match the Windows sequence")
84 changes: 6 additions & 78 deletions runtime/test/d3d12_residency_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
// fence): counts of 0, null arrays, null entries, the same object twice, evicting twice, every named priority and a
// few others, residency flags, a null fence, and the fence values EnqueueMakeResident signals (the value the fence
// reaches is recorded too). Every HRESULT is recorded and the two records must be the same, step by step. A step the
// host runtime faults on is reported and not compared. No shaders or game data. Skips (77) without a Vulkan GPU.
// The layer's record is first checked on its own (layer_wrong: the valid calls succeed, the fence reaches the values
// asked for), on every host; without a host D3D12 device that is all that is checked, and so it is under Wine, whose
// host is vkd3d (host_wine.h: it answers S_OK to calls Microsoft's runtime refuses). Set LEONIDA_D3D49_VERBOSE=1 to
// print every step.
#include "vk_test_device.h"
// host runtime faults on is reported and not compared. No shaders or game data. Skips (77) without a Vulkan GPU;
// without a host D3D12 device only the layer's own record is printed. Set LEONIDA_D3D49_VERBOSE=1 to print every
// step.
#include "host_wine.h"
#include "vk_test_device.h"
#include "../shims/d3d12_com.h"

#include <cstdint>
Expand Down Expand Up @@ -340,68 +338,6 @@ bool run(ID3D12Device* device, bool host, Record& out) {
return true;
}

// Steps that are plain, valid use of the API on a committed buffer, a heap and a fence: they have to succeed.
bool must_succeed(const char* name) {
static const char* const kValid[] = {
"MakeResident a resident buffer", "Evict the buffer", "MakeResident the evicted buffer",
"SetResidencyPriority the buffer", "SetResidencyPriority the heap", "SetResidencyPriority MINIMUM",
"SetResidencyPriority LOW", "SetResidencyPriority HIGH", "SetResidencyPriority MAXIMUM",
"EnqueueMakeResident NONE, two objects, value 7", "EnqueueMakeResident all six, value 10",
};
for (const char* valid : kValid)
if (std::strcmp(name, valid) == 0) return true;
return false;
}

// What the layer has to answer whatever the host is, checked on its record alone (the one run() makes with `host`
// false) so that a run with no host to compare with (no host device, or Wine's) still fails on a wrong answer: no
// call raises an exception; the valid calls above succeed; the device is never removed (the host removes its own on
// some steps, the layer has no reason to); and after an EnqueueMakeResident that succeeded the fence holds the value
// asked for, or stays where it was when that value is below it (a Vulkan timeline only goes up, docs/d3d12_vulkan.md),
// and after one that failed it has not moved. The HRESULTs of the invalid calls are the host comparison's.
// Returns the number of wrong answers.
int layer_wrong(const Record& ours) {
int wrong = 0;
const auto bad = [&](const std::string& name, std::uint64_t got, const char* why) {
std::printf("residency %s: the layer answers 0x%llx: %s\n", name.c_str(),
static_cast<unsigned long long>(got), why);
++wrong;
};
std::size_t i = 0;
const auto next = [&](const std::string& name, std::uint64_t* value) {
if (i >= ours.values.size() || ours.names[i] != name) {
bad(name, 0, "missing from the layer's record");
return false;
}
*value = ours.values[i++];
return true;
};
UINT64 fence = 0; // make() creates it at 0
for (const Step& s : kSteps) {
std::uint64_t hr = 0;
if (!next(s.name, &hr)) return wrong;
if (hr == kFaulted) bad(s.name, hr, "the call raised an exception");
else if (must_succeed(s.name) && hr != std::uint32_t(S_OK)) bad(s.name, hr, "a valid call has to succeed");
if (s.isolated) continue;
std::uint64_t removed = 0;
if (!next(std::string(s.name) + " (removed reason)", &removed)) return wrong;
if (removed != std::uint32_t(S_OK))
bad(std::string(s.name) + " (removed reason)", removed, "the device was removed");
if (!s.fence_value) continue;
std::uint64_t reached = 0;
if (!next(std::string(s.name) + " (fence)", &reached)) return wrong;
const bool succeeded = hr != kFaulted && SUCCEEDED(HRESULT(std::uint32_t(hr)));
const UINT64 want = succeeded && s.fence_value > fence ? s.fence_value : fence;
if (reached != want)
bad(std::string(s.name) + " (fence)", reached,
succeeded ? "the fence has to hold the value asked for, or stay where it was for a lower one"
: "a call that failed must not move the fence");
else
fence = reached;
}
return wrong;
}

// --host-step N: one isolated step on a fresh host device; the exit code is its HRESULT.
int host_step(std::size_t index) {
if (index >= sizeof(kSteps) / sizeof(kSteps[0])) return int(kNoChild);
Expand Down Expand Up @@ -434,21 +370,13 @@ int main(int argc, char** argv) {
EXPECT(SUCCEEDED(rt::d3d12::create_vulkan_device(info, IID_PPV_ARGS(&device.p))));
Record ours;
EXPECT(run(device.p, false, ours));
// The layer's own answers first, on every host: the comparison below needs a host, and Wine's is not one.
const int layer_wrong_answers = layer_wrong(ours);
std::printf("residency: the layer's %zu values checked on their own, %d wrong\n", ours.values.size(),
layer_wrong_answers);
EXPECT(layer_wrong_answers == 0);

Ref<ID3D12Device> host;
host.p = hostwine::host_is_wine() ? nullptr : create_host();
if (!host.p) {
std::printf("residency: no host D3D12 device to compare with; %zu steps recorded, not compared\n",
std::printf("residency: no host D3D12 reference (Wine, or no device) to compare with; %zu steps recorded, "
"not compared\n",
ours.values.size());
if (verbose)
for (std::size_t i = 0; i < ours.values.size(); ++i)
std::printf("residency %s: ours 0x%llx\n", ours.names[i].c_str(),
static_cast<unsigned long long>(ours.values[i]));
} else {
Record theirs;
EXPECT(run(host.p, true, theirs));
Expand Down
3 changes: 2 additions & 1 deletion runtime/test/d3d12_sampler2_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ int main() {
if (host_nn)
EXPECT(host2(desc2(point)) != host2(desc2(point, D3D12_SAMPLER_FLAG_NON_NORMALIZED_COORDINATES)));
} else {
std::printf("no host D3D12 device: edge cases checked against their recorded answers only\n");
std::printf("no host D3D12 reference (Wine, or no device): edge cases checked against their recorded "
"answers only\n");
}
}

Expand Down
6 changes: 6 additions & 0 deletions runtime/test/device_proxy_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ int main(int argc, char** argv) {
hr = create_device(warp.Get(), params, &iid_device, &created);
check(SUCCEEDED(hr) && created != nullptr, "D3D12XboxCreateDevice returns a device");
if (!created) {
// Wine's vkd3d rejects the console device over its WARP stand-in; the proxy needs Microsoft's runtime.
if (hostwine::host_is_wine()) {
std::printf("SKIP device_proxy_test: D3D12XboxCreateDevice failed under Wine (0x%08lX)\n",
static_cast<unsigned long>(hr));
return 77;
}
std::printf("device_proxy_test: FAILED (no device)\n");
return 1;
}
Expand Down
20 changes: 18 additions & 2 deletions runtime/test/gameinput_host_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
// - GameInputCreate succeeds from mapped code, and the library answers GetCurrentTimestamp;
// - GetCurrentReading says either "reading" or "no reading found": no crash, no other error. With a gamepad attached
// GetGamepadState must succeed on the reading; the test passes with or without one.
// Skips (exit 77) only where Windows itself cannot load GameInput.dll (asked before mapping, with LoadLibraryExW).
// When the DLL is there, an import that binds to nothing is a failure, not a skip. No game files.
// Skips (exit 77) only where Windows itself cannot load GameInput.dll (asked before mapping, with LoadLibraryExW),
// and under Wine, whose GameInput.dll is a stub: there the loader's binding is checked and the stub's answers are
// not. When the DLL is there, an import that binds to nothing is a failure, not a skip. No game files.
#include <windows.h>

#include <cstdio>
Expand Down Expand Up @@ -65,6 +66,21 @@ int main(int argc, char** argv) {
}
check(seen == 1 && binding == rt::Binding::Host, "the GameInput.dll import binds to the host's copy");

// Wine's GameInput.dll is a stub: GameInputCreate returns E_NOTIMPL and GetCurrentTimestamp E_FAIL, so its
// answers say nothing about the loader. The binding above is the one part observable there, and a wrong one
// is still a failure (checked) rather than a skip.
const bool wine = GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "wine_get_version") != nullptr;
if (wine) {
FreeLibrary(host_gameinput);
if (g_failures) {
std::printf("gameinput_host_test: FAILED (%d failures)\n", g_failures);
return 1;
}
std::printf("SKIP: Wine's GameInput.dll is a stub (GameInputCreate returns E_NOTIMPL, GetCurrentTimestamp "
"E_FAIL), so only the import binding can be checked here\n");
return 77;
}

loader.initialise();
const auto probe = reinterpret_cast<ProbeFn>(m.exports.at("gameinput_host_probe"));
long create_hr = -1, reading_hr = -1;
Expand Down
Loading