diff --git a/bin/kaleidoscope-builder b/bin/kaleidoscope-builder index bc32a801..dff8f9e5 100755 --- a/bin/kaleidoscope-builder +++ b/bin/kaleidoscope-builder @@ -53,6 +53,7 @@ build_filenames () { HEX_FILE_PATH="${HEX_FILE_PATH:-${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.hex}" HEX_FILE_WITH_BOOTLOADER_PATH="${HEX_FILE_WITH_BOOTLOADER_PATH:-${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}-with-bootloader.hex}" ELF_FILE_PATH="${ELF_FILE_PATH:-${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.elf}" + LIB_FILE_PATH="${LIB_FILE_PATH:-${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.a}" } @@ -416,11 +417,15 @@ compile () { ${ARDUINO_AVR_GCC_PREFIX_PARAM} \ "${SKETCH_DIR}/${SKETCH}.ino" - cp "${BUILD_PATH}/${SKETCH}.ino.hex" "${HEX_FILE_PATH}" - cp "${BUILD_PATH}/${SKETCH}.ino.elf" "${ELF_FILE_PATH}" - ln -sf "${OUTPUT_FILE_PREFIX}.hex" "${OUTPUT_PATH}/${SKETCH}-latest.hex" - ln -sf "${OUTPUT_FILE_PREFIX}.elf" "${OUTPUT_PATH}/${SKETCH}-latest.elf" - + if [ -z "${LIBONLY}" ]; then + cp "${BUILD_PATH}/${SKETCH}.ino.hex" "${HEX_FILE_PATH}" + cp "${BUILD_PATH}/${SKETCH}.ino.elf" "${ELF_FILE_PATH}" + ln -sf "${OUTPUT_FILE_PREFIX}.hex" "${OUTPUT_PATH}/${SKETCH}-latest.hex" + ln -sf "${OUTPUT_FILE_PREFIX}.elf" "${OUTPUT_PATH}/${SKETCH}-latest.elf" + else + cp "${BUILD_PATH}/${SKETCH}.ino.a" "${LIB_FILE_PATH}" + ln -sf "${OUTPUT_FILE_PREFIX}.a" "${OUTPUT_PATH}/${SKETCH}-latest.a" + fi if [ "${ARDUINO_VERBOSE}" = "-verbose" ]; then echo "Build artifacts can be found in ${BUILD_PATH}"; diff --git a/testing/.gitignore b/testing/.gitignore index ddf7a912..61f03267 100644 --- a/testing/.gitignore +++ b/testing/.gitignore @@ -1,3 +1,3 @@ -bin/ -lib/ -obj/ +**/bin/ +**/lib/ +**/obj/ diff --git a/testing/Makefile b/testing/Makefile index fbba1c2d..086e7866 100644 --- a/testing/Makefile +++ b/testing/Makefile @@ -1,20 +1,9 @@ -TEST_DIRS = $(dir $(wildcard */tests.h)) - -all: ${TEST_DIRS} - @: +TEST_DIRS=$(dir $(wildcard */*_test.cpp)) Makefile: ${TEST_DIRS} @: -%: FORCE - @if [ ! -f "$@/tests.h" ]; then \ - echo 'Unable to find tests file "$@/tests.h"'; \ - else \ - echo "Running test in $@"; \ - env LOCAL_CFLAGS='-DTESTING_INCLUDE_FILE="$@/tests.h" "-I$(PWD)/$@"' VERBOSE=1 $(MAKE) -f delegate.mk; \ - fi +%: FORCE + cd "$@" && $(MAKE) .PHONY: FORCE - - - diff --git a/testing/.kaleidoscope-builder.conf b/testing/hello-simulator/.kaleidoscope-builder.conf similarity index 100% rename from testing/.kaleidoscope-builder.conf rename to testing/hello-simulator/.kaleidoscope-builder.conf diff --git a/testing/hello-simulator/Makefile b/testing/hello-simulator/Makefile new file mode 100644 index 00000000..824a9279 --- /dev/null +++ b/testing/hello-simulator/Makefile @@ -0,0 +1,45 @@ +BIN_DIR=bin +LIB_DIR=lib +OBJ_DIR=obj + +SKETCH_FILE=$(wildcard *.ino) +BIN_FILE=$(subst .ino,,$(SKETCH_FILE)) +LIB_FILE=${BIN_FILE}-latest.a + +TEST_FILES=$(wildcard *_test.cpp) +TEST_OBJS=$(patsubst %.cpp,${OBJ_DIR}/%.o,$(TEST_FILES)) + +run: ${BIN_DIR}/${BIN_FILE} + @echo "run" + "./${BIN_DIR}/${BIN_FILE}" -t + +${BIN_DIR}/${BIN_FILE}: ${TEST_OBJS} FORCE + @echo "link" + mkdir -p "${BIN_DIR}" "${LIB_DIR}" + env LIBONLY=yes LOCAL_CFLAGS='"-I$(PWD)"' OUTPUT_PATH="$(PWD)/$(LIB_DIR)" VERBOSE=1 $(MAKE) -f delegate.mk + g++ -o "${BIN_DIR}/${BIN_FILE}" -lpthread -g -w -lm -lXtst -lX11 ${TEST_OBJS} "${LIB_DIR}/${LIB_FILE}" -L"$(PWD)/../googletest/lib" -lgtest -lgmock + +${OBJ_DIR}/%.o: %.cpp + @echo "compile $@" + mkdir -p "${OBJ_DIR}" + g++ -o "$@" -c \ + -I../../src \ + -I../../../../../virtual/cores/arduino \ + -I../../../Kaleidoscope-HIDAdaptor-KeyboardioHID/src \ + -I../../../KeyboardioHID/src \ + -I../../testing/googletest/googletest/include \ + -DARDUINO=10607 \ + -DARDUINO_AVR_MODEL01 \ + '-DKALEIDOSCOPE_HARDWARE_H="Kaleidoscope-Hardware-Model01.h"' \ + -DKALEIDOSCOPE_VIRTUAL_BUILD=1 \ + -DKEYBOARDIOHID_BUILD_WITHOUT_HID=1 \ + -DUSBCON=dummy \ + -DARDUINO_ARCH_AVR=1 \ + '-DUSB_PRODUCT="Model 01"' \ + $< + +clean: FORCE + rm -rf "${BIN_DIR}" "${LIB_DIR}" "${OBJ_DIR}" + +.PHONY: FORCE + diff --git a/testing/delegate.mk b/testing/hello-simulator/delegate.mk similarity index 100% rename from testing/delegate.mk rename to testing/hello-simulator/delegate.mk diff --git a/testing/hello-simulator/hello-simulator_test.cpp b/testing/hello-simulator/hello-simulator_test.cpp new file mode 100644 index 00000000..3908a88f --- /dev/null +++ b/testing/hello-simulator/hello-simulator_test.cpp @@ -0,0 +1,136 @@ +/* -*- mode: c++ -*- + * Copyright (C) 2020 Eric Paniagua (epaniagua@google.com) + * + * 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 . + */ + +#ifdef KALEIDOSCOPE_VIRTUAL_BUILD + +// The Kaleidoscope core +#include "Kaleidoscope.h" + +// Support for storing the keymap in EEPROM +#include "Kaleidoscope-EEPROM-Settings.h" +#include "Kaleidoscope-EEPROM-Keymap.h" + +// Support for communicating with the host via a simple Serial protocol +#include "Kaleidoscope-FocusSerial.h" + +// Support for keys that move the mouse +#include "Kaleidoscope-MouseKeys.h" + +// Support for macros +#include "Kaleidoscope-Macros.h" + +// Support for controlling the keyboard's LEDs +#include "Kaleidoscope-LEDControl.h" + +// Support for "Numpad" mode, which is mostly just the Numpad specific LED mode +#include "Kaleidoscope-NumPad.h" + +// Support for the "Boot greeting" effect, which pulses the 'LED' button for 10s +// when the keyboard is connected to a computer (or that computer is powered on) +#include "Kaleidoscope-LEDEffect-BootGreeting.h" + +// Support for LED modes that set all LEDs to a single color +#include "Kaleidoscope-LEDEffect-SolidColor.h" + +// Support for an LED mode that makes all the LEDs 'breathe' +#include "Kaleidoscope-LEDEffect-Breathe.h" + +// Support for an LED mode that makes a red pixel chase a blue pixel across the keyboard +#include "Kaleidoscope-LEDEffect-Chase.h" + +// Support for LED modes that pulse the keyboard's LED in a rainbow pattern +#include "Kaleidoscope-LEDEffect-Rainbow.h" + +// Support for an LED mode that lights up the keys as you press them +#include "Kaleidoscope-LED-Stalker.h" + +// Support for an LED mode that prints the keys you press in letters 4px high +#include "Kaleidoscope-LED-AlphaSquare.h" + +// Support for an LED mode that lets one configure per-layer color maps +#include "Kaleidoscope-Colormap.h" + +// Support for Keyboardio's internal keyboard testing mode +#include "Kaleidoscope-HardwareTestMode.h" + +// Support for host power management (suspend & wakeup) +#include "Kaleidoscope-HostPowerManagement.h" + +// Support for magic combos (key chords that trigger an action) +#include "Kaleidoscope-MagicCombo.h" + +// Support for USB quirks, like changing the key state report protocol +#include "Kaleidoscope-USB-Quirks.h" + +#include "Kaleidoscope-Simulator.h" + +#undef min +#undef max +#undef T +#undef U +#undef TEST + +#include "gtest/gtest.h" + +void executeTestFunction() { + setup(); /* setup Kaleidoscope */ + testing::InitGoogleTest(); + RUN_ALL_TESTS(); +} + +namespace kaleidoscope { +namespace simulator { +namespace { + +using namespace actions; +using namespace interface; +using namespace interface::actions; + +class SimulatorTest : public ::testing::Test { + protected: + void SetUp() { + sim_ = &Simulator::getInstance(); + } + + Simulator* sim_; +}; + +class KeyboardReports : public SimulatorTest {}; + +TEST_F(KeyboardReports, ActiveKeycodesAreAccurate) { + // Assert that the next cycle generates exactly one keyboard report. + // + sim_->cycleActionsQueue().queue(AssertCycleGeneratesNReports {1}); + + sim_->tapKey(2, 1); // A + sim_->cycleExpectReports(AssertKeycodesActive{Key_A}); + + sim_->cycleExpectReports(AssertReportEmpty{}); +} + +TEST(Test, ThatPasses) { + EXPECT_TRUE(true); +} + +TEST(Test, ThatFails) { + EXPECT_TRUE(false); +} + +} // namespace +} // namespace simulator +} // namespace kaleidoscope + +#endif // KALEIDOSCOPE_VIRTUAL_BUILD diff --git a/testing/hello-simulator/hello-simulator_test.h b/testing/hello-simulator/hello-simulator_test.h deleted file mode 100644 index 7d4e7240..00000000 --- a/testing/hello-simulator/hello-simulator_test.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- mode: c++ -*- - * Copyright (C) 2020 Eric Paniagua (epaniagua@google.com) - * - * 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 . - */ - -#ifdef KALEIDOSCOPE_VIRTUAL_BUILD - -#pragma once - -#undef min -#undef max -#undef T -#undef U - -#include "fake-gtest.h" -#include "gtest/gtest.h" - -#include "Kaleidoscope-Simulator.h" - -void executeTestFunction() { - setup(); /* setup Kaleidoscope */ - testing::InitGoogleTest(); - RUN_ALL_TESTS(); -} - -namespace kaleidoscope { -namespace simulator { -namespace { - -using namespace actions; -using namespace interface; -using namespace interface::actions; - -class SimulatorTest : public ::testing::Test { - protected: - void SetUp() { - sim_ = &Simulator::getInstance(); - } - - Simulator* sim_; -}; - -class KeyboardReports : public SimulatorTest {}; - -TEST_F(KeyboardReports, ActiveKeycodesAreAccurate) { - // Assert that the next cycle generates exactly one keyboard report. - // - sim_->cycleActionsQueue().queue(AssertCycleGeneratesNReports {1}); - - sim_->tapKey(2, 1); // A - sim_->cycleExpectReports(AssertKeycodesActive{Key_A}); - - sim_->cycleExpectReports(AssertReportEmpty{}); -} - -TEST(Test, ThatPasses) { - EXPECT_TRUE(true); -} - -TEST(Test, ThatFails) { - EXPECT_TRUE(false); -} - -} // namespace -} // namespace simulator -} // namespace kaleidoscope - -#endif // KALEIDOSCOPE_VIRTUAL_BUILD diff --git a/testing/sketch.ino b/testing/hello-simulator/sketch.ino similarity index 99% rename from testing/sketch.ino rename to testing/hello-simulator/sketch.ino index 70d291ad..c35a7555 100644 --- a/testing/sketch.ino +++ b/testing/hello-simulator/sketch.ino @@ -535,5 +535,3 @@ void setup() { void loop() { Kaleidoscope.loop(); } - -#include TESTING_INCLUDE_FILE diff --git a/testing/hello-simulator/tests.h b/testing/hello-simulator/tests.h deleted file mode 100644 index 9ebffde9..00000000 --- a/testing/hello-simulator/tests.h +++ /dev/null @@ -1 +0,0 @@ -#include "./hello-simulator_test.h"