Skip to content

Commit

Permalink
Fix unit tests after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Michail-Antropov committed Sep 15, 2023
1 parent 43fad40 commit 539b499
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 59 deletions.
3 changes: 3 additions & 0 deletions ports/zephyr/bacnet/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#ifndef BITS_H
#define BITS_H

#ifdef ARRAY_SIZE
#undef ARRAY_SIZE
#endif
#include <zephyr/sys/util.h> /* defines BIT(n) */

/********************************************************************
Expand Down
4 changes: 1 addition & 3 deletions src/bacnet/basic/sys/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
#endif

#ifndef ARRAY_SIZE
# if !defined(__ZEPHYR__)
# define ARRAY_SIZE(array) ((size_t)(sizeof(array) / sizeof((array)[0])))
# endif
#define ARRAY_SIZE(array) ((size_t)(sizeof(array) / sizeof((array)[0])))
#endif

/* marking some code as 'deprecated' */
Expand Down
2 changes: 1 addition & 1 deletion src/bacnet/hostnport.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ int host_n_port_decode(uint8_t *apdu,
}
apdu_len += len;

return len;
return apdu_len;
}

int host_n_port_context_decode(uint8_t *apdu,
Expand Down
1 change: 1 addition & 0 deletions test/bacnet/basic/object/channel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/wp.c
${SRC_DIR}/bacnet/weeklyschedule.c
${SRC_DIR}/bacnet/dailyschedule.c
${SRC_DIR}/bacnet/sc_status.c
# Test and test library files
./src/main.c
../mock/device_mock.c
Expand Down
1 change: 1 addition & 0 deletions test/bacnet/basic/object/csv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/bactimevalue.c
${SRC_DIR}/bacnet/dailyschedule.c
${SRC_DIR}/bacnet/memcopy.c
${SRC_DIR}/bacnet/sc_status.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
Expand Down
54 changes: 4 additions & 50 deletions test/bacnet/basic/object/device/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
/**
* @brief Test ReadProperty API
*/
#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(device_tests, test_Device_ReadProperty)
#else
static void test_Device_ReadProperty(void)
#endif
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
Expand Down Expand Up @@ -123,56 +127,6 @@ static void testDevice(void)
return;
}

/**
* @brief Test
*/
static void test_Device_ReadProperty(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0, test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata = { 0 };
BACNET_APPLICATION_DATA_VALUE value = {0};
const int *required_property = NULL;
const uint32_t instance = 1;
bool status = false;

Device_Init(NULL);
status = Device_Set_Object_Instance_Number(instance);
zassert_true(status, NULL);
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_DEVICE;
rpdata.object_instance = instance;
rpdata.array_index = BACNET_ARRAY_ALL;

Device_Property_Lists(&required_property, NULL, NULL);
while ((*required_property) >= 0) {
rpdata.object_property = *required_property;
len = Device_Read_Property(&rpdata);
if (len < 0) {
printf("property %u: failed to read!\n",
(unsigned)rpdata.object_property);
}
zassert_true(len >= 0, NULL);
if (len >= 0) {
test_len = bacapp_decode_known_property(rpdata.application_data,
len, &value, rpdata.object_type, rpdata.object_property);
if (len != test_len) {
printf("property %u: failed to decode!\n",
(unsigned)rpdata.object_property);
}
if (rpdata.object_property == PROP_OBJECT_LIST) {
/* FIXME: known fail to decode */
len = test_len;
}
zassert_equal(len, test_len, NULL);
}
required_property++;
}

return;
}

/**
* @}
*/
Expand Down
1 change: 1 addition & 0 deletions test/bacnet/basic/object/iv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/weeklyschedule.c
${SRC_DIR}/bacnet/bactimevalue.c
${SRC_DIR}/bacnet/dailyschedule.c
${SRC_DIR}/bacnet/sc_status.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
Expand Down
1 change: 1 addition & 0 deletions test/bacnet/basic/object/trendlog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/wp.c
${SRC_DIR}/bacnet/weeklyschedule.c
${SRC_DIR}/bacnet/dailyschedule.c
${SRC_DIR}/bacnet/sc_status.c
# Test and test library files
./src/main.c
../mock/device_mock.c
Expand Down
1 change: 1 addition & 0 deletions test/bacnet/create_object/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/weeklyschedule.c
${SRC_DIR}/bacnet/bactimevalue.c
${SRC_DIR}/bacnet/dailyschedule.c
${SRC_DIR}/bacnet/sc_status.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
Expand Down
10 changes: 5 additions & 5 deletions test/bacnet/datalink/bsc-node/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,7 @@ static void test_node_duplicated_vmac(void)
}

#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(test_node_3, test_node_send)
ZTEST(node_test_3, test_node_send)
#else
static void test_node_send(void)
#endif
Expand Down Expand Up @@ -2029,7 +2029,7 @@ static void test_node_send(void)
}

#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(test_node_4, test_node_local_hub_function)
ZTEST(node_test_4, test_node_local_hub_function)
#else
static void test_node_local_hub_function(void)
#endif
Expand Down Expand Up @@ -2209,7 +2209,7 @@ static void test_node_local_hub_function(void)
}

#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(test_node_5, test_node_direct_connection)
ZTEST(node_test_5, test_node_direct_connection)
#else
static void test_node_direct_connection(void)
#endif
Expand Down Expand Up @@ -2873,7 +2873,7 @@ static void test_node_direct_connection(void)
}

#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(test_node_6, test_node_direct_connection_unsupported)
ZTEST(node_test_6, test_node_direct_connection_unsupported)
#else
static void test_node_direct_connection_unsupported(void)
#endif
Expand Down Expand Up @@ -3092,7 +3092,7 @@ static void node_switch_event(BSC_NODE_SWITCH_EVENT ev,
}

#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(test_node_7, test_node_bad_cases)
ZTEST(node_test_7, test_node_bad_cases)
#else
static void test_node_bad_cases(void)
#endif
Expand Down
1 change: 1 addition & 0 deletions test/bacnet/delete_object/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/memcopy.c
${SRC_DIR}/bacnet/weeklyschedule.c
${SRC_DIR}/bacnet/bactimevalue.c
${SRC_DIR}/bacnet/sc_status.c
${SRC_DIR}/bacnet/dailyschedule.c
# Test and test library files
./src/main.c
Expand Down
1 change: 1 addition & 0 deletions test/bacnet/hostnport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/weeklyschedule.c
${SRC_DIR}/bacnet/bactimevalue.c
${SRC_DIR}/bacnet/dailyschedule.c
${SRC_DIR}/bacnet/sc_status.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
Expand Down
1 change: 1 addition & 0 deletions test/bacnet/list_element/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/weeklyschedule.c
${SRC_DIR}/bacnet/bactimevalue.c
${SRC_DIR}/bacnet/dailyschedule.c
${SRC_DIR}/bacnet/sc_status.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
Expand Down
1 change: 1 addition & 0 deletions test/bacnet/wpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/weeklyschedule.c
${SRC_DIR}/bacnet/bactimevalue.c
${SRC_DIR}/bacnet/dailyschedule.c
${SRC_DIR}/bacnet/sc_status.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
Expand Down
6 changes: 6 additions & 0 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ else()
message(FATAL_ERROR "ZEPHYR_BASE needs to be defined for Zephyr builds")
endif()

option(BACNET_STACK_DEPRECATED_DISABLE "Disable deprecation compile warnings" ON)

if(BACNET_STACK_DEPRECATED_DISABLE)
add_definitions(-DBACNET_STACK_DEPRECATED_DISABLE)
endif()

#
# options managed through Kconfig and use names CONFIG_*
#
Expand Down
1 change: 1 addition & 0 deletions zephyr/tests/ports/bsc_event/prj.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
CONFIG_BACNETSTACK=y
CONFIG_BACDL_BSC=y

Expand Down
18 changes: 18 additions & 0 deletions zephyr/tests/ports/bsc_event/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ static void child_func(void *p1, void *p2, void *p3)
bsc_event_signal(event);
}

#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(bsc_event_test1, test_bsc_event1)
#else
static void test_bsc_event1(void)
#endif
{
BSC_EVENT *event;
k_tid_t tid_child;
Expand Down Expand Up @@ -114,7 +118,11 @@ static void thread_func(void *p1, void *p2, void *p3)
bsc_event_wait(event);
}

#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(bsc_event_test2, test_bsc_event2)
#else
static void test_bsc_event2(void)
#endif
{
BSC_EVENT *event;
k_tid_t tid_child[MULTIPLE_WAIT_THREADS_NUM];
Expand Down Expand Up @@ -155,7 +163,11 @@ static void thread_func2(void *p1, void *p2, void *p3)
p->result = bsc_event_timedwait(p->event, 24*60*60*1000);
}

#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(bsc_event_test3, test_bsc_event3)
#else
static void test_bsc_event3(void)
#endif
{
BSC_EVENT *event;
k_tid_t tid[MULTIPLE_WAIT_THREADS_NUM];
Expand Down Expand Up @@ -189,6 +201,11 @@ static void test_bsc_event3(void)
bsc_event_deinit(event);
}

#if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(bsc_event_test1, NULL, NULL, NULL, NULL, NULL);
ZTEST_SUITE(bsc_event_test2, NULL, NULL, NULL, NULL, NULL);
ZTEST_SUITE(bsc_event_test3, NULL, NULL, NULL, NULL, NULL);
#else
void test_main(void)
{
ztest_test_suite(bsc_event_test1, ztest_unit_test(test_bsc_event1));
Expand All @@ -198,3 +215,4 @@ void test_main(void)
ztest_run_test_suite(bsc_event_test2);
ztest_run_test_suite(bsc_event_test3);
}
#endif

0 comments on commit 539b499

Please sign in to comment.