-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this requires us to switch our mocking support framework from CMock to FFF, since the former also requires Ruby
- Loading branch information
1 parent
abfc306
commit 716481a
Showing
14 changed files
with
166 additions
and
64 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
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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,39 @@ | ||
include(FetchContent) | ||
|
||
FetchContent_Declare( | ||
unity | ||
GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git | ||
GIT_TAG v2.6.0 | ||
) | ||
|
||
FetchContent_Declare( | ||
fff | ||
GIT_REPOSITORY https://github.com/meekrosoft/fff.git | ||
GIT_TAG v1.1 | ||
) | ||
|
||
FetchContent_MakeAvailable(unity fff) | ||
|
||
add_executable(test_led test_led.c ${CMAKE_SOURCE_DIR}/Src/led.c) | ||
target_compile_definitions(test_led PUBLIC TEST) | ||
target_include_directories(test_led PRIVATE ${CMAKE_SOURCE_DIR}/Inc support) | ||
target_link_libraries(test_led unity) | ||
add_test(test_led test_led) | ||
|
||
add_executable(test_main test_main.c ${CMAKE_SOURCE_DIR}/Src/main.c) | ||
target_compile_definitions(test_main PUBLIC TEST) | ||
target_include_directories(test_main PRIVATE ${CMAKE_SOURCE_DIR}/Inc support ${CMAKE_BINARY_DIR}/_deps/fff-src) | ||
target_link_libraries(test_main unity) | ||
add_test(test_main test_main) | ||
|
||
add_executable(test_timer test_timer.c ${CMAKE_SOURCE_DIR}/Src/timer.c) | ||
target_compile_definitions(test_timer PUBLIC TEST) | ||
target_include_directories(test_timer PRIVATE ${CMAKE_SOURCE_DIR}/Inc support) | ||
target_link_libraries(test_timer unity) | ||
add_test(test_timer test_timer) | ||
|
||
add_executable(test_superloop test_superloop.c ${CMAKE_SOURCE_DIR}/Src/superloop.c) | ||
target_compile_definitions(test_superloop PUBLIC TEST) | ||
target_include_directories(test_superloop PRIVATE ${CMAKE_SOURCE_DIR}/Inc support ${CMAKE_BINARY_DIR}/_deps/fff-src) | ||
target_link_libraries(test_superloop unity) | ||
add_test(test_superloop test_superloop) |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,34 +1,64 @@ | ||
/* test_superloop.c */ | ||
|
||
#ifdef TEST | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
|
||
#include "unity.h" | ||
#include "fff.h" | ||
|
||
DEFINE_FFF_GLOBALS; | ||
|
||
FAKE_VOID_FUNC(led_init); | ||
FAKE_VOID_FUNC(timer_init); | ||
FAKE_VALUE_FUNC(bool, timer_deadline_reached); | ||
FAKE_VOID_FUNC(led_toggle); | ||
|
||
#include "superloop.h" | ||
#include "mock_led.h" | ||
#include "mock_timer.h" | ||
|
||
void setUp(void) {} | ||
void setUp(void) | ||
{ | ||
RESET_FAKE(led_init); | ||
RESET_FAKE(timer_init); | ||
RESET_FAKE(timer_deadline_reached); | ||
RESET_FAKE(led_toggle); | ||
} | ||
|
||
void tearDown(void) {} | ||
|
||
void test_superloop_init_should_initializePeripherals(void) | ||
{ | ||
led_init_Expect(); | ||
timer_init_Expect(); | ||
|
||
superloop_init(); | ||
TEST_ASSERT_EQUAL(1, led_init_fake.call_count); | ||
TEST_ASSERT_EQUAL(1, timer_init_fake.call_count); | ||
} | ||
|
||
void test_superloop_run_should_toggleLedIfDeadlineReached(void) | ||
{ | ||
timer_deadline_reached_IgnoreAndReturn(false); | ||
timer_deadline_reached_fake.return_val = true; | ||
|
||
superloop_run(); | ||
|
||
timer_deadline_reached_IgnoreAndReturn(true); | ||
timer_get_stamp_IgnoreAndReturn(0); | ||
led_toggle_Expect(); | ||
TEST_ASSERT_EQUAL(1, led_toggle_fake.call_count); | ||
} | ||
|
||
void test_superloop_run_should_notToggleLedIfDeadlineNotYetReached(void) | ||
{ | ||
timer_deadline_reached_fake.return_val = false; | ||
|
||
superloop_run(); | ||
|
||
TEST_ASSERT_EQUAL(0, led_toggle_fake.call_count); | ||
} | ||
|
||
int main(void) | ||
{ | ||
UNITY_BEGIN(); | ||
RUN_TEST(test_superloop_init_should_initializePeripherals); | ||
RUN_TEST(test_superloop_run_should_toggleLedIfDeadlineReached); | ||
RUN_TEST(test_superloop_run_should_notToggleLedIfDeadlineNotYetReached); | ||
return UNITY_END(); | ||
} | ||
|
||
#endif // TEST |
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 |
---|---|---|
|
@@ -12,4 +12,3 @@ make | |
nano | ||
python3 | ||
python3-pip | ||
ruby |