Skip to content
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

Improve unit test to work on every OS with multiple configurations #422

Merged
merged 26 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cac6438
Remove OS specific things on unit tests
nicolas-rabault Feb 7, 2023
f1c4490
Execute GH unit test on all OS
nicolas-rabault Feb 8, 2023
eaf4bd6
Fix unit test mock HAL
nicolas-rabault Feb 7, 2023
0401c3f
Remove mocked functions
nicolas-rabault Feb 7, 2023
8fe2b9f
Remove some unit test warning
nicolas-rabault Feb 7, 2023
524c5b0
Fix unit tests to scale depending on the node_config.h settings
nicolas-rabault Feb 8, 2023
d91c259
Remove unit_test weak function that are not compatible with linux
nicolas-rabault Feb 8, 2023
939a21a
Move the test Platformio from test to root having a more standard way…
nicolas-rabault Feb 8, 2023
f146260
Create a TRY CATCH macro for unit tests
nicolas-rabault Feb 9, 2023
d8f188c
Create a unit-tests global check for GH actions
nicolas-rabault Feb 14, 2023
ba2ab08
Remove useless transmit_msg pointer
nicolas-rabault Feb 13, 2023
d3e1ef2
Remove very suspect messaging pointers on the default scenario
nicolas-rabault Feb 13, 2023
8e0c7cc
Completely remove tx_msg from default scenarios
nicolas-rabault Feb 13, 2023
683b030
Use a passive DEFAULT_CMD for default scenario message command
nicolas-rabault Feb 13, 2023
2ff6030
Fix a potential segfault with try catch
nicolas-rabault Feb 13, 2023
0b6241e
Remove streaming_channels of the default scenario
nicolas-rabault Feb 13, 2023
03d4838
Remove useless code on default scenario
nicolas-rabault Feb 13, 2023
ad1ae47
Group all luos_assert unit test function at the same place
nicolas-rabault Feb 14, 2023
0f43957
Create a STUB HAL used by testU
nicolas-rabault Feb 13, 2023
4d6b641
Remove unused test template to avoid maintainability issues on unit t…
nicolas-rabault Feb 13, 2023
1a71b87
Secure unit test services detection
nicolas-rabault Feb 13, 2023
3c4b297
Remove Reset_Context because it wasn't used.
nicolas-rabault Feb 13, 2023
66d528d
Simplify unit test assert.
nicolas-rabault Feb 14, 2023
58bcc12
Fix test_robus Mask 4096 limits
nicolas-rabault Feb 14, 2023
7c38415
Fix test_robus wrong assert test
nicolas-rabault Feb 14, 2023
6bdaddc
Merge pull request #424 from Luos-io/feat/secure_tests_default_scenario
Feb 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ defaults:
shell: bash

jobs:
unit-tests:
name: Unit tests
runs-on: windows-latest
tests-run:
name: Tests run
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
steps:
- name: Check out Luos repository
uses: actions/checkout@v3
Expand All @@ -36,10 +39,17 @@ jobs:
- name: Run PlatformIO Unit Tests
run: |
# Clean all projects
platformio run -t clean -c ./test/_resources/platformio.ini
platformio run -t clean

# Run Unit tests
platformio test -c ./test/_resources/platformio.ini -vvv
platformio test -vvv

unit-tests:
name: Unit tests
needs: tests-run
runs-on: ubuntu-latest
steps:
- run: echo "Tests succeed!"

code-format:
name: Code format
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 5 additions & 3 deletions engine/core/src/luos_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ __attribute__((weak)) void node_assert(char *file, uint32_t line)
return;
}

#ifndef UNIT_TEST
/******************************************************************************
* @brief Luos assertion management
* @param file : File name as a string
* @param line : Line number
* @return None
* warning : this function can be redefined only for mock testing purpose
******************************************************************************/
_CRITICAL _WEAKED void Luos_assert(char *file, uint32_t line)
_CRITICAL void Luos_assert(char *file, uint32_t line)
{
// prepare a message as a node.
// To do that we have to reset the service ID and clear PTP states to unlock others.
Expand All @@ -57,15 +58,16 @@ _CRITICAL _WEAKED void Luos_assert(char *file, uint32_t line)
// wait for the transmission to finish before killing IRQ
while (MsgAlloc_TxAllComplete() == FAILED)
;
#ifdef WITH_BOOTLOADER
#ifdef WITH_BOOTLOADER
// We're in a failed app,
// Restart this node in bootloader mode instead of don't do anything
// We will come back on this app after a reboot.
// Set bootloader mode, save node ID and reboot
LuosBootloader_JumpToBootloader();
#endif
#endif
LuosHAL_SetIrqState(false);
while (1)
{
}
}
#endif
4 changes: 2 additions & 2 deletions engine/core/src/routing_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static void RoutingTB_AddNumToAlias(char *alias, uint8_t num)
* @param intro_msg : into route table message
* @return None
******************************************************************************/
_WEAKED bool RoutingTB_WaitRoutingTable(service_t *service, msg_t *intro_msg)
bool RoutingTB_WaitRoutingTable(service_t *service, msg_t *intro_msg)
{
const uint8_t timeout = 15; // timeout in ms
const uint16_t entry_bkp = last_routing_table_entry;
Expand Down Expand Up @@ -499,7 +499,7 @@ uint16_t RoutingTB_GetLastEntry(void)
/******************************************************************************
* @brief Check if result is in routing table
* @param result : Pointer to search result structure
* @return SUCCEED : If the result address is available, else FAILED
* @return SUCCEED : If the result address is available, else FAILED
******************************************************************************/

error_return_t RTFilter_InitCheck(search_result_t *result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ void RobusHAL_SetRxState(uint8_t Enable)
******************************************************************************/
void RobusHAL_ComTransmit(uint8_t *data, uint16_t size)
{
// We consider this information sent
Recep_Timeout();
}

/******************************************************************************
Expand All @@ -114,6 +116,7 @@ void RobusHAL_SetRxDetecPin(uint8_t Enable)
******************************************************************************/
uint8_t RobusHAL_GetTxLockState(void)
{
return 0;
}

/******************************************************************************
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion network/robus/src/reception.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ _CRITICAL static inline error_return_t Recep_TopicCompare(uint16_t topic_id)
* warning : this function can be redefined only for mock testing purpose
* _CRITICAL function call in IRQ
******************************************************************************/
_WEAKED _CRITICAL luos_localhost_t Recep_NodeConcerned(header_t *header)
_CRITICAL luos_localhost_t Recep_NodeConcerned(header_t *header)
{
uint16_t i = 0;

Expand Down
6 changes: 5 additions & 1 deletion test/_resources/platformio.ini → platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ platform = native

lib_deps=
throwtheswitch/Unity
test_framework = unity

lib_extra_dirs = $PROJECT_DIR/../

build_unflags = -Os
build_flags =
-O1
-include ./test/_resources/node_config.h
-DUNIT_TEST
-D LUOSHAL=STUB

build_type = debug
test_build_src = true

; To debug a test :
; 1) Copy this file in Luos root directory
; 2) Replace "test_template" by the directory test name you want to debug (example : "routing_table")
debug_test = test_template
;debug_test = test_template
54 changes: 23 additions & 31 deletions source_filter_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,46 +101,38 @@
"\t* Telemetry disabled, please consider enabling it by removing the 'NOTELEMETRY' flag to help Luos_engine improve.", fg="red")
click.secho("")

# Native only
find_MOCK_HAL = False
# Native only => we should put this on a specific script on engine/HAL/STUB
for item in env.ParseFlags(env['BUILD_FLAGS'])["CPPDEFINES"]:
if (item == 'UNIT_TEST'):
click.secho("Native unit testing:", underline=True)
current_os = pf.system()
if find_MOCK_HAL == False:
click.secho("\t* Native Mock HAL for %s is selected for Luos and Robus." % current_os, fg="green")
find_MOCK_HAL = True
find_HAL = True
env.Replace(SRC_FILTER=sources)
env.Append(SRC_FILTER=["-<test/>"])
click.secho("\t* Native Mock HAL for %s is selected for Luos and Robus." %
current_os, fg="green")

env.Append(SRC_FILTER=["+<../../../test/_resources/*>"])
for resources in scandir(getcwd() + "/test/_resources"):
if resources.is_dir():
env.Append(CPPPATH=[(resources.path)])

if (current_os == 'Linux') or (current_os == 'Darwin'):
env.Append(LINKFLAGS=["-m32"])
elif current_os == 'Windows':
env.Append(LINKFLAGS=["-lgcov"])
env.Append(LINKFLAGS=["--coverage"])
env.Append(LINKFLAGS=["-fprofile-arcs"])

def generateCoverageInfo(source, target, env):
for file in os.listdir("test"):
env.Execute(".pio/build/native/program test/"+file)
env.Execute("lcov -d .pio/build/native/ -c -o lcov.info")
env.Execute(
"lcov --remove lcov.info '*/tool-unity/*' '*/test/*' -o filtered_lcov.info")
env.Execute(
"genhtml -o cov/ --demangle-cpp filtered_lcov.info")

# Generate code coverage when testing workflow is ended
# CODE COVERAGE WILL BE ADDED SOON
# env.AddPostAction(".pio/build/native/program", generateCoverageInfo)
else:
click.echo("Unit tests are not supported on your os ", current_os)
break
else:
# CODE COVERAGE WILL BE ADDED SOON
# if (current_os == 'Linux') or (current_os == 'Darwin') or (current_os == 'Windows'):
# env.Append(LINKFLAGS=["-lgcov"])
# env.Append(LINKFLAGS=["--coverage"])
# env.Append(LINKFLAGS=["-fprofile-arcs"])

# def generateCoverageInfo(source, target, env):
# for file in os.listdir("test"):
# env.Execute(".pio/build/native/program test/"+file)
# env.Execute("lcov -d .pio/build/native/ -c -o lcov.info")
# env.Execute(
# "lcov --remove lcov.info '*/tool-unity/*' '*/test/*' -o filtered_lcov.info")
# env.Execute(
# "genhtml -o cov/ --demangle-cpp filtered_lcov.info")

# Generate code coverage when testing workflow is ended
# env.AddPostAction(".pio/build/native/program", generateCoverageInfo)
# else:
# click.echo("Unit tests are not supported on your os ", current_os)
break

if not visited_key in global_env:
Expand Down
27 changes: 0 additions & 27 deletions test/_resources/Mock/Mock_Luos_Assert.c

This file was deleted.

32 changes: 0 additions & 32 deletions test/_resources/Mock/Mock_Recep_NodeConcerned.c

This file was deleted.

33 changes: 0 additions & 33 deletions test/_resources/Mock/Mock_RoutingTB_WaitRoutingTable.c

This file was deleted.

Loading