Feature/zephyr ztest (#118)
* Leverage (older) embedded unit tests into external unit tests build upon copy of Zephyr's ztest library and CMake. * Expand top-level CMake build to run external unit tests. * Expand Zephyr module extension to run external unit tests via west or sanitycheck. Co-authored-by: Gregory Shue <gregory.shue@legrand.us>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
|
||||
|
||||
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
project(test_${basename}
|
||||
VERSION 1.0.0
|
||||
LANGUAGES C)
|
||||
|
||||
|
||||
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(ZTST_DIR "${TST_DIR}/ztest/src")
|
||||
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
|
||||
|
||||
add_compile_definitions(
|
||||
BIG_ENDIAN=0
|
||||
CONFIG_ZTEST=1
|
||||
BACNET_PROPERTY_LISTS=1
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${SRC_DIR}
|
||||
${TST_DIR}/ztest/include
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
# File(s) under test
|
||||
${SRC_DIR}/bacnet/property.c
|
||||
${SRC_DIR}/bacnet/proplist.c
|
||||
# Support files and stubs (pathname alphabetical)
|
||||
${SRC_DIR}/bacnet/bacdcode.c
|
||||
${SRC_DIR}/bacnet/bacint.c
|
||||
${SRC_DIR}/bacnet/bacreal.c
|
||||
${SRC_DIR}/bacnet/bacstr.c
|
||||
${SRC_DIR}/bacnet/basic/sys/bigend.c
|
||||
# Test and test library files
|
||||
./src/main.c
|
||||
${ZTST_DIR}/ztest_mock.c
|
||||
${ZTST_DIR}/ztest.c
|
||||
)
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Legrand North America, LLC.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
/* @file
|
||||
* @brief test BACnet integer encode/decode APIs
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
#include <bacnet/property.h>
|
||||
|
||||
/**
|
||||
* @addtogroup bacnet_tests
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Test
|
||||
*/
|
||||
void testPropList(void)
|
||||
{
|
||||
unsigned i = 0, j = 0;
|
||||
unsigned count = 0;
|
||||
BACNET_PROPERTY_ID property = MAX_BACNET_PROPERTY_ID;
|
||||
unsigned object_id = 0, object_name = 0, object_type = 0;
|
||||
struct special_property_list_t property_list = { 0 };
|
||||
|
||||
for (i = 0; i < OBJECT_PROPRIETARY_MIN; i++) {
|
||||
count = property_list_special_count((BACNET_OBJECT_TYPE)i, PROP_ALL);
|
||||
zassert_true(count >= 3, NULL);
|
||||
object_id = 0;
|
||||
object_name = 0;
|
||||
object_type = 0;
|
||||
for (j = 0; j < count; j++) {
|
||||
property = property_list_special_property(
|
||||
(BACNET_OBJECT_TYPE)i, PROP_ALL, j);
|
||||
if (property == PROP_OBJECT_TYPE) {
|
||||
object_type++;
|
||||
}
|
||||
if (property == PROP_OBJECT_IDENTIFIER) {
|
||||
object_id++;
|
||||
}
|
||||
if (property == PROP_OBJECT_NAME) {
|
||||
object_name++;
|
||||
}
|
||||
}
|
||||
zassert_equal(object_type, 1, NULL);
|
||||
zassert_equal(object_id, 1, NULL);
|
||||
zassert_equal(object_name, 1, NULL);
|
||||
/* test member function */
|
||||
property_list_special((BACNET_OBJECT_TYPE)i, &property_list);
|
||||
zassert_true(
|
||||
property_list_member(
|
||||
property_list.Required.pList, PROP_OBJECT_TYPE), NULL);
|
||||
zassert_true(
|
||||
property_list_member(
|
||||
property_list.Required.pList, PROP_OBJECT_IDENTIFIER), NULL);
|
||||
zassert_true(
|
||||
property_list_member(
|
||||
property_list.Required.pList, PROP_OBJECT_NAME), NULL);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(property_tests,
|
||||
ztest_unit_test(testPropList)
|
||||
);
|
||||
|
||||
ztest_run_test_suite(property_tests);
|
||||
}
|
||||
Reference in New Issue
Block a user