[WIP]: Test in testing/kaleidoscope builds, links, and segfaults.

Signed-off-by: Eric Paniagua <epaniagua@google.com>
epan/testing/readable
Eric Paniagua 4 years ago
parent a72b444dbd
commit eabea8f03c

@ -13,7 +13,7 @@ googletest: FORCE
common: FORCE
cd common && env LIB_DIR="${LIB_DIR}" $(MAKE)
%: FORCE
%: common googltest FORCE
if [ -f "$@/Makefile" ]; then cd "$@"; $(MAKE); fi
.PHONY: FORCE googletest build-libs

@ -29,7 +29,7 @@ KeyboardReport::KeyboardReport(const void* data) {
std::vector<uint8_t> KeyboardReport::ActiveKeycodes() const {
std::vector<uint8_t> active_keys;
for (uint8_t i = 0; i <= HID_LAST_KEY; ++i) {
for (uint8_t i = 0; i < HID_LAST_KEY; ++i) {
uint8_t bit = 1 << (uint8_t(i) % 8);
uint8_t key_code = report_data_.keys[i/8] & bit;
if (key_code) active_keys.push_back(i);

@ -3,27 +3,27 @@ OBJ_DIR ?= ${PWD}/obj
CXX_FILES=$(wildcard *.cpp)
LIB_FILE=common.a
LIB_FILE=libcommon.a
OBJ_FILES=$(patsubst %.cpp,${OBJ_DIR}/%.o,$(CXX_FILES))
Makefile: ${LIB_DIR}/${LIB_FILE}
Makefile: ${OBJ_FILES} ${LIB_DIR}/${LIB_FILE}
@:
${LIB_DIR}/${LIB_FILE}: ${OBJ_FILES}
mkdir -p "${LIB_DIR}"
ar rcs "${LIB_DIR}/${LIB_FILE}" ${OBJ_FILES}
${OBJ_DIR}/%.o: %.cpp
${OBJ_DIR}/%.o: %.cpp $(wildcard *.h)
@echo "compile $@"
mkdir -p "${OBJ_DIR}"
g++ -o "$@" -c \
-I../.. \
-I../../src \
-I../../../../../virtual/cores/arduino \
-I../../../Kaleidoscope-HIDAdaptor-KeyboardioHID/src \
-I../../../KeyboardioHID/src \
-I../../testing/googletest/googlemock/include \
-I../../testing/googletest/googletest/include \
-I${PWD}/../.. \
-I${PWD}/../../src \
-I${PWD}/../../../../../virtual/cores/arduino \
-I${PWD}/../../../Kaleidoscope-HIDAdaptor-KeyboardioHID/src \
-I${PWD}/../../../KeyboardioHID/src \
-I${PWD}/../../testing/googletest/googlemock/include \
-I${PWD}/../../testing/googletest/googletest/include \
-DARDUINO=10607 \
-DARDUINO_AVR_MODEL01 \
'-DKALEIDOSCOPE_HARDWARE_H="Kaleidoscope-Hardware-Model01.h"' \

@ -17,11 +17,16 @@
#include "Kaleidoscope.h"
#include "testing/common/Simulator.h"
#include "testing/common/fix-macros.h"
#include <iostream>
namespace kaleidoscope {
namespace testing {
void Simulator::RunCycle() {
std::cout << "epan 2.2.1" << std::endl;
Kaleidoscope.loop();
std::cout << "epan 2.2.2" << std::endl;
}
void Simulator::RunCycles(size_t n) {
@ -34,5 +39,11 @@ void Simulator::Press(uint8_t row, uint8_t col) {
kaleidoscope::Device::Props::KeyScanner::KeyState::Pressed);
}
void Simulator::Release(uint8_t row, uint8_t col) {
Kaleidoscope.device().keyScanner().setKeystate(
KeyAddr{row, col},
kaleidoscope::Device::Props::KeyScanner::KeyState::NotPressed);
}
} // namespace testing
} // namespace kaleidoscope

@ -59,7 +59,7 @@ void State::ProcessHidReport(
break;
}
case HID_REPORTID_NKRO_KEYBOARD: {
ProcessReport(KeyboardReport{data});
ProcessKeyboardReport(KeyboardReport{data});
break;
}
default:
@ -75,5 +75,9 @@ const KeyboardReport& State::KeyboardReports(size_t i) const {
return keyboard_reports_.at(i);
}
void State::ProcessKeyboardReport(const KeyboardReport& report) {
keyboard_reports_.push_back(report);
}
} // namespace testing
} // namespace kaleidoscope

@ -39,20 +39,10 @@ class State {
const KeyboardReport& KeyboardReports(size_t i) const;
private:
template <class R>
void ProcessReport(const R& report);
void ProcessKeyboardReport(const KeyboardReport& report);
std::vector<KeyboardReport> keyboard_reports_;
};
/*
* Implementation
*/
template <>
void State::ProcessReport<KeyboardReport>(const KeyboardReport& report) {
keyboard_reports_.push_back(report);
}
} // namespace testing
} // namespace kaleidoscope

@ -20,8 +20,11 @@ namespace kaleidoscope {
namespace testing {
void VirtualDeviceTest::RunCycle() {
std::cout << "epan 2.1" << std::endl;
state_.Clear();
std::cout << "epan 2.2" << std::endl;
sim_.RunCycle();
std::cout << "epan 2.3" << std::endl;
}
void VirtualDeviceTest::RunCycles(size_t n) {

@ -0,0 +1,4 @@
# -*- mode: sh -*-
DEFAULT_SKETCH=sketch
ARCH=virtual

@ -1,13 +1,14 @@
BIN_DIR=bin
LIB_DIR=lib
OBJ_DIR=obj
SRC_DIR=test
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))
TEST_FILES=$(wildcard $(SRC_DIR)/*_test.cpp)
TEST_OBJS=$(patsubst $(SRC_DIR)/%.cpp,${OBJ_DIR}/%.o,$(TEST_FILES))
run: ${BIN_DIR}/${BIN_FILE}
@echo "run"
@ -17,19 +18,32 @@ ${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
g++ -o "${BIN_DIR}/${BIN_FILE}" \
-lpthread \
-g \
-w \
${TEST_OBJS} \
"${LIB_DIR}/${LIB_FILE}" \
-L"$(PWD)/../googletest/lib" \
-L"${PWD}/../lib" \
-lcommon \
-lgtest \
-lgmock \
-lm \
-lXtst \
-lX11
${OBJ_DIR}/%.o: ${SRC_DIR}/%.cpp
@echo "compile $@"
mkdir -p "${OBJ_DIR}"
g++ -o "$@" -c \
-I../.. \
-I../../src \
-I../../../../../virtual/cores/arduino \
-I../../../Kaleidoscope-HIDAdaptor-KeyboardioHID/src \
-I../../../KeyboardioHID/src \
-I../../testing/googletest/googlemock/include \
-I../../testing/googletest/googletest/include \
-I${PWD}/../.. \
-I${PWD}/../../src \
-I${PWD}/../../../../../virtual/cores/arduino \
-I${PWD}/../../../Kaleidoscope-HIDAdaptor-KeyboardioHID/src \
-I${PWD}/../../../KeyboardioHID/src \
-I${PWD}/../../testing/googletest/googlemock/include \
-I${PWD}/../../testing/googletest/googletest/include \
-DARDUINO=10607 \
-DARDUINO_AVR_MODEL01 \
'-DKALEIDOSCOPE_HARDWARE_H="Kaleidoscope-Hardware-Model01.h"' \

@ -22,6 +22,8 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <iostream>
#include "testing/common/matchers.h"
#include "testing/common/VirtualDeviceTest.h"
@ -36,18 +38,27 @@ using ::testing::IsEmpty;
class KeyboardReports : public VirtualDeviceTest {};
TEST_F(KeyboardReports, KeysActiveWhenPressed) {
std::cout << "epan 1" << std::endl;
sim_.Press(2, 1); // A
std::cout << "epan 2" << std::endl;
RunCycle();
std::cout << "epan 3" << std::endl;
EXPECT_EQ(Result().KeyboardReports().size(), 1);
std::cout << "epan 4" << std::endl;
EXPECT_THAT(
Result().KeyboardReports(0).ActiveKeycodes(),
ContainsKey(Key_A));
std::cout << "epan 5" << std::endl;
sim_.Release(2, 1); // A
std::cout << "epan 6" << std::endl;
RunCycles(2);
std::cout << "epan 7" << std::endl;
std::cout << "epan 8" << std::endl;
EXPECT_THAT(Result().KeyboardReports(), IsEmpty());
std::cout << "epan 9" << std::endl;
}
} // namespace
Loading…
Cancel
Save