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

Allow simulator tests for devices other than the Model 01 #1394

Merged
merged 7 commits into from
Feb 24, 2024
Merged
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
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Cache arduino dep downloads
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ github.workspace}}/.arduino/downloads
key: ${{ runner.os }}-arduino-downloads
- run: make setup
- run: KALEIDOSCOPE_TEMP_PATH=${{ github.workspace}}/.kaleidoscope-temp make -j $(nproc) smoke-sketches
run-google-tests:
run-simulator-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache arduino dep downloads
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ github.workspace}}/.arduino/downloads
key: ${{ runner.os }}-arduino-downloads
- run: sudo apt update
- run: sudo apt update
- name: ccache
uses: hendrikmuhs/[email protected]
uses: hendrikmuhs/[email protected].11
- run: make setup
- run: KALEIDOSCOPE_CCACHE=1 make -j $(nproc) --output-sync=recurse simulator-tests
check-code-style:
Expand Down
2 changes: 1 addition & 1 deletion etc/makefiles/arduino-cli.mk
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ endif
# emoji, since it accurately represents our feelings on this
# state of affairs. Later, when finding props, we need to reverse
# this process, turning fire into space.
_arduino_props := $(shell ${ARDUINO_CLI} compile $(fqbn_arg) --show-properties "$(_arduino_props_sketch_arg)"|perl -p -e"s/ /🔥/g")
_arduino_props := $(shell ${ARDUINO_CLI} compile $(fqbn_arg) --show-properties=expanded "$(_arduino_props_sketch_arg)"|perl -p -e"s/ /🔥/g")

_arduino_prop = $(subst $1=,,$(subst 🔥, ,$(filter $1=%,$(_arduino_props))))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
#ifdef ARDUINO_AVR_KEYBOARDIO_ATREUS

#include "kaleidoscope/Runtime.h"
Expand All @@ -40,6 +39,8 @@ namespace keyboardio {
// resolved as `KeyScannerProps::matrix_rows`.
const uint8_t KeyScannerProps::matrix_rows;
const uint8_t KeyScannerProps::matrix_columns;

#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
constexpr uint8_t KeyScannerProps::matrix_row_pins[matrix_rows];
constexpr uint8_t KeyScannerProps::matrix_col_pins[matrix_columns];

Expand All @@ -59,10 +60,9 @@ KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows]
ISR(TIMER1_OVF_vect) {
Runtime.device().keyScanner().do_scan_ = true;
}

#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
} // namespace keyboardio
} // namespace device
} // namespace kaleidoscope

#endif
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
6 changes: 4 additions & 2 deletions testing/makefiles/libcommon.mk
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
mkfile_dir := $(dir $(lastword ${MAKEFILE_LIST}))
top_dir := $(abspath $(mkfile_dir)../..)
shared_mk := $(mkfile_dir)/shared.mk

include $(mkfile_dir)/shared.mk
pathsafe_fqbn := $(subst :,_,${FQBN})


build_dir := ${top_dir}/_build
build_dir := ${top_dir}/_build/$(pathsafe_fqbn)

LIB_DIR := ${build_dir}/lib
OBJ_DIR := ${build_dir}/obj
Expand Down Expand Up @@ -39,3 +40,4 @@ clean:
$(QUIET) rm -rf -- "${build_dir}"

include $(top_dir)/etc/makefiles/arduino-cli.mk
include $(shared_mk)
14 changes: 10 additions & 4 deletions testing/makefiles/shared.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ shared_defines := \
-DKEYBOARDIOHID_BUILD_WITHOUT_HID=1 \
-DUSBCON=dummy \
-DARDUINO_ARCH_AVR=1 \
-DARDUINO_AVR_MODEL01 \
'-DKALEIDOSCOPE_HARDWARE_H="Kaleidoscope-Hardware-Keyboardio-Model01.h"' \
'-DUSB_PRODUCT="Model 01"'
$(call _arduino_prop,build.extra_flags) \
-DARDUINO_$(call _arduino_prop,build.board) \
-DUSB_PRODUCT='$(call _arduino_prop,build.usb_product)'

# Extract the kaleidoscope_hardware_h from shared defines
_hardware_h := $(shell echo $(shared_defines) | sed -n 's/.*-DKALEIDOSCOPE_HARDWARE_H="\([^"]*\)".*/\1/p')

# Find the directory containing the file
_hardware_plugin_path := $(shell find $(top_dir)/plugins/ -type f -name "$(_hardware_h)" -exec dirname {} \;)

shared_includes := \
-I${top_dir} \
-I${top_dir}/src \
-I${top_dir}/plugins/Kaleidoscope-Hardware-Keyboardio-Model01/src \
-I${_hardware_plugin_path} \
-I${arduino_platform_path}/cores/keyboardio \
-I${top_dir}/plugins/KeyboardioHID/src \
-I${top_dir}/testing/googletest/googlemock/include \
Expand Down
25 changes: 20 additions & 5 deletions testing/makefiles/testcase.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,32 @@ MAKEFLAGS += --no-builtin-rules
mkfile_dir := $(dir $(lastword ${MAKEFILE_LIST}))
top_dir := $(abspath $(mkfile_dir)../..)

include $(mkfile_dir)/shared.mk

# need to set this before we get the FQBN
SKETCH_FILE := $(wildcard *.ino)
FQBN = $(shell cat sketch.yaml|grep default_fqbn | cut -d " " -f 2)

pathsafe_fqbn := $(subst :,_,${FQBN})

build_root := ${top_dir}/_build/$(pathsafe_fqbn)


export KALEIDOSCOPE_TEMP_PATH := ${build_root}/kaleidoscope

include_plugins_dir := -I${top_dir}/plugins \

build_dir := ${top_dir}/_build/${testcase}
build_dir := ${build_root}/${testcase}

LIB_DIR := ${build_dir}/lib
OBJ_DIR := ${build_dir}/obj
BIN_DIR := ${build_dir}/bin

COMMON_LIB_DIR := ${top_dir}/_build/lib
COMMON_LIB_DIR := ${build_root}/lib
libcommon_a := ${COMMON_LIB_DIR}/libcommon.a

shared_mk := $(mkfile_dir)/shared.mk
include $(top_dir)/etc/makefiles/arduino-cli.mk
include $(shared_mk)

ifneq ($(KALEIDOSCOPE_CCACHE),)
COMPILER_WRAPPER := ccache
Expand All @@ -43,7 +56,6 @@ endif

SRC_DIR := test

SKETCH_FILE=$(wildcard *.ino)
BIN_FILE=$(subst .ino,,$(SKETCH_FILE))
LIB_FILE=${BIN_FILE}-latest.a

Expand Down Expand Up @@ -78,7 +90,7 @@ ${BIN_DIR}/${BIN_FILE}: compile-sketch

# We force sketch recompiliation because otherwise, make won't pick up changes to...anything on the arduino side
.PHONY: compile-sketch
compile-sketch: ${TEST_OBJS}
compile-sketch: ${libcommon_a} ${TEST_OBJS}
-@install -d "${BIN_DIR}" "${LIB_DIR}"
$(QUIET) env LIBONLY=yes VERBOSE=${VERBOSE} \
OUTPUT_PATH="${LIB_DIR}" \
Expand All @@ -91,6 +103,9 @@ compile-sketch: ${TEST_OBJS}
-L"${top_dir}/testing/googletest/build/lib" \
-lgtest -lgmock -lpthread -lm

${libcommon_a}:
$(QUIET) ${MAKE} -f ${top_dir}/testing/makefiles/libcommon.mk -C ${top_dir}/testing


# If we have a test.ktest file, it should be processed into a c++ testcase
.PHONY: generate-testcase
Expand Down
25 changes: 13 additions & 12 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,36 @@ tests_dir := $(abspath $(dir $(lastword ${MAKEFILE_LIST})))

top_dir := $(abspath $(tests_dir)/..)

build_dir := ${top_dir}/_build
# Hardocde an FQBN that gets the virtual core here so that when arduino_prop
# gets called, it picks up the virtual platform compiler settings

LIB_DIR := ${build_dir}/lib
export FQBN := keyboardio:virtual:model01

libcommon_a := ${top_dir}/_build/lib/libcommon.a
build_dir := ${top_dir}/_build

TEST_PATH ?= .

export FQBN ?= keyboardio:virtual:model01

TESTS := $(shell cd $(tests_dir); find ${TEST_PATH} -name '*.ino' -exec dirname {} \;)

# The clutter up the test output on Make 4.0 and newer
MAKEFLAGS += --no-print-directory

include $(top_dir)/etc/makefiles/arduino-cli.mk



ifneq ($(KALEIDOSCOPE_CCACHE),)
_compiler_wrappers := -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
endif

.DEFAULT_GOAL := all

# If we start off in tests to run make all, the sketch makefiles guess the wrong location for
# Kaleidoscope's makefiles
KALEIDOSCOPE_ETC_DIR ?= $(top_dir)/etc

.PHONY: all
all: ${libcommon_a} googletest run-all
all: googletest run-all
@:

.PHONY: cmake-clean
Expand All @@ -64,7 +69,7 @@ run-other-tests: run-cache-warmer
@$(MAKE) $(filter-out ./_cache-warmer/%,${TESTS})


${TESTS}: ${libcommon_a} googletest
${TESTS}: googletest
$(QUIET) { \
$(MAKE) -s -f ${top_dir}/testing/makefiles/testcase.mk -C $@ testcase=$@ build run; \
if [ $$? -ne 0 ]; then \
Expand Down Expand Up @@ -119,11 +124,7 @@ ${top_dir}/testing/googletest/build/Makefile:
-B ${top_dir}/testing/googletest/build \
-DCMAKE_C_COMPILER=$(call _arduino_prop,compiler.path)$(call _arduino_prop,compiler.c.cmd) \
-DCMAKE_CXX_COMPILER=$(call _arduino_prop,compiler.path)$(call _arduino_prop,compiler.cpp.cmd) \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache

${libcommon_a}:
$(QUIET) ${MAKE} -f ${top_dir}/testing/makefiles/libcommon.mk -C ${top_dir}/testing
$(_compiler_wrappers)

Makefile:
@:
Expand Down
42 changes: 42 additions & 0 deletions tests/examples/basic-keypress-atreus/basic-keypress-atreus.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* -*- 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 <Kaleidoscope.h>

// *INDENT-OFF*
KEYMAPS(
[0] = KEYMAP_STACKED(
Key_Q ,Key_W ,Key_E ,Key_R ,Key_T
,Key_A ,Key_S ,Key_D ,Key_F ,Key_G
,Key_Z ,Key_X ,Key_C ,Key_V ,Key_B, Key_Backtick
,Key_Esc ,Key_Tab ,Key_LeftGui ,Key_LeftShift ,Key_Backspace ,Key_LeftControl

,Key_Y ,Key_U ,Key_I ,Key_O ,Key_P
,Key_H ,Key_J ,Key_K ,Key_L ,Key_Semicolon
,Key_Backslash,Key_N ,Key_M ,Key_Comma ,Key_Period ,Key_Slash
,Key_LeftAlt ,Key_Space ,___ ,Key_Minus ,Key_Quote ,Key_Enter

)
)
// *INDENT-ON*

void setup() {
Kaleidoscope.setup();
}

void loop() {
Kaleidoscope.loop();
}
6 changes: 6 additions & 0 deletions tests/examples/basic-keypress-atreus/sketch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cpu": {
"fqbn": "keyboardio:virtual:keyboardio_atreus",
"port": ""
}
}
1 change: 1 addition & 0 deletions tests/examples/basic-keypress-atreus/sketch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_fqbn: keyboardio:virtual:keyboardio_atreus
34 changes: 34 additions & 0 deletions tests/examples/basic-keypress-atreus/test.ktest
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
VERSION 1

KEYSWITCH A 1 0
KEYSWITCH S 1 1

# ==============================================================================
NAME Keys active when pressed

RUN 4 ms
PRESS A
RUN 1 cycle
EXPECT keyboard-report Key_A # Key A should be pressed

RUN 4 ms
RELEASE A
RUN 1 cycle
EXPECT keyboard-report empty # No keys should be pressed

RUN 4 ms
PRESS A
PRESS S
RUN 1 ms
EXPECT keyboard-report Key_A # Key A should be pressed
EXPECT keyboard-report Key_A, Key_S # A and S should be pressed

RUN 4 ms
RELEASE A
RELEASE S
RUN 1 cycle
# A is released first because of scan order
EXPECT keyboard-report Key_S # Key S should be pressed
EXPECT keyboard-report empty # No keys should be pressed

RUN 5 ms
2 changes: 1 addition & 1 deletion tests/features/layers/mod-layer/sketch.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
default_fqbn: keyboardio:avr:model01
default_fqbn: keyboardio:virtual:model01
2 changes: 1 addition & 1 deletion tests/issues/1042/sketch.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
default_fqbn: keyboardio:avr:model01
default_fqbn: keyboardio:virtual:model01
1 change: 1 addition & 0 deletions tests/issues/980/sketch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_fqbn: keyboardio:virtual:model01
Loading