Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add housekeeping execution to tests #22999

Merged
merged 10 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
19 changes: 19 additions & 0 deletions tests/housekeeping/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Copyright 2024 leep-frog
*
* 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, either version 2 of the License, or
* (at your option) any later version.
*
* 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 "test_common.h"
38 changes: 38 additions & 0 deletions tests/housekeeping/housekeeping_keyboard.c
zvecr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Copyright 2024 leep-frog
*
* 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, either version 2 of the License, or
* (at your option) any later version.
*
* 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 "quantum.h"
#include "housekeeping_keyboard.h"

// clang-format off

bool do_housekeeping = false;

void housekeeping_task_user(void) {
if (do_housekeeping) {
do_housekeeping = false;
tap_code16(KC_I);
}
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (keycode == KC_H && !record->event.pressed) {
do_housekeeping = true;
}
return true;
}

// clang-format on
25 changes: 25 additions & 0 deletions tests/housekeeping/housekeeping_keyboard.h
zvecr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Copyright 2024 leep-frog
*
* 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, either version 2 of the License, or
* (at your option) any later version.
*
* 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

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif
20 changes: 20 additions & 0 deletions tests/housekeeping/test.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 leep-frog
#
# 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, either version 2 of the License, or
# (at your option) any later version.
#
# 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/>.

# --------------------------------------------------------------------------------
# Keep this file, even if it is empty, as a marker that this folder contains tests
# --------------------------------------------------------------------------------

SRC = housekeeping_keyboard.c
zvecr marked this conversation as resolved.
Show resolved Hide resolved
54 changes: 54 additions & 0 deletions tests/housekeeping/test_housekeeping.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* Copyright 2024 leep-frog
*
* 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, either version 2 of the License, or
* (at your option) any later version.
*
* 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 "keyboard_report_util.hpp"
#include "keycode.h"
#include "test_common.hpp"
#include "action_tapping.h"
#include "test_keymap_key.hpp"
#include "housekeeping_keyboard.h"

using testing::_;
using testing::InSequence;
zvecr marked this conversation as resolved.
Show resolved Hide resolved

class Housekeeping : public TestFixture {};

TEST_F(Housekeeping, Works) {
TestDriver driver;
InSequence s;
auto key_a = KeymapKey{0, 1, 0, KC_A};
auto key_h = KeymapKey{0, 2, 0, KC_H};

set_keymap({key_a, key_h});

// Key that doesn't affect housekeeping
key_a.press();
EXPECT_REPORT(driver, (KC_A));
run_one_scan_loop();
key_a.release();
EXPECT_EMPTY_REPORT(driver);
run_one_scan_loop();

// Key that does affect housekeeping
key_h.press();
EXPECT_REPORT(driver, (KC_H));
run_one_scan_loop();
key_h.release();
EXPECT_EMPTY_REPORT(driver);
EXPECT_REPORT(driver, (KC_I));
EXPECT_EMPTY_REPORT(driver);
run_one_scan_loop();
}
zvecr marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 3 additions & 1 deletion tests/test_common/test_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void TestFixture::TearDownTestCase() {}
TestFixture::TestFixture() {
m_this = this;
timer_clear();
test_logger.info() << "tapping term is " << +GET_TAPPING_TERM(KC_TRANSPARENT, &(keyrecord_t){}) << "ms" << std::endl;
keyrecord_t empty_keyrecord = {};
zvecr marked this conversation as resolved.
Show resolved Hide resolved
test_logger.info() << "tapping term is " << +GET_TAPPING_TERM(KC_TRANSPARENT, &empty_keyrecord) << "ms" << std::endl;
zvecr marked this conversation as resolved.
Show resolved Hide resolved
}

TestFixture::~TestFixture() {
Expand Down Expand Up @@ -175,6 +176,7 @@ void TestFixture::idle_for(unsigned time) {
test_logger.trace() << +time << " keyboard task " << (time > 1 ? "loops" : "loop") << std::endl;
for (unsigned i = 0; i < time; i++) {
keyboard_task();
housekeeping_task();
advance_time(1);
}
}
Expand Down
Loading