Skip to content

Commit

Permalink
Daniel/orbit/tests integration (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan authored Aug 21, 2023
1 parent d39a525 commit 15472e2
Show file tree
Hide file tree
Showing 230 changed files with 604,712 additions and 28 deletions.
21 changes: 7 additions & 14 deletions .github/workflows/orbit_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,21 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout outer repository
- name: Checkout current repository
uses: actions/checkout@v3
with:
repository: "StoneOrbits/VortexEmulator"
path: VortexEmulator
- name: Checkout current repository inside the outer repository
uses: actions/checkout@v3
with:
path: VortexEmulator/VortexTestingFramework/VortexEngine
- name: Update Package Lists
run: sudo apt-get update
- name: Install Dependencies
run: sudo apt-get install valgrind g++ make --fix-missing
- name: Build
run: make -j
working-directory: VortexEmulator/VortexTestingFramework
working-directory: VortexEngine
- name: Set execute permissions for test script
run: chmod +x ./runtests.sh
working-directory: VortexEmulator/VortexTestingFramework/tests
- name: Run tests
run: ./runtests.sh --orbit
working-directory: VortexEmulator/VortexTestingFramework/tests
working-directory: VortexEngine/tests
- name: Run general tests
run: ./runtests.sh --general
working-directory: VortexEngine/tests

embedded:
needs: test
Expand Down Expand Up @@ -63,7 +56,7 @@ jobs:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/orbit'
steps:
- name: Checkout current repository inside the outer repository
- name: Checkout current repository
uses: actions/checkout@v3
- name: Update Package Lists
run: sudo apt-get update
Expand Down
4 changes: 3 additions & 1 deletion VortexEngine/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ TARGETS=\
vortex \
vortex.a

.PHONY: $(TARGETS)

# Default target for 'make' command
all: $(TARGETS)

Expand All @@ -29,6 +31,6 @@ vortex:

# generic clean target
clean:
@$(RM) $(TARGETS) $(TESTS)
@$(RM) $(TARGETS) $(TESTS) vortex.exe
$(MAKE) -C VortexLib clean
$(MAKE) -C VortexCLI clean
51 changes: 51 additions & 0 deletions VortexEngine/VortexCLI/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Vortex CLI

This folder contains the command line interface vortex tool

This tool allows the vortex engine to be run on the command line and print it's output in various ways.

The usage includes options to control the engine in various ways, this allows for robust tests to be
designed around this tool to test the vortex engine to ensure it is behaving correctly.

The usage of the tool is as follows:

Usage: ../vortex [options] < input commands
Output Selection (at least one required):
-x, --hex Use hex values to represent led colors
-c, --color Use console color codes to represent led colors

Engine Control Flags (optional):
-t, --no-timestep Bypass the timestep and run as fast as possible
-l, --lockstep Only step once each time an input is received
-i, --in-place Print the output in-place (interactive mode)
-r, --record Record the inputs and dump to a file after (recorded_input.txt)
-a, --autowake Automatically and instantly wake on sleep (disable sleep)
-n, --nolock Automatically unlock upon locking the chip (disable lock)
-s, --storage [file] Persistent storage to file (default file: FlashStorage.flash)

Initial Pattern Options (optional):
-P, --pattern <id> Preset the pattern ID on the first mode
-C, --colorset c1,c2... Preset the colorset on the first mode (csv list of hex codes or color names)
-A, --arguments a1,a2... Preset the arguments on the first mode (csv list of arguments)

Other Options:
-h, --help Display this help message

Input Commands (pass to stdin):
c standard short click
l standard long click
m open menus length click
a enter adv menu length click (enter adv menu from menus)
d delete length click (delete color in col select)
s enter sleep length click (enter sleep at main modes)
f force sleep length click (force sleep anywhere)
t toggle button pressed (only way to wake after sleep)
r rapid button click (ex: r15)
w wait 1 tick
<digits> repeat command n times (only single digits in -i mode)
q quit
Example Usage:
./vortex -ci
./vortex -ci -P42 -Ccyan,purple
./vortex -ct -P0 -Cred,green -A1,2 <<< w10q

35 changes: 29 additions & 6 deletions VortexEngine/VortexLib/VortexLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void Vortex::doCommand(char c)
case 'q':
//case '\n':
if (m_lastCommand != c) {
DEBUG_LOG("Injecting quit click");
DEBUG_LOG("Injecting quit click\n");
}
Vortex::quitClick();
break;
Expand Down Expand Up @@ -337,12 +337,9 @@ bool Vortex::tick()
cleanup();
return false;
}
// On linux we need to poll stdin for input to handle commands
#if !defined(_WIN32) && !defined(WASM)
// use ioctl to determine how many characters are on stdin so that
// we don't call getchar() too many times and accidentally block
uint32_t numInputs = 0;
ioctl(STDIN_FILENO, FIONREAD, &numInputs);
uint32_t numInputs = getNumInputs();
if (m_lockstepEnabled && !numInputs) {
// don't tick till we have input
return true;
Expand All @@ -354,7 +351,6 @@ bool Vortex::tick()
for (uint32_t i = 0; i < numInputs; ++i) {
doCommand(getchar());
}
#endif
// tick the vortex engine forward
VortexEngine::tick();
return true;
Expand Down Expand Up @@ -1125,6 +1121,33 @@ void Vortex::handleInputQueue(Button *buttons, uint32_t numButtons)
}
}

uint32_t Vortex::getNumInputs()
{
uint32_t numInputs = 0;
// On linux we need to poll stdin for input to handle commands
#if !defined(_WIN32) && !defined(WASM)
ioctl(STDIN_FILENO, FIONREAD, &numInputs);
#elif defined(_WIN32)
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);

if (GetFileType(hStdin) == FILE_TYPE_CHAR) {
// Handle console input
if (!GetNumberOfConsoleInputEvents(hStdin, (DWORD *)&numInputs)) {
// Handle error here
}
} else {
// Handle redirected input
DWORD availableBytes;
if (PeekNamedPipe(hStdin, NULL, 0, NULL, &availableBytes, NULL)) {
numInputs = availableBytes;
} else {
// Handle error here
}
}
#endif
return numInputs;
}

void Vortex::printlog(const char *file, const char *func, int line, const char *msg, va_list list)
{
if (!Vortex::m_consoleHandle) {
Expand Down
1 change: 1 addition & 0 deletions VortexEngine/VortexLib/VortexLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ class Vortex
// the input deque that is fed by the apis like shortClick() above and translate
// those messages into actual button events by overwriting button data that tick
static void handleInputQueue(Button *buttons, uint32_t numButtons);
static uint32_t getNumInputs();

// The various different button events that can be injected into vortex
enum VortexButtonEventType
Expand Down
12 changes: 5 additions & 7 deletions VortexEngine/src/Patterns/Single/BlendPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ void BlendPattern::init()

void BlendPattern::onBlinkOn()
{
if ((Time::getCurtime() % 4) == 0) {
if (m_cur == m_next) {
m_next = m_colorset.getNext();
}
interpolate(m_cur.red, m_next.red);
interpolate(m_cur.green, m_next.green);
interpolate(m_cur.blue, m_next.blue);
if (m_cur == m_next) {
m_next = m_colorset.getNext();
}
interpolate(m_cur.red, m_next.red);
interpolate(m_cur.green, m_next.green);
interpolate(m_cur.blue, m_next.blue);
RGBColor col = m_cur;
if (m_flip) {
// convert to hsv
Expand Down
9 changes: 9 additions & 0 deletions VortexEngine/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Vortex Tests

At the moment this folders only contains a set of integration tests which test the entire Vortex Engine from end to end.

The tests use the command line vortex tool with various inputs and parameters and compare the output against prerecorded
test files. If the output differs then the test fails. These tests are rather rudimentary and not the most robust.

These tests will catch if anything changes in the output of the vortex engine, including if something as simple as a blink
timing has been changed. That can be both a helpful and annoying aspect of these tests.
Loading

0 comments on commit 15472e2

Please sign in to comment.