Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9be32a8
Add CRC implementations #sonar
pavel-kirienko Jun 30, 2023
7ff170a
Cavl test: reduce the iteration count in the randomized test from 100…
pavel-kirienko Jun 30, 2023
1988da6
udpardTxInit
pavel-kirienko Jun 30, 2023
f5e9b13
Add txPushSingleFrame() #sonar
pavel-kirienko Jun 30, 2023
4ebcffd
Test header serialization
pavel-kirienko Jun 30, 2023
140129c
nits #sonar
pavel-kirienko Jun 30, 2023
99e4892
Add txGenerateMultiFrameChain
pavel-kirienko Jun 30, 2023
66ccad1
AVR-specific conversion fixes
pavel-kirienko Jun 30, 2023
65a523b
Check deallocation size; initialize tx precedence based on priority
pavel-kirienko Jul 1, 2023
4a8eb09
txMakeChain is finished but not all cases are covered yet #sonar
pavel-kirienko Jul 1, 2023
b9c252b
make chain tests done #sonar
pavel-kirienko Jul 1, 2023
5b834b7
txPush
pavel-kirienko Jul 1, 2023
3cff534
Finish the TX pipeline, two tests missing #sonar
pavel-kirienko Jul 1, 2023
f1a0936
Extend error handling
pavel-kirienko Jul 1, 2023
6bfea6d
Fix nits #sonar
pavel-kirienko Jul 1, 2023
5de3f60
Add missing tests #sonar
pavel-kirienko Jul 1, 2023
5e27852
Minor adjustmet before sending the PR
pavel-kirienko Jul 1, 2023
e9929e6
Use plain priority instead of precedence for simplification
pavel-kirienko Jul 2, 2023
1564317
Use fewer test data strings
pavel-kirienko Jul 2, 2023
53e9f87
Add prioritization test across multiple transfers
pavel-kirienko Jul 2, 2023
8974689
Address simple review comments; mostly renamings and comments
pavel-kirienko Jul 4, 2023
0c6e7f8
Define HEADER_FRAME_INDEX_MAX for clarity
pavel-kirienko Jul 4, 2023
d4875cd
UDPARD_UDP_PORT does not need to be public
pavel-kirienko Jul 4, 2023
b583110
Nits
pavel-kirienko Jul 6, 2023
a35339c
BROKEN: switch to one-test-per-executable with #include <udpard.c>; n…
pavel-kirienko Jul 6, 2023
1f711fa
Revert "BROKEN: switch to one-test-per-executable with #include <udpa…
pavel-kirienko Jul 6, 2023
055358d
Switch from Google Test to Unity; make the internal tests include udp…
pavel-kirienko Jul 8, 2023
7a85301
Add a test for UDPARD_MTU_DEFAULT_MAX_SINGLE_FRAME
pavel-kirienko Jul 8, 2023
f871b4a
Do not leak memory from intrusive tests
pavel-kirienko Jul 8, 2023
a3f64f0
Add a NOLINT comment in Cavl to suppress bogus warning from Clang flo…
pavel-kirienko Jul 8, 2023
a6837dd
Naming nits & formatting, nothing to see here
pavel-kirienko Jul 8, 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
21 changes: 5 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ jobs:
cxx-compiler: clang++
steps:
- uses: actions/checkout@v3
# language=bash
- run: |
# TODO https://github.com/OpenCyphal/docker_toolchains/issues/36
dpkg --add-architecture i386
apt-get update
apt-get install -y libgtest-dev libgtest-dev:i386
with:
submodules: true
# language=bash
- run: >
cmake
Expand Down Expand Up @@ -65,12 +61,8 @@ jobs:
cxx-compiler: clang++
steps:
- uses: actions/checkout@v3
# language=bash
- run: |
# TODO https://github.com/OpenCyphal/docker_toolchains/issues/36
dpkg --add-architecture i386
apt-get update
apt-get install -y libgtest-dev libgtest-dev:i386
with:
submodules: true
# language=bash
- run: >
cmake
Expand Down Expand Up @@ -147,17 +139,14 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
submodules: true
- uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'zulu'
# language=bash
- run: |
clang --version
# TODO https://github.com/OpenCyphal/docker_toolchains/issues/36
dpkg --add-architecture i386
apt-get update
apt-get install -y libgtest-dev libgtest-dev:i386
- name: Install Sonar tools
env:
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "submodules/unity"]
path = submodules/unity
url = https://github.com/ThrowTheSwitch/Unity
3 changes: 2 additions & 1 deletion libudpard/_udpard_cavl.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ static inline Cavl* cavlPrivateAdjustBalance(Cavl* const x, const bool increment
const bool r = new_bf < 0; // bf<0 if left-heavy --> right rotation is needed.
const int8_t sign = r ? +1 : -1; // Positive if we are rotating right.
Cavl* const z = x->lr[!r];
CAVL_ASSERT(z != NULL); // Heavy side cannot be empty.
CAVL_ASSERT(z != NULL); // Heavy side cannot be empty.
// NOLINTNEXTLINE(clang-analyzer-core.NullDereference)
if ((z->bf * sign) <= 0) // Parent and child are heavy on the same side or the child is balanced.
{
out = z;
Expand Down
634 changes: 632 additions & 2 deletions libudpard/udpard.c

Large diffs are not rendered by default.

139 changes: 70 additions & 69 deletions libudpard/udpard.h

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions submodules/unity
Submodule unity added at 0b899a
1 change: 1 addition & 0 deletions tests/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Checks: >-
-cert-msc30-c,
-cert-msc50-cpp,
-modernize-macro-to-enum,
-modernize-use-trailing-return-type,
-cppcoreguidelines-owning-memory,
WarningsAsErrors: '*'
HeaderFilterRegex: '.*\.hpp'
Expand Down
2 changes: 2 additions & 0 deletions tests/.idea/dictionaries/pavel.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 41 additions & 36 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ cmake_minimum_required(VERSION 3.12)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wnon-virtual-dtor -Wsign-promo")

project(udpard_tests C CXX)
enable_testing()

set(CTEST_OUTPUT_ON_FAILURE ON)
set(library_dir "${CMAKE_SOURCE_DIR}/../libudpard")

set(NO_STATIC_ANALYSIS OFF CACHE BOOL "disable udpard static analysis")

set(library_dir "${CMAKE_SOURCE_DIR}/../libudpard")
set(unity_root "${CMAKE_CURRENT_SOURCE_DIR}/../submodules/unity")

# Use -DNO_STATIC_ANALYSIS=1 to suppress static analysis.
# If not suppressed, the tools used here shall be available, otherwise the build will fail.
if (NOT NO_STATIC_ANALYSIS)
Expand All @@ -24,62 +26,65 @@ if (NOT NO_STATIC_ANALYSIS)
message(FATAL_ERROR "Could not locate clang-tidy")
endif ()
message(STATUS "Using clang-tidy: ${clang_tidy}")
set(CMAKE_C_CLANG_TIDY ${clang_tidy})
set(CMAKE_CXX_CLANG_TIDY ${clang_tidy})
endif ()

# clang-format
find_program(clang_format NAMES clang-format)
if (NOT clang_format)
message(STATUS "Could not locate clang-format")
else ()
file(GLOB format_files ${library_dir}/*.[ch] ${CMAKE_SOURCE_DIR}/*.[ch]pp)
file(GLOB_RECURSE format_files
${library_dir}/*.[ch]
${CMAKE_SOURCE_DIR}/src/*.[ch]
${CMAKE_SOURCE_DIR}/src/*.[ch]pp)
message(STATUS "Using clang-format: ${clang_format}; files: ${format_files}")
add_custom_target(format COMMAND ${clang_format} -i -fallback-style=none -style=file --verbose ${format_files})
endif ()

add_compile_options(
-Wall -Wextra -Werror -pedantic -Wdouble-promotion -Wswitch-enum -Wfloat-equal -Wundef
-Wconversion -Wtype-limits -Wsign-conversion -Wcast-align
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wnon-virtual-dtor -Wsign-promo")

function(gen_test name files compile_definitions compile_flags link_flags c_standard)
add_executable(${name} ${library_dir}/udpard.c ${files})
# Unity
add_library("${name}_unity" STATIC "${unity_root}/src/unity.c")
target_include_directories("${name}_unity" SYSTEM PUBLIC "${unity_root}/src/")
target_compile_definitions("${name}_unity" PUBLIC
UNITY_INCLUDE_DOUBLE=1 UNITY_OUTPUT_COLOR=1 UNITY_SUPPORT_64=1 UNITY_SHORTHAND_AS_RAW=1)
set_target_properties(
"${name}_unity"
PROPERTIES
COMPILE_FLAGS "${compile_flags} \
-Wno-sign-conversion -Wno-conversion -Wno-switch-enum -Wno-float-equal -Wno-double-promotion"
LINK_FLAGS "${link_flags}"
)
# Target executable
add_executable(${name} ${files})
target_include_directories(${name} PUBLIC ${library_dir})
target_compile_definitions(${name} PUBLIC ${compile_definitions})
# We're not using find_package(GTest) because this method can only find the package for one specific architecture,
# which is not what we want. We build tests for AMD64 and x86 separately, which requires linking against different
# GTest libraries located in different directories. Instead of doing it the hard way via find_package separately
# per architecture, we just pass the library names directly and let the linker figure out where to find them.
target_link_libraries(${name} pthread gtest gtest_main)
target_link_libraries(${name} "${name}_unity")
set_target_properties(
${name}
PROPERTIES
COMPILE_FLAGS "${compile_flags}"
COMPILE_FLAGS "${compile_flags} -Wall -Wextra -Werror -pedantic -Wdouble-promotion -Wswitch-enum \
-Wfloat-equal -Wundef -Wconversion -Wtype-limits -Wsign-conversion -Wcast-align -Wmissing-declarations"
LINK_FLAGS "${link_flags}"
C_STANDARD "${c_standard}"
C_EXTENSIONS OFF
C_CLANG_TIDY "${clang_tidy}"
CXX_CLANG_TIDY "${clang_tidy}"
)
add_test("run_${name}" "${name}" --gtest_random_seed=0 --gtest_color=yes)
add_test("run_${name}" "${name}")
endfunction()

function(gen_test_matrix name files compile_definitions compile_flags link_flags)
gen_test("${name}_x64_c99" "${files}" "${compile_definitions}" "${compile_flags} -m64" "-m64 ${link_flags}" "99")
gen_test("${name}_x32_c99" "${files}" "${compile_definitions}" "${compile_flags} -m32" "-m32 ${link_flags}" "99")
gen_test("${name}_x64_c11" "${files}" "${compile_definitions}" "${compile_flags} -m64" "-m64 ${link_flags}" "11")
gen_test("${name}_x32_c11" "${files}" "${compile_definitions}" "${compile_flags} -m32" "-m32 ${link_flags}" "11")
function(gen_test_matrix name files)
gen_test("${name}_x64_c99" "${files}" "" "-m64" "-m64" "99")
gen_test("${name}_x32_c99" "${files}" "" "-m32" "-m32" "99")
gen_test("${name}_x64_c11" "${files}" "" "-m64" "-m64" "11")
gen_test("${name}_x32_c11" "${files}" "" "-m32" "-m32" "11")
endfunction()

# Disable missing declaration warning to allow exposure of private definitions.
gen_test_matrix(test_private
"test_private_cavl.cpp;"
"-DUDPARD_CONFIG_HEADER=\"${CMAKE_CURRENT_SOURCE_DIR}/udpard_config_private.h\""
"-Wno-missing-declarations"
"")

gen_test_matrix(test_public
"test_self.cpp"
""
"-Wmissing-declarations"
"")
# Add the test targets.
# Those that are written in C may #include <udpard.c> to reach its internals; they are called "intrusive".
# The public interface tests may be written in C++ for convenience.
gen_test_matrix(test_helpers "src/test_helpers.c")
gen_test_matrix(test_cavl "src/test_cavl.cpp")
gen_test_matrix(test_tx "${library_dir}/udpard.c;src/test_tx.cpp")
gen_test_matrix(test_intrusive_crc "src/test_intrusive_crc.c")
gen_test_matrix(test_intrusive_tx "src/test_intrusive_tx.c")
171 changes: 0 additions & 171 deletions tests/helpers.hpp

This file was deleted.

Loading