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
+5 -3
View File
@@ -73,7 +73,7 @@ int bacerror_decode_error_class_and_code(uint8_t *apdu,
uint32_t len_value_type = 0;
uint32_t decoded_value = 0;
if (apdu_len) {
if (apdu && apdu_len) {
/* error class */
len += decode_tag_number_and_value(
&apdu[len], &tag_number, &len_value_type);
@@ -109,15 +109,17 @@ int bacerror_decode_service_request(uint8_t *apdu,
{
int len = 0;
if (apdu_len > 2) {
if (apdu && apdu_len > 2) {
if (invoke_id) {
*invoke_id = apdu[0];
}
if (service) {
*service = (BACNET_CONFIRMED_SERVICE)apdu[1];
}
len += 2;
/* decode the application class and code */
len = bacerror_decode_error_class_and_code(
len += bacerror_decode_error_class_and_code(
&apdu[2], apdu_len - 2, error_class, error_code);
}