8#include "pedigree/kernel/Log.h"
9#include "pedigree/kernel/machine/Ps2CaptureState.h"
12bool check(
bool condition,
const char* test,
const char* detail) {
17 ERROR(
"HOSTED-WAIT-TEST: FAIL " << test <<
": " << detail);
21bool oneShotAdmission() {
22 constexpr const char* Test =
"ps2-one-shot-hard-admission";
25 const bool first = gate.tryAcquire();
26 const bool contended = !gate.tryAcquire();
27 const bool remainedOwned = gate.owned();
29 const bool reacquired = gate.tryAcquire();
33 check(first && contended && remainedOwned && reacquired && !gate.owned(), Test,
34 "a failed hard-stage admission changed ownership or required a retry");
36 NOTICE(
"HOSTED-WAIT-TEST: PASS ps2-one-shot-hard-admission");
41bool debuggerTransitionLockIndependent() {
42 constexpr const char* Test =
"ps2-debug-state-lock-independent";
46 bool passed = check(gate.tryAcquire() && gate.owned() && !debugState.active(), Test,
47 "the test could not freeze an ordinary 8042 transaction");
49 passed &= check(debugState.active() && gate.owned() && !gate.tryAcquire(), Test,
50 "debugger entry waited on or changed 8042 admission");
51 debugState.set(
false);
52 passed &= check(!debugState.active() && gate.owned(), Test,
53 "debugger exit waited on or changed 8042 admission");
57 NOTICE(
"HOSTED-WAIT-TEST: PASS ps2-debug-state-lock-independent");
62bool captureQueueFidelity() {
63 constexpr const char* Test =
"ps2-capture-queue-fidelity";
69 Test,
"captured keyboard and auxiliary bytes were not retained");
73 check(queue.pop(record) && record.value == 0x1E && !record.secondPort && queue.pop(record) &&
74 record.value == 0xA5 && record.secondPort && !queue.pop(record) && !queue.pending(),
75 Test,
"capture order or status-based destination identity changed");
77 for (
size_t i = 0; i < Ps2CaptureQueue::Capacity; ++i) {
78 passed &= queue.tryPush(
Ps2CapturedByte(
static_cast<uint8_t
>(i), (i & 1) != 0));
81 queue.pending() == Ps2CaptureQueue::Capacity,
82 Test,
"a full hard-stage queue overwrote an unread byte");
84 for (
size_t i = 0; i < Ps2CaptureQueue::Capacity; ++i) {
85 passed &= queue.pop(record) && record.value ==
static_cast<uint8_t
>(i) &&
86 record.secondPort == ((i & 1) != 0);
88 passed &= check(!queue.pending() && queue.
hasCapacity() &&
90 record.value == 0x42 && !record.secondPort,
91 Test,
"the bounded queue did not recover after wraparound");
94 NOTICE(
"HOSTED-WAIT-TEST: PASS ps2-capture-queue-fidelity");
100bool runHostedPs2ControllerRegressions() {
101 return oneShotAdmission() && debuggerTransitionLockIndependent() && captureQueueFidelity();