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,36 @@
|
||||
# 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
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${SRC_DIR}
|
||||
${TST_DIR}/ztest/include
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
# File(s) under test
|
||||
${SRC_DIR}/bacnet/basic/object/objects.c
|
||||
# Support files and stubs (pathname alphabetical)
|
||||
${SRC_DIR}/bacnet/basic/sys/key.c
|
||||
${SRC_DIR}/bacnet/basic/sys/keylist.c
|
||||
./stubs.c
|
||||
# Test and test library files
|
||||
./src/main.c
|
||||
${ZTST_DIR}/ztest_mock.c
|
||||
${ZTST_DIR}/ztest.c
|
||||
)
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Legrand North America, LLC.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
/* @file
|
||||
* @brief test BACnet integer encode/decode APIs
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
#include <bacnet/basic/sys/keylist.h>
|
||||
#include <bacnet/basic/object/objects.h>
|
||||
|
||||
/**
|
||||
* @addtogroup bacnet_tests
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Test
|
||||
*/
|
||||
#if 0 /*TODO: Change to use external methods */
|
||||
static void testBACnetObjectsCompare(
|
||||
OBJECT_DEVICE_T *pDevice, uint32_t device_id)
|
||||
{
|
||||
zassert_not_null(pDevice, NULL);
|
||||
if (pDevice) {
|
||||
zassert_not_null(pDevice->Object_List, NULL);
|
||||
zassert_equal(pDevice->Object_Identifier.instance, device_id, NULL);
|
||||
zassert_equal(pDevice->Object_Identifier.type, OBJECT_DEVICE, NULL);
|
||||
zassert_equal(pDevice->Object_Type, OBJECT_DEVICE, NULL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void testBACnetObjects(void)
|
||||
{
|
||||
#if 0 /*TODO: Change to use external methods */
|
||||
uint32_t device_id = 0;
|
||||
unsigned test_point = 0;
|
||||
const unsigned max_test_points = 20;
|
||||
OBJECT_DEVICE_T *pDevice;
|
||||
|
||||
for (test_point = 0; test_point < max_test_points; test_point++) {
|
||||
device_id = test_point * (BACNET_MAX_INSTANCE / max_test_points);
|
||||
pDevice = objects_device_new(device_id);
|
||||
testBACnetObjectsCompare(pDevice, device_id);
|
||||
pDevice = objects_device_by_instance(device_id);
|
||||
testBACnetObjectsCompare(pDevice, device_id);
|
||||
}
|
||||
zassert_equal(max_test_points, objects_device_count(), NULL);
|
||||
for (test_point = 0; test_point < max_test_points; test_point++) {
|
||||
device_id = test_point * (BACNET_MAX_INSTANCE / max_test_points);
|
||||
pDevice = objects_device_by_instance(device_id);
|
||||
testBACnetObjectsCompare(pDevice, device_id);
|
||||
}
|
||||
for (test_point = 0; test_point < max_test_points; test_point++) {
|
||||
device_id = test_point * (BACNET_MAX_INSTANCE / max_test_points);
|
||||
pDevice = objects_device_data(test_point);
|
||||
testBACnetObjectsCompare(
|
||||
pDevice, Keylist_Key(Device_List, test_point));
|
||||
}
|
||||
for (test_point = 0; test_point < max_test_points; test_point++) {
|
||||
pDevice = objects_device_delete(0);
|
||||
}
|
||||
#else
|
||||
ztest_test_skip();
|
||||
#endif
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(objects_tests,
|
||||
ztest_unit_test(testBACnetObjects)
|
||||
);
|
||||
|
||||
ztest_run_test_suite(objects_tests);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*********************************************************************/
|
||||
|
||||
/* Binary Input Objects customize for your use */
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "bacnet/bacapp.h"
|
||||
|
||||
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
|
||||
uint8_t ucExpectedTag,
|
||||
BACNET_ERROR_CLASS *pErrorClass,
|
||||
BACNET_ERROR_CODE *pErrorCode)
|
||||
{
|
||||
pValue = pValue;
|
||||
ucExpectedTag = ucExpectedTag;
|
||||
pErrorClass = pErrorClass;
|
||||
pErrorCode = pErrorCode;
|
||||
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user