Add Qukeys testcase for #1107
This is closer to a real-world scenario than the QueueLeaker plugin testcase. It doesn't test the bug as deliberately, but it shows the failure of Qukeys prior to the fix. Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>pull/1108/head
parent
b68ea18212
commit
e31fe2be10
@ -0,0 +1,77 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Copyright (C) 2022 Keyboard.io, Inc.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by the Free Software
|
||||||
|
* Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Kaleidoscope.h>
|
||||||
|
#include <Kaleidoscope-Qukeys.h>
|
||||||
|
|
||||||
|
#include "./common.h"
|
||||||
|
|
||||||
|
// *INDENT-OFF*
|
||||||
|
KEYMAPS(
|
||||||
|
[0] = KEYMAP_STACKED
|
||||||
|
(
|
||||||
|
Key_A, Key_B, ___, ___, ___, ___, ___,
|
||||||
|
SFT_T(X), CTL_T(Y), ___, ___, ___, ___, ___,
|
||||||
|
Key_C, Key_D, ___, ___, ___, ___,
|
||||||
|
___, ___, ___, ___, ___, ___, ___,
|
||||||
|
___, ___, ___, ___,
|
||||||
|
___,
|
||||||
|
|
||||||
|
___, ___, ___, ___, ___, ___, ___,
|
||||||
|
___, ___, ___, ___, ___, ___, ___,
|
||||||
|
___, ___, ___, ___, ___, ___,
|
||||||
|
___, ___, ___, ___, ___, ___, ___,
|
||||||
|
___, ___, ___, ___,
|
||||||
|
___
|
||||||
|
),
|
||||||
|
)
|
||||||
|
// *INDENT-ON*
|
||||||
|
|
||||||
|
#include <kaleidoscope/KeyAddrEventQueue.h>
|
||||||
|
|
||||||
|
namespace kaleidoscope {
|
||||||
|
namespace plugin {
|
||||||
|
|
||||||
|
class QueueLeaker : public Plugin {
|
||||||
|
public:
|
||||||
|
EventHandlerResult afterEachCycle() {
|
||||||
|
queue_.shift();
|
||||||
|
return EventHandlerResult::OK;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
KeyAddrEventQueue<8> queue_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace plugin
|
||||||
|
} // namespace kaleidoscope
|
||||||
|
|
||||||
|
kaleidoscope::plugin::QueueLeaker QueueLeaker;
|
||||||
|
|
||||||
|
KALEIDOSCOPE_INIT_PLUGINS(Qukeys, QueueLeaker);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Qukeys.setHoldTimeout(kaleidoscope::testing::QUKEYS_HOLD_TIMEOUT);
|
||||||
|
Qukeys.setOverlapThreshold(kaleidoscope::testing::QUKEYS_OVERLAP_THRESHOLD);
|
||||||
|
Qukeys.setMinimumHoldTime(kaleidoscope::testing::QUKEYS_MINIMUM_HOLD_TIME);
|
||||||
|
Qukeys.setMinimumPriorInterval(kaleidoscope::testing::QUKEYS_MIN_PRIOR_INTERVAL);
|
||||||
|
Qukeys.setMaxIntervalForTapRepeat(kaleidoscope::testing::QUKEYS_MAX_INTERVAL_FOR_TAP_REPEAT);
|
||||||
|
|
||||||
|
Kaleidoscope.setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
Kaleidoscope.loop();
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
// -*- mode: c++ -*-
|
||||||
|
|
||||||
|
/* Kaleidoscope - Firmware for computer input devices
|
||||||
|
* Copyright (C) 2021 Keyboard.io, Inc.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by the Free Software
|
||||||
|
* Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace kaleidoscope {
|
||||||
|
namespace testing {
|
||||||
|
|
||||||
|
constexpr uint16_t QUKEYS_HOLD_TIMEOUT = 10;
|
||||||
|
constexpr uint8_t QUKEYS_OVERLAP_THRESHOLD = 0;
|
||||||
|
constexpr uint8_t QUKEYS_MINIMUM_HOLD_TIME = 0;
|
||||||
|
constexpr uint8_t QUKEYS_MIN_PRIOR_INTERVAL = 0;
|
||||||
|
constexpr uint8_t QUKEYS_MAX_INTERVAL_FOR_TAP_REPEAT = 0;
|
||||||
|
|
||||||
|
} // namespace testing
|
||||||
|
} // namespace kaleidoscope
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"cpu": {
|
||||||
|
"fqbn": "keyboardio:virtual:model01",
|
||||||
|
"port": ""
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Copyright (C) 2020 Keyboard.io, Inc.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by the Free Software
|
||||||
|
* Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "testing/setup-googletest.h"
|
||||||
|
|
||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
SETUP_GOOGLETEST();
|
||||||
|
|
||||||
|
namespace kaleidoscope {
|
||||||
|
namespace testing {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr KeyAddr key_addr_A{0, 0};
|
||||||
|
constexpr KeyAddr key_addr_B{0, 1};
|
||||||
|
constexpr KeyAddr key_addr_X{1, 0};
|
||||||
|
constexpr KeyAddr key_addr_Y{1, 1};
|
||||||
|
|
||||||
|
using ::testing::IsEmpty;
|
||||||
|
|
||||||
|
class QukeysIssue1107 : public VirtualDeviceTest {
|
||||||
|
protected:
|
||||||
|
std::set<uint8_t> expected_keycodes_ = {};
|
||||||
|
std::unique_ptr<State> state_ = nullptr;
|
||||||
|
public:
|
||||||
|
void testDelayedTimeout() {
|
||||||
|
state_ = RunCycle();
|
||||||
|
|
||||||
|
// Press `X`
|
||||||
|
sim_.Press(key_addr_X);
|
||||||
|
state_ = RunCycle();
|
||||||
|
|
||||||
|
ASSERT_EQ(state_->HIDReports()->Keyboard().size(), 0)
|
||||||
|
<< "There should be no HID report after the qukey is pressed";
|
||||||
|
|
||||||
|
// Record time at start
|
||||||
|
uint32_t start = Kaleidoscope.millisAtCycleStart();
|
||||||
|
|
||||||
|
uint8_t n = QUKEYS_HOLD_TIMEOUT + 1;
|
||||||
|
while (n-- > 0)
|
||||||
|
millis();
|
||||||
|
|
||||||
|
// Release `X`
|
||||||
|
sim_.Release(key_addr_X);
|
||||||
|
state_ = RunCycle();
|
||||||
|
|
||||||
|
// Record time at end
|
||||||
|
uint32_t end = Kaleidoscope.millisAtCycleStart();
|
||||||
|
|
||||||
|
ASSERT_EQ((end - start), (QUKEYS_HOLD_TIMEOUT + 2))
|
||||||
|
<< "Only one millisecond should be registered elapsed per cycle";
|
||||||
|
|
||||||
|
ASSERT_EQ(state_->HIDReports()->Keyboard().size(), 2)
|
||||||
|
<< "There should be two HID reports after the release of a timed-out qukey";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(QukeysIssue1107, DelayedTimeoutRelease) {
|
||||||
|
for (int i = 0; i < 10; ++i)
|
||||||
|
testDelayedTimeout();
|
||||||
|
|
||||||
|
state_ = RunCycle();
|
||||||
|
ASSERT_EQ(state_->HIDReports()->Keyboard().size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace testing
|
||||||
|
} // namespace kaleidoscope
|
Loading…
Reference in new issue