Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Add CLang formatter check to CI #125

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
64 changes: 60 additions & 4 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,8 +1,64 @@
---
BasedOnStyle: WebKit
ColumnLimit: '120'
# IndentWidth: '4'
# TabWidth: '4'
# UseTab: Always
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: 'true'
AlignConsecutiveAssignments: 'true'
AlignConsecutiveDeclarations: 'false'
AlignEscapedNewlines: Left
AlignOperands: 'true'
AlignTrailingComments: 'true'
AllowAllArgumentsOnNextLine: 'true'
AllowAllConstructorInitializersOnNextLine: 'true'
AllowAllParametersOfDeclarationOnNextLine: 'true'
AllowShortBlocksOnASingleLine: 'true'
AllowShortCaseLabelsOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: 'false'
AlwaysBreakTemplateDeclarations: 'No'
BinPackArguments: 'true'
BinPackParameters: 'true'
BreakAfterJavaFieldAnnotations: 'true'
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: 'true'
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
ColumnLimit: '150'
CompactNamespaces: 'false'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'false'
Cpp11BracedListStyle: 'false'
DerivePointerAlignment: 'false'
DisableFormat: 'false'
FixNamespaceComments: 'false'
IncludeBlocks: Preserve
IndentCaseLabels: 'true'
IndentPPDirectives: BeforeHash
IndentWidth: '4'
IndentWrappedFunctionNames: 'true'
KeepEmptyLinesAtTheStartOfBlocks: 'false'
Language: Cpp
MaxEmptyLinesToKeep: '1'
PointerAlignment: Left
ReflowComments: 'true'
SortIncludes: 'true'
SpaceAfterCStyleCast: 'false'
SpaceAfterLogicalNot: 'false'
SpaceAfterTemplateKeyword: 'false'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeCpp11BracedList: 'false'
SpaceBeforeCtorInitializerColon: 'false'
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: 'false'
SpaceInEmptyParentheses: 'false'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
TabWidth: '4'
UseTab: Never

...
133 changes: 133 additions & 0 deletions .github/workflows/github-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: Sub-IoT-Stack CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

run-unit-tests:
name: Run Unit Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Build stack natively
run: |
mkdir build && cd build
platform="NATIVE"
cmake ../stack/ -DPLATFORM=$platform -DCMAKE_TOOLCHAIN_FILE="../stack/cmake/toolchains/gcc.cmake" -DBUILD_UNIT_TESTS=y -DFRAMEWORK_CONSOLE_ENABLED=n -DTEST_AES=y -DTEST_FEC=y -DTEST_ALP=y -DTEST_FIFO=y -DMODULE_D7AP=n -DMODULE_ALP_SERIAL_INTERFACE_ENABLED=n
make -j

- name: Run unit tests
run: |
./build/tests/aes/test_aes &> results_aes.txt
./build/tests/alp/test_alp &> results_alp.txt
./build/tests/fec/test_fec &> results_fec.txt
./build/tests/fifo/test_fifo &> results_fifo.txt

- name: Upload the results
uses: actions/upload-artifact@v2
with:
name: results
path: |
results_aes.txt
results_alp.txt
results_fec.txt
results_fifo.txt

- name: Handle results
run: |
if ! grep -q 'AES all unit tests OK !' "results_aes.txt"; then exit 1; fi
if ! grep -q 'Unit-tests for ALP completed' "results_alp.txt"; then exit 1; fi
if ! grep -q 'Input was decoded successfully' "results_fec.txt"; then exit 1; fi
if ! grep -q 'All FIFO tests passed!' "results_fifo.txt"; then exit 1; fi

generate-builds:
name: Generate Builds
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up compiler
uses: fiam/arm-none-eabi-gcc@v1
with:
release: '8-2018-q4'

- name: Build stack
run: |
mkdir build && cd build
platform="B_L072Z_LRWAN1"
cmake ../stack/ -DAPP_GATEWAY=y -DAPP_MODEM=y -DAPP_SENSOR_PUSH=y -DPLATFORM=$platform -DFRAMEWORK_DEBUG_ASSERT_REBOOT=y -DMODULE_D7AP_FS_DISABLE_PERMISSIONS=y -DAPP_MODEM_FORWARD_ALP_OVER_SERIAL=y
make -j
cd ..

- name: Upload the builds
uses: actions/upload-artifact@v2
with:
name: build
path: |
build/apps/gateway/
build/apps/modem/
build/apps/sensor_push/

run-testsuite:
name: Run Testsuite
runs-on: self-hosted
needs: generate-builds

steps:
- uses: actions/download-artifact@v3

- name: Flash builds to devices
run: |
if [ lsof -i -P -n | grep -q JLinkExe ] ; then exit 1; fi
if [ lsof -n /dev/ttyUSB0 | grep -q /dev/ttyUSB0 ] ; then exit 1; fi
if [ lsof -n /dev/ttyUSB1 | grep -q /dev/ttyUSB1 ] ; then exit 1; fi
cd build/apps/modem
JLinkExe -SelectEmuBySN 770821797 -CommandFile jlink-flash-full.script > flashOutput1.txt
JLinkExe -SelectEmuBySN 772958091 -CommandFile jlink-flash-full.script > flashOutput2.txt
cat flashOutput1.txt
cat flashOutput2.txt
if grep -q 'FAILED\|ERROR' "flashOutput1.txt"; then exit 1; fi
if grep -q 'FAILED\|ERROR' "flashOutput2.txt"; then exit 1; fi

- name: Run testsuite
run: |
rm -rf Sub-IoT-testsuite
git clone --recurse-submodules https://github.com/Sub-IoT/Sub-IoT-testsuite.git
cd Sub-IoT-testsuite
pip install -r requirements.txt
cd lib/pyd7a/
pip install -r requirements.txt
cd ../..
python2 run.py --serial-test-device=/dev/ttyUSB0 --serial-dut=/dev/ttyUSB1 -m "not band433 and not band915 and not known_issue" --junitxml report.xml -v

- name: Upload test results
uses: actions/upload-artifact@v2
with:
name: test-results
path: Sub-IoT-testsuite/report.xml

check-clang-format:
name: Check CLang format
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Apply formatter
run: |
./clang-format-patch.sh
if [[ -f clang_format.patch ]]; then exit 1; fi

- name: Upload patch
uses: actions/upload-artifact@v2
if: failure()
with:
name: patch
path: clang_format.patch
13 changes: 13 additions & 0 deletions clang-format-patch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

find . -type d \( -path ./stack/cmake -o -path ./stack/framework/hal \) -prune -o -iname *.h -o -iname *.c | xargs clang-format-10 -style=file -i -fallback-style=none

git diff > clang_format.patch

# Delete if 0 size
if [ ! -s clang_format.patch ]
then
rm clang_format.patch
fi

exit 0
17 changes: 11 additions & 6 deletions stack/tests/alp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "debug.h"

#include "alp.h"
Expand All @@ -36,28 +38,29 @@ void test_alp_parse_length_operand()
fifo_init(&fifo, data, sizeof(data));

fifo_put_byte(&fifo, 0x01);
uint32_t length = alp_parse_length_operand(&fifo);
uint32_t length;
assert(alp_parse_length_operand(&fifo, &length));
assert(length == 1);

fifo_clear(&fifo);
fifo_put_byte(&fifo, 0x40);
fifo_put_byte(&fifo, 0x41);
length = alp_parse_length_operand(&fifo);
assert(alp_parse_length_operand(&fifo, &length));
assert(length == 65);

fifo_clear(&fifo);
fifo_put_byte(&fifo, 0x80);
fifo_put_byte(&fifo, 0x40);
fifo_put_byte(&fifo, 0x01);
length = alp_parse_length_operand(&fifo);
assert(alp_parse_length_operand(&fifo, &length));
assert(length == 0x4001);

fifo_clear(&fifo);
fifo_put_byte(&fifo, 0xC0);
fifo_put_byte(&fifo, 0x41);
fifo_put_byte(&fifo, 0x10);
fifo_put_byte(&fifo, 0x00);
length = alp_parse_length_operand(&fifo);
assert(alp_parse_length_operand(&fifo, &length));
assert(length == 4263936);
}

Expand All @@ -68,6 +71,8 @@ void bootstrap()
printf("Testing alp_parse_length_operand ... ");
test_alp_parse_length_operand();
printf("Success!\n");

printf("Unit-tests for ALP completed\n");

exit(0);
}
2 changes: 1 addition & 1 deletion stack/tests/fec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
project(fec)
project(test_fec)
cmake_minimum_required(VERSION 2.8)
add_executable(${PROJECT_NAME}
fec.c
Expand Down
9 changes: 9 additions & 0 deletions stack/tests/fec/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ int main(int argc, char *argv[])
int notrecovered = 0;
srand(time(NULL));

if(memcmp(input, decoded, input_length) == 0)
{
printf("Input was decoded successfully\n");
}
else
{
printf("error\n");
}

// while (notrecovered < 1)
// {
// int r = rand() % (lenght_encoded * 8);
Expand Down
2 changes: 2 additions & 0 deletions stack/tests/fifo/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,6 @@ int main(int argc, char *argv[])
test_pop_empty();
printf("Success!\n");

printf("All FIFO tests passed!\n");

}