-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Add unit testing framework (#26948)
- Add a framework to build and execute unit tests for Marlin. - Enable unit test execution as part of PR checks. --------- Co-authored-by: Costas Basdekis <[email protected]> Co-authored-by: Scott Lahteine <[email protected]>
- Loading branch information
1 parent
cf7c86d
commit d10861e
Showing
21 changed files
with
710 additions
and
111 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# | ||
# ci-unit-tests.yml | ||
# Build and execute unit tests to catch functional issues in code | ||
# | ||
|
||
name: CI - Unit Tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- bugfix-2.1.x | ||
# Cannot be enabled on 2.1.x until it contains the unit test framework | ||
#- 2.1.x | ||
paths-ignore: | ||
- config/** | ||
- data/** | ||
- docs/** | ||
- '**/*.md' | ||
push: | ||
branches: | ||
- bugfix-2.1.x | ||
# Cannot be enabled on 2.1.x until it contains the unit test framework | ||
#- 2.1.x | ||
paths-ignore: | ||
- config/** | ||
- data/** | ||
- docs/** | ||
- '**/*.md' | ||
|
||
jobs: | ||
# This runs all unit tests as a single job. While it should be possible to break this up into | ||
# multiple jobs, they currently run quickly and finish long before the compilation tests. | ||
run_unit_tests: | ||
name: Unit Test | ||
# These tests will only be able to run on the bugfix-2.1.x branch, until the next release | ||
# pulls them into additional branches. | ||
if: github.repository == 'MarlinFirmware/Marlin' | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out the PR | ||
uses: actions/checkout@v4 | ||
|
||
- name: Cache pip | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
- name: Cache PlatformIO | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.platformio | ||
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} | ||
|
||
- name: Select Python 3.9 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.9' | ||
architecture: 'x64' | ||
|
||
- name: Install PlatformIO | ||
run: | | ||
pip install -U platformio | ||
pio upgrade --dev | ||
pio pkg update --global | ||
- name: Run All Unit Tests | ||
run: | | ||
make unit-test-all-local |
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,5 @@ | ||
These test files are executed by the unit-tests built from the `<root>/test` folder. | ||
|
||
These are placed outside of the main PlatformIO test folder so we can 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,58 @@ | ||
/** | ||
* Marlin 3D Printer Firmware | ||
* Copyright (c) 2024 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] | ||
* | ||
* Based on Sprinter and grbl. | ||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm | ||
* | ||
* 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, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* 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 <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "../test/unit_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,36 @@ | ||
/** | ||
* Marlin 3D Printer Firmware | ||
* Copyright (c) 2024 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] | ||
* | ||
* Based on Sprinter and grbl. | ||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm | ||
* | ||
* 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, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* 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 <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "../test/unit_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.