20 Star 0 Fork 32

openEuler-RISC-V/gazelle

forked from src-openEuler/gazelle 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0185-add-unitest.patch 71.60 KB
一键复制 编辑 原始数据 按行查看 历史
jinag12 提交于 2023-02-06 10:19 . sync add gazelle setup tools
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962
From 4154201d36719047c7a74d5b6d495228234ff54a Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Wed, 1 Feb 2023 15:58:00 +0800
Subject: [PATCH] add unitest
---
src/lstack/include/lstack_protocol_stack.h | 1 +
test/unitest/CMakeLists.txt | 17 ++
test/unitest/lstack/CMakeLists.txt | 29 ++
test/unitest/lstack/config/lstack.conf | 21 ++
test/unitest/lstack/lstack_param_test.c | 206 +++++++++++++
test/unitest/lstack/lstack_test_case.h | 24 ++
test/unitest/lstack/lstack_unit_test.c | 206 +++++++++++++
test/unitest/lstack/main.c | 75 +++++
test/unitest/lstack/stub.c | 110 +++++++
test/unitest/ltran/CMakeLists.txt | 58 ++++
test/unitest/ltran/config/ltran.conf | 23 ++
test/unitest/ltran/libnet_tcp_test.c | 133 +++++++++
test/unitest/ltran/ltran_instance_test.c | 75 +++++
test/unitest/ltran/ltran_param_test.c | 320 +++++++++++++++++++++
test/unitest/ltran/ltran_stack_test.c | 75 +++++
test/unitest/ltran/ltran_test_case.h | 29 ++
test/unitest/ltran/main.c | 80 ++++++
test/unitest/stub.c | 34 +++
test/unitest/test.sh | 279 ++++++++++++++++++
19 files changed, 1795 insertions(+)
create mode 100644 test/unitest/CMakeLists.txt
create mode 100644 test/unitest/lstack/CMakeLists.txt
create mode 100644 test/unitest/lstack/config/lstack.conf
create mode 100644 test/unitest/lstack/lstack_param_test.c
create mode 100644 test/unitest/lstack/lstack_test_case.h
create mode 100644 test/unitest/lstack/lstack_unit_test.c
create mode 100644 test/unitest/lstack/main.c
create mode 100644 test/unitest/lstack/stub.c
create mode 100644 test/unitest/ltran/CMakeLists.txt
create mode 100644 test/unitest/ltran/config/ltran.conf
create mode 100644 test/unitest/ltran/libnet_tcp_test.c
create mode 100644 test/unitest/ltran/ltran_instance_test.c
create mode 100644 test/unitest/ltran/ltran_param_test.c
create mode 100644 test/unitest/ltran/ltran_stack_test.c
create mode 100644 test/unitest/ltran/ltran_test_case.h
create mode 100644 test/unitest/ltran/main.c
create mode 100644 test/unitest/stub.c
create mode 100644 test/unitest/test.sh
diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h
index 4fe06cd..b093362 100644
--- a/src/lstack/include/lstack_protocol_stack.h
+++ b/src/lstack/include/lstack_protocol_stack.h
@@ -15,6 +15,7 @@
#include <semaphore.h>
#include <sys/epoll.h>
+#include <stdbool.h>
#include <lwip/list.h>
#include <lwip/netif.h>
diff --git a/test/unitest/CMakeLists.txt b/test/unitest/CMakeLists.txt
new file mode 100644
index 0000000..e4946e8
--- /dev/null
+++ b/test/unitest/CMakeLists.txt
@@ -0,0 +1,17 @@
+# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+# gazelle is licensed under the Mulan PSL v2.
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
+# You may obtain a copy of Mulan PSL v2 at:
+# http://license.coscl.org.cn/MulanPSL2
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+# PURPOSE.
+# See the Mulan PSL v2 for more details.
+
+cmake_minimum_required(VERSION 3.12.1)
+project(gazelle_unittest)
+
+set(CMAKE_C_FLAGS "-g -D_FORTIFY_SOURCE=2 -O3 -fPIE -fstack-protector-strong -msse4.1")
+
+add_subdirectory(lstack)
+add_subdirectory(ltran)
diff --git a/test/unitest/lstack/CMakeLists.txt b/test/unitest/lstack/CMakeLists.txt
new file mode 100644
index 0000000..66dac0f
--- /dev/null
+++ b/test/unitest/lstack/CMakeLists.txt
@@ -0,0 +1,29 @@
+# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+# gazelle is licensed under the Mulan PSL v2.
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
+# You may obtain a copy of Mulan PSL v2 at:
+# http://license.coscl.org.cn/MulanPSL2
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+# PURPOSE.
+# See the Mulan PSL v2 for more details.
+
+cmake_minimum_required(VERSION 3.12.1)
+project(gazelle_unittest)
+
+set(SRC_PATH ../../../src/lstack/core)
+set(COMMON_PATH ../../../src/common)
+set(LIB_PATH ../../../src/lstack /usr/include/dpdk /usr/include/lwip ${COMMON_PATH} ../../../src/lstack/include /usr/lib64)
+set(EXECUTABLE_OUTPUT_PATH ../)
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g -fprofile-arcs -ftest-coverage -lgcov")
+
+set(LIBRTE_LIB rte_pci rte_bus_pci rte_cmdline rte_hash rte_mempool rte_mempool_ring rte_timer rte_eal rte_ring rte_mbuf rte_kni rte_net_ixgbe rte_ethdev rte_net rte_kvargs)
+
+add_executable(lstack_test lstack_param_test.c stub.c main.c ${SRC_PATH}/lstack_cfg.c ${COMMON_PATH}/gazelle_parse_config.c)
+target_include_directories(lstack_test PRIVATE ${LIB_PATH})
+target_link_libraries(lstack_test PRIVATE config boundscheck cunit lwip pthread ${LIBRTE_LIB})
+#target_link_libraries(lstack_param_test PRIVATE config cunit)
+
+target_compile_options(lstack_test PRIVATE -DUSE_LIBOS_MEM)
diff --git a/test/unitest/lstack/config/lstack.conf b/test/unitest/lstack/config/lstack.conf
new file mode 100644
index 0000000..4be9173
--- /dev/null
+++ b/test/unitest/lstack/config/lstack.conf
@@ -0,0 +1,21 @@
+# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+# gazelle is licensed under the Mulan PSL v2.
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
+# You may obtain a copy of Mulan PSL v2 at:
+# http://license.coscl.org.cn/MulanPSL2
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+# PURPOSE.
+# See the Mulan PSL v2 for more details.
+
+dpdk_args=["--socket-mem", "2048,0,0,0", "--huge-dir", "/mnt/hugepages-2M", "--proc-type", "primary"]
+use_ltran=0
+low_power_mode=0
+num_cpus="0,2,4"
+num_weakup="1,3,5"
+
+numa_bind=1
+host_addr="192.168.1.10"
+mask_addr="255.255.255.0"
+gateway_addr="192.168.1.1"
+devices="aa:bb:cc:dd:ee:ff"
diff --git a/test/unitest/lstack/lstack_param_test.c b/test/unitest/lstack/lstack_param_test.c
new file mode 100644
index 0000000..efd07a2
--- /dev/null
+++ b/test/unitest/lstack/lstack_param_test.c
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+ * gazelle is licensed under the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+#include <stdlib.h>
+#include <CUnit/Basic.h>
+#include <CUnit/Automated.h>
+#include <CUnit/Console.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <securec.h>
+#include "lstack_cfg.h"
+
+#define MAX_CMD_LEN 1024
+
+int parse_conf_file(const char *path);
+
+static int execute_cmd(const char *cmd)
+{
+ int result;
+ result = system(cmd);
+ if (result < 0) {
+ printf("Executing cmd: %s error!!!\n", cmd);
+ }
+ return result;
+}
+
+static int lstack_bad_param(const char *conf_file_filed)
+{
+ int ret;
+ const char *conf_file_path = "../lstack/config/lstack_tmp.conf";
+ char cmd[MAX_CMD_LEN];
+
+ execute_cmd("rm -rf ../lstack/config/lstack_tmp.conf");
+ execute_cmd("cp -f ../lstack/config/lstack.conf ../lstack/config/lstack_tmp.conf");
+
+ ret = sprintf_s(cmd, MAX_CMD_LEN, "sed -i '%s' %s", conf_file_filed, conf_file_path);
+ if (ret < 0) {
+ printf("sprintf_s cmd error %s %s!!!\n", conf_file_filed, conf_file_path);
+ return ret;
+ }
+
+ execute_cmd(cmd);
+
+ ret = parse_conf_file(conf_file_path);
+
+ return ret;
+}
+
+void test_lstack_bad_params_lowpower(void)
+{
+ /* lstack start lowpower empty */
+ CU_ASSERT(lstack_bad_param("/^low_power_mode/clow_power_mode=/") != 0);
+
+ /* lstack start lowpower none */
+ CU_ASSERT(lstack_bad_param("/low_power_mode/d") == 0);
+
+ /* lstack start lowpower exceed str */
+ CU_ASSERT(lstack_bad_param("/^low_power_mode/clow_power_mode=aaa/") != 0);
+}
+
+void test_lstack_bad_params_num_cpus(void)
+{
+ /* lstack start num_cpus empty */
+ CU_ASSERT(lstack_bad_param("/^num_cpus/cnum_cpus=/") != 0);
+
+ /* lstack start num_cpus none */
+ CU_ASSERT(lstack_bad_param("/num_cpus/d") != 0);
+
+ /* lstack start num_cpus exceed str */
+ CU_ASSERT(lstack_bad_param("/^num_cpus/cnum_cpus=aaa/") != 0);
+}
+
+void test_lstack_bad_params_host_addr(void)
+{
+ /* lstack start host_addr empty */
+ CU_ASSERT(lstack_bad_param("/^host_addr/chost_addr=/") != 0);
+
+ /* lstack start host_addr none */
+ CU_ASSERT(lstack_bad_param("/^host_addr/d") != 0);
+
+ /* lstack start host_addr invaild str */
+ CU_ASSERT(lstack_bad_param("/^host_addr/chost_addr=\"aaa\"/") != 0);
+
+ /* lstack start host_addr exceed str */
+ CU_ASSERT(lstack_bad_param("/^host_addr/chost_addr=\"192.168.1.256\"/") != 0);
+}
+
+void test_lstack_bad_params_mask_addr(void)
+{
+ /* lstack start mask_addr empty */
+ CU_ASSERT(lstack_bad_param("/^mask_addr/cmask_addr=/") != 0);
+
+ /* lstack start mask_addr none */
+ CU_ASSERT(lstack_bad_param("/^mask_addr/d") != 0);
+
+ /* lstack start mask_addr invaild str */
+ CU_ASSERT(lstack_bad_param("/^mask_addr/cmask_addr=\"aaa\"/") != 0);
+
+ /* lstack start mask_addr exceed str */
+ CU_ASSERT(lstack_bad_param("/^mask_addr/cmask_addr=\"256.255.255.0\"/") != 0);
+
+ /* lstack start mask_addr exceed str */
+ CU_ASSERT(lstack_bad_param("/^mask_addr/cmask_addr=\"255.254.255.0\"/") != 0);
+}
+
+void test_lstack_bad_params_gateway_addr(void)
+{
+ /* lstack start gateway_addr empty */
+ CU_ASSERT(lstack_bad_param("/^gateway_addr/cgateway_addr=/") != 0);
+
+ /* lstack start gateway_addr none */
+ CU_ASSERT(lstack_bad_param("/^gateway_addr/d") != 0);
+
+ /* lstack start gateway_addr invaild str */
+ CU_ASSERT(lstack_bad_param("/^gateway_addr/cgateway_addr=\"aaa\"/") != 0);
+
+ /* lstack start gateway_addr exceed str */
+ CU_ASSERT(lstack_bad_param("/^gateway_addr/cgateway_addr=\"192.168.1.256\"/") != 0);
+}
+
+void test_lstack_bad_params_devices(void)
+{
+ /* lstack start devices empty */
+ CU_ASSERT(lstack_bad_param("/^devices/cdevices=/") != 0);
+
+ /* lstack start devices none */
+ CU_ASSERT(lstack_bad_param("/^devices/d") != 0);
+
+ /* lstack start devices invaild str */
+ CU_ASSERT(lstack_bad_param("/^devices/cdevices=\"aaa\"/") != 0);
+
+ /* lstack start devices exceed str */
+ CU_ASSERT(lstack_bad_param("/^devices/cdevices=\"ff:ff:ff:ff:ff:ff:ff\"/") != 0);
+
+ /* lstack start devices exceed str */
+ CU_ASSERT(lstack_bad_param("/^devices/cdevices=\"ff:ff:ff:ff:ff-ff\"/") != 0);
+
+ /* lstack start devices exceed str */
+ CU_ASSERT(lstack_bad_param("/^devices/cdevices=\"ff:ff:ff:ff:ff:fg\"/") != 0);
+}
+
+void test_lstack_normal_param(void)
+{
+ int ret;
+ char ip_str[16] = {0}; /* 16:IP max len */
+ char str[18] = {0};
+ const char *config_file_path = "../lstack/config/lstack.conf";
+
+ ret = parse_conf_file(config_file_path);
+ CU_ASSERT(ret == 0);
+ struct cfg_params *global_params = get_global_cfg_params();
+ for (int i =0; i< global_params->dpdk_argc; i++)
+ printf("arcv is %s\n", global_params->dpdk_argv[i]);
+
+ CU_ASSERT(global_params->dpdk_argc == 9); /* 9:参数个数 */
+ CU_ASSERT(strcmp(global_params->dpdk_argv[0], "lstack") == 0);
+ CU_ASSERT(strcmp(global_params->dpdk_argv[1], "--socket-mem") == 0); /* 1:lstack 参数 */
+ CU_ASSERT(strcmp(global_params->dpdk_argv[2], "2048,0,0,0") == 0); /* 2:lstack 参数 */
+ CU_ASSERT(strcmp(global_params->dpdk_argv[3], "--huge-dir") == 0); /* 3:lstack socket内存参数 */
+ CU_ASSERT(strcmp(global_params->dpdk_argv[4], "/mnt/hugepages-2M") == 0); /* 4:lstack socket内存值 */
+ CU_ASSERT(strcmp(global_params->dpdk_argv[5], "--proc-type") == 0); /* 5:lstack huge路径参数 */
+ CU_ASSERT(strcmp(global_params->dpdk_argv[6], "primary") == 0); /* 6:lstack huge路径值 */
+ CU_ASSERT(strcmp(global_params->dpdk_argv[7], "-l") == 0); /* 7:lstack进程类型参数 */
+ CU_ASSERT(strcmp(global_params->dpdk_argv[8], "0,2,4") == 0); /* 8:lstack参数 */
+
+ struct in_addr tmp_subnet;
+ tmp_subnet.s_addr = global_params->host_addr.addr;
+ char *subnet_str = strdup(inet_ntop(AF_INET, &tmp_subnet, ip_str, sizeof(ip_str)));
+ CU_ASSERT(subnet_str != NULL);
+ CU_ASSERT(strcmp(subnet_str, "192.168.1.10") == 0);
+ free(subnet_str);
+
+ tmp_subnet.s_addr = global_params->netmask.addr;
+ subnet_str = strdup(inet_ntop(AF_INET, &tmp_subnet, ip_str, sizeof(ip_str)));
+ CU_ASSERT(subnet_str != NULL);
+ CU_ASSERT(strcmp(subnet_str, "255.255.255.0") == 0);
+ free(subnet_str);
+
+ tmp_subnet.s_addr = global_params->gateway_addr.addr;
+ subnet_str = strdup(inet_ntop(AF_INET, &tmp_subnet, ip_str, sizeof(ip_str)));
+ CU_ASSERT(subnet_str != NULL);
+ CU_ASSERT(strcmp(subnet_str, "192.168.1.1") == 0);
+ free(subnet_str);
+
+ /* MAC地址转换为字符串 */
+ ret = sprintf_s(str, sizeof(str), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", global_params->mac_addr[0],
+ global_params->mac_addr[1],
+ global_params->mac_addr[2], // 2mac地址
+ global_params->mac_addr[3], // 3mac地址
+ global_params->mac_addr[4], // 4mac地址
+ global_params->mac_addr[5]); // 5mac地址
+ CU_ASSERT(ret > 0);
+ CU_ASSERT(strcmp(str, "aa:bb:cc:dd:ee:ff") == 0); /* 匹配的MAC地址 */
+}
diff --git a/test/unitest/lstack/lstack_test_case.h b/test/unitest/lstack/lstack_test_case.h
new file mode 100644
index 0000000..cdb2550
--- /dev/null
+++ b/test/unitest/lstack/lstack_test_case.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+ * gazelle is licensed under the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+#ifndef __LSTACK_TEST_CASE_H__
+#define __LSTACK_TEST_CASE_H__
+
+void test_lstack_normal_param(void);
+void test_lstack_bad_params_devices(void);
+void test_lstack_bad_params_gateway_addr(void);
+void test_lstack_bad_params_mask_addr(void);
+void test_lstack_bad_params_host_addr(void);
+void test_lstack_bad_params_num_cpus(void);
+void test_lstack_bad_params_lowpower(void);
+
+#endif
diff --git a/test/unitest/lstack/lstack_unit_test.c b/test/unitest/lstack/lstack_unit_test.c
new file mode 100644
index 0000000..041a7cc
--- /dev/null
+++ b/test/unitest/lstack/lstack_unit_test.c
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+ * gazelle is licensed under the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+#include <stdlib.h>
+#include <CUnit/Basic.h>
+#include <CUnit/Automated.h>
+#include <CUnit/Console.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <securec.h>
+#include "lstack_cfg.h"
+
+#define MAX_CMD_LEN 1024
+
+int parse_conf_file(const char *path);
+
+static int execute_cmd(const char *cmd)
+{
+ int result;
+ result = system(cmd);
+ if (result < 0) {
+ printf("Executing cmd: %s error!!!\n", cmd);
+ }
+ return result;
+}
+
+static int lstack_bad_param(const char *conf_file_filed)
+{
+ int ret;
+ const char *conf_file_path = "../lstack/config/lstack_tmp.conf";
+ char cmd[MAX_CMD_LEN];
+
+ execute_cmd("rm -rf ../lstack/config/lstack_tmp.conf");
+ execute_cmd("cp -f ../lstack/config/lstack.conf ../lstack/config/lstack_tmp.conf");
+
+ ret = sprintf_s(cmd, MAX_CMD_LEN, "sed -i '%s' %s", conf_file_filed, conf_file_path);
+ if (ret < 0) {
+ printf("sprintf_s cmd error %s %s!!!\n", conf_file_filed, conf_file_path);
+ return ret;
+ }
+
+ execute_cmd(cmd);
+
+ ret = parse_conf_file(conf_file_path);
+
+ return ret;
+}
+
+void test_lstack_bad_params_lowpower(void)
+{
+ /* lstack start lowpower empty */
+ CU_ASSERT(lstack_bad_param("/^low_power_mode/clow_power_mode=/") != 0);
+
+ /* lstack start lowpower none */
+ CU_ASSERT(lstack_bad_param("/low_power_mode/d") == 0);
+
+ /* lstack start lowpower exceed str */
+ CU_ASSERT(lstack_bad_param("/^low_power_mode/clow_power_mode=aaa/") != 0);
+}
+
+void test_lstack_bad_params_num_cpus(void)
+{
+ /* lstack start num_cpus empty */
+ CU_ASSERT(lstack_bad_param("/^num_cpus/cnum_cpus=/") != 0);
+
+ /* lstack start num_cpus none */
+ CU_ASSERT(lstack_bad_param("/num_cpus/d") != 0);
+
+ /* lstack start num_cpus exceed str */
+ CU_ASSERT(lstack_bad_param("/^num_cpus/cnum_cpus=aaa/") != 0);
+}
+
+void test_lstack_bad_params_host_addr(void)
+{
+ /* lstack start host_addr empty */
+ CU_ASSERT(lstack_bad_param("/^host_addr/chost_addr=/") != 0);
+
+ /* lstack start host_addr none */
+ CU_ASSERT(lstack_bad_param("/^host_addr/d") != 0);
+
+ /* lstack start host_addr invaild str */
+ CU_ASSERT(lstack_bad_param("/^host_addr/chost_addr=\"aaa\"/") != 0);
+
+ /* lstack start host_addr exceed str */
+ CU_ASSERT(lstack_bad_param("/^host_addr/chost_addr=\"192.168.1.256\"/") != 0);
+}
+
+void test_lstack_bad_params_mask_addr(void)
+{
+ /* lstack start mask_addr empty */
+ CU_ASSERT(lstack_bad_param("/^mask_addr/cmask_addr=/") != 0);
+
+ /* lstack start mask_addr none */
+ CU_ASSERT(lstack_bad_param("/^mask_addr/d") != 0);
+
+ /* lstack start mask_addr invaild str */
+ CU_ASSERT(lstack_bad_param("/^mask_addr/cmask_addr=\"aaa\"/") != 0);
+
+ /* lstack start mask_addr exceed str */
+ CU_ASSERT(lstack_bad_param("/^mask_addr/cmask_addr=\"256.255.255.0\"/") != 0);
+
+ /* lstack start mask_addr exceed str */
+ CU_ASSERT(lstack_bad_param("/^mask_addr/cmask_addr=\"255.254.255.0\"/") != 0);
+}
+
+void test_lstack_bad_params_gateway_addr(void)
+{
+ /* lstack start gateway_addr empty */
+ CU_ASSERT(lstack_bad_param("/^gateway_addr/cgateway_addr=/") != 0);
+
+ /* lstack start gateway_addr none */
+ CU_ASSERT(lstack_bad_param("/^gateway_addr/d") != 0);
+
+ /* lstack start gateway_addr invaild str */
+ CU_ASSERT(lstack_bad_param("/^gateway_addr/cgateway_addr=\"aaa\"/") != 0);
+
+ /* lstack start gateway_addr exceed str */
+ CU_ASSERT(lstack_bad_param("/^gateway_addr/cgateway_addr=\"192.168.1.256\"/") != 0);
+}
+
+void test_lstack_bad_params_devices(void)
+{
+ /* lstack start devices empty */
+ CU_ASSERT(lstack_bad_param("/^devices/cdevices=/") != 0);
+
+ /* lstack start devices none */
+ CU_ASSERT(lstack_bad_param("/^devices/d") != 0);
+
+ /* lstack start devices invaild str */
+ CU_ASSERT(lstack_bad_param("/^devices/cdevices=\"aaa\"/") != 0);
+
+ /* lstack start devices exceed str */
+ CU_ASSERT(lstack_bad_param("/^devices/cdevices=\"ff:ff:ff:ff:ff:ff:ff\"/") != 0);
+
+ /* lstack start devices exceed str */
+ CU_ASSERT(lstack_bad_param("/^devices/cdevices=\"ff:ff:ff:ff:ff-ff\"/") != 0);
+
+ /* lstack start devices exceed str */
+ CU_ASSERT(lstack_bad_param("/^devices/cdevices=\"ff:ff:ff:ff:ff:fg\"/") != 0);
+}
+
+void test_lstack_normal_param(void)
+{
+ int ret;
+ char ip_str[16] = {0}; /* 16:IP max len */
+ char str[18] = {0};
+ const char *config_file_path = "../lstack/config/lstack.conf";
+
+ ret = parse_conf_file(config_file_path);
+ CU_ASSERT(ret == 0);
+ struct cfg_params *global_params = get_global_cfg_params();
+ for (int i =0; i< global_params->dpdk_argc; i++)
+ printf("arcv is %s\n", global_params->dpdk_argv[i]);
+
+ CU_ASSERT(global_params->dpdk_argc == 9); /* 9:参数个数 */
+ CU_ASSERT(strcmp(global_params->dpdk_argv[0], "lstack") == 0);
+ CU_ASSERT(strcmp(global_params->dpdk_argv[1], "--socket-mem") == 0); /* 1:lstack 参数 */
+ CU_ASSERT(strcmp(global_params->dpdk_argv[2], "2048,0,0,0") == 0); /* 2:lstack 参数 */
+ CU_ASSERT(strcmp(global_params->dpdk_argv[3], "--huge-dir") == 0); /* 3:lstack socket内存参数 */
+ CU_ASSERT(strcmp(global_params->dpdk_argv[4], "/mnt/hugepages-2M") == 0); /* 4:lstack socket内存值 */
+ CU_ASSERT(strcmp(global_params->dpdk_argv[5], "--proc-type") == 0); /* 5:lstack huge路径参数 */
+ CU_ASSERT(strcmp(global_params->dpdk_argv[6], "primary") == 0); /* 6:lstack huge路径值 */
+ CU_ASSERT(strcmp(global_params->dpdk_argv[7], "-l") == 0); /* 7:lstack进程类型参数 */
+ CU_ASSERT(strcmp(global_params->dpdk_argv[8], "0,2,4") == 0); /* 8:lstack参数 */
+
+ struct in_addr tmp_subnet;
+ tmp_subnet.s_addr = global_params->host_addr.addr;
+ char *subnet_str = strdup(inet_ntop(AF_INET, &tmp_subnet, ip_str, sizeof(ip_str)));
+ CU_ASSERT(subnet_str != NULL);
+ CU_ASSERT(strcmp(subnet_str, "192.168.1.10") == 0);
+ free(subnet_str);
+
+ tmp_subnet.s_addr = global_params->netmask.addr;
+ subnet_str = strdup(inet_ntop(AF_INET, &tmp_subnet, ip_str, sizeof(ip_str)));
+ CU_ASSERT(subnet_str != NULL);
+ CU_ASSERT(strcmp(subnet_str, "255.255.255.0") == 0);
+ free(subnet_str);
+
+ tmp_subnet.s_addr = global_params->gateway_addr.addr;
+ subnet_str = strdup(inet_ntop(AF_INET, &tmp_subnet, ip_str, sizeof(ip_str)));
+ CU_ASSERT(subnet_str != NULL);
+ CU_ASSERT(strcmp(subnet_str, "192.168.1.1") == 0);
+ free(subnet_str);
+
+ /* MAC地址转换为字符串 */
+ ret = sprintf_s(str, sizeof(str), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", global_params->ethdev.addr_bytes[0],
+ global_params->ethdev.addr_bytes[1],
+ global_params->ethdev.addr_bytes[2], // 2mac地址
+ global_params->ethdev.addr_bytes[3], // 3mac地址
+ global_params->ethdev.addr_bytes[4], // 4mac地址
+ global_params->ethdev.addr_bytes[5]); // 5mac地址
+ CU_ASSERT(ret > 0);
+ CU_ASSERT(strcmp(str, "aa:bb:cc:dd:ee:ff") == 0); /* 匹配的MAC地址 */
+}
diff --git a/test/unitest/lstack/main.c b/test/unitest/lstack/main.c
new file mode 100644
index 0000000..84285dd
--- /dev/null
+++ b/test/unitest/lstack/main.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+ * gazelle is licensed under the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+#include <stdlib.h>
+#include <CUnit/Basic.h>
+#include <CUnit/Automated.h>
+#include <CUnit/Console.h>
+#include "lstack_test_case.h"
+
+typedef enum {
+ LSTACK_SCREEN = 0,
+ LSTACK_XMLFILE,
+ LSTACK_CONSOLE
+} CU_RunMode;
+
+int main(int argc, char **argv)
+{
+ CU_pSuite suite;
+ int num_failures;
+ CU_RunMode g_cunit_mode = LSTACK_SCREEN;
+
+ if (argc > 1) {
+ g_cunit_mode = atoi(argv[1]);
+ }
+
+ if (CU_initialize_registry() != CUE_SUCCESS) {
+ return CU_get_error();
+ }
+
+ suite = CU_add_suite("lstack", NULL, NULL);
+ if (suite == NULL) {
+ CU_cleanup_registry();
+ return CU_get_error();
+ }
+
+ (void)CU_ADD_TEST(suite, test_lstack_normal_param);
+ (void)CU_ADD_TEST(suite, test_lstack_bad_params_devices);
+ (void)CU_ADD_TEST(suite, test_lstack_bad_params_gateway_addr);
+ (void)CU_ADD_TEST(suite, test_lstack_bad_params_mask_addr);
+ (void)CU_ADD_TEST(suite, test_lstack_bad_params_host_addr);
+ (void)CU_ADD_TEST(suite, test_lstack_bad_params_num_cpus);
+ (void)CU_ADD_TEST(suite, test_lstack_bad_params_lowpower);
+
+ switch (g_cunit_mode) {
+ case LSTACK_SCREEN:
+ CU_basic_set_mode(CU_BRM_VERBOSE);
+ CU_basic_run_tests();
+ break;
+ case LSTACK_XMLFILE:
+ CU_set_output_filename("param");
+ CU_list_tests_to_file();
+ CU_automated_run_tests();
+ break;
+ case LSTACK_CONSOLE:
+ CU_console_run_tests();
+ break;
+ default:
+ (void)printf("not suport cunit mode, only suport: 0 or 1\n");
+ CU_cleanup_registry();
+ return CU_get_error();
+ }
+
+ num_failures = (int)CU_get_number_of_failures();
+ CU_cleanup_registry();
+ return num_failures;
+}
diff --git a/test/unitest/lstack/stub.c b/test/unitest/lstack/stub.c
new file mode 100644
index 0000000..f1a3a84
--- /dev/null
+++ b/test/unitest/lstack/stub.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+ * gazelle is licensed under the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <arch/sys_arch.h>
+#include <lwip/sys.h>
+#include <lwip/api.h>
+
+int lwip_epoll_create(int size)
+{
+ return 0;
+}
+int lwip_epoll_ctl(int epfd, int op, int fd, const void *event)
+{
+ return 0;
+}
+int lwip_epoll_wait(int epfd, const void* events, int maxevents, int timeout)
+{
+ return 0;
+}
+void libnet_per_thread_init(void)
+{
+ return;
+}
+int lwip_sigaction(int signum, const void *act, const void *oldact)
+{
+ return 0;
+}
+int lwip_fork(void)
+{
+ return 0;
+}
+int del_epoll_event(const void *conn, int event)
+{
+ return 0;
+}
+int add_epoll_event(const void *conn, int event)
+{
+ return 0;
+}
+int rearm_accept_fd(int fd)
+{
+ return 0;
+}
+void clean_host_fd(int fd)
+{
+ return;
+}
+int rearm_host_fd(int fd)
+{
+ return 0;
+}
+int lwip_is_epfd(int epfd)
+{
+ return 0;
+}
+int lwip_epoll_close(int epfd)
+{
+ return 0;
+}
+int eth_dev_poll(void)
+{
+ return 0;
+}
+int vdev_reg_xmit(int type, const void *qtuple)
+{
+ return 0;
+}
+
+void *__wrap_memp_malloc(int type)
+{
+ void *memp;
+
+ memp = malloc(5 * 1024 * 1024); /* 5 * 1024 * 1024 = 5M */
+
+ return memp;
+}
+
+int __wrap_sys_mbox_new(const struct sys_mbox **mb, int size)
+{
+ return 0;
+}
+
+int __wrap_netconn_prepare_delete(const struct netconn *conn)
+{
+ return 0;
+}
+
+int __wrap_netconn_delete(struct netconn *conn)
+{
+ if (conn != NULL) {
+ free(conn->pcb.tcp);
+ free(conn->op_completed);
+ free(conn);
+ conn = NULL;
+ }
+ return 0;
+}
diff --git a/test/unitest/ltran/CMakeLists.txt b/test/unitest/ltran/CMakeLists.txt
new file mode 100644
index 0000000..9496053
--- /dev/null
+++ b/test/unitest/ltran/CMakeLists.txt
@@ -0,0 +1,58 @@
+# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+# gazelle is licensed under the Mulan PSL v2.
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
+# You may obtain a copy of Mulan PSL v2 at:
+# http://license.coscl.org.cn/MulanPSL2
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+# PURPOSE.
+# See the Mulan PSL v2 for more details.
+
+cmake_minimum_required(VERSION 3.12.1)
+project(gazelle_unittest)
+
+set(LIB_PATH ../../../src/ltran /usr/include/dpdk ../../../src/common ../../../src/lstack/include)
+set(SRC_PATH_LTRAN ../../../src/ltran)
+set(EXECUTABLE_OUTPUT_PATH ../)
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g -fprofile-arcs -ftest-coverage -lgcov")
+
+add_executable(ltran_test
+ ltran_instance_test.c
+ ltran_param_test.c
+ ltran_stack_test.c
+ libnet_tcp_test.c
+ main.c
+ ../stub.c
+ ${SRC_PATH_LTRAN}/ltran_param.c
+ ${SRC_PATH_LTRAN}/ltran_errno.c
+ ${SRC_PATH_LTRAN}/ltran_instance.c
+ ${SRC_PATH_LTRAN}/ltran_stack.c
+ ${SRC_PATH_LTRAN}/ltran_tcp_sock.c
+ ${SRC_PATH_LTRAN}/ltran_tcp_conn.c
+ ${SRC_PATH_LTRAN}/../common/gazelle_dfx_msg.c
+ ${SRC_PATH_LTRAN}/../common/gazelle_parse_config.c
+)
+
+set_target_properties(ltran_test PROPERTIES LINK_FLAGS "-L$ENV{DPDK_LIB_PATH} -Wl,--whole-archive -Wl,-lrte_pipeline -Wl,--wrap=rte_free -Wl,--wrap=rte_malloc \
+ -Wl,--no-whole-archive -Wl,--whole-archive -Wl,-lrte_table -Wl,--no-whole-archive -Wl,--whole-archive -Wl,-lrte_port -Wl,--no-whole-archive \
+ -Wl,-lrte_distributor -Wl,-lrte_ip_frag -Wl,-lrte_meter -Wl,-lrte_lpm -Wl,--whole-archive -Wl,-lrte_acl -Wl,--no-whole-archive \
+ -Wl,-lrte_jobstats -Wl,-lrte_bitratestats -Wl,-lrte_metrics -Wl,-lrte_latencystats -Wl,-lrte_power -Wl,-lrte_efd -Wl,-lrte_bpf \
+ -Wl,--whole-archive -Wl,-lrte_gro -Wl,-lrte_cfgfile -Wl,-lrte_gso -Wl,-lrte_hash -Wl,-lrte_member -Wl,-lrte_vhost -Wl,-lrte_kvargs \
+ -Wl,-lrte_mbuf -Wl,-lrte_ethdev -Wl,-lrte_net -Wl,-lrte_bbdev -Wl,-lrte_cryptodev -Wl,-lrte_security -Wl,-lrte_compressdev -Wl,-lrte_eventdev \
+ -Wl,-lrte_rawdev -Wl,-lrte_timer -Wl,-lrte_mempool -Wl,-lrte_mempool_ring -Wl,-lrte_ring -Wl,-lrte_pci \
+ -Wl,-Bstatic -lrte_eal -Wl,-Bdynamic -Wl,-lrte_cmdline \
+ -Wl,-lrte_sched -Wl,-lrte_reorder -Wl,-lrte_kni -Wl,-lrte_common_cpt -Wl,-lrte_common_octeontx -Wl,-lrte_common_dpaax -Wl,-lrte_bus_pci \
+ -Wl,-lrte_bus_dpaa -Wl,-lrte_bus_vdev -Wl,-lrte_bus_fslmc -Wl,-lrte_mempool_bucket -Wl,-lrte_mempool_stack -Wl,-lrte_mempool_dpaa \
+ -Wl,-lrte_mempool_dpaa2 -Wl,-lrte_net_af_packet -Wl,-lrte_net_ark -Wl,-lrte_net_atlantic -Wl,-lrte_net_axgbe \
+ -Wl,-lrte_net_bnxt -Wl,-lrte_net_bond -Wl,-lrte_net_cxgbe -Wl,-lrte_net_dpaa -Wl,-lrte_net_dpaa2 -Wl,-lrte_net_e1000 -Wl,-lrte_net_ena \
+ -Wl,-lrte_net_enetc -Wl,-lrte_net_enic -Wl,-lrte_net_failsafe -Wl,-lrte_net_i40e -Wl,-lrte_net_hinic -Wl,-lrte_net_ixgbe -Wl,-lrte_net_kni \
+ -Wl,-lrte_net_nfp -Wl,-lrte_net_null -Wl,-lpcap -Wl,-lrte_net_qede -Wl,-lrte_net_ring -Wl,-lrte_net_softnic \
+ -Wl,-lrte_net_tap -Wl,-lrte_net_vdev_netvsc -Wl,-lrte_net_virtio -Wl,-lrte_net_vhost \
+ -Wl,-lrte_bus_vmbus -Wl,-lrte_net_netvsc -Wl,-lrte_mempool_octeontx -Wl,-lrte_net_octeontx \
+ -Wl,-lrte_bus_ifpga -Wl,-lrte_stack -Wl,-lrte_telemetry\
+ -Wl,--no-whole-archive -Wl,-lm -Wl,-lrt -Wl,-lnuma -Wl,-ldl -Wl,-export-dynamic -Wl,-export-dynamic \
+ -Wl,--as-needed -Wl,-export-dynamic -Wl,-Map=ltran.map -Wl,--cref")
+target_include_directories(ltran_test PRIVATE ${LIB_PATH})
+target_link_libraries(ltran_test PRIVATE config boundscheck cunit pthread)
diff --git a/test/unitest/ltran/config/ltran.conf b/test/unitest/ltran/config/ltran.conf
new file mode 100644
index 0000000..bbab844
--- /dev/null
+++ b/test/unitest/ltran/config/ltran.conf
@@ -0,0 +1,23 @@
+# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+# gazelle is licensed under the Mulan PSL v2.
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
+# You may obtain a copy of Mulan PSL v2 at:
+# http://license.coscl.org.cn/MulanPSL2
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+# PURPOSE.
+# See the Mulan PSL v2 for more details.
+
+forward_kit = "dpdk"
+forward_kit_args = "-l 0,1 --socket-mem 1024,0,0,0 --huge-dir /mnt/hugepages --proc-type auto -n 4"
+kni_switch = 0
+
+dispatch_subnet = "192.168.1.0"
+dispatch_subnet_length = 8
+dispatch_max_clients = 32
+
+bond_mode = 1
+bond_miimon = 100
+bond_mtu = 1500
+bond_ports = "0x3, 0xC"
+bond_macs = "52:54:00:25:ef:e0, aa:bb:cc:dd:ee:ff"
diff --git a/test/unitest/ltran/libnet_tcp_test.c b/test/unitest/ltran/libnet_tcp_test.c
new file mode 100644
index 0000000..6a6eadc
--- /dev/null
+++ b/test/unitest/ltran/libnet_tcp_test.c
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+ * gazelle is licensed under the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+#include <stdlib.h>
+#include <CUnit/Basic.h>
+#include <CUnit/Automated.h>
+#include <CUnit/Console.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <securec.h>
+#include "ltran_tcp_sock.h"
+#include "ltran_tcp_conn.h"
+
+#define MAX_CONN 10
+#define MAX_SOCK 10
+void test_tcp_conn(void)
+{
+ struct gazelle_tcp_conn_htable *tcp_conn_htable = NULL;
+ struct gazelle_tcp_conn *tcp_conn = NULL;
+ struct gazelle_tcp_conn *exist_tcp_conn = NULL;
+ struct gazelle_quintuple quintuple;
+ /* 1: set instance on */
+ int32_t instance_cur_tick = 1;
+
+ tcp_conn_htable = gazelle_tcp_conn_htable_create(MAX_CONN);
+ CU_ASSERT(tcp_conn_htable != NULL);
+ gazelle_set_tcp_conn_htable(tcp_conn_htable);
+
+ quintuple.src_ip = inet_addr("192.168.1.1");
+ quintuple.dst_ip = inet_addr("192.168.1.2");
+ quintuple.src_port = 22; /* 22:src port id */
+ quintuple.dst_port = 23; /* 23:dst port id */
+ quintuple.protocol = 0;
+ tcp_conn = gazelle_conn_add_by_quintuple(gazelle_get_tcp_conn_htable(), &quintuple);
+ CU_ASSERT(tcp_conn != NULL);
+ tcp_conn->instance_cur_tick = &instance_cur_tick;
+ /* 1: set instacn_cur_tick = instance_reg_tick indicate instance is on */
+ tcp_conn->instance_reg_tick = 1;
+
+ exist_tcp_conn = gazelle_conn_get_by_quintuple(gazelle_get_tcp_conn_htable(), &quintuple);
+ CU_ASSERT(exist_tcp_conn != NULL);
+
+ gazelle_conn_del_by_quintuple(gazelle_get_tcp_conn_htable(), &quintuple);
+ exist_tcp_conn = gazelle_conn_get_by_quintuple(gazelle_get_tcp_conn_htable(), &quintuple);
+ CU_ASSERT(exist_tcp_conn == NULL);
+
+ gazelle_conn_del_by_quintuple(gazelle_get_tcp_conn_htable(), &quintuple);
+
+ for (int i = 0; i <= MAX_CONN; i++) {
+ quintuple.src_port++;
+ tcp_conn = gazelle_conn_add_by_quintuple(gazelle_get_tcp_conn_htable(), &quintuple);
+ if (i < MAX_CONN) {
+ CU_ASSERT(tcp_conn != NULL);
+ tcp_conn->instance_cur_tick = &instance_cur_tick;
+ /* 1: set instacn_cur_tick = instance_reg_tick indicate instance is on */
+ tcp_conn->instance_reg_tick = 1;
+ } else {
+ CU_ASSERT(tcp_conn == NULL);
+ }
+
+ tcp_conn = gazelle_conn_get_by_quintuple(gazelle_get_tcp_conn_htable(), &quintuple);
+ if (i < MAX_CONN) {
+ CU_ASSERT(tcp_conn != NULL);
+ } else {
+ CU_ASSERT(tcp_conn == NULL);
+ }
+ }
+
+ gazelle_tcp_conn_htable_destroy();
+}
+
+void test_tcp_sock(void)
+{
+ char ip_str[16] = {0};
+ struct in_addr tmp_subnet;
+ struct gazelle_tcp_sock *tcp_sock = NULL;
+ struct gazelle_tcp_sock *exist_tcp_sock = NULL;
+ /* 1: set instance on */
+ int32_t instance_cur_tick = 1;
+
+ gazelle_set_tcp_sock_htable(gazelle_tcp_sock_htable_create(MAX_SOCK));
+ gazelle_set_tcp_conn_htable(gazelle_tcp_conn_htable_create(GAZELLE_MAX_CONN_NUM));
+
+ /* 22:dst port id 1111:dst tid number */
+ tcp_sock = gazelle_sock_add_by_ipporttid(gazelle_get_tcp_sock_htable(), inet_addr("192.168.1.1"), 22, 1111);
+ CU_ASSERT(tcp_sock != NULL);
+ CU_ASSERT(tcp_sock->tid == 1111); /* 1111:tid number */
+ CU_ASSERT(tcp_sock->port == 22); /* 22:port id */
+
+ tmp_subnet.s_addr = tcp_sock->ip;
+ CU_ASSERT(strcmp(inet_ntoa(tmp_subnet), "192.168.1.1") == 0);
+ tcp_sock->instance_cur_tick = &instance_cur_tick;
+ /* 1: set instacn_cur_tick = instance_reg_tick indicate instance is on */
+ tcp_sock->instance_reg_tick = 1;
+
+ /* 22:port id */
+ exist_tcp_sock = gazelle_sock_get_by_min_conn(gazelle_get_tcp_sock_htable(), inet_addr("192.168.1.1"), 22);
+ CU_ASSERT(exist_tcp_sock != NULL);
+ CU_ASSERT(exist_tcp_sock->tid == 1111); /* 1111:tid number */
+
+ /* 22:dst port id 1111:dst tid number */
+ gazelle_sock_del_by_ipporttid(gazelle_get_tcp_sock_htable(), inet_addr("192.168.1.1"), 22, 1111);
+ /* 22:dst port id */
+ exist_tcp_sock = gazelle_sock_get_by_min_conn(gazelle_get_tcp_sock_htable(), inet_addr("192.168.1.1"), 22);
+ CU_ASSERT(exist_tcp_sock == NULL);
+
+ /* 22:port id 1111:dst tid number */
+ gazelle_sock_del_by_ipporttid(gazelle_get_tcp_sock_htable(), inet_addr("192.168.1.1"), 22, 1111);
+
+ for (int i = 0; i <= MAX_CONN; i++) {
+ /* 22:dst port id 1111:dst tid number */
+ tcp_sock = gazelle_sock_add_by_ipporttid(gazelle_get_tcp_sock_htable(), inet_addr("192.168.1.1"), 22, i);
+ if (i < MAX_CONN) {
+ CU_ASSERT(tcp_sock != NULL);
+ } else {
+ CU_ASSERT(tcp_sock == NULL);
+ }
+ }
+
+ gazelle_tcp_sock_htable_destroy();
+}
diff --git a/test/unitest/ltran/ltran_instance_test.c b/test/unitest/ltran/ltran_instance_test.c
new file mode 100644
index 0000000..53acea1
--- /dev/null
+++ b/test/unitest/ltran/ltran_instance_test.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+ * gazelle is licensed under the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+#include <stdlib.h>
+#include <CUnit/Basic.h>
+#include <CUnit/Automated.h>
+#include <CUnit/Console.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <securec.h>
+#include "ltran_instance.h"
+#include "ltran_param.h"
+#include "ltran_stack.h"
+
+void test_ltran_instance(void)
+{
+ struct gazelle_instance *instance = NULL;
+ uint32_t ret;
+
+ get_ltran_config()->dispatcher.num_clients = 30; /* 30:clients num */
+ get_ltran_config()->dispatcher.ipv4_subnet_size = 256; /* 256:ipv4 subnet size */
+ get_ltran_config()->dispatcher.ipv4_net_mask = get_ltran_config()->dispatcher.ipv4_subnet_size - 1;
+ set_instance_mgr(gazelle_instance_mgr_create());
+ CU_ASSERT(get_instance_mgr() != NULL);
+
+ instance = gazelle_instance_add_by_pid(get_instance_mgr(), 1111); /* 1111:test pid */
+ CU_ASSERT(instance != NULL);
+ CU_ASSERT(instance->pid == 1111); /* 1111:test pid */
+
+ instance = gazelle_instance_get_by_pid(get_instance_mgr(), 1111); /* 1111:test pid */
+ CU_ASSERT(instance != NULL);
+ CU_ASSERT(instance->pid == 1111); /* 1111:test pid */
+
+ instance->ip_addr.s_addr = inet_addr("192.168.1.1");
+
+ instance = gazelle_instance_get_by_ip(get_instance_mgr(), inet_addr("192.168.1.1"));
+ CU_ASSERT(instance != NULL);
+ CU_ASSERT(instance->pid == 1111); /* 1111:test pid */
+ CU_ASSERT(instance->ip_addr.s_addr == inet_addr("192.168.1.1"));
+
+ instance = gazelle_instance_get_by_ip(get_instance_mgr(), inet_addr("192.168.1.2"));
+ CU_ASSERT(instance == NULL);
+
+ instance = gazelle_instance_get_by_pid(get_instance_mgr(), 1112); /* 1112:test pid */
+ CU_ASSERT(instance == NULL);
+
+ for (int i = 1; i <= get_instance_mgr()->max_instance_num; i++) {
+ instance = gazelle_instance_add_by_pid(get_instance_mgr(), i);
+ if (i < get_instance_mgr()->max_instance_num) {
+ CU_ASSERT(instance != NULL);
+ } else {
+ CU_ASSERT(instance == NULL);
+ }
+ instance = gazelle_instance_get_by_pid(get_instance_mgr(), i);
+ if (i < get_instance_mgr()->max_instance_num) {
+ CU_ASSERT(instance != NULL);
+ } else {
+ CU_ASSERT(instance == NULL);
+ }
+ }
+
+ gazelle_instance_mgr_destroy();
+}
diff --git a/test/unitest/ltran/ltran_param_test.c b/test/unitest/ltran/ltran_param_test.c
new file mode 100644
index 0000000..3b2a24d
--- /dev/null
+++ b/test/unitest/ltran/ltran_param_test.c
@@ -0,0 +1,320 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+ * gazelle is licensed under the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+#include <stdlib.h>
+#include <CUnit/Basic.h>
+#include <CUnit/Automated.h>
+#include <CUnit/Console.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <securec.h>
+#include "ltran_param.h"
+
+#define MAX_CMD_LEN 1024
+
+static int execute_cmd(const char *cmd)
+{
+ int ret;
+ ret = system(cmd);
+ if (ret < 0) {
+ printf("Executing cmd: %s error!!!\n", cmd);
+ abort();
+ }
+ return ret;
+}
+
+static void restore_tmp_config(void)
+{
+ execute_cmd("rm -rf ../ltran/config/ltran_tmp.conf");
+ execute_cmd("cp -f ../ltran/config/ltran.conf ../ltran/config/ltran_tmp.conf");
+}
+
+static int ltran_bad_param(const char *conf_file_filed)
+{
+ int ret;
+ struct ltran_config ltran_conf;
+ const char *conf_file_path = "../ltran/config/ltran_tmp.conf";
+ char cmd[MAX_CMD_LEN];
+
+ restore_tmp_config();
+ gazelle_set_errno(GAZELLE_SUCCESS);
+
+ ret = sprintf_s(cmd, MAX_CMD_LEN, "sed -i '%s' %s", conf_file_filed, conf_file_path);
+ if (ret < 0) {
+ printf("sprintf_s return error!!!\n");
+ return ret;
+ }
+
+ execute_cmd(cmd);
+
+ ret = parse_config_file_args(conf_file_path, &ltran_conf);
+
+ return ret;
+}
+
+void test_ltran_bad_params_clients(void)
+{
+ /* ltran start negative client */
+ CU_ASSERT(ltran_bad_param("s/dispatch_max_clients = 32/dispatch_max_clients = -1/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
+
+ /* ltran start 0 client */
+ CU_ASSERT(ltran_bad_param("s/dispatch_max_clients = 32/dispatch_max_clients = 0/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
+
+ /* ltran start 999 clinet */
+ CU_ASSERT(ltran_bad_param("s/dispatch_max_clients = 32/dispatch_max_clients = 999/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
+
+ /* ltran start str client */
+ CU_ASSERT(ltran_bad_param("s/dispatch_max_clients = 32/dispatch_max_clients = \"aaa\"/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_EPARAM);
+
+ /* ltran start none client */
+ CU_ASSERT(ltran_bad_param("s/dispatch_max_clients = 32//") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_EPARAM);
+
+ /* ltran start empty client */
+ CU_ASSERT(ltran_bad_param("s/dispatch_max_clients = 32/dispatch_max_clients = /") == -GAZELLE_EPATH);
+}
+
+void test_ltran_bad_params_port(void)
+{
+ /* ltran start zero port */
+ CU_ASSERT(ltran_bad_param("s/0x3/0x0/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
+
+ /* ltran start max port */
+ CU_ASSERT(ltran_bad_param("s/0x3/0xff/") == 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_SUCCESS);
+
+ /* ltran start str port */
+ CU_ASSERT(ltran_bad_param("s/0x3/aaa/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_EPARAM);
+
+ /* ltran start none port */
+ CU_ASSERT(ltran_bad_param("s/bond_ports = \"0x3, 0xC\"//") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_EPARAM);
+
+ /* ltran start empty port */
+ CU_ASSERT(ltran_bad_param("s/bond_ports = \"0x3, 0xC\"/bond_ports = /") == -GAZELLE_EPATH);
+
+ /* ltran start exceed max port */
+ CU_ASSERT(ltran_bad_param("s/bond_ports = \"0x3, 0xC\"/bond_ports = \"0xffffffff\"/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
+}
+
+void test_ltran_bad_params_subnet(void)
+{
+ /* ltran start bad subnet */
+ CU_ASSERT(ltran_bad_param("s/dispatch_subnet =/cdispatch_subnet = \"aaa\"/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_EPARAM);
+
+ /* ltran start empty subnet */
+ CU_ASSERT(ltran_bad_param("/^dispatch_subnet /cdispatch_subnet=") == -GAZELLE_EPATH);
+
+ /* ltran start none subnet */
+ CU_ASSERT(ltran_bad_param("/dispatch_subnet =/d") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_EPARAM);
+
+ /* ltran start not match subnet */
+ CU_ASSERT(ltran_bad_param("s/.0\"/.1\"/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_EHOSTADDR);
+
+ /* ltran start error subnet */
+ CU_ASSERT(ltran_bad_param("s/1.0\"/288.0\"/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_EINETATON);
+
+ /* ltran start exceed subnet length */
+ CU_ASSERT(ltran_bad_param("s/dispatch_subnet_length = 8/dispatch_subnet_length = 17/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
+
+ /* ltran start exceed subnet length */
+ CU_ASSERT(ltran_bad_param("s/dispatch_subnet_length = 8/dispatch_subnet_length = 0/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
+
+ /* ltran start str subnet length */
+ CU_ASSERT(ltran_bad_param("s/dispatch_subnet_length = 8/dispatch_subnet_length = aaa/") == -GAZELLE_EPATH);
+
+ /* ltran start empty subnet length */
+ CU_ASSERT(ltran_bad_param("s/dispatch_subnet_length = 8/dispatch_subnet_length = /") == -GAZELLE_EPATH);
+
+ /* ltran start none subnet length */
+ CU_ASSERT(ltran_bad_param("s/dispatch_subnet_length = 8//") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_EPARAM);
+}
+
+void test_ltran_bad_params_bond_mode(void)
+{
+ /* ltran start negative bond mode */
+ CU_ASSERT(ltran_bad_param("s/bond_mode = 1/bond_mode = -1/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
+
+ /* ltran start unsupport bond mode0 */
+ CU_ASSERT(ltran_bad_param("s/bond_mode = 1/bond_mode = 0/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
+
+ /* ltran start unsupport bond mode2 */
+ CU_ASSERT(ltran_bad_param("s/bond_mode = 1/bond_mode = 2/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
+
+ /* ltran start empty bond mode */
+ CU_ASSERT(ltran_bad_param("/^bond_mode /cbond_mode =") == -GAZELLE_EPATH);
+
+ /* ltran start unsupport none mode2 */
+ CU_ASSERT(ltran_bad_param("s/bond_mode = 1//") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_EPARAM);
+}
+
+void test_ltran_bad_params_bond_miimon(void)
+{
+ /* ltran start negative bond miimon */
+ CU_ASSERT(ltran_bad_param("s/bond_miimon = 100/bond_miimon = -1/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
+
+ /* ltran start zero bond miimon */
+ CU_ASSERT(ltran_bad_param("s/bond_miimon = 100/bond_miimon = 0/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
+
+ /* ltran start max bond miimon */
+ CU_ASSERT(ltran_bad_param("s/bond_miimon = 100/bond_miimon = 2147483647/") == 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_SUCCESS);
+
+ /* ltran start exceed str bond miimon */
+ CU_ASSERT(ltran_bad_param("s/bond_miimon = 100/bond_miimon = aaa/") == -GAZELLE_EPATH);
+
+ /* ltran start empty bond miimon */
+ CU_ASSERT(ltran_bad_param("s/bond_miimon = 100/bond_miimon = /") == -GAZELLE_EPATH);
+
+ /* ltran start none bond miimon */
+ CU_ASSERT(ltran_bad_param("s/bond_miimon = 100//") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_EPARAM);
+}
+
+void test_ltran_bad_params_bond_mtu(void)
+{
+ /* ltran start negative bond mtu */
+ CU_ASSERT(ltran_bad_param("s/bond_mtu = 1500/bond_mtu = -1/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
+
+ /* ltran start exceed min bond mtu */
+ CU_ASSERT(ltran_bad_param("s/bond_mtu = 1500/bond_mtu = 67/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
+
+ /* ltran start exceed max bond mtu */
+ CU_ASSERT(ltran_bad_param("s/bond_mtu = 1500/bond_mtu = 1501/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
+
+ /* ltran start str bond mtu */
+ CU_ASSERT(ltran_bad_param("s/bond_mtu = 1500/bond_mtu = aaa/") == -GAZELLE_EPATH);
+
+ /* ltran start empty bond mtu */
+ CU_ASSERT(ltran_bad_param("s/bond_mtu = 1500/bond_mtu = /") == -GAZELLE_EPATH);
+
+ /* ltran start none bond mtu */
+ CU_ASSERT(ltran_bad_param("s/bond_mtu = 1500//") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_EPARAM);
+}
+
+void test_ltran_bad_params_macs(void)
+{
+ /* ltran start max macs */
+ CU_ASSERT(ltran_bad_param("s/52:54:00:25:ef:e0/ff:ff:ff:ff:ff:ff/") == 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_SUCCESS);
+
+ /* ltran start error macs */
+ CU_ASSERT(ltran_bad_param("s/52:54:00:25:ef:e0/ff:ff:ff:ff:ff:fg/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ECONSIST);
+
+ /* ltran start error macs */
+ CU_ASSERT(ltran_bad_param("s/52:54:00:25:ef:e0/ff:ff:ff:ff:ff:ff:ff/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ECONSIST);
+
+ /* ltran start error macs */
+ CU_ASSERT(ltran_bad_param("s/52:54:00:25:ef:e0/ff:ff:ff:ff:ff-ff/") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ECONSIST);
+
+ /* ltran start empty macs */
+ CU_ASSERT(ltran_bad_param("s/52:54:00:25:ef:e0, aa:bb:cc:dd:ee:ff//") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_ECONSIST);
+
+ /* ltran start none macs */
+ CU_ASSERT(ltran_bad_param("s/bond_macs = \"52:54:00:25:ef:e0, aa:bb:cc:dd:ee:ff\"//") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_EPARAM);
+
+ /* ltran start duplicated macs */
+ CU_ASSERT(ltran_bad_param("/bond_macs/cbond_macs = \"52:54:00:25:ef:e0, 52:54:00:25:ef:e0\"") != 0);
+ CU_ASSERT(gazelle_get_errno() == GAZELLE_EMAC);
+}
+
+void check_bond_param(const struct ltran_config *ltran_conf)
+{
+ CU_ASSERT(ltran_conf->bond.mode == 1);
+ CU_ASSERT(ltran_conf->bond.miimon == 100); /* 100:bond链路监控时间 */
+ CU_ASSERT(ltran_conf->bond.mtu == 1500); /* 1500:bond mtu值 */
+ CU_ASSERT(ltran_conf->bond.port_num == 2); /* 2:bond port数目 */
+ CU_ASSERT(ltran_conf->bond.portmask[0] == 3); /* 3:bond mac端口掩码 */
+ CU_ASSERT(ltran_conf->bond.portmask[1] == 12); /* 12:bond mac端口掩码 */
+ CU_ASSERT(ltran_conf->bond.mac_num == 2); /* 2:bond mac地址数目 */
+ CU_ASSERT(ltran_conf->bond.mac[0].addr_bytes[0] == 82); /* 82:bond mac地址 */
+ CU_ASSERT(ltran_conf->bond.mac[0].addr_bytes[1] == 84); /* 84:bond mac地址 */
+ CU_ASSERT(ltran_conf->bond.mac[0].addr_bytes[2] == 0); /* 2:bond mac地址 */
+ CU_ASSERT(ltran_conf->bond.mac[0].addr_bytes[3] == 37); /* 3:37:bond mac地址 */
+ CU_ASSERT(ltran_conf->bond.mac[0].addr_bytes[4] == 239); /* 4:239:bond mac地址 */
+ CU_ASSERT(ltran_conf->bond.mac[0].addr_bytes[5] == 224); /* 5:224:bond mac地址 */
+ CU_ASSERT(ltran_conf->bond.mac[1].addr_bytes[0] == 170); /* 170:bond mac地址 */
+ CU_ASSERT(ltran_conf->bond.mac[1].addr_bytes[1] == 187); /* 187:bond mac地址 */
+ CU_ASSERT(ltran_conf->bond.mac[1].addr_bytes[2] == 204); /* 2:204:bond mac地址 */
+ CU_ASSERT(ltran_conf->bond.mac[1].addr_bytes[3] == 221); /* 3:221:bond mac地址 */
+ CU_ASSERT(ltran_conf->bond.mac[1].addr_bytes[4] == 238); /* 4:238:bond mac地址 */
+ CU_ASSERT(ltran_conf->bond.mac[1].addr_bytes[5] == 255); /* 5:255:bond mac地址 */
+}
+
+void test_ltran_normal_param(void)
+{
+ int ret;
+ struct ltran_config ltran_conf;
+ char ip_str[16] = {0}; /* 16:IP max len */
+ const char *config_file_path = "../ltran/config/ltran.conf";
+
+ (void)memset_s(&ltran_conf, sizeof(struct ltran_config), 0, sizeof(struct ltran_config));
+ ret = parse_config_file_args(config_file_path, &ltran_conf);
+ CU_ASSERT(ret == GAZELLE_OK);
+
+ struct in_addr tmp_subnet;
+ tmp_subnet.s_addr = ntohl(ltran_conf.dispatcher.ipv4_subnet_addr.s_addr);
+ char *subnet_str = strdup(inet_ntop(AF_INET, &tmp_subnet, ip_str, sizeof(ip_str)));
+ CU_ASSERT(subnet_str != NULL);
+ CU_ASSERT(ltran_conf.dpdk.dpdk_argc == 11); /* 11:参数个数 */
+ CU_ASSERT(strcmp(ltran_conf.dpdk.dpdk_argv[0], "ltran") == 0);
+ CU_ASSERT(strcmp(ltran_conf.dpdk.dpdk_argv[1], "-l") == 0);
+ CU_ASSERT(strcmp(ltran_conf.dpdk.dpdk_argv[2], "0,1") == 0); /* 2:ltran绑在0,1核 */
+ CU_ASSERT(strcmp(ltran_conf.dpdk.dpdk_argv[3], "--socket-mem") == 0); /* 3:ltran socket内存参数 */
+ CU_ASSERT(strcmp(ltran_conf.dpdk.dpdk_argv[4], "1024,0,0,0") == 0); /* 4:ltran socket内存值 */
+ CU_ASSERT(strcmp(ltran_conf.dpdk.dpdk_argv[5], "--huge-dir") == 0); /* 5:ltran huge路径参数 */
+ CU_ASSERT(strcmp(ltran_conf.dpdk.dpdk_argv[6], "/mnt/hugepages") == 0); /* 6:ltran huge路径值 */
+ CU_ASSERT(strcmp(ltran_conf.dpdk.dpdk_argv[7], "--proc-type") == 0); /* 7:ltran进程类型参数 */
+ CU_ASSERT(strcmp(ltran_conf.dpdk.dpdk_argv[8], "auto") == 0); /* 8:ltran进程类型值 */
+ CU_ASSERT(strcmp(ltran_conf.dpdk.dpdk_argv[9], "-n") == 0); /* 9:ltran处理器socket内存通道数目 */
+ CU_ASSERT(strcmp(ltran_conf.dpdk.dpdk_argv[10], "4") == 0); /* 10:ltran处理器socket内存通道数值 */
+ CU_ASSERT(ltran_conf.dpdk.kni_switch == 0);
+ CU_ASSERT(strcmp(subnet_str, "192.168.1.0") == 0);
+ CU_ASSERT(ltran_conf.dispatcher.ipv4_subnet_length == 8); /* 8:ipv4子网长度, 表示ltran能识别的子网长度 */
+ CU_ASSERT(ltran_conf.dispatcher.ipv4_subnet_size == 256); /* 256:ipv4子网大小 */
+ CU_ASSERT(ltran_conf.dispatcher.ipv4_net_mask == 255); /* 255:ipv4掩码 */
+ CU_ASSERT(ltran_conf.dispatcher.num_clients == 32); /* 32:client 数目 */
+ check_bond_param(&ltran_conf);
+ free(subnet_str);
+}
diff --git a/test/unitest/ltran/ltran_stack_test.c b/test/unitest/ltran/ltran_stack_test.c
new file mode 100644
index 0000000..72af3ef
--- /dev/null
+++ b/test/unitest/ltran/ltran_stack_test.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+ * gazelle is licensed under the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+#include <stdlib.h>
+#include <CUnit/Basic.h>
+#include <CUnit/Automated.h>
+#include <CUnit/Console.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <securec.h>
+#include "ltran_stack.h"
+
+void test_ltran_stack(void)
+{
+ struct gazelle_stack *stack = NULL;
+ const struct gazelle_stack *exist_stack = NULL;
+ struct gazelle_stack_htable *stack_htable;
+ /* 1: tick init val */
+ int32_t instance_cur_tick = 1;
+
+ stack_htable = gazelle_stack_htable_create(GAZELLE_MAX_STACK_NUM);
+ CU_ASSERT(stack_htable != NULL);
+ gazelle_set_stack_htable(stack_htable);
+
+ stack = gazelle_stack_add_by_tid(gazelle_get_stack_htable(), 1111); /* 1111:tid number */
+ CU_ASSERT(stack != NULL);
+ CU_ASSERT(stack->tid == 1111); /* 1111: tid number */
+ stack->instance_cur_tick = &instance_cur_tick;
+ /* 1: set instacn_cur_tick = instance_reg_tick indicate instance is on */
+ stack->instance_reg_tick = 1;
+
+ exist_stack = gazelle_stack_get_by_tid(gazelle_get_stack_htable(), 1111); /* 1111: tid number */
+
+ CU_ASSERT(exist_stack != NULL);
+ CU_ASSERT(exist_stack->tid == 1111); /* 1111:tid number */
+
+ gazelle_stack_del_by_tid(gazelle_get_stack_htable(), 1111); /* 1111:tid number */
+ exist_stack = gazelle_stack_get_by_tid(gazelle_get_stack_htable(), 1111); /* 1111:tid number */
+
+ CU_ASSERT(exist_stack == NULL);
+
+ gazelle_stack_del_by_tid(gazelle_get_stack_htable(), 1111);
+
+ for (int i = 0; i <= stack_htable->max_stack_num; i++) {
+ stack = gazelle_stack_add_by_tid(gazelle_get_stack_htable(), i);
+ if (i < stack_htable->max_stack_num) {
+ CU_ASSERT(stack != NULL);
+ stack->instance_cur_tick = &instance_cur_tick;
+ /* 1: set instacn_cur_tick = instance_reg_tick indicate instance is on */
+ stack->instance_reg_tick = 1;
+ } else {
+ CU_ASSERT(stack == NULL);
+ }
+ exist_stack = gazelle_stack_get_by_tid(gazelle_get_stack_htable(), i);
+ if (i < stack_htable->max_stack_num) {
+ CU_ASSERT(exist_stack != NULL);
+ } else {
+ CU_ASSERT(exist_stack == NULL);
+ }
+ }
+
+ gazelle_stack_htable_destroy();
+}
diff --git a/test/unitest/ltran/ltran_test_case.h b/test/unitest/ltran/ltran_test_case.h
new file mode 100644
index 0000000..fd81a1b
--- /dev/null
+++ b/test/unitest/ltran/ltran_test_case.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+ * gazelle is licensed under the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+#ifndef __LTRAN_TEST_CASE_H__
+#define __LTRAN_TEST_CASE_H__
+
+void test_ltran_stack(void);
+void test_ltran_instance(void);
+void test_ltran_normal_param(void);
+void test_ltran_bad_params_clients(void);
+void test_ltran_bad_params_port(void);
+void test_ltran_bad_params_subnet(void);
+void test_ltran_bad_params_bond_mode(void);
+void test_ltran_bad_params_bond_miimon(void);
+void test_ltran_bad_params_bond_mtu(void);
+void test_ltran_bad_params_macs(void);
+void test_tcp_conn(void);
+void test_tcp_sock(void);
+
+#endif
diff --git a/test/unitest/ltran/main.c b/test/unitest/ltran/main.c
new file mode 100644
index 0000000..c9d04f5
--- /dev/null
+++ b/test/unitest/ltran/main.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+ * gazelle is licensed under the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+#include <stdlib.h>
+#include <CUnit/Basic.h>
+#include <CUnit/Automated.h>
+#include <CUnit/Console.h>
+#include "ltran_test_case.h"
+
+typedef enum {
+ CUNIT_SCREEN = 0,
+ CUNIT_XMLFILE,
+ CUNIT_CONSOLE
+} CU_RunMode;
+
+int main(int argc, char **argv)
+{
+ CU_pSuite suite;
+ int num_failures;
+ CU_RunMode g_cunit_mode = CUNIT_SCREEN;
+
+ if (argc > 1) {
+ g_cunit_mode = atoi(argv[1]);
+ }
+
+ if (CU_initialize_registry() != CUE_SUCCESS) {
+ return CU_get_error();
+ }
+
+ suite = CU_add_suite("ltran", NULL, NULL);
+ if (suite == NULL) {
+ CU_cleanup_registry();
+ return CU_get_error();
+ }
+
+ (void)CU_ADD_TEST(suite, test_ltran_instance);
+ (void)CU_ADD_TEST(suite, test_ltran_stack);
+ (void)CU_ADD_TEST(suite, test_ltran_normal_param);
+ (void)CU_ADD_TEST(suite, test_ltran_bad_params_clients);
+ (void)CU_ADD_TEST(suite, test_ltran_bad_params_port);
+ (void)CU_ADD_TEST(suite, test_ltran_bad_params_subnet);
+ (void)CU_ADD_TEST(suite, test_ltran_bad_params_bond_mode);
+ (void)CU_ADD_TEST(suite, test_ltran_bad_params_bond_miimon);
+ (void)CU_ADD_TEST(suite, test_ltran_bad_params_bond_mtu);
+ (void)CU_ADD_TEST(suite, test_ltran_bad_params_macs);
+ (void)CU_ADD_TEST(suite, test_tcp_conn);
+ (void)CU_ADD_TEST(suite, test_tcp_sock);
+
+ switch (g_cunit_mode) {
+ case CUNIT_SCREEN:
+ CU_basic_set_mode(CU_BRM_VERBOSE);
+ CU_basic_run_tests();
+ break;
+ case CUNIT_XMLFILE:
+ CU_set_output_filename("instance");
+ CU_list_tests_to_file();
+ CU_automated_run_tests();
+ break;
+ case CUNIT_CONSOLE:
+ CU_console_run_tests();
+ break;
+ default:
+ (void)printf("not suport mode=%d\n", g_cunit_mode);
+ CU_cleanup_registry();
+ return CU_get_error();
+ }
+
+ num_failures = (int)CU_get_number_of_failures();
+ CU_cleanup_registry();
+ return num_failures;
+}
diff --git a/test/unitest/stub.c b/test/unitest/stub.c
new file mode 100644
index 0000000..8f37c90
--- /dev/null
+++ b/test/unitest/stub.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+ * gazelle is licensed under the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+
+uint64_t get_current_time(void)
+{
+ return 0;
+}
+
+int rte_pdump_init(void)
+{
+ return 0;
+}
+
+void *__wrap_rte_malloc(const char *type, size_t size, unsigned align)
+{
+ return malloc(size);
+}
+
+void __wrap_rte_free(void *ptr)
+{
+ free(ptr);
+}
diff --git a/test/unitest/test.sh b/test/unitest/test.sh
new file mode 100644
index 0000000..90fbbe6
--- /dev/null
+++ b/test/unitest/test.sh
@@ -0,0 +1,279 @@
+# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+# gazelle is licensed under the Mulan PSL v2.
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
+# You may obtain a copy of Mulan PSL v2 at:
+# http://license.coscl.org.cn/MulanPSL2
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+# PURPOSE.
+# See the Mulan PSL v2 for more details.
+
+usage()
+{
+ echo "Usage: sh llt.sh [OPTIONS]"
+ echo "Use llt.sh to control llt operation"
+ echo
+ echo "Misc:"
+ echo " -h, --help Print this help, then exit"
+ echo
+ echo "Compile Options:"
+ echo " -m, --cmake <option> use cmake genenate Makefile, eg: -m(default), -mcoverage, -masan, --cmake, --cmake=coverage"
+ echo " -c, --compile Enable compile"
+ echo " -e, --empty Enable compile empty(make clean)"
+ echo
+ echo "TestRun Options"
+ echo " -r, --run-llt <option> Run all llt, eg: -r, -rscreen(default), -rxml, --run-llt, --run-llt=screen, --run-llt=xml"
+ echo " -s, --specify-llt FILE Only Run specify llt executable FILE, eg: -smain_llt, --specify-llt=main_llt"
+ echo
+ echo "Coverage Options"
+ echo " -t, --cover-report <option> Enable coverage report. eg: -t, -thtml(default), -ttxt, --cover-report, --cover-report=html, --cover-report=txt"
+ echo " -f, --cover-file FILE Specified FILE coverage report, eg: -fmain.c, --cover-file=main.c"
+ echo
+}
+
+ARGS=`getopt -o "hcer::m::t::s:f:" -l "help,cmake::,empty,cover-report::,run-llt::,specify-llt:,cover-file:" -n "run_llt.sh" -- "$@"`
+if [ $? != 0 ]; then
+ usage
+ exit 1
+fi
+
+eval set -- "${ARGS}"
+
+if [ x"$ARGS" = x" --" ]; then
+ #set default value
+ COMPILE_ENABLE=no
+ COVERAGE_ENABLE=no
+ ASAN_ENABLE=no
+ EMPTY_ENABLE=no
+ RUN_LLT=yes
+ RUN_MODE=screen #value: screen or xml
+ COVER_REPORT_ENABLE=no
+fi
+
+while true; do
+ case "${1}" in
+ -m|--cmake)
+ CMAKE_ENABLE=yes
+ case "$2" in
+ "") shift 2;;
+ coverage) COVERAGE_ENABLE=yes; shift 2;;
+ asan) ASAN_ENABLE=yes; shift 2;;
+ *) echo "Error param: $2"; exit 1;;
+ esac;;
+ -h|--help)
+ usage; exit 0;;
+ -c|--compile)
+ COMPILE_ENABLE=yes
+ shift;;
+ -e|--empty)
+ EMPTY_ENABLE=yes
+ shift;;
+ -r|--run-llt)
+ RUN_LLT=yes
+ case "$2" in
+ "") RUN_MODE=screen; shift 2;;
+ screen) RUN_MODE=screen; shift 2;;
+ xml) RUN_MODE=xml; shift 2;;
+ *)echo "Error param: $2"; exit 1;;
+ esac;;
+ -t|--cover-report)
+ COVER_REPORT_ENABLE=yes
+ case "$2" in
+ "") COVER_STYLE=html;shift 2;;
+ html) COVER_STYLE=html;shift 2;;
+ txt) COVER_STYLE=txt;shift 2;;
+ *)echo "Error param: $2"; exit 1;;
+ esac;;
+ -s|--specify-llt)
+ SPECIFY_CASES=$2
+ shift 2;;
+ -f|--cover-file)
+ COVER_FILE=$2
+ shift 2;;
+ --)
+ shift; break;;
+ esac
+done
+
+function test_empty()
+{
+ echo ---------------------- llt empty begin ----------------------
+ set -x
+ echo "remove directory build"
+ rm -rf build
+ set +x
+ echo ---------------------- llt empty end ------------------------
+}
+
+function test_cmake()
+{
+ local CMAKE_OPTION="-DCMAKE_BUILD_TYPE=Debug"
+
+ echo ---------------------- llt cmake begin ----------------------
+ if [ ! -d "build" ]; then
+ mkdir build
+ fi
+ chmod 755 build
+ cd build
+ if [ x"${COVERAGE_ENABLE}" = x"yes" ]; then
+ CMAKE_OPTION="${CMAKE_OPTION} -DCOVERAGE_ENABLE=1"
+ fi
+
+ if [ x"${ASAN_ENABLE}" = x"yes" ]; then
+ CMAKE_OPTION="${CMAKE_OPTION} -DASAN_ENABLE=1"
+ fi
+
+ cmake .. ${CMAKE_OPTION}
+ cd -
+ echo ---------------------- llt cmake end ------------------------
+ echo
+}
+
+function test_compile()
+{
+ echo ---------------------- llt compile begin ----------------------
+ cd build
+ make -j
+ cd -
+ echo ---------------------- llt compile end ------------------------
+ echo
+}
+
+function test_run_all_test()
+{
+ ret=1
+ echo ---------------------- llt run begin --------------------------
+ if [ x"${RUN_MODE}" = x"screen" ]; then
+ RUN_MODE=0
+ elif [ x"${RUN_MODE}" = x"xml" ]; then
+ RUN_MODE=1
+ elif [ x"${RUN_MODE}" = x"" ]; then
+ RUN_MODE=0
+ else
+ echo "not suport run mode <${RUN_MODE}>"
+ usage
+ exit 1
+ fi
+
+ cd build
+ if [ x"${SPECIFY_CASES}" = x"" ]; then
+ SPECIFY_CASES=`find -name "*_test"` # run all test
+ else
+ SPECIFY_CASES=`find -name "${SPECIFY_CASES}"`
+ fi
+
+ TEST_LOG=test_result.log
+ >$TEST_LOG
+
+ for TEST in $SPECIFY_CASES; do
+ echo $TEST
+ $TEST $RUN_MODE
+ if [ $? != 0 ];then
+ echo $TEST FAILED >> $TEST_LOG
+ ret=1
+ else
+ echo $TEST success >> $TEST_LOG
+ ret=0
+ fi
+ done
+ echo ""
+ echo '######################test result begin######################'
+ cat $TEST_LOG
+ echo '#######################test result end#######################'
+ echo ""
+ cd -
+ echo ---------------------- llt run end --------------------------
+ return $ret
+}
+
+function test_coverage()
+{
+ echo ------------------ llt generate coverage begin --------------
+ cd build
+ if [ x"${COVER_STYLE}" = x"txt" ]; then
+ GCDAS=`find -name "${COVER_FILE}.gcda"`
+ if [ x"$GCDAS" = x"" ]; then
+ echo "not find ${COVER_FILE}.gcda"
+ echo
+ exit 1
+ fi
+
+ for GCDA in $GCDAS; do
+ gcov $GCDA
+ done
+
+ find -name "*.h.gcov" | xargs rm -f
+ echo '#################################'
+ find -name "${COVER_FILE}.gcov"
+ echo '#################################'
+ elif [ x"${COVER_STYLE}" = x"html" ]; then
+ if [ -d coverage ]; then
+ rm -rf coverage
+ fi
+ mkdir coverage
+ if [ x"${COVER_FILE}" = x"" ]; then
+ LCOV_CMD="-d ./"
+ else
+ GCDAS=`find -name "${COVER_FILE}.gcda"`
+ if [ $? != 0 ]; then
+ echo "not match ${COVER_FILE}.gcda"
+ exit 1
+ fi
+
+ for GCDA in ${GCDAS}; do
+ TMP_STR=" -d ${GCDA}";
+ LCOV_CMD="${LCOV_CMD} ${TMP_STR}";
+ done
+ fi
+
+ lcov -c -d . -o coverage/coverage.info --exclude "/usr/*" --exclude "*stub*" --exclude "*test*" --exclude "libnet_dfx_msg.c" --rc lcov_branch_coverage=1 --ignore-errors gcov --ignore-errors source --ignore-errors graph
+ if [ $? != 0 ]; then
+ echo "lcov generate coverage.info fail."
+ exit 1
+ fi
+
+ genhtml coverage/coverage.info -o coverage/html --branch-coverage --rc lcov_branch_coverage=1 -s --legend --ignore-errors source
+ if [ $? != 0 ]; then
+ echo "genhtml fail."
+ exit 1
+ fi
+ chmod 755 -R coverage
+ fi
+ cd -
+ echo ------------------ llt generate coverage end ----------------
+}
+
+exit_ret=0
+
+starttime=`date +'%Y-%m-%d %H:%M:%S'`
+sed -i "s/^static int32_t parse_conf_file/int32_t parse_conf_file/" ../../src/lstack/core/lstack_cfg.c
+sed -i "s/^ get_protocol_stack_group/ \/\/get_protocol_stack_group/" ../../src/lstack/core/lstack_cfg.c
+sed -i "/int32_t init_stack_numa_cpuset/i\ #if 0" ../../src/lstack/core/lstack_cfg.c
+sed -i "/static int32_t gazelle_parse_base_virtaddr/i\ #endif" ../../src/lstack/core/lstack_cfg.c
+if [ x"${EMPTY_ENABLE}" = x"yes" ]; then
+ test_empty
+fi
+
+if [ x"${CMAKE_ENABLE}" = x"yes" ]; then
+ test_cmake
+fi
+
+if [ x"${COMPILE_ENABLE}" = x"yes" ]; then
+ test_compile
+fi
+
+if [ x"${RUN_LLT}" = x"yes" ]; then
+ test_run_all_test
+ exit_val=$?
+fi
+
+if [ x"${COVER_REPORT_ENABLE}" = x"yes" ]; then
+ test_coverage
+fi
+git checkout HEAD -- ../../src/lstack/core/lstack_cfg.c
+
+endtime=`date +'%Y-%m-%d %H:%M:%S'`
+start_seconds=$(date --date="$starttime" +%s);
+end_seconds=$(date --date="$endtime" +%s);
+echo "Running time: "$((end_seconds-start_seconds))"s"
+exit $exit_val
--
2.23.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openeuler-risc-v/gazelle.git
git@gitee.com:openeuler-risc-v/gazelle.git
openeuler-risc-v
gazelle
gazelle
master

搜索帮助