Skip to content

Commit

Permalink
Update how we do our simulator builds to try to avoid a race when bui…
Browse files Browse the repository at this point in the history
…lding the arduino core (#1371)

* Current Docker Desktop no longer accepts that trailing colon

* Make the firmwaredump plugin not explode when compiled against the simulator

This makes it easier to smoke test more stuff in the simulator

* Add a cache warmer to our test suite.

This will be run before any other tests when running simulator tests.
In theory, this might help prevent race conditions during simulator
testing in CI from causing test failures

* Remove an extra internal / from a path

* Build the cache warmer test before any other (including everything in the plugins directory)

Update the "tests failed" output to be a little bit more friendly

* There was a typo in a directory name that only bit us when building on
case-sensitive filesystems. (This is an older plugin not used in current code)
  • Loading branch information
obra authored Dec 14, 2023
1 parent e08ec31 commit 5058e80
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bin/run-docker
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if [ -z "$DOCKER_LIVE_KALEIDOSCOPE_DIR" ]; then
_KALEIDOSCOPE_MOUNT="--mount type=tmpfs,destination=/kaleidoscope:exec"
else
echo "Kaleidoscope is mounted read/write inside docker"
_KALEIDOSCOPE_MOUNT="-v $(pwd):/kaleidoscope:"
_KALEIDOSCOPE_MOUNT="-v $(pwd):/kaleidoscope"
fi


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#pragma once

#ifdef KALEIDOSCOPE_VIRTUAL_BUILD
#error "Firmware Dump is not available for virtual builds"
#warning "Firmware Dump is not available for virtual builds"
#else

#ifdef __AVR__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "Kaleidoscope/plugin/LEDEffect-BootAnimation.h"
#include "Kaleidoscope-LEDEffect-BootAnimation.h"

#include <Arduino.h> // for PROGMEM, pgm_read_byte
#include <stdint.h> // for uint16_t, uint8_t
Expand Down
1 change: 1 addition & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/bin/
**/lib/
**/obj/
_cache-warmer/warm-cache/generated-all-plugins.h
74 changes: 62 additions & 12 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ LIB_DIR := ${build_dir}/lib

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

TEST_PATH ?= ./
TEST_PATH ?= .

export FQBN ?= keyboardio:virtual:model01

Expand All @@ -46,29 +46,65 @@ include $(top_dir)/etc/makefiles/arduino-cli.mk
KALEIDOSCOPE_ETC_DIR ?= $(top_dir)/etc

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

.PHONY: cmake-clean
cmake-clean:
rm -rf "${top_dir}"/testing/googletest/build/*

run-all: ${TESTS}
@for test in ${TESTS}; do \
${MAKE} -s -f ${top_dir}/testing/makefiles/testcase.mk \
-C $${test} \
testcase=$${test} run || ERROR=$$?; \
.PHONY: run-all
run-all: run-cache-warmer run-other-tests aggregate-test-results

.PHONY: run-cache-warmer
run-cache-warmer: generate-all-plugins-header $(filter ./_cache-warmer/%,${TESTS})

.PHONY: run-other-tests
run-other-tests: run-cache-warmer
@$(MAKE) $(filter-out ./_cache-warmer/%,${TESTS})


${TESTS}: ${libcommon_a} googletest
$(QUIET) { \
$(MAKE) -s -f ${top_dir}/testing/makefiles/testcase.mk -C $@ testcase=$@ build run; \
if [ $$? -ne 0 ]; then \
hash=$$(echo "$$@" | shasum | cut -f1 -d' '); \
echo "$@ failed" > ${build_dir}/test_failures_$$hash.log; \
fi; \
}


.PHONY: aggregate-test-results
aggregate-test-results: run-other-tests
$(QUIET) TEST_ERRORS=0; \
for file in ${build_dir}/test_failures_*.log; do \
if [ -f "$$file" ]; then \
TEST_ERRORS=$$((TEST_ERRORS + 1)); \
cat "$$file" >> ${build_dir}/combined_test_failures.log; \
rm -f "$$file"; \
fi; \
done; \
if [ -n $${ERROR} ]; then exit $${ERROR}; fi
if [ -f ${build_dir}/combined_test_failures.log ]; then \
echo "Test failures: $$TEST_ERRORS"; \
cat ${build_dir}/combined_test_failures.log; \
rm -f ${build_dir}/combined_test_failures.log; \
exit 1; \
else \
echo "All tests passed."; \
fi





.PHONY: clean
clean: cmake-clean
@for test in ${TESTS}; do \
$(QUIET) for test in ${TESTS}; do \
${MAKE} -s -f ${top_dir}/testing/makefiles/testcase.mk \
-C $${test} \
testcase=$${test} clean; \
done
rm -rf "${build_dir}"/*
$(QUIET) rm -rf "${build_dir}"/*

.PHONY: googletest
googletest: ${top_dir}/testing/googletest/build/Makefile
Expand All @@ -92,5 +128,19 @@ ${libcommon_a}:
Makefile:
@:

${TESTS}: ${libcommon_a} googletest
$(QUIET) ${MAKE} -f ${top_dir}/testing/makefiles/testcase.mk -C $@ testcase=$@ build run


.PHONY: generate-all-plugins-header
generate-all-plugins-header:
$(QUIET) echo "// This file is generated automatically. Do not edit." > _cache-warmer/warm-cache/generated-all-plugins.h
$(QUIET) for dir in ../plugins/*; do \
if [ -d "$$dir" ]; then \
header_path="$$dir/$$(basename $$dir).h"; \
header_src_path="$$dir/src/$$(basename $$dir).h"; \
header="$$(basename $$dir).h"; \
if [ -f "$$header_path" -o -f "$$header_src_path" ]; then \
echo '#include "'$$header'"' >> _cache-warmer/warm-cache/generated-all-plugins.h; \
fi; \
fi; \
done

6 changes: 6 additions & 0 deletions tests/_cache-warmer/warm-cache/sketch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cpu": {
"fqbn": "keyboardio:virtual:model01",
"port": ""
}
}
1 change: 1 addition & 0 deletions tests/_cache-warmer/warm-cache/sketch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_fqbn: keyboardio:virtual:model01
13 changes: 13 additions & 0 deletions tests/_cache-warmer/warm-cache/test.ktest
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
VERSION 1

KEYSWITCH A 2 1
KEYSWITCH S 2 2

# ==============================================================================
NAME Warm the cache

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

46 changes: 46 additions & 0 deletions tests/_cache-warmer/warm-cache/warm-cache.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* -*- 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>
#include "generated-all-plugins.h"
// *INDENT-OFF*
KEYMAPS(
[0] = KEYMAP_STACKED
(
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, Key_A, Key_S, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___,
___,

___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___,
___
),
)
// *INDENT-ON*

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

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

0 comments on commit 5058e80

Please sign in to comment.