Zephyr cleanup (fix date-time.c, cleanout device.c, use full C lib) (#124)
Co-authored-by: Gregory Shue <gregory.shue@legrand.us>
This commit is contained in:
@@ -12,7 +12,11 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if CONFIG_NATIVE_APPLICATION
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
#include <posix/sys/time.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include "bacnet/datetime.h"
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -43,6 +43,16 @@
|
||||
#include <ctype.h> /* for isalnum */
|
||||
#endif
|
||||
|
||||
/* TODO: For some reason my Zephyr build for non-native targets does not
|
||||
* see a definition for strnlen(), but it is visible in when
|
||||
* compiling for native_posix. This results in the compiler
|
||||
* emitting a warning, forcing Zephyr's sanitycheck() script to stop.
|
||||
* Until this is chased down, the definition is being provided here.
|
||||
*/
|
||||
#if __ZEPHYR__ && ! CONFIG_NATIVE_APPLICATION
|
||||
size_t strnlen (const char *, size_t);
|
||||
#endif
|
||||
|
||||
/** @file bacstr.c Manipulate Bit/Char/Octet Strings */
|
||||
#ifndef BACNET_STRING_UTF8_VALIDATION
|
||||
#define BACNET_STRING_UTF8_VALIDATION 1
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
# 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)
|
||||
|
||||
|
||||
set(TST_DIR "../..")
|
||||
set(ZTST_DIR "${TST_DIR}/ztest/src")
|
||||
set(SRC_DIR "${TST_DIR}/../src")
|
||||
|
||||
add_compile_definitions(
|
||||
BIG_ENDIAN=0
|
||||
CONFIG_ZTEST=1
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${SRC_DIR}
|
||||
${TST_DIR}/ztest/include
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
${SRC_DIR}/device.c
|
||||
./src/main.c
|
||||
${ZTST_DIR}/ztest_mock.c
|
||||
${ZTST_DIR}/ztest.c
|
||||
)
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Legrand North America, LLC.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
#include <bacnet/bacstr.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h> /* for memmove */
|
||||
#include "bacnet/bacdef.h"
|
||||
#include "bacnet/bacdcode.h"
|
||||
#include "bacnet/bacenum.h"
|
||||
#include "bacnet/bacapp.h"
|
||||
#include "bacnet/config.h" /* the custom stuff */
|
||||
#include "bacnet/datetime.h"
|
||||
#include "bacnet/apdu.h"
|
||||
#include "bacnet/wp.h" /* WriteProperty handling */
|
||||
#include "bacnet/rp.h" /* ReadProperty handling */
|
||||
#include "bacnet/dcc.h" /* DeviceCommunicationControl handling */
|
||||
#include "bacnet/version.h"
|
||||
#include "bacnet/basic/object/device.h" /* me */
|
||||
#include "bacnet/basic/services.h"
|
||||
#include "bacnet/datalink/datalink.h"
|
||||
#include "bacnet/basic/binding/address.h"
|
||||
/* include the device object */
|
||||
#include "bacnet/basic/object/device.h"
|
||||
#include "bacnet/basic/object/acc.h"
|
||||
#include "bacnet/basic/object/ai.h"
|
||||
#include "bacnet/basic/object/ao.h"
|
||||
#include "bacnet/basic/object/av.h"
|
||||
#include "bacnet/basic/object/bi.h"
|
||||
#include "bacnet/basic/object/bo.h"
|
||||
#include "bacnet/basic/object/bv.h"
|
||||
#include "bacnet/basic/object/channel.h"
|
||||
#include "bacnet/basic/object/command.h"
|
||||
#include "bacnet/basic/object/csv.h"
|
||||
#include "bacnet/basic/object/iv.h"
|
||||
#include "bacnet/basic/object/lc.h"
|
||||
#include "bacnet/basic/object/lsp.h"
|
||||
#include "bacnet/basic/object/ms-input.h"
|
||||
#include "bacnet/basic/object/mso.h"
|
||||
#include "bacnet/basic/object/msv.h"
|
||||
|
||||
|
||||
static void testDevice(void)
|
||||
{
|
||||
const char *dev_name = "Patricia";
|
||||
|
||||
zassert_true(Device_Set_Object_Instance_Number(0),
|
||||
"Device_Set_Object_Instance_Number(0) failed");
|
||||
zassert_true(Device_Object_Instance_Number()==0,
|
||||
"Failed to set device object instance number to 0.");
|
||||
|
||||
zassert_true(Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE),
|
||||
"Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE) failed");
|
||||
zassert_true(Device_Object_Instance_Number()==BACNET_MAX_INSTANCE,
|
||||
"Failed to set device object instance number to BACNET_MAX_INSTANCE");
|
||||
|
||||
zassert_true(Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE / 2),
|
||||
"Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE / 2) failed");
|
||||
zassert_true(Device_Object_Instance_Number()==(BACNET_MAX_INSTANCE / 2),
|
||||
"Failed to set device object instance number to BACNET_MAX_INSTANCE / 2");
|
||||
|
||||
zassert_false(Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE + 1),
|
||||
"Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE + 1) uncaught");
|
||||
zassert_false(Device_Object_Instance_Number()==(BACNET_MAX_INSTANCE + 1),
|
||||
"Set device object instance number to illegal value BACNET_MAX_INSTANCE + 1");
|
||||
|
||||
zassert_false(Device_Set_System_Status(STATUS_NON_OPERATIONAL, true),
|
||||
"Device_Set_System_Status() failed");
|
||||
zassert_true(Device_System_Status() == STATUS_NON_OPERATIONAL,
|
||||
"Failed to set device status to STATUS_NON_OPERATIONAL");
|
||||
|
||||
zassert_true(Device_Vendor_Identifier() == BACNET_VENDOR_ID,
|
||||
"Incorrect BACNET_VENDOR_ID");
|
||||
|
||||
zassert_true(Device_Set_Model_Name(dev_name, strlen(dev_name)),
|
||||
"Device_Set_Model_Name() failed");
|
||||
zassert_false( strcmp(Device_Model_Name(), dev_name) ,
|
||||
"Failed to set device model name");
|
||||
}
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(device_tests,
|
||||
ztest_unit_test(testDevice)
|
||||
);
|
||||
|
||||
ztest_run_test_suite(device_tests);
|
||||
}
|
||||
@@ -394,11 +394,7 @@ set(BACNETSTACK_PORT ${CMAKE_CURRENT_LIST_DIR}/../ports/zephyr)
|
||||
|
||||
list(
|
||||
APPEND BACNETSTACK_SRCS
|
||||
$<IF:$<BOOL:${CONFIG_NATIVE_APPLICATION}>,
|
||||
${BACNETSTACK_BASIC_SRCS}
|
||||
,#else
|
||||
${BACNETSTACK_PORT}/device.c
|
||||
>
|
||||
${BACNETSTACK_BASIC_SRCS}
|
||||
${BACNETSTACK_PORT}/datetime-init.c
|
||||
$<$<BOOL:${CONFIG_BACDL_BIP}>:${BACNETSTACK_PORT}/bip-init.c>
|
||||
$<$<BOOL:${CONFIG_BACDL_BIP6}>:${BACNETSTACK_PORT}/bip6-init.c>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
menuconfig BACNETSTACK
|
||||
bool "BACnet-Stack Support"
|
||||
select REQUIRES_FULL_LIBC
|
||||
help
|
||||
This option enables the BACnet-Stack BACnet library.
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
|
||||
# Extract module path and names
|
||||
string(REGEX REPLACE
|
||||
"/zephyr/tests/[a-zA-Z_/-]*$" ""
|
||||
BACNET_BASE
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
string(REGEX REPLACE
|
||||
"/zephyr/tests/" "/test/"
|
||||
BACNET_TEST_PATH
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
get_filename_component(BACNET_NAME ${BACNET_BASE} NAME)
|
||||
|
||||
# Update include path for this module
|
||||
list(APPEND BACNET_INCLUDE ${BACNET_BASE}/src)
|
||||
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(${BACNET_NAME})
|
||||
|
||||
target_include_directories(app PRIVATE ${BACNET_INCLUDE})
|
||||
target_sources(app PRIVATE
|
||||
${BACNET_TEST_PATH}/src/main.c
|
||||
)
|
||||
@@ -1,11 +0,0 @@
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_BACNETSTACK=y
|
||||
|
||||
CONFIG_NETWORKING=y
|
||||
CONFIG_NET_IPV4=y
|
||||
CONFIG_NET_IPV6=y
|
||||
CONFIG_NET_ARP=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_UDP=y
|
||||
|
||||
CONFIG_NEWLIB_LIBC=y
|
||||
@@ -1,3 +0,0 @@
|
||||
tests:
|
||||
bacnet.device:
|
||||
tags: bacnet
|
||||
Reference in New Issue
Block a user