summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortongzongzhen <[email protected]>2024-08-08 09:56:24 +0800
committertongzongzhen <[email protected]>2024-08-08 09:56:24 +0800
commit16787d2c1f51d445a03264fac7714386754fcfac (patch)
tree24e6ea58800c82f8ccd9aa60e02301247ec56597
parente4c866ebc59b72b62b62be13f6517dd189d841bd (diff)
add olp unit test back
In the unit test of olp, use cmocka to replace gtest and add it back to the build process
-rw-r--r--.gitlab-ci.yml2
-rw-r--r--service/CMakeLists.txt9
-rw-r--r--service/test/test_olp.c (renamed from service/test/TestOLP.cc)419
3 files changed, 235 insertions, 195 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d8b1225..4a6f967 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -29,7 +29,7 @@ stages:
- make VERBOSE=1
- if [[ "${TEST_OPTIONS}" == *"ENABLE_CTEST"* ]]; then
cd ${BUILD_ROOT_DIR};
- ctest --output-on-failure -V;
+ ctest --output-on-failure;
fi
- if [[ "${TEST_OPTIONS}" == *"ENABLE_PACKAGE_TEST"* ]]; then
cd ${BUILD_ROOT_DIR};
diff --git a/service/CMakeLists.txt b/service/CMakeLists.txt
index 937e426..e4d9d04 100644
--- a/service/CMakeLists.txt
+++ b/service/CMakeLists.txt
@@ -18,11 +18,10 @@ install(TARGETS mrzcpd RUNTIME DESTINATION ${MR_INSTALL_BINDIR} COMPONENT Progra
########################################### UNITTESTS ###########################################
-#add_executable(TestOLP test/TestOLP.cc src/olp_6500.c)
-#target_link_libraries(TestOLP gtest_main MESA_prof_load_static ${SYSTEMD_LIBRARIES} libdpdk)
-#target_link_libraries(TestOLP rt pthread dl infra z elf)
-#target_include_directories(TestOLP PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include/")
-#target_include_directories(TestOLP PRIVATE ${SYSTEMD_INCLUDE_DIRS})
+add_executable(test_olp test/test_olp.c src/olp_6500.c)
+target_include_directories(test_olp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/)
+target_link_libraries(test_olp MESA_prof_load_static libcmocka rt pthread dl infra z elf ${SYSTEMD_LIBRARIES} libdpdk)
+add_test(NAME test_olp COMMAND test_olp)
add_executable(test_node_vwire test/test_node_mocks.c test/test_node_vwire.c ${MRZCPD_SERVICE_SOURCE_FILES})
target_compile_options(test_node_vwire PRIVATE --coverage -fprofile-arcs -ftest-coverage)
diff --git a/service/test/TestOLP.cc b/service/test/test_olp.c
index 6294737..3835f92 100644
--- a/service/test/TestOLP.cc
+++ b/service/test/test_olp.c
@@ -1,6 +1,14 @@
-#include <gtest/gtest.h>
-
#include <arpa/inet.h>
+#include <setjmp.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <cmocka.h>
+
#include <common.h>
#include <olp_dev.h>
@@ -32,18 +40,15 @@ struct olp6500_packet
unsigned int g_logger_to_stdout = 1;
unsigned int g_logger_level = LOG_DEBUG;
unsigned int g_keep_running = 1;
-uint8_t g_ctrlzone_id = 0;
+uint8_t g_setzone_id = 0;
#define BUFF_MAX 256
#define NR_OLP6500_CHANNEL_PER_DEVICE_MAX (17)
-extern "C"
-{
extern int olp6500_packet_construct(struct olp_channel * channel, int type, char * buff);
extern int olp6500_check_recv_data(char * buff, uint16_t object);
extern int olp6500_apply_control_command_to_peer(struct olp_dev_desc * dev_desc, uint32_t channel_id);
extern int olp6500_destroy_timer(struct olp_device * olp_dev);
-}
void olp_dev_desc_init(struct olp_dev_desc * dev_desc, struct olp_channel * channel)
{
@@ -62,7 +67,7 @@ void olp_dev_desc_init(struct olp_dev_desc * dev_desc, struct olp_channel * chan
dev_desc->channels = channel;
}
-TEST(OLP_PACKET, OLP_SET_HEARTBEAT_SWITCH)
+static void testcase_heartbeat_set_packet_construct(void ** state)
{
int pkt_len = 0;
char buff[BUFF_MAX] = {0};
@@ -75,20 +80,20 @@ TEST(OLP_PACKET, OLP_SET_HEARTBEAT_SWITCH)
olp_dev_desc_init(&dev_desc, &dev_channel);
pkt_len = olp6500_packet_construct(&dev_desc.channels[0], OLP_SET_HEARTBEAT_SWITCH, buff);
- EXPECT_TRUE(pkt_len == 10);
- EXPECT_TRUE(buff[0] == 0x01);
- EXPECT_TRUE(buff[1] == 0x01);
- EXPECT_TRUE(buff[2] == 0x06);
- EXPECT_TRUE(buff[3] == 0x00);
- EXPECT_TRUE(buff[4] == 0x00);
- EXPECT_TRUE(buff[5] == 0x04);
- EXPECT_TRUE(buff[6] == 0x01);
- EXPECT_TRUE(buff[7] == 0x01);
- EXPECT_TRUE(buff[8] == 0x03);
- EXPECT_TRUE(buff[9] == 0x03);
+ assert_true(pkt_len == 10);
+ assert_true(buff[0] == 0x01);
+ assert_true(buff[1] == 0x01);
+ assert_true(buff[2] == 0x06);
+ assert_true(buff[3] == 0x00);
+ assert_true(buff[4] == 0x00);
+ assert_true(buff[5] == 0x04);
+ assert_true(buff[6] == 0x01);
+ assert_true(buff[7] == 0x01);
+ assert_true(buff[8] == 0x03);
+ assert_true(buff[9] == 0x03);
}
-TEST(OLP_PACKET, OLP_SET_WORK_MODE)
+static void testcase_work_mode_set_packet_construct(void ** state)
{
int pkt_len = 0;
char buff[256] = {0};
@@ -101,17 +106,17 @@ TEST(OLP_PACKET, OLP_SET_WORK_MODE)
olp_dev_desc_init(&dev_desc, &dev_channel);
pkt_len = olp6500_packet_construct(&dev_desc.channels[0], OLP_SET_WORK_MODE, buff);
- EXPECT_TRUE(pkt_len == 7);
- EXPECT_TRUE(buff[0] == 0x01);
- EXPECT_TRUE(buff[1] == 0x01);
- EXPECT_TRUE(buff[2] == 0x10);
- EXPECT_TRUE(buff[3] == 0x10);
- EXPECT_TRUE(buff[4] == 0x00);
- EXPECT_TRUE(buff[5] == 0x01);
- EXPECT_TRUE(buff[6] == 0x01);
+ assert_true(pkt_len == 7);
+ assert_true(buff[0] == 0x01);
+ assert_true(buff[1] == 0x01);
+ assert_true(buff[2] == 0x10);
+ assert_true(buff[3] == 0x10);
+ assert_true(buff[4] == 0x00);
+ assert_true(buff[5] == 0x01);
+ assert_true(buff[6] == 0x01);
}
-TEST(OLP_PACKET, OLP_SET_WORK_LINE)
+static void testcase_work_line_set_packet_construct(void ** state)
{
int pkt_len = 0;
char buff[256] = {0};
@@ -124,17 +129,17 @@ TEST(OLP_PACKET, OLP_SET_WORK_LINE)
olp_dev_desc_init(&dev_desc, &dev_channel);
pkt_len = olp6500_packet_construct(&dev_desc.channels[0], OLP_SET_WORK_LINE, buff);
- EXPECT_TRUE(pkt_len == 7);
- EXPECT_TRUE(buff[0] == 0x01);
- EXPECT_TRUE(buff[1] == 0x01);
- EXPECT_TRUE(buff[2] == 0x10);
- EXPECT_TRUE(buff[3] == 0x70);
- EXPECT_TRUE(buff[4] == 0x00);
- EXPECT_TRUE(buff[5] == 0x01);
- EXPECT_TRUE(buff[6] == 0x30);
+ assert_true(pkt_len == 7);
+ assert_true(buff[0] == 0x01);
+ assert_true(buff[1] == 0x01);
+ assert_true(buff[2] == 0x10);
+ assert_true(buff[3] == 0x70);
+ assert_true(buff[4] == 0x00);
+ assert_true(buff[5] == 0x01);
+ assert_true(buff[6] == 0x30);
}
-TEST(OLP_PACKET, OLP_SET_SWITCHBACK_MODE)
+static void testcase_switchback_mode_set_packet_construct(void ** state)
{
int pkt_len = 0;
char buff[256] = {0};
@@ -147,17 +152,17 @@ TEST(OLP_PACKET, OLP_SET_SWITCHBACK_MODE)
olp_dev_desc_init(&dev_desc, &dev_channel);
pkt_len = olp6500_packet_construct(&dev_desc.channels[0], OLP_SET_SWITCHBACK_MODE, buff);
- EXPECT_TRUE(pkt_len == 7);
- EXPECT_TRUE(buff[0] == 0x01);
- EXPECT_TRUE(buff[1] == 0x01);
- EXPECT_TRUE(buff[2] == 0x10);
- EXPECT_TRUE(buff[3] == 0x20);
- EXPECT_TRUE(buff[4] == 0x00);
- EXPECT_TRUE(buff[5] == 0x01);
- EXPECT_TRUE(buff[6] == 0x02);
+ assert_true(pkt_len == 7);
+ assert_true(buff[0] == 0x01);
+ assert_true(buff[1] == 0x01);
+ assert_true(buff[2] == 0x10);
+ assert_true(buff[3] == 0x20);
+ assert_true(buff[4] == 0x00);
+ assert_true(buff[5] == 0x01);
+ assert_true(buff[6] == 0x02);
}
-TEST(OLP_PACKET, OLP_HEARTBEAT_PACKET)
+static void testcase_heartbeat_packet_construct(void ** state)
{
int pkt_len = 0;
char buff[256] = {0};
@@ -170,16 +175,16 @@ TEST(OLP_PACKET, OLP_HEARTBEAT_PACKET)
olp_dev_desc_init(&dev_desc, &dev_channel);
pkt_len = olp6500_packet_construct(&dev_desc.channels[0], OLP_HEARTBEAT_PACKET, buff);
- EXPECT_TRUE(pkt_len == 6);
- EXPECT_TRUE(buff[0] == 0x00);
- EXPECT_TRUE(buff[1] == 0x01);
- EXPECT_TRUE(buff[2] == 0x06);
- EXPECT_TRUE(buff[3] == 0x01);
- EXPECT_TRUE(buff[4] == 0x00);
- EXPECT_TRUE(buff[5] == 0x00);
+ assert_true(pkt_len == 6);
+ assert_true(buff[0] == 0x00);
+ assert_true(buff[1] == 0x01);
+ assert_true(buff[2] == 0x06);
+ assert_true(buff[3] == 0x01);
+ assert_true(buff[4] == 0x00);
+ assert_true(buff[5] == 0x00);
}
-TEST(OLP_PACKET, OLP_GET_CHANNEL_INFO)
+static void testcase_channel_info_packet_construct(void ** state)
{
int pkt_len = 0;
char buff[256] = {0};
@@ -192,16 +197,16 @@ TEST(OLP_PACKET, OLP_GET_CHANNEL_INFO)
olp_dev_desc_init(&dev_desc, &dev_channel);
pkt_len = olp6500_packet_construct(&dev_desc.channels[0], OLP_GET_CHANNEL_INFO, buff);
- EXPECT_TRUE(pkt_len == 6);
- EXPECT_TRUE(buff[0] == 0x00);
- EXPECT_TRUE(buff[1] == 0x01);
- EXPECT_TRUE(buff[2] == 0x02);
- EXPECT_TRUE(buff[3] == 0x00);
- EXPECT_TRUE(buff[4] == 0x00);
- EXPECT_TRUE(buff[5] == 0x00);
+ assert_true(pkt_len == 6);
+ assert_true(buff[0] == 0x00);
+ assert_true(buff[1] == 0x01);
+ assert_true(buff[2] == 0x02);
+ assert_true(buff[3] == 0x00);
+ assert_true(buff[4] == 0x00);
+ assert_true(buff[5] == 0x00);
}
-TEST(OLP_PACKET, OLP_GET_CHANNEL_CONF)
+static void testcase_channel_conf_get_packet_construct(void ** state)
{
int pkt_len = 0;
char buff[256] = {0};
@@ -214,100 +219,100 @@ TEST(OLP_PACKET, OLP_GET_CHANNEL_CONF)
olp_dev_desc_init(&dev_desc, &dev_channel);
pkt_len = olp6500_packet_construct(&dev_desc.channels[0], OLP_GET_CHANNEL_CONF, buff);
- EXPECT_TRUE(pkt_len == 6);
- EXPECT_TRUE(buff[0] == 0x00);
- EXPECT_TRUE(buff[1] == 0x01);
- EXPECT_TRUE(buff[2] == 0x05);
- EXPECT_TRUE(buff[3] == 0x01);
- EXPECT_TRUE(buff[4] == 0x00);
- EXPECT_TRUE(buff[5] == 0x00);
+ assert_true(pkt_len == 6);
+ assert_true(buff[0] == 0x00);
+ assert_true(buff[1] == 0x01);
+ assert_true(buff[2] == 0x05);
+ assert_true(buff[3] == 0x01);
+ assert_true(buff[4] == 0x00);
+ assert_true(buff[5] == 0x00);
}
-TEST(OLP_RECV_PACKET, OLP_SET_HEARTBEAT_SWITCH)
+static void testcase_heartbeat_switch_set_packet_recv(void ** state)
{
int ret = 0;
unsigned char data_succ[] = {0x01, 0x00, 0x06, 0x00, 0x00, 0x04, 0x01, 0x01, 0x05, 0x03};
unsigned char data_fail[] = {0x01, 0x00, 0x86, 0x00, 0x00, 0x02, 0xFF, 0xEE};
ret = olp6500_check_recv_data((char *)data_succ, OLP_SET_HEARTBEAT_SWITCH);
- EXPECT_TRUE(ret == 0);
+ assert_true(ret == 0);
ret = olp6500_check_recv_data((char *)data_fail, OLP_SET_HEARTBEAT_SWITCH);
- EXPECT_TRUE(ret == -1);
+ assert_true(ret == -1);
}
-TEST(OLP_RECV_PACKET, OLP_SET_WORK_MODE)
+static void testcase_work_mode_set_packet_recv(void ** state)
{
int ret = 0;
unsigned char data_succ[] = {0x01, 0x00, 0x10, 0x10, 0x00, 0x01, 0x02};
unsigned char data_fail[] = {0x01, 0x00, 0x90, 0x10, 0x00, 0x02, 0xFF, 0xEE};
ret = olp6500_check_recv_data((char *)data_succ, OLP_SET_WORK_MODE);
- EXPECT_TRUE(ret == 0);
+ assert_true(ret == 0);
ret = olp6500_check_recv_data((char *)data_fail, OLP_SET_WORK_MODE);
- EXPECT_TRUE(ret == -1);
+ assert_true(ret == -1);
}
-TEST(OLP_RECV_PACKET, OLP_SET_WORK_LINE)
+static void testcase_work_line_set_packet_recv(void ** state)
{
int ret = 0;
unsigned char data_succ[] = {0x01, 0x00, 0x10, 0x70, 0x00, 0x01, 0x30};
unsigned char data_fail[] = {0x01, 0x00, 0x90, 0x70, 0x00, 0x02, 0xFF, 0xEE};
ret = olp6500_check_recv_data((char *)data_succ, OLP_SET_WORK_LINE);
- EXPECT_TRUE(ret == 0);
+ assert_true(ret == 0);
ret = olp6500_check_recv_data((char *)data_fail, OLP_SET_WORK_LINE);
- EXPECT_TRUE(ret == -1);
+ assert_true(ret == -1);
}
-TEST(OLP_RECV_PACKET, OLP_SET_SWITCHBACK_MODE)
+static void testcase_switchback_mode_set_packet_recv(void ** state)
{
int ret = 0;
unsigned char data_succ[] = {0x01, 0x00, 0x10, 0x20, 0x00, 0x01, 0x02};
unsigned char data_fail[] = {0x01, 0x00, 0x90, 0x20, 0x00, 0x02, 0xFF, 0xEE};
ret = olp6500_check_recv_data((char *)data_succ, OLP_SET_SWITCHBACK_MODE);
- EXPECT_TRUE(ret == 0);
+ assert_true(ret == 0);
ret = olp6500_check_recv_data((char *)data_fail, OLP_SET_SWITCHBACK_MODE);
- EXPECT_TRUE(ret == -1);
+ assert_true(ret == -1);
}
-TEST(OLP_RECV_PACKET, OLP_HEARTBEAT_PACKET)
+static void testcase_heartbeat_packet_recv(void ** state)
{
int ret = 0;
unsigned char data_succ[] = {0x00, 0x00, 0x06, 0x01, 0x00, 0x00};
unsigned char data_fail[] = {0x00, 0x00, 0x86, 0x01, 0x00, 0x02, 0xFF, 0xEE};
ret = olp6500_check_recv_data((char *)data_succ, OLP_HEARTBEAT_PACKET);
- EXPECT_TRUE(ret == 0);
+ assert_true(ret == 0);
ret = olp6500_check_recv_data((char *)data_fail, OLP_HEARTBEAT_PACKET);
- EXPECT_TRUE(ret == -1);
+ assert_true(ret == -1);
}
-TEST(OLP_RECV_PACKET, OLP_GET_CHANNEL_INFO)
+static void testcase_channel_info_get_packet_recv(void ** state)
{
int ret = 0;
unsigned char data_succ[] = {0x00, 0x00, 0x02, 0x00, 0x00, 0x00};
unsigned char data_fail[] = {0x00, 0x00, 0x82, 0x00, 0x00, 0x02, 0xFF, 0xEE};
ret = olp6500_check_recv_data((char *)data_succ, OLP_GET_CHANNEL_INFO);
- EXPECT_TRUE(ret == 0);
+ assert_true(ret == 0);
ret = olp6500_check_recv_data((char *)data_fail, OLP_GET_CHANNEL_INFO);
- EXPECT_TRUE(ret == -1);
+ assert_true(ret == -1);
}
-TEST(OLP_RECV_PACKET, OLP_GET_CHANNEL_CONF)
+static void testcase_channel_conf_get_packet_recv(void ** state)
{
int ret = 0;
unsigned char data_succ[] = {0x00, 0x00, 0x05, 0x01, 0x00, 0x00};
unsigned char data_fail[] = {0x00, 0x00, 0x85, 0x01, 0x00, 0x02, 0xFF, 0xEE};
ret = olp6500_check_recv_data((char *)data_succ, OLP_GET_CHANNEL_CONF);
- EXPECT_TRUE(ret == 0);
+ assert_true(ret == 0);
ret = olp6500_check_recv_data((char *)data_fail, OLP_GET_CHANNEL_CONF);
- EXPECT_TRUE(ret == -1);
+ assert_true(ret == -1);
}
-TEST(OLP_CONTROL_COMMAND, CHANNEL_1)
+static void channel_1_ctrl_cmd(void ** state)
{
int ret = 0;
struct olp_device olp_dev;
@@ -341,16 +346,16 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_1)
olp_dev.olp_dev_descs[olp_dev.nr_olp_dev_descs++] = &olp_dev_desc;
ret = olp6500_apply_control_command_to_peer(&olp_dev_desc, 1);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 1);
- EXPECT_TRUE(channel->runtime.errcode == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 1);
+ assert_true(channel->runtime.errcode == 0);
ret = olp6500_destroy_timer(&olp_dev);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
}
-TEST(OLP_CONTROL_COMMAND, CHANNEL_2)
+static void channel_2_ctrl_cmd(void ** state)
{
int ret = 0;
struct olp_device olp_dev;
@@ -384,16 +389,16 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_2)
olp_dev.olp_dev_descs[olp_dev.nr_olp_dev_descs++] = &olp_dev_desc;
ret = olp6500_apply_control_command_to_peer(&olp_dev_desc, 1);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 1);
- EXPECT_TRUE(channel->runtime.errcode == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 1);
+ assert_true(channel->runtime.errcode == 0);
ret = olp6500_destroy_timer(&olp_dev);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
}
-TEST(OLP_CONTROL_COMMAND, CHANNEL_3)
+static void channel_3_ctrl_cmd(void ** state)
{
int ret = 0;
struct olp_device olp_dev;
@@ -427,16 +432,16 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_3)
olp_dev.olp_dev_descs[olp_dev.nr_olp_dev_descs++] = &olp_dev_desc;
ret = olp6500_apply_control_command_to_peer(&olp_dev_desc, 1);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 1);
- EXPECT_TRUE(channel->runtime.errcode == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 1);
+ assert_true(channel->runtime.errcode == 0);
ret = olp6500_destroy_timer(&olp_dev);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
}
-TEST(OLP_CONTROL_COMMAND, CHANNEL_4)
+static void channel_4_ctrl_cmd(void ** state)
{
int ret = 0;
struct olp_device olp_dev;
@@ -470,16 +475,16 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_4)
olp_dev.olp_dev_descs[olp_dev.nr_olp_dev_descs++] = &olp_dev_desc;
ret = olp6500_apply_control_command_to_peer(&olp_dev_desc, 1);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
- EXPECT_TRUE(channel->runtime.errcode == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
+ assert_true(channel->runtime.errcode == 0);
ret = olp6500_destroy_timer(&olp_dev);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
}
-TEST(OLP_CONTROL_COMMAND, CHANNEL_5)
+static void channel_5_ctrl_cmd(void ** state)
{
int ret = 0;
struct olp_device olp_dev;
@@ -513,16 +518,16 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_5)
olp_dev.olp_dev_descs[olp_dev.nr_olp_dev_descs++] = &olp_dev_desc;
ret = olp6500_apply_control_command_to_peer(&olp_dev_desc, 1);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
- EXPECT_TRUE(channel->runtime.errcode == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
+ assert_true(channel->runtime.errcode == 0);
ret = olp6500_destroy_timer(&olp_dev);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
}
-TEST(OLP_CONTROL_COMMAND, CHANNEL_6)
+static void channel_6_ctrl_cmd(void ** state)
{
int ret = 0;
struct olp_device olp_dev;
@@ -556,16 +561,16 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_6)
olp_dev.olp_dev_descs[olp_dev.nr_olp_dev_descs++] = &olp_dev_desc;
ret = olp6500_apply_control_command_to_peer(&olp_dev_desc, 1);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 1);
- EXPECT_TRUE(channel->runtime.errcode == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 1);
+ assert_true(channel->runtime.errcode == 0);
ret = olp6500_destroy_timer(&olp_dev);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
}
-TEST(OLP_CONTROL_COMMAND, CHANNEL_7)
+static void channel_7_ctrl_cmd(void ** state)
{
int ret = 0;
struct olp_device olp_dev;
@@ -599,16 +604,16 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_7)
olp_dev.olp_dev_descs[olp_dev.nr_olp_dev_descs++] = &olp_dev_desc;
ret = olp6500_apply_control_command_to_peer(&olp_dev_desc, 1);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 1);
- EXPECT_TRUE(channel->runtime.errcode == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 1);
+ assert_true(channel->runtime.errcode == 0);
ret = olp6500_destroy_timer(&olp_dev);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
}
-TEST(OLP_CONTROL_COMMAND, CHANNEL_8)
+static void channel_8_ctrl_cmd(void ** state)
{
int ret = 0;
struct olp_device olp_dev;
@@ -642,16 +647,16 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_8)
olp_dev.olp_dev_descs[olp_dev.nr_olp_dev_descs++] = &olp_dev_desc;
ret = olp6500_apply_control_command_to_peer(&olp_dev_desc, 1);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 1);
- EXPECT_TRUE(channel->runtime.errcode == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 1);
+ assert_true(channel->runtime.errcode == 0);
ret = olp6500_destroy_timer(&olp_dev);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
}
-TEST(OLP_CONTROL_COMMAND, CHANNEL_9)
+static void channel_9_ctrl_cmd(void ** state)
{
int ret = 0;
struct olp_device olp_dev;
@@ -685,16 +690,16 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_9)
olp_dev.olp_dev_descs[olp_dev.nr_olp_dev_descs++] = &olp_dev_desc;
ret = olp6500_apply_control_command_to_peer(&olp_dev_desc, 1);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 1);
- EXPECT_TRUE(channel->runtime.errcode == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 1);
+ assert_true(channel->runtime.errcode == 0);
ret = olp6500_destroy_timer(&olp_dev);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
}
-TEST(OLP_CONTROL_COMMAND, CHANNEL_10)
+static void channel_10_ctrl_cmd(void ** state)
{
int ret = 0;
struct olp_device olp_dev;
@@ -728,16 +733,16 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_10)
olp_dev.olp_dev_descs[olp_dev.nr_olp_dev_descs++] = &olp_dev_desc;
ret = olp6500_apply_control_command_to_peer(&olp_dev_desc, 1);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 1);
- EXPECT_TRUE(channel->runtime.errcode == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 1);
+ assert_true(channel->runtime.errcode == 0);
ret = olp6500_destroy_timer(&olp_dev);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
}
-TEST(OLP_CONTROL_COMMAND, CHANNEL_11)
+static void channel_11_ctrl_cmd(void ** state)
{
int ret = 0;
struct olp_device olp_dev;
@@ -771,16 +776,16 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_11)
olp_dev.olp_dev_descs[olp_dev.nr_olp_dev_descs++] = &olp_dev_desc;
ret = olp6500_apply_control_command_to_peer(&olp_dev_desc, 1);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 1);
- EXPECT_TRUE(channel->runtime.errcode == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 1);
+ assert_true(channel->runtime.errcode == 0);
ret = olp6500_destroy_timer(&olp_dev);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
}
-TEST(OLP_CONTROL_COMMAND, CHANNEL_12)
+static void channel_12_ctrl_cmd(void ** state)
{
int ret = 0;
struct olp_device olp_dev;
@@ -814,16 +819,16 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_12)
olp_dev.olp_dev_descs[olp_dev.nr_olp_dev_descs++] = &olp_dev_desc;
ret = olp6500_apply_control_command_to_peer(&olp_dev_desc, 1);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 1);
- EXPECT_TRUE(channel->runtime.errcode == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 1);
+ assert_true(channel->runtime.errcode == 0);
ret = olp6500_destroy_timer(&olp_dev);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
}
-TEST(OLP_CONTROL_COMMAND, CHANNEL_13)
+static void channel_13_ctrl_cmd(void ** state)
{
int ret = 0;
struct olp_device olp_dev;
@@ -857,16 +862,16 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_13)
olp_dev.olp_dev_descs[olp_dev.nr_olp_dev_descs++] = &olp_dev_desc;
ret = olp6500_apply_control_command_to_peer(&olp_dev_desc, 1);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 1);
- EXPECT_TRUE(channel->runtime.errcode == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 1);
+ assert_true(channel->runtime.errcode == 0);
ret = olp6500_destroy_timer(&olp_dev);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
}
-TEST(OLP_CONTROL_COMMAND, CHANNEL_14)
+static void channel_14_ctrl_cmd(void ** state)
{
int ret = 0;
struct olp_device olp_dev;
@@ -900,16 +905,16 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_14)
olp_dev.olp_dev_descs[olp_dev.nr_olp_dev_descs++] = &olp_dev_desc;
ret = olp6500_apply_control_command_to_peer(&olp_dev_desc, 1);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 1);
- EXPECT_TRUE(channel->runtime.errcode == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 1);
+ assert_true(channel->runtime.errcode == 0);
ret = olp6500_destroy_timer(&olp_dev);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
}
-TEST(OLP_CONTROL_COMMAND, CHANNEL_15)
+static void channel_15_ctrl_cmd(void ** state)
{
int ret = 0;
struct olp_device olp_dev;
@@ -943,16 +948,16 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_15)
olp_dev.olp_dev_descs[olp_dev.nr_olp_dev_descs++] = &olp_dev_desc;
ret = olp6500_apply_control_command_to_peer(&olp_dev_desc, 1);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 1);
- EXPECT_TRUE(channel->runtime.errcode == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 1);
+ assert_true(channel->runtime.errcode == 0);
ret = olp6500_destroy_timer(&olp_dev);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
}
-TEST(OLP_CONTROL_COMMAND, CHANNEL_16)
+static void channel_16_ctrl_cmd(void ** state)
{
int ret = 0;
struct olp_device olp_dev;
@@ -986,13 +991,13 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_16)
olp_dev.olp_dev_descs[olp_dev.nr_olp_dev_descs++] = &olp_dev_desc;
ret = olp6500_apply_control_command_to_peer(&olp_dev_desc, 1);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 1);
- EXPECT_TRUE(channel->runtime.errcode == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 1);
+ assert_true(channel->runtime.errcode == 0);
ret = olp6500_destroy_timer(&olp_dev);
- EXPECT_TRUE(ret == 0);
- EXPECT_TRUE(channel->timer.enable == 0);
+ assert_true(ret == 0);
+ assert_true(channel->timer.enable == 0);
}
void * olp_device_server(void * args)
@@ -1044,13 +1049,49 @@ int main(int argc, char * argv[])
{
int ret = 0;
pthread_t tid;
- ::testing::InitGoogleTest(&argc, argv);
ret = pthread_create(&tid, NULL, olp_device_server, NULL);
if (ret != 0)
{
- MR_ERROR("olp devices server start error: %s", strerror(ret));
+ fprintf(stderr, "olp devices server start error: %s", strerror(ret));
return -1;
}
- return RUN_ALL_TESTS();
+
+ const struct CMUnitTest group_packet_construct[] = {
+ cmocka_unit_test(testcase_heartbeat_set_packet_construct),
+ cmocka_unit_test(testcase_work_mode_set_packet_construct),
+ cmocka_unit_test(testcase_work_line_set_packet_construct),
+ cmocka_unit_test(testcase_switchback_mode_set_packet_construct),
+ cmocka_unit_test(testcase_heartbeat_packet_construct),
+ cmocka_unit_test(testcase_channel_info_packet_construct),
+ cmocka_unit_test(testcase_channel_conf_get_packet_construct),
+ };
+
+ const struct CMUnitTest group_packet_recv[] = {
+ cmocka_unit_test(testcase_heartbeat_switch_set_packet_recv),
+ cmocka_unit_test(testcase_work_mode_set_packet_recv),
+ cmocka_unit_test(testcase_work_line_set_packet_recv),
+ cmocka_unit_test(testcase_switchback_mode_set_packet_recv),
+ cmocka_unit_test(testcase_heartbeat_packet_recv),
+ cmocka_unit_test(testcase_channel_info_get_packet_recv),
+ cmocka_unit_test(testcase_channel_conf_get_packet_recv),
+ };
+
+ const struct CMUnitTest group_control_command[] = {
+ cmocka_unit_test(channel_1_ctrl_cmd), cmocka_unit_test(channel_2_ctrl_cmd),
+ cmocka_unit_test(channel_3_ctrl_cmd), cmocka_unit_test(channel_4_ctrl_cmd),
+ cmocka_unit_test(channel_5_ctrl_cmd), cmocka_unit_test(channel_6_ctrl_cmd),
+ cmocka_unit_test(channel_7_ctrl_cmd), cmocka_unit_test(channel_8_ctrl_cmd),
+ cmocka_unit_test(channel_9_ctrl_cmd), cmocka_unit_test(channel_10_ctrl_cmd),
+ cmocka_unit_test(channel_11_ctrl_cmd), cmocka_unit_test(channel_12_ctrl_cmd),
+ cmocka_unit_test(channel_13_ctrl_cmd), cmocka_unit_test(channel_14_ctrl_cmd),
+ cmocka_unit_test(channel_15_ctrl_cmd), cmocka_unit_test(channel_16_ctrl_cmd),
+ };
+
+ // 0 on success, or the number of failed tests.
+ ret = cmocka_run_group_tests(group_packet_construct, NULL, NULL);
+ ret += cmocka_run_group_tests(group_packet_recv, NULL, NULL);
+ ret += cmocka_run_group_tests(group_control_command, NULL, NULL);
+
+ return ret;
}