Feature/bacnet bacerror unit tests (#407)

* Add <zephyr/fff.h> from zephyr v3.1.0

Zephyr is deprecating the zmock library in favor of using
the FFF faking library for defining and controlling fake
implementations of depended-upon APIs called by the code-under-test.

Signed-off-by: Gregory Shue <gregory.shue@legrand.com>

* Fix bacerror_decode_service_request return value; add unit tests

bacerror_decode_service_request() return value now includes
the apdu bytes parsed for invoke_id and service.

Also added a unit test for functions in bacerror.c, using `fff`
for faking the depended-upon functions.

Verified by:

1. (Pass) cd $bacnet-stack/test && make test

2. (Pass) west build -p always -b unit_testing \
              bacnet-stack/zephyr/tests/unit/bacnet/bacerror/ && \
              ./build/testbinary

3. (Pass) ./zephyr/scripts/twister -p unit_testing  \
              -T bacnet-stack/zephyr/tests/unit/bacnet/bacerror/

Signed-off-by: Gregory Shue <gregory.shue@legrand.com>

---------

Signed-off-by: Gregory Shue <gregory.shue@legrand.com>
Co-authored-by: Gregory Shue <gregory.shue@legrand.com>
This commit is contained in:
Greg Shue
2023-03-07 15:01:33 -08:00
committed by GitHub
parent fe69978387
commit c74a8cf3a9
11 changed files with 1587 additions and 3 deletions
@@ -0,0 +1,37 @@
# Copyright (c) 2022 Legrand North America, LLC.
#
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
if(NOT ZEPHYR_CURRENT_MODULE_DIR)
string(REGEX REPLACE "/zephyr/tests/[a-zA-Z_/-]*$" ""
ZEPHYR_CURRENT_MODULE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
endif()
if(BOARD STREQUAL unit_testing)
find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE})
set(target testbinary)
else()
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
set(target app)
endif()
project(bacnet_bacerror)
target_sources(${target} PRIVATE
${ZEPHYR_CURRENT_MODULE_DIR}/src/bacnet/bacerror.c
${ZEPHYR_CURRENT_MODULE_DIR}/test/unit/bacnet/bacerror/src/main.c
${ZEPHYR_CURRENT_MODULE_DIR}/test/unit/bacnet/bacerror/src/fakes/bacdcode.c
${CMAKE_CURRENT_SOURCE_DIR}/main.c
)
# NOTE for Zephyr >= v3.2.0:
# - Zephyr unittest builds for target 'testbinary' instead of 'app'.
# - Zephyr unittest does not generate ZEPHYR_<modulename>_MODULE_DIR.
# So we have to use relative paths to get to the source.
target_include_directories(${target} PRIVATE
${ZEPHYR_CURRENT_MODULE_DIR}/test/unit/bacnet/bacerror/src
${ZEPHYR_CURRENT_MODULE_DIR}/src
)
+1
View File
@@ -0,0 +1 @@
/* This file is intentionally empty */
@@ -0,0 +1 @@
# This file is intentionally empty
@@ -0,0 +1,3 @@
tests:
bacnet.bacerror.unit:
type: unit