summaryrefslogtreecommitdiff
path: root/service/test
diff options
context:
space:
mode:
authortongzongzhen <[email protected]>2024-08-06 14:07:47 +0800
committertongzongzhen <[email protected]>2024-08-06 14:07:47 +0800
commit47a6607c8d440e8a567d918d7739432dde6ef888 (patch)
tree8de94f225dc77d22f88a6a21c1b2298cbfbfd9e9 /service/test
parente279579397030323cb451cba23660ac823b3fab0 (diff)
fix pthread_create ret checkv4.8.19-20240806
- On success, pthread_create() returns 0; on error, it returns an error number. error number greater than zero. - When the pthread_create() fails, errno is not set. The error number is stored in the return value.
Diffstat (limited to 'service/test')
-rw-r--r--service/test/TestOLP.cc124
1 files changed, 48 insertions, 76 deletions
diff --git a/service/test/TestOLP.cc b/service/test/TestOLP.cc
index 77b5bc9..6294737 100644
--- a/service/test/TestOLP.cc
+++ b/service/test/TestOLP.cc
@@ -4,7 +4,7 @@
#include <common.h>
#include <olp_dev.h>
-enum
+enum
{
OLP_SET_HEARTBEAT_SWITCH = 0,
OLP_SET_WORK_MODE = 1,
@@ -27,7 +27,7 @@ struct olp6500_packet
uint8_t port;
uint8_t len;
char data[0];
-}__attribute__((packed));
+} __attribute__((packed));
unsigned int g_logger_to_stdout = 1;
unsigned int g_logger_level = LOG_DEBUG;
@@ -39,17 +39,17 @@ uint8_t g_ctrlzone_id = 0;
extern "C"
{
-extern int olp6500_packet_construct(struct olp_channel * channel, int type, char *buff);
+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)
+void olp_dev_desc_init(struct olp_dev_desc * dev_desc, struct olp_channel * channel)
{
snprintf(dev_desc->devsym, sizeof(dev_desc->devsym), "olp0");
dev_desc->type = OLP_DEVICE_TYPE_OLP_6500;
-
+
channel->olp_channel_id = 1;
channel->state = OLP_CHANNEL_STATE_FORCE_PASS;
channel->en_heartbeat = 1;
@@ -91,7 +91,7 @@ TEST(OLP_PACKET, OLP_SET_HEARTBEAT_SWITCH)
TEST(OLP_PACKET, OLP_SET_WORK_MODE)
{
int pkt_len = 0;
- char buff[256] = {0};
+ char buff[256] = {0};
struct olp_dev_desc dev_desc;
struct olp_channel dev_channel;
@@ -114,7 +114,7 @@ TEST(OLP_PACKET, OLP_SET_WORK_MODE)
TEST(OLP_PACKET, OLP_SET_WORK_LINE)
{
int pkt_len = 0;
- char buff[256] = {0};
+ char buff[256] = {0};
struct olp_dev_desc dev_desc;
struct olp_channel dev_channel;
@@ -137,7 +137,7 @@ TEST(OLP_PACKET, OLP_SET_WORK_LINE)
TEST(OLP_PACKET, OLP_SET_SWITCHBACK_MODE)
{
int pkt_len = 0;
- char buff[256] = {0};
+ char buff[256] = {0};
struct olp_dev_desc dev_desc;
struct olp_channel dev_channel;
@@ -160,7 +160,7 @@ TEST(OLP_PACKET, OLP_SET_SWITCHBACK_MODE)
TEST(OLP_PACKET, OLP_HEARTBEAT_PACKET)
{
int pkt_len = 0;
- char buff[256] = {0};
+ char buff[256] = {0};
struct olp_dev_desc dev_desc;
struct olp_channel dev_channel;
@@ -182,7 +182,7 @@ TEST(OLP_PACKET, OLP_HEARTBEAT_PACKET)
TEST(OLP_PACKET, OLP_GET_CHANNEL_INFO)
{
int pkt_len = 0;
- char buff[256] = {0};
+ char buff[256] = {0};
struct olp_dev_desc dev_desc;
struct olp_channel dev_channel;
@@ -204,7 +204,7 @@ TEST(OLP_PACKET, OLP_GET_CHANNEL_INFO)
TEST(OLP_PACKET, OLP_GET_CHANNEL_CONF)
{
int pkt_len = 0;
- char buff[256] = {0};
+ char buff[256] = {0};
struct olp_dev_desc dev_desc;
struct olp_channel dev_channel;
@@ -226,12 +226,8 @@ TEST(OLP_PACKET, OLP_GET_CHANNEL_CONF)
TEST(OLP_RECV_PACKET, OLP_SET_HEARTBEAT_SWITCH)
{
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
- };
+ 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);
@@ -242,12 +238,8 @@ TEST(OLP_RECV_PACKET, OLP_SET_HEARTBEAT_SWITCH)
TEST(OLP_RECV_PACKET, OLP_SET_WORK_MODE)
{
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
- };
+ 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);
@@ -258,12 +250,8 @@ TEST(OLP_RECV_PACKET, OLP_SET_WORK_MODE)
TEST(OLP_RECV_PACKET, OLP_SET_WORK_LINE)
{
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
- };
+ 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);
@@ -274,12 +262,8 @@ TEST(OLP_RECV_PACKET, OLP_SET_WORK_LINE)
TEST(OLP_RECV_PACKET, OLP_SET_SWITCHBACK_MODE)
{
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
- };
+ 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);
@@ -290,12 +274,8 @@ TEST(OLP_RECV_PACKET, OLP_SET_SWITCHBACK_MODE)
TEST(OLP_RECV_PACKET, OLP_HEARTBEAT_PACKET)
{
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
- };
+ 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);
@@ -306,12 +286,8 @@ TEST(OLP_RECV_PACKET, OLP_HEARTBEAT_PACKET)
TEST(OLP_RECV_PACKET, OLP_GET_CHANNEL_INFO)
{
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
- };
+ 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);
@@ -322,12 +298,8 @@ TEST(OLP_RECV_PACKET, OLP_GET_CHANNEL_INFO)
TEST(OLP_RECV_PACKET, OLP_GET_CHANNEL_CONF)
{
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
- };
+ 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);
@@ -341,7 +313,7 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_1)
struct olp_device olp_dev;
struct olp_dev_desc olp_dev_desc;
struct olp_channel olp_channel[NR_OLP6500_CHANNEL_PER_DEVICE_MAX];
- struct olp_channel *channel = NULL;
+ struct olp_channel * channel = NULL;
memset(&olp_dev, 0, sizeof(olp_dev));
memset(&olp_dev_desc, 0, sizeof(olp_dev_desc));
@@ -384,7 +356,7 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_2)
struct olp_device olp_dev;
struct olp_dev_desc olp_dev_desc;
struct olp_channel olp_channel[NR_OLP6500_CHANNEL_PER_DEVICE_MAX];
- struct olp_channel *channel = NULL;
+ struct olp_channel * channel = NULL;
memset(&olp_dev, 0, sizeof(olp_dev));
memset(&olp_dev_desc, 0, sizeof(olp_dev_desc));
@@ -427,7 +399,7 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_3)
struct olp_device olp_dev;
struct olp_dev_desc olp_dev_desc;
struct olp_channel olp_channel[NR_OLP6500_CHANNEL_PER_DEVICE_MAX];
- struct olp_channel *channel = NULL;
+ struct olp_channel * channel = NULL;
memset(&olp_dev, 0, sizeof(olp_dev));
memset(&olp_dev_desc, 0, sizeof(olp_dev_desc));
@@ -470,7 +442,7 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_4)
struct olp_device olp_dev;
struct olp_dev_desc olp_dev_desc;
struct olp_channel olp_channel[NR_OLP6500_CHANNEL_PER_DEVICE_MAX];
- struct olp_channel *channel = NULL;
+ struct olp_channel * channel = NULL;
memset(&olp_dev, 0, sizeof(olp_dev));
memset(&olp_dev_desc, 0, sizeof(olp_dev_desc));
@@ -513,7 +485,7 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_5)
struct olp_device olp_dev;
struct olp_dev_desc olp_dev_desc;
struct olp_channel olp_channel[NR_OLP6500_CHANNEL_PER_DEVICE_MAX];
- struct olp_channel *channel = NULL;
+ struct olp_channel * channel = NULL;
memset(&olp_dev, 0, sizeof(olp_dev));
memset(&olp_dev_desc, 0, sizeof(olp_dev_desc));
@@ -556,7 +528,7 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_6)
struct olp_device olp_dev;
struct olp_dev_desc olp_dev_desc;
struct olp_channel olp_channel[NR_OLP6500_CHANNEL_PER_DEVICE_MAX];
- struct olp_channel *channel = NULL;
+ struct olp_channel * channel = NULL;
memset(&olp_dev, 0, sizeof(olp_dev));
memset(&olp_dev_desc, 0, sizeof(olp_dev_desc));
@@ -599,7 +571,7 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_7)
struct olp_device olp_dev;
struct olp_dev_desc olp_dev_desc;
struct olp_channel olp_channel[NR_OLP6500_CHANNEL_PER_DEVICE_MAX];
- struct olp_channel *channel = NULL;
+ struct olp_channel * channel = NULL;
memset(&olp_dev, 0, sizeof(olp_dev));
memset(&olp_dev_desc, 0, sizeof(olp_dev_desc));
@@ -642,7 +614,7 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_8)
struct olp_device olp_dev;
struct olp_dev_desc olp_dev_desc;
struct olp_channel olp_channel[NR_OLP6500_CHANNEL_PER_DEVICE_MAX];
- struct olp_channel *channel = NULL;
+ struct olp_channel * channel = NULL;
memset(&olp_dev, 0, sizeof(olp_dev));
memset(&olp_dev_desc, 0, sizeof(olp_dev_desc));
@@ -685,7 +657,7 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_9)
struct olp_device olp_dev;
struct olp_dev_desc olp_dev_desc;
struct olp_channel olp_channel[NR_OLP6500_CHANNEL_PER_DEVICE_MAX];
- struct olp_channel *channel = NULL;
+ struct olp_channel * channel = NULL;
memset(&olp_dev, 0, sizeof(olp_dev));
memset(&olp_dev_desc, 0, sizeof(olp_dev_desc));
@@ -728,7 +700,7 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_10)
struct olp_device olp_dev;
struct olp_dev_desc olp_dev_desc;
struct olp_channel olp_channel[NR_OLP6500_CHANNEL_PER_DEVICE_MAX];
- struct olp_channel *channel = NULL;
+ struct olp_channel * channel = NULL;
memset(&olp_dev, 0, sizeof(olp_dev));
memset(&olp_dev_desc, 0, sizeof(olp_dev_desc));
@@ -771,7 +743,7 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_11)
struct olp_device olp_dev;
struct olp_dev_desc olp_dev_desc;
struct olp_channel olp_channel[NR_OLP6500_CHANNEL_PER_DEVICE_MAX];
- struct olp_channel *channel = NULL;
+ struct olp_channel * channel = NULL;
memset(&olp_dev, 0, sizeof(olp_dev));
memset(&olp_dev_desc, 0, sizeof(olp_dev_desc));
@@ -814,7 +786,7 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_12)
struct olp_device olp_dev;
struct olp_dev_desc olp_dev_desc;
struct olp_channel olp_channel[NR_OLP6500_CHANNEL_PER_DEVICE_MAX];
- struct olp_channel *channel = NULL;
+ struct olp_channel * channel = NULL;
memset(&olp_dev, 0, sizeof(olp_dev));
memset(&olp_dev_desc, 0, sizeof(olp_dev_desc));
@@ -857,7 +829,7 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_13)
struct olp_device olp_dev;
struct olp_dev_desc olp_dev_desc;
struct olp_channel olp_channel[NR_OLP6500_CHANNEL_PER_DEVICE_MAX];
- struct olp_channel *channel = NULL;
+ struct olp_channel * channel = NULL;
memset(&olp_dev, 0, sizeof(olp_dev));
memset(&olp_dev_desc, 0, sizeof(olp_dev_desc));
@@ -900,7 +872,7 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_14)
struct olp_device olp_dev;
struct olp_dev_desc olp_dev_desc;
struct olp_channel olp_channel[NR_OLP6500_CHANNEL_PER_DEVICE_MAX];
- struct olp_channel *channel = NULL;
+ struct olp_channel * channel = NULL;
memset(&olp_dev, 0, sizeof(olp_dev));
memset(&olp_dev_desc, 0, sizeof(olp_dev_desc));
@@ -943,7 +915,7 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_15)
struct olp_device olp_dev;
struct olp_dev_desc olp_dev_desc;
struct olp_channel olp_channel[NR_OLP6500_CHANNEL_PER_DEVICE_MAX];
- struct olp_channel *channel = NULL;
+ struct olp_channel * channel = NULL;
memset(&olp_dev, 0, sizeof(olp_dev));
memset(&olp_dev_desc, 0, sizeof(olp_dev_desc));
@@ -986,7 +958,7 @@ TEST(OLP_CONTROL_COMMAND, CHANNEL_16)
struct olp_device olp_dev;
struct olp_dev_desc olp_dev_desc;
struct olp_channel olp_channel[NR_OLP6500_CHANNEL_PER_DEVICE_MAX];
- struct olp_channel *channel = NULL;
+ struct olp_channel * channel = NULL;
memset(&olp_dev, 0, sizeof(olp_dev));
memset(&olp_dev_desc, 0, sizeof(olp_dev_desc));
@@ -1032,7 +1004,7 @@ void * olp_device_server(void * args)
struct sockaddr_in addr;
struct sockaddr cli_addr;
socklen_t cli_len = sizeof(cli_addr);
- struct olp6500_packet *pkt = NULL;
+ struct olp6500_packet * pkt = NULL;
pthread_detach(pthread_self());
@@ -1044,8 +1016,8 @@ void * olp_device_server(void * args)
addr.sin_family = AF_INET;
addr.sin_port = htons(6800);
addr.sin_addr.s_addr = htonl(INADDR_ANY);
- bind(sock, (struct sockaddr*)&addr, sizeof(addr));
- while(1)
+ bind(sock, (struct sockaddr *)&addr, sizeof(addr));
+ while (1)
{
memset(recv_buff, 0, sizeof(recv_buff));
memset(send_buff, 0, sizeof(send_buff));
@@ -1057,8 +1029,8 @@ void * olp_device_server(void * args)
continue;
}
- pkt = (struct olp6500_packet*)recv_buff;
- ret = sendto(sock, recv_buff, pkt->len+6, 0, &cli_addr, cli_len);
+ pkt = (struct olp6500_packet *)recv_buff;
+ ret = sendto(sock, recv_buff, pkt->len + 6, 0, &cli_addr, cli_len);
if (ret == -1)
{
printf("sendto fail! error:%s\n", strerror(errno));
@@ -1075,9 +1047,9 @@ int main(int argc, char * argv[])
::testing::InitGoogleTest(&argc, argv);
ret = pthread_create(&tid, NULL, olp_device_server, NULL);
- if (ret < 0)
+ if (ret != 0)
{
- MR_ERROR("olp devices server start error: %s", strerror(errno));
+ MR_ERROR("olp devices server start error: %s", strerror(ret));
return -1;
}
return RUN_ALL_TESTS();