From 502e0241ea1d6f1ffe01fbfe8272fb90003c3327 Mon Sep 17 00:00:00 2001 From: jiangheng12 Date: Tue, 7 Feb 2023 11:39:40 +0800 Subject: [PATCH] add fucntest --- test/functest/CMakeLists.txt | 16 + test/functest/common/common.c | 248 +++++++++++++ test/functest/common/common.h | 68 ++++ test/functest/common/uitls.c | 0 test/functest/common/utils.c | 261 ++++++++++++++ test/functest/common/utils.h | 42 +++ test/functest/signal_hijack/CMakeLists.txt | 16 + test/functest/signal_hijack/signal_hijack.c | 39 ++ test/functest/test.sh | 336 ++++++++++++++++++ test/functest/test_ltran/CMakeLists.txt | 20 ++ .../test_ltran/config/config_example.conf | 14 + test/functest/test_ltran/ltran_func_test.c | 195 ++++++++++ 12 files changed, 1255 insertions(+) create mode 100644 test/functest/CMakeLists.txt create mode 100644 test/functest/common/common.c create mode 100644 test/functest/common/common.h create mode 100644 test/functest/common/uitls.c create mode 100644 test/functest/common/utils.c create mode 100644 test/functest/common/utils.h create mode 100644 test/functest/signal_hijack/CMakeLists.txt create mode 100644 test/functest/signal_hijack/signal_hijack.c create mode 100644 test/functest/test.sh create mode 100644 test/functest/test_ltran/CMakeLists.txt create mode 100644 test/functest/test_ltran/config/config_example.conf create mode 100644 test/functest/test_ltran/ltran_func_test.c diff --git a/test/functest/CMakeLists.txt b/test/functest/CMakeLists.txt new file mode 100644 index 0000000..ea42854 --- /dev/null +++ b/test/functest/CMakeLists.txt @@ -0,0 +1,16 @@ +# 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_integration_test) + +add_subdirectory(signal_hijack) + +add_subdirectory(test_ltran) diff --git a/test/functest/common/common.c b/test/functest/common/common.c new file mode 100644 index 0000000..46f1647 --- /dev/null +++ b/test/functest/common/common.c @@ -0,0 +1,248 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// test header +#include "utils.h" +#include "common.h" + +int check_if_socket_server_start_succeed(void) +{ + int ret; + ret = check_if_process_exist("socket_server"); + if (ret != LIBOS_OK) { + return LIBOS_ERR; + } + + return LIBOS_OK; +} + +int check_if_socket_client_start_succeed(void) +{ + int ret; + ret = check_if_process_exist("socket_client"); + if (ret != LIBOS_OK) { + return LIBOS_ERR; + } + + return LIBOS_OK; +} + +int check_if_socket_ltran_start_succeed(void) +{ + int ret; + + ret = check_if_process_exist("socket_ltran"); + if (ret != LIBOS_OK) { + return LIBOS_ERR; + } + + return LIBOS_OK; +} + + +int check_if_process_start_succeed(const char* proces_name) +{ + int ret; + + ret = check_if_process_exist(proces_name); + if (ret != LIBOS_OK) { + return LIBOS_ERR; + } + + return LIBOS_OK; +} + +int check_if_ltran_start_succeed(void) +{ + int ret; + + ret = check_if_process_exist("ltran"); + if (ret != LIBOS_OK) { + return LIBOS_ERR; + } + + ret = check_if_file_contains(LTRAN_LOG_PATH, "Runing Process forward", LTRAN_START_TMOUT_S); + if (ret != LIBOS_OK) { + return LIBOS_ERR; + } + return LIBOS_OK; +} + +int check_if_ltran_quit_succeed(void) +{ + char cmd[MAX_CMD_LEN]; + + FILE *fstream = NULL; + char *gets_ret = NULL; + char buf[MAX_CMD_RESULT_BUF_LEN]; + (void)memset_s(buf, MAX_CMD_RESULT_BUF_LEN, 0, MAX_CMD_RESULT_BUF_LEN); + (void)memset_s(cmd, MAX_CMD_LEN, 0, MAX_CMD_LEN); + + (void)sprintf_s(cmd, MAX_CMD_LEN, "ps aux | grep -w ltran | grep -v grep"); +#ifdef LLT_DEBUG + printf("Executing cmd: %s\n", cmd); +#endif + + fstream = popen(cmd, "r"); + if (fstream == NULL) { + return LIBOS_ERR; + } + + gets_ret = fgets(buf, MAX_CMD_RESULT_BUF_LEN, fstream); + if (gets_ret == NULL) { + pclose(fstream); + return LIBOS_OK; + } + + pclose(fstream); + return LIBOS_ERR; +} + + +int check_if_lstack_start_succeed(const char *server_name) +{ + int ret; + ret = check_if_process_exist(server_name); + if (ret != LIBOS_OK) { + return LIBOS_ERR; + } + + // times for lstack online + sleep(LSTACK_START_TMOUT_S); + return LIBOS_OK; +} + +void test_benchmark_flow(char *ltran_start_cmd, char *server_start_cmd, char *client_start_cmd, const char *ltran_conf, + const char *lstack_conf) +{ + int ret; + + char ip[MAX_IP_ADDR_LEN]; + CU_ASSERT(get_test_ip(lstack_conf, 0, ip, MAX_IP_ADDR_LEN) == LIBOS_OK); + ret = sprintf_s(ltran_start_cmd, MAX_CMD_LEN, "ltran --config-file %s > %s 2>&1 &", ltran_conf, LTRAN_LOG_PATH); + ret |= sprintf_s(server_start_cmd, MAX_CMD_LEN, "export LSTACK_CONF_PATH=%s;" + "GAZELLE_BIND_PROCNAME=benchmark_usr GAZELLE_BIND_THREADNAME=disp " + "stdbuf -oL /etc/gazelle/benchmark_usr -sMode dn -pSize 0 -mSize 1024 -pdSize 2 -cFile /etc/gazelle/config.ini" + " > %s 2>&1 &", lstack_conf, SOCKET_SERVER_LOG_PATH); + ret |= sprintf_s(client_start_cmd, MAX_CMD_LEN, "stdbuf -oL /etc/gazelle/benchmark_ker -sMode \ + client -mSize 1024 -tNums 5 -cNums 2 -cFile /etc/gazelle/config.ini > %s 2>&1 &", SOCKET_CLIENT_LOG_PATH); + CU_ASSERT(ret > 0); + + execute_cmd(ltran_start_cmd); + CU_ASSERT(check_if_ltran_start_succeed() == LIBOS_OK); + + execute_cmd(server_start_cmd); + ret = check_if_file_contains(SOCKET_SERVER_LOG_PATH, "Packet wrong rate", BENCHMARK_START_TMOUT_S); + CU_ASSERT(ret == LIBOS_OK); + + execute_cmd(client_start_cmd); + ret = check_if_file_contains(SOCKET_CLIENT_LOG_PATH, "Packet wrong rate", BENCHMARK_2WCONN_TMOUT_S); + CU_ASSERT(ret == LIBOS_OK); +} + +void test_preload_benchmark_flow_no_ltran(char *server_start_cmd, char *client_start_cmd, const char *lstack_conf) +{ + int ret; + + ret = sprintf_s(server_start_cmd, MAX_CMD_LEN, "export LSTACK_CONF_PATH=%s;" + "GAZELLE_BIND_PROCNAME=benchmark_ker GAZELLE_BIND_THREADNAME=disp LD_PRELOAD=/lib64/liblstack.so " + "stdbuf -oL /etc/gazelle/benchmark_ker -sMode dn -pSize 0 -mSize 1024 -pdSize 2 -cFile /etc/gazelle/config.ini" + " > %s 2>&1 &", lstack_conf, SOCKET_SERVER_LOG_PATH); + ret |= sprintf_s(client_start_cmd, MAX_CMD_LEN, "stdbuf -oL /etc/gazelle/benchmark_ker -sMode " + "client -mSize 1024 -tNums 5 -cNums 2 -cFile /etc/gazelle/config.ini > %s 2>&1 &", SOCKET_CLIENT_LOG_PATH); + CU_ASSERT(ret > 0); + + execute_cmd(server_start_cmd); + ret = check_if_file_contains(SOCKET_SERVER_LOG_PATH, "Packet wrong rate", BENCHMARK_START_TMOUT_S); + CU_ASSERT(ret == LIBOS_OK); + + execute_cmd(client_start_cmd); + ret = check_if_file_contains(SOCKET_CLIENT_LOG_PATH, "Packet wrong rate", BENCHMARK_2WCONN_TMOUT_S); + CU_ASSERT(ret == LIBOS_OK); +} + +void test_preload_benchmark_flow(char *ltran_start_cmd, char *server_start_cmd, char *client_start_cmd, + const char *ltran_conf, const char *lstack_conf) +{ + int ret; + + ret = sprintf_s(ltran_start_cmd, MAX_CMD_LEN, "ltran --config-file %s > %s 2>&1 &", ltran_conf, LTRAN_LOG_PATH); + CU_ASSERT(ret > 0); + + execute_cmd(ltran_start_cmd); + CU_ASSERT(check_if_ltran_start_succeed() == LIBOS_OK); + + test_preload_benchmark_flow_no_ltran(server_start_cmd, client_start_cmd, lstack_conf); +} + +void rm_log(void) +{ + execute_cmd("rm -f /tmp/ltran.log > /dev/null"); + execute_cmd("rm -f /tmp/lstack.log > /dev/null"); + execute_cmd("rm -f /tmp/libnet_dfx.log > /dev/null"); + execute_cmd("rm -f /tmp/socket_server.log > /dev/null"); + execute_cmd("rm -f /tmp/socket_client.log > /dev/null"); +} + +void kill_ltran(void) +{ + execute_cmd("killall -s TERM ltran > /dev/null 2>&1"); + for (;;) { + if (check_if_ltran_quit_succeed() == LIBOS_OK) { + break; + } + sleep(SLEPP_CYCLE_S); + } +} + +void kill_gazellectl(void) +{ + execute_cmd("killall -s TERM gazellectl > /dev/null 2>&1"); +} + +void kill_lstack(void) +{ + execute_cmd("killall -s TERM server_user1 > /dev/null 2>&1"); + execute_cmd("killall -s TERM server_user2 > /dev/null 2>&1"); + execute_cmd("killall -s TERM server_user3 > /dev/null 2>&1"); + execute_cmd("killall -s TERM client_user1 > /dev/null 2>&1"); + execute_cmd("killall -s TERM client_user2 > /dev/null 2>&1"); + execute_cmd("killall -s TERM client_user3 > /dev/null 2>&1"); + execute_cmd("killall -s TERM server_poll_user1 > /dev/null 2>&1"); + execute_cmd("killall -s TERM server > /dev/null 2>&1"); + execute_cmd("killall -s TERM client > /dev/null 2>&1"); + execute_cmd("killall -s TERM benchmark_ker > /dev/null 2>&1"); + execute_cmd("killall -s TERM benchmark_usr > /dev/null 2>&1"); +} + +void reset_env(void) +{ + kill_ltran(); + kill_gazellectl(); + kill_lstack(); + rm_log(); +} diff --git a/test/functest/common/common.h b/test/functest/common/common.h new file mode 100644 index 0000000..00fab9f --- /dev/null +++ b/test/functest/common/common.h @@ -0,0 +1,68 @@ +/* + * 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 __COMMON_H__ +#define __COMMON_H__ + +#define LTRAN_START_TMOUT_S 5 +#define LSTACK_START_TMOUT_S 2 +#define LANTENCY_LOG_TMOUT_S 5 +#define CAT_LOG_TMOUT_S 5 +#define LSTACK_LOGOUT_TMOUT_S 10 +#define BENCHMARK_START_TMOUT_S 10 +#define BENCHMARK_2WCONN_TMOUT_S 20 + +#define MAX_BOND_PORT_NUM 8 +#define MAX_BOND_MAC_NUM 8 + +#define MAX_PORT_MASK_LEN 64 +#define MAX_MAC_LEN 64 +#define MAX_IP_ADDR_LEN 64 +#define MAX_FILE_PATH_LEN 128 + +#define LTRAN_LOG_PATH "/tmp/ltran.log " +#define LSTACK_LOG_PATH "/tmp/lstack.log" +#define LIBNET_DFX_LOG_PATH "/tmp/libnet_dfx.log" +#define CP_SOCK_FILE "cp.sock" + +#define SOCKET_SERVER_LOG_PATH "/tmp/socket_server.log" +#define SOCKET_CLIENT_LOG_PATH "/tmp/socket_client.log" + +#define STUB_LSTACK_LIVE_TIME_S 3 + +#define SERVERBIN_IP_OFFSET 1 +#define KNI_IP_OFFSET 2 + +void test_benchmark_flow(char *ltran_start_cmd, char *server_start_cmd, char *client_start_cmd, const char *ltran_conf, + const char *lstack_conf); +void test_preload_benchmark_flow_no_ltran(char *server_start_cmd, char *client_start_cmd, const char *lstack_conf); +void test_preload_benchmark_flow(char *ltran_start_cmd, char *server_start_cmd, char *client_start_cmd, + const char *ltran_conf, const char *lstack_conf); +int check_if_process_start_succeed(const char* proces_name); +int check_if_socket_server_start_succeed(void); +int check_if_socket_client_start_succeed(void); +int check_if_socket_ltran_start_succeed(void); +int check_if_ltran_start_succeed(void); +int check_if_lstack_start_succeed(const char *ip_addr); + + +void rm_log(void); +void kill_ltran(void); +void ko_clean(void); +void ko_init(void); + +void kill_stub_lstack(void); + +void reset_env(void); + + +#endif diff --git a/test/functest/common/uitls.c b/test/functest/common/uitls.c new file mode 100644 index 0000000..e69de29 diff --git a/test/functest/common/utils.c b/test/functest/common/utils.c new file mode 100644 index 0000000..d74ddba --- /dev/null +++ b/test/functest/common/utils.c @@ -0,0 +1,261 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include "utils.h" + +#define IP_ADD_STEP 0x1000000 +/* input path must lstack.conf */ +int get_test_ip(const char *path, int offset, char *ip, int ip_maxlen) +{ + FILE *fstream = NULL; + char cmd[MAX_CMD_LEN] = {0}; + struct in_addr tmp_ip; + int ret; + + if (access(path, 0) < 0) { + printf("%s is not exit\n", path); + return -LIBOS_ERR; + } + + if (ip == NULL) { + printf("ip is NULL\n"); + return -LIBOS_ERR; + } + + ret = sprintf_s(cmd, MAX_CMD_LEN, "cat %s | grep host_addr= | awk -F '\"' '{print $2}'", path); + if (ret < 0) { + printf("sprintf_s err ret=%d\n", ret); + return -LIBOS_ERR; + } + + fstream = popen(cmd, "r"); + if (fstream == NULL) { + return -LIBOS_ERR; + } + + if (fgets(ip, ip_maxlen, fstream) == NULL) { + pclose(fstream); + return -LIBOS_ERR; + } + pclose(fstream); + + /* delete \n */ + int i = 0; + while (i < ip_maxlen && ip[i] != '\0') { + if (ip[i] == '\n') { + ip[i] = '\0'; + break; + } + i++; + } + + if (inet_pton(AF_INET, ip, &tmp_ip) > 0) { + tmp_ip.s_addr += offset * IP_ADD_STEP; + if (inet_ntop(AF_INET, &tmp_ip, ip, ip_maxlen)) { + return LIBOS_OK; + } + } + + return -LIBOS_ERR; +} +void execute_cmd(const char *cmd) +{ + int ret; +#ifdef LLT_DEBUG + printf("Executing cmd: %s\n", cmd); +#endif + ret = system(cmd); + if (ret < 0) { + printf("Executing cmd: %s error!!!\n", cmd); + abort(); + } + return; +} + +int check_cmd_ret(const char* cmd) +{ + FILE *fstream = NULL; + char *gets_ret = NULL; + char buf[MAX_CMD_RESULT_BUF_LEN]; + (void)memset_s(buf, MAX_CMD_RESULT_BUF_LEN, 0, MAX_CMD_RESULT_BUF_LEN); + + fstream = popen(cmd, "r"); + if (fstream == NULL) { + return LIBOS_ERR; + } + + gets_ret = fgets(buf, MAX_CMD_RESULT_BUF_LEN, fstream); + if (gets_ret != NULL) { + pclose(fstream); + return LIBOS_OK; + } + + pclose(fstream); + system(cmd); + return LIBOS_ERR; +} + +int check_if_cmd_ret_contains(const char *exec_cmd, const char *expect_ret) +{ + int ret; + char cmd[MAX_CMD_LEN]; + (void)memset_s(cmd, MAX_CMD_LEN, 0, MAX_CMD_LEN); + + ret = sprintf_s(cmd, MAX_CMD_LEN, "%s | grep \"%s\"", exec_cmd, expect_ret); + if (ret < 0) { + return LIBOS_ERR; + } +#ifdef LLT_DEBUG + printf("Executing cmd: %s\n", cmd); +#endif + return check_cmd_ret(cmd); +} + +static int check_cmd_contains(const char *subcmd, const char *expect_str, const unsigned int timeout_s) +{ + char cmd[MAX_CMD_LEN]; + unsigned int time_s = 0; + int ret; + + (void)memset_s(cmd, MAX_CMD_LEN, 0, MAX_CMD_LEN); + + ret = sprintf_s(cmd, MAX_CMD_LEN, "%s | grep --text \"%s\"", subcmd, expect_str); + if (ret < 0) { + return LIBOS_ERR; + } + while (time_s < timeout_s) { + sleep(SLEPP_CYCLE_S); + time_s += SLEPP_CYCLE_S; + +#ifdef LLT_DEBUG + printf("Executing cmd: %s\n", cmd); +#endif + ret = check_cmd_ret(cmd); + if (ret == LIBOS_OK) { + return LIBOS_OK; + } + } + system(subcmd); + return LIBOS_ERR; +} + +int check_cpu_uasge(const char *file_path) +{ + int ret; + int usage_integer; + int usage_float; + + FILE *fstream = NULL; + fstream = fopen(file_path, "r"); + if (fstream == NULL) { + return LIBOS_ERR; + } + + ret = fscanf_s(fstream, "%d.%d", &usage_integer, &usage_float); + if (ret < 1) { + pclose(fstream); + return LIBOS_ERR; + } + + ret = LIBOS_OK; + if (usage_integer > 40) { /* when low power mode is on, cpu usage should below 40% */ + ret = LIBOS_ERR; + } + pclose(fstream); + return ret; +} + +int check_journalctl_contains(const char *expect_str, const unsigned int timeout_s) +{ + return check_cmd_contains("journalctl", expect_str, timeout_s); +} + +int check_if_file_contains(const char *filepath, const char *expect_str, const unsigned int timeout_s) +{ + char cmd[MAX_CMD_LEN] = {0}; + int ret = sprintf_s(cmd, MAX_CMD_LEN, "cat %s", filepath); + if (ret < 0) { + return LIBOS_ERR; + } + + return check_cmd_contains(cmd, expect_str, timeout_s); +} + +int check_if_process_exist(const char *process_name) +{ + char cmd[MAX_CMD_LEN]; + int ret; + + (void)memset_s(cmd, MAX_CMD_LEN, 0, MAX_CMD_LEN); + + ret = sprintf_s(cmd, MAX_CMD_LEN, "pidof %s", process_name); + if (ret < 0) { + return LIBOS_ERR; + } +#ifdef LLT_DEBUG + printf("Executing cmd: %s\n", cmd); +#endif + + return check_cmd_ret(cmd); +} + +void create_dir(const char *dir_path) +{ + char cmd[MAX_CMD_LEN]; + (void)memset_s(cmd, MAX_CMD_LEN, 0, MAX_CMD_LEN); + int ret = sprintf_s(cmd, MAX_CMD_LEN, "mkdir -p %s", dir_path); + if (ret < 0) { + return; + } + execute_cmd(cmd); +} + +void remove_dir(const char *dir_path) +{ + char cmd[MAX_CMD_LEN]; + (void)memset_s(cmd, MAX_CMD_LEN, 0, MAX_CMD_LEN); + int ret = sprintf_s(cmd, MAX_CMD_LEN, "rm -rf %s", dir_path); + if (ret < 0) { + return; + } + execute_cmd(cmd); +} + +void create_file(const char *file_path) +{ + char cmd[MAX_CMD_LEN]; + (void)memset_s(cmd, MAX_CMD_LEN, 0, MAX_CMD_LEN); + int ret = sprintf_s(cmd, MAX_CMD_LEN, "touch %s", file_path); + if (ret < 0) { + return; + } + execute_cmd(cmd); +} + +void remove_file(const char *file_path) +{ + char cmd[MAX_CMD_LEN]; + (void)memset_s(cmd, MAX_CMD_LEN, 0, MAX_CMD_LEN); + int ret = sprintf_s(cmd, MAX_CMD_LEN, "rm -f %s", file_path); + if (ret < 0) { + return; + } + execute_cmd(cmd); +} diff --git a/test/functest/common/utils.h b/test/functest/common/utils.h new file mode 100644 index 0000000..f11e04b --- /dev/null +++ b/test/functest/common/utils.h @@ -0,0 +1,42 @@ +/* + * 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 __UTILS_H__ +#define __UTILS_H__ + +#define LIBOS_OK 0 +#define LIBOS_ERR 1 + +#define LIBOS_TRUE 1 +#define LIBOS_FALSE 0 + +#define MAX_TESTCASE_NAME_LEN 128 +#define MAX_CMD_RESULT_BUF_LEN 1024 +#define SLEPP_CYCLE_S 1 +#define MAX_CMD_LEN 512 +#define MAX_PATH_LEN 256 + +void execute_cmd(const char *cmd); + +int check_if_cmd_ret_contains(const char *exec_cmd, const char *expect_ret); +int check_journalctl_contains(const char *expect_ret, const unsigned int timeout_s); +int check_if_file_contains(const char *file_path, const char *expect_str, const unsigned int timeout_s); +int check_if_process_exist(const char *process_name); +int check_cpu_uasge(const char *file_path); + +void create_dir(const char *dir_path); +void remove_dir(const char *dir_path); +void create_file(const char *file_path); +void remove_file(const char *file_path); +int get_test_ip(const char *path, int offset, char *ip, int ip_maxlen); + +#endif diff --git a/test/functest/signal_hijack/CMakeLists.txt b/test/functest/signal_hijack/CMakeLists.txt new file mode 100644 index 0000000..0921060 --- /dev/null +++ b/test/functest/signal_hijack/CMakeLists.txt @@ -0,0 +1,16 @@ +# 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_func_test) + +set(LIBRARY_OUTPUT_PATH ../) + +add_library(signal_hijack SHARED signal_hijack.c) diff --git a/test/functest/signal_hijack/signal_hijack.c b/test/functest/signal_hijack/signal_hijack.c new file mode 100644 index 0000000..cfb82a3 --- /dev/null +++ b/test/functest/signal_hijack/signal_hijack.c @@ -0,0 +1,39 @@ +/* + * 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 +#include +#include + +void signal_handler(int signo) +{ + exit(signo); +} + +__attribute__((constructor)) void signal_reg(void) +{ + int sigs[] = { + SIGILL, SIGFPE, SIGABRT, SIGBUS, + SIGSEGV, SIGHUP, SIGINT, SIGQUIT, + SIGTERM + }; + int i; + struct sigaction sa; + sa.sa_handler = signal_handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESETHAND; + for (i = 0; i < sizeof(sigs) / sizeof(sigs[0]); i++) { + if (sigaction(sigs[i], &sa, NULL) == -1) { + perror("Could not set signal handler"); + } + } +} diff --git a/test/functest/test.sh b/test/functest/test.sh new file mode 100644 index 0000000..fe8c424 --- /dev/null +++ b/test/functest/test.sh @@ -0,0 +1,336 @@ +#! /bin/bash + +#set -xe + +usage() +{ + echo "Usage: sh test.sh [OPTIONS]" + echo "Use test.sh to control integration test operation" + echo + echo "Misc:" + echo " -h, --help Print this help, then exit" + echo + echo "Compile Options:" + echo " -m, --cmake