-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
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
✅ Add unit testing framework #26948
Merged
sjasonsmith
merged 36 commits into
MarlinFirmware:bugfix-2.1.x
from
sjasonsmith:InWork/costas/2024_better-tests-rebased-squashed2
Apr 13, 2024
Merged
✅ Add unit testing framework #26948
Changes from 8 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
ec14521
Add exec_tests_failing, to test unhappy paths
costas-basdekis 0e946ff
Add ability to run unit tests
costas-basdekis b7c3462
Update tooling to work with modern Platform I/O and Marlin
sjasonsmith da97377
Refactor test mechanism to make tests more self-discovering and easie…
sjasonsmith 9648cd8
Update READMEs
sjasonsmith e855bb8
Add to test-builds workflow
sjasonsmith ea5076d
Rename job
sjasonsmith 41f0dcc
Restrict to bugfix-2.1.x branch, update comments.
sjasonsmith 53ce692
whitespace, formatting, etc.
thinkyhead f3ad255
Split CI testing into two workflows
sjasonsmith 903d5da
Use INI files inside test folders instead of CPP files
sjasonsmith 8889e4f
Use config.ini
sjasonsmith e5ed773
Remove unused code
sjasonsmith efc9b54
parser.parse() does not accept const
sjasonsmith 9484cb3
Revert unrelated changes
sjasonsmith 68fac74
Update README to reflect config.ini change
sjasonsmith 5514777
TEMPORARY changes to test github workflows
sjasonsmith 28ec011
Revert unrelated changes
sjasonsmith 791ddf3
Avoid main conflict with LINUX_HAL
sjasonsmith e0eee1a
Avoid SIGSEGV on timer cleanup
sjasonsmith 3b6e647
Remove parse_line test
sjasonsmith c014c62
Revert "TEMPORARY changes to test github workflows"
sjasonsmith 9e9a008
move YML
thinkyhead 2767706
readme updates
thinkyhead 6d90aab
rename
thinkyhead 187e186
table format
thinkyhead 6e7b10a
not force-pushed
thinkyhead 55d836e
sort CI tests
thinkyhead e3da66e
test name from file
thinkyhead c0cbc71
not force-pushed
thinkyhead 10c81cc
move string tests
thinkyhead 296048d
tests-code => unit-test
thinkyhead fd351a9
split up string test
thinkyhead 4118f36
fix docker "make" invocation
thinkyhead 9d6f47d
string test
thinkyhead 6a4be39
tweak readme
thinkyhead File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
These test files are executed through the unit-tests built from the <root>/test folder. | ||
|
||
By placing these outside of the main PlatformIO test folder, we are able to collect | ||
all test files and compile them into multiple PlatformIO test binaries. This enables | ||
tests to be executed against a variety of Marlin configurations. | ||
|
||
To execute these tests, refer to the top-level Makefile. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "../test/marlin_tests.h" | ||
#include <src/gcode/gcode.h> | ||
#include <src/gcode/parser.h> | ||
|
||
MARLIN_TEST(gcode, process_parsed_command) { | ||
GcodeSuite suite; | ||
parser.command_letter = 'G'; | ||
parser.codenum = 0; | ||
suite.process_parsed_command(false); | ||
} | ||
|
||
MARLIN_TEST(gcode, parse_g1_xz) | ||
{ | ||
char current_command[] = "G0 X10 Z30"; | ||
parser.command_letter = -128; | ||
parser.codenum = -1; | ||
parser.parse(current_command); | ||
TEST_ASSERT_EQUAL('G', parser.command_letter); | ||
TEST_ASSERT_EQUAL(0, parser.codenum); | ||
TEST_ASSERT_TRUE(parser.seen('X')); | ||
TEST_ASSERT_FALSE(parser.seen('Y')); | ||
TEST_ASSERT_TRUE(parser.seen('Z')); | ||
TEST_ASSERT_FALSE(parser.seen('E')); | ||
} | ||
|
||
MARLIN_TEST(gcode, parse_g1_nxz) { | ||
char current_command[] = "N123 G0 X10 Z30"; | ||
parser.command_letter = -128; | ||
parser.codenum = -1; | ||
parser.parse(current_command); | ||
TEST_ASSERT_EQUAL('G', parser.command_letter); | ||
TEST_ASSERT_EQUAL(0, parser.codenum); | ||
TEST_ASSERT_TRUE(parser.seen('X')); | ||
TEST_ASSERT_FALSE(parser.seen('Y')); | ||
TEST_ASSERT_TRUE(parser.seen('Z')); | ||
TEST_ASSERT_FALSE(parser.seen('E')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "../test/marlin_tests.h" | ||
#include <unity.h> | ||
#include <src/gcode/queue.h> | ||
|
||
static void test_parse_line(const char *command, const char *expected) { | ||
char buffer[MAX_CMD_SIZE]; | ||
int buffer_index = 0; | ||
uint8_t input_state = PS_NORMAL; | ||
|
||
for (int position = 0 ; command[position] ; position++) { | ||
process_stream_char(command[position], input_state, buffer, buffer_index); | ||
} | ||
buffer[buffer_index] = 0; | ||
|
||
TEST_ASSERT_EQUAL_STRING(expected, buffer); | ||
} | ||
|
||
MARLIN_TEST(parse_line, g1_x_and_parenthesis_comment) | ||
{ | ||
#if ENABLED(PAREN_COMMENTS) | ||
test_parse_line("G0 X10 (Z30)", "G0 X10 "); | ||
#else | ||
test_parse_line("G0 X10 (Z30)", "G0 X10 (Z30)"); | ||
#endif | ||
} | ||
|
||
MARLIN_TEST(parse_line, g1_x_and_parenthesis_inline_comment) | ||
{ | ||
#if ENABLED(PAREN_COMMENTS) | ||
test_parse_line("G0 X10 (Y20) Z30", "G0 X10 Z30"); | ||
#else | ||
test_parse_line("G0 X10 (Y20) Z30", "G0 X10 (Y20) Z30"); | ||
#endif | ||
} | ||
|
||
MARLIN_TEST(parse_line, g1_xz) | ||
{ | ||
test_parse_line("G0 X10 Z30", "G0 X10 Z30"); | ||
} | ||
|
||
MARLIN_TEST(parse_line, g1_x_and_comment) | ||
{ | ||
test_parse_line("G0 X10 ; Z30", "G0 X10 "); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "../test/marlin_tests.h" | ||
|
||
#if ENABLED(FILAMENT_RUNOUT_SENSOR) | ||
|
||
#include <src/feature/runout.h> | ||
|
||
MARLIN_TEST(runout, poll_runout_states) | ||
{ | ||
FilamentSensorBase sensor; | ||
// Expected default value is one bit set for each extruder | ||
uint8_t expected = static_cast<uint8_t>(~(~0u << NUM_RUNOUT_SENSORS)); | ||
TEST_ASSERT_EQUAL(expected, sensor.poll_runout_states()); | ||
} | ||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I tested that the workflow worked on my own repo/branch, I didn't test this
github.ref
check. I'm attempting to prevent this from running on the 2.1.x branch, since it won't work yet.If we don't want to gamble whether this will work once merged, we could split this into a new YML file with different branch requirements. I thought it made sense to add it to this file because then it can re-use all the trigger configuration regarding file paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That github.ref syntax came from GitHub Copilot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also move this to its own action, if that helps to make things cleaner.