diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..8a440b353bb0514f7b053ab3460e6b60d25a3440 --- /dev/null +++ b/Makefile @@ -0,0 +1,135 @@ +VERSION = 1.0.2 +.PHONY: all install test + +PREFIX ?= /usr +ETCDIR ?= /etc +VARDIR ?= /var +BINDIR = $(DESTDIR)$(PREFIX)/bin +SYSTEMDDIR = $(DESTDIR)$(PREFIX)/lib/systemd/system +INCLUDEDIR = $(DESTDIR)$(PREFIX)/include +LIBINSTALLDIR = $(DESTDIR)$(PREFIX)/lib64 +LOGSAVEDIR = $(DESTDIR)$(VARDIR)/log/sysSentry +LOGROTEDIR = $(DESTDIR)$(ETCDIR)/logrotate.d + +SRCVERSION = $(shell git rev-parse --short HEAD 2>/dev/null) +SHELL = /bin/bash + +CURDIR = $(shell pwd) +CURSRCDIR = $(CURDIR)/src +CURLIBDIR = $(CURDIR)/libs +CURTESTDIR = $(CURDIR)/selftest +CURSERVICEDIR = $(CURDIR)/service +CURCONFIGDIR = $(CURDIR)/config + +PYBIN = $(shell which python3) +PYNAME = $(shell ls /usr/lib |grep -E '^python'| sort -V | tail -n1) +PYDIR = $(DESTDIR)$(PREFIX)/lib/$(PYNAME)/site-packages + +ifeq ($(shell uname -r | grep -q "4.19" && echo 1 || echo 0), 1) + KERNEL_IS_4_19 := 1 +else + KERNEL_IS_4_19 := 0 +endif + +all: lib sentry + + +install: dirs ilib isentry + + +dirs: + mkdir -p $(BINDIR) + mkdir -p $(ETCDIR) + mkdir -p $(PYDIR) + mkdir -p $(SYSTEMDDIR) + mkdir -p $(LOGSAVEDIR) + mkdir -p $(LOGROTEDIR) + install -d -m 700 $(ETCDIR)/sysSentry/ + install -d -m 700 $(ETCDIR)/sysSentry/tasks/ + install -d -m 700 $(ETCDIR)/sysSentry/plugins/ + +sentry: + @echo "Kernel version is $(shell uname -r)" + @if [ $(KERNEL_IS_4_19) -eq 1 ]; then \ + cd $(CURSRCDIR)/sentryCollector/ebpf_collector/ && make; \ + else \ + echo "Kernel is not 4.19, skipping building ebpf_collector"; \ + fi + +isentry: + cd $(CURSRCDIR) && $(PYBIN) setup.py install -O1 --root=build/ --record=SENTRY_FILES + find $(CURSRCDIR)/build/ -type d -name '__pycache__' -exec rm -rf {} + + install -m 600 $(CURCONFIGDIR)/logrotate $(LOGROTEDIR)/sysSentry + install -m 600 $(CURCONFIGDIR)/inspect.conf $(ETCDIR)/sysSentry/ + install -m 600 $(CURCONFIGDIR)/xalarm.conf $(ETCDIR)/sysSentry/ + install -m 600 $(CURCONFIGDIR)/collector.conf $(ETCDIR)/sysSentry/ + install -m 600 $(CURSERVICEDIR)/sysSentry.service $(SYSTEMDDIR) + install -m 600 $(CURSERVICEDIR)/xalarmd.service $(SYSTEMDDIR) + install -m 600 $(CURSERVICEDIR)/sentryCollector.service $(SYSTEMDDIR) + install -d -m 550 $(PYDIR)/syssentry + install -d -m 550 $(PYDIR)/xalarm + install -d -m 550 $(PYDIR)/sentryCollector + install -m 550 src/build/usr/local/lib/$(PYNAME)/site-packages/syssentry/* $(PYDIR)/syssentry + install -m 550 src/build/usr/local/lib/$(PYNAME)/site-packages/xalarm/* $(PYDIR)/xalarm + install -m 550 libs/pyxalarm/register_xalarm.py $(PYDIR)/xalarm + install -m 550 src/build/usr/local/lib/$(PYNAME)/site-packages/sentryCollector/* $(PYDIR)/sentryCollector + install -m 550 $(CURSRCDIR)/syssentry/sentryctl $(BINDIR) + install -m 550 $(CURSRCDIR)/build/usr/local/bin/syssentry $(BINDIR) + install -m 550 $(CURSRCDIR)/build/usr/local/bin/xalarmd $(BINDIR) + install -m 550 $(CURSRCDIR)/build/usr/local/bin/sentryCollector $(BINDIR) + @if [ -f "$(CURSRCDIR)/sentryCollector/ebpf_collector/ebpf_collector" ]; then \ + install -m 550 $(CURSRCDIR)/sentryCollector/ebpf_collector/ebpf_collector $(BINDIR); \ + fi + +lib: + cd $(CURLIBDIR) && cmake . -DXD_INSTALL_BINDIR=$(LIBINSTALLDIR) -B build + cd $(CURLIBDIR)/build && make + +ilib: + cd $(CURLIBDIR)/build && make install + install -d -m 644 $(INCLUDEDIR)/xalarm + install -m 644 $(CURLIBDIR)/libxalarm/register_xalarm.h $(INCLUDEDIR)/xalarm/ + + +clean-install: + rm -rf $(CURLIBDIR)/build + rm -rf $(CURSRCDIR)/build + rm -rf $(CURSRCDIR)/sentryCollector/ebpf_collector/ebpf_collector + rm -rf $(CURSRCDIR)/sentryCollector/ebpf_collector/output + rm -rf $(CURSRCDIR)/syssentry.egg-info + rm -rf $(CURSRCDIR)/SENTRY_FILES + +clean: clean-install + rm -rf $(BINDIR)/sentryctl + rm -rf $(BINDIR)/syssentry + rm -rf $(BINDIR)/xalarmd + rm -rf $(BINDIR)/sentryCollector + rm -rf $(BINDIR)/ebpf_collector + rm -rf $(LIBINSTALLDIR)/libxalarm.so + rm -rf $(INCLUDEDIR)/xalarm + rm -rf $(ETCDIR)/sysSentry + rm -rf $(LOGROTEDIR)/sysSentry + rm -rf $(LOGSAVEDIR)/sysSentry + rm -rf $(PYDIR)/syssentry + rm -rf $(PYDIR)/xalarm + rm -rf $(PYDIR)/sentryCollector + rm -rf $(SYSTEMDDIR)/sysSentry.service + rm -rf $(SYSTEMDDIR)/xalarmd.service + rm -rf $(SYSTEMDDIR)/sentryCollector.service + systemctl daemon-reload + +test: + @if [[ -z "$(log)" ]]; then \ + log="console"; \ + fi + @if [[ -z "$t" ]]; then \ + cd $(CURTESTDIR) && sh ./test.sh "all" $(log); \ + else \ + cd $(CURTESTDIR) && sh ./test.sh $t $(log); \ + fi + +startup: + systemctl daemon-reload + systemctl restart xalarmd + systemctl restart sysSentry + systemctl restart sentryCollector diff --git a/selftest/test/common.sh b/selftest/libs/common.sh similarity index 36% rename from selftest/test/common.sh rename to selftest/libs/common.sh index ce058b380265aba387dab0de9c68ee8818275596..b60b4b9b8a3c3e9fcbdf53f21e8bd34f3b1c4414 100644 --- a/selftest/test/common.sh +++ b/selftest/libs/common.sh @@ -13,34 +13,45 @@ function common_pre_test() { heartbeat_interval="$5" test_task_name="$6" - update_test_config "$task_start" "$task_stop" "$type" $interval $heartbeat_interval + add_test_config "$task_start" "$task_stop" "$type" $interval $heartbeat_interval $test_task_name - gcc mod/test_task.c -o test_task - cp test_task /usr/bin - cp mod/test_config.mod /etc/sysSentry/tasks/"$test_task_name".mod + gcc test/sysSentry/test_task.c -o test/sysSentry/test_task + cp test/sysSentry/test_task /usr/bin syssentry & sleep 1 } function update_test_config() { - config_file="mod/test_config.mod" - task_start="$1" - task_stop="$2" - type="$3" - interval="$4" - heartbeat_interval="$5" - - if [ -f "$config_file" ]; then - sed -i "s/^task_start=.*/task_start=$task_start/" "$config_file" - sed -i "s/^task_stop=.*/task_stop=$task_stop/" "$config_file" - sed -i "s/^type=.*/type=$type/" "$config_file" - sed -i "s/^interval=.*/interval=$interval/" "$config_file" - sed -i "s/^heartbeat_interval=.*/heartbeat_interval=$heartbeat_interval/" "$config_file" - echo "test_config.mod file has been updated." - else - echo "test_config.mod file not found." - fi + task_start="$1" + task_stop="$2" + type="$3" + interval="$4" + heartbeat_interval="$5" + config_file="config/sysSentry/$6.mod" + + if [ -f "$config_file" ]; then + if [ -n "$task_start" ]; then + sed -i "s/^task_start=.*/task_start=$task_start/" "$config_file" + fi + if [ -n "$task_stop" ]; then + sed -i "s/^task_stop=.*/task_stop=$task_stop/" "$config_file" + fi + if [ -n "$type" ]; then + sed -i "s/^type=.*/type=$type/" "$config_file" + fi + if [ -n "$interval" ]; then + sed -i "s/^interval=.*/interval=$interval/" "$config_file" + fi + if [ -n "$heartbeat_interval" ]; then + sed -i "s/^heartbeat_interval=.*/heartbeat_interval=$heartbeat_interval/" "$config_file" + fi + echo "$config_file file has been updated." + return 0 + else + log_error "at update_test_config, $config_file file not found." + fi + return 1 } function add_test_config() { @@ -49,7 +60,16 @@ function add_test_config() { type="$3" interval="$4" heartbeat_interval="$5" - config_file="/etc/sysSentry/tasks/$6" + config_file="/etc/sysSentry/tasks/$6.mod" + + if [[ -z "$task_start" || -z "$task_stop" || -z "$type" ]]; then + log_error "at add_test_config, task_start, task_stop and type can't be empty str" + return 1 + fi + + if [ -f $config_file ];then + rm -rf $config_file + fi touch "$config_file" @@ -59,18 +79,18 @@ function add_test_config() { echo "task_start=$task_start">> "$config_file" echo "task_stop=$task_stop">> "$config_file" echo "type=$type">> "$config_file" - echo "interval=$interval">> "$config_file" - echo "heartbeat_interval=$heartbeat_interval">> "$config_file" - echo "test_config.mod file has been added." + if [ -n "$interval" ]; then + echo "interval=$interval">> "$config_file" + fi + if [ -n "heartbeat_interval" ];then + echo "heartbeat_interval=$heartbeat_interval">> "$config_file" + fi + echo "$config_file file has been added." + return 0 else - echo "test_config.mod file not added." + log_error "$config_file file not added." fi - - gcc mod/test_task.c -o test_task - cp test_task /usr/bin - - syssentry & - sleep 1 + return 1 } function look_pid() { @@ -78,10 +98,10 @@ function look_pid() { pid=$(ps -ef | grep '$task_task' | grep -v grep | awk '{print $2}') if [ -z "$pid"] then - echo "task_task is not existed" + echo "$task_task is not existed" return 0 else - echo "task_task is existed" + echo "$task_task is existed" return 1 fi -} \ No newline at end of file +} diff --git a/selftest/libs/expect.sh b/selftest/libs/expect.sh index 9fc097dfbcac63d5c31fbfc98e004621d4640eac..a0845419f525be84c2f45a44af222d08ba571cb5 100644 --- a/selftest/libs/expect.sh +++ b/selftest/libs/expect.sh @@ -3,25 +3,25 @@ source "libs/log.sh" -ets_expects_failed=0 -unexp_cmd="((++ets_expects_failed))" +syssentry_expects_failed=0 +unexp_cmd="((++syssentry_expects_failed))" function get_file_line() { echo "$(basename "${BASH_SOURCE[2]}")": ${BASH_LINENO[1]} } function get_expects_failed_num() { - echo "${ets_expects_failed}" + echo "${syssentry_expects_failed}" } function clean_expects_failed_num() { - ets_expects_failed=0 + syssentry_expects_failed=0 } function add_failure() { local msg=${1:-} - ((++ets_expects_failed)) + ((++syssentry_expects_failed)) log_error "add_failure(msg=${msg}) - $(get_file_line)" return 1 } @@ -33,7 +33,7 @@ function expect_eq() { if [ "${actual}" -eq "${expect}" ]; then return 0 else - ((++ets_expects_failed)) + ((++syssentry_expects_failed)) echo "expect_eq(${actual}, ${expect}, msg=${msg}) - $(get_file_line)" return 1 fi @@ -47,7 +47,7 @@ function expect_ne() { if [ "${actual}" -ne "${expect}" ]; then return 0 else - ((++ets_expects_failed)) + ((++syssentry_expects_failed)) log_error "expect_ne(${actual}, ${expect}, msg=${msg}) - $(get_file_line)" return 1 fi @@ -61,7 +61,7 @@ function expect_gt() { if [ "${actual}" -gt "${expect}" ]; then return 0 else - ((++ets_expects_failed)) + ((++syssentry_expects_failed)) log_error "expect_gt(${actual}, ${expect}, msg=${msg}) - $(get_file_line)" return 1 fi @@ -74,7 +74,7 @@ function expect_true() { if eval "${cmd}" &> /dev/null; then return 0 else - ((++ets_expects_failed)) + ((++syssentry_expects_failed)) log_error "expect_true(${cmd}, msg=${msg}) - $(get_file_line)" return 1 fi @@ -85,10 +85,51 @@ function expect_false() { local msg=$2 if eval "${cmd}" &> /dev/null; then - ((++ets_expects_failed)) + ((++syssentry_expects_failed)) log_error "expect_false(${cmd}, msg=${msg}) - $(get_file_line)" return 1 else return 0 fi -} \ No newline at end of file +} + +function expect_str_eq() { + local actual=$1 + local expect=$2 + local msg=$3 + + if [ "${actual}" = "${expect}" ]; then + return 0 + else + ((++syssentry_expects_failed)) + log_error "expect_str_eq(${actual}, ${expect}, msg=${msg}) - $(get_file_line)" + return 1 + fi +} + +function expect_str_ne() { + local actual=$1 + local expect=$2 + local msg=$3 + + if [ "${actual}" != "${expect}" ]; then + return 0 + else + ((++syssentry_expects_failed)) + log_error "expect_str_ne(${actual}, ${expect}, msg=${msg}) - $(get_file_line)" + return 1 + fi +} + +function expect_task_status_eq() { + local task_name="$1" + local expect_status="$2" + local status + for i in $(seq 3); do + status=$(sentryctl status ${task_name} | awk '{print $2}') + [[ "${status}" == "${expect_status}" ]] && break + sleep 1 + done + expect_str_eq "${status}" "${expect_status}" "current status is ${status}, expect ${expect_status}" +} + diff --git a/selftest/libs/shopt.sh b/selftest/libs/shopt.sh index 806439819b139d6e17255dff5478759b7890ad4f..31d733e1dbc555e3d7550912461b99f1c31a29f8 100644 --- a/selftest/libs/shopt.sh +++ b/selftest/libs/shopt.sh @@ -2,13 +2,13 @@ # Copyright (c), 2023-2024, Huawei Tech. Co., Ltd. -ets_shopt="" +syssentry_shopt="" function shopt_set() { local new_opt=$1 - if [ -z "$ets_shopt" ]; then - ets_shopt="$-" + if [ -z "$syssentry_shopt" ]; then + syssentry_shopt="$-" fi set "$new_opt" @@ -16,6 +16,6 @@ function shopt_set() { function shopt_recover() { set +$- - set -${ets_shopt} - unset ets_shopt + set -${syssentry_shopt} + unset syssentry_shopt } diff --git a/selftest/libs/wait.sh b/selftest/libs/wait.sh index 33dd643eb01602ddd26947d48821941b3a3394e0..beb108bbbab7a9d82d2473214a650594709526ff 100644 --- a/selftest/libs/wait.sh +++ b/selftest/libs/wait.sh @@ -1,6 +1,8 @@ #!/bin/bash # Copyright (c), 2023-2024, Huawei Tech. Co., Ltd. +source "libs/shopt.sh" + function wait_cmd_condition() { local cmd=$1 local condition=$2 @@ -50,4 +52,4 @@ function wait_cmd_nok() { wait_cmd_condition "$cmd" "!=" "0" "$interval" "$count" "$debug" return $? -} \ No newline at end of file +} diff --git a/selftest/mod/test_config.mod b/selftest/mod/test_config.mod deleted file mode 100644 index bdef47560b3405c00b75ae9cd2fc1c0b3fac4f1e..0000000000000000000000000000000000000000 --- a/selftest/mod/test_config.mod +++ /dev/null @@ -1,7 +0,0 @@ -[common] -enabled=yes -task_start=test_task -task_stop=pkill test_task -type=oneshot -interval=60 -heartbeat_interval=3600 \ No newline at end of file diff --git a/selftest/test.sh b/selftest/test.sh index 9e69e0163924fdcfe6a5dd2a92aede71cfec5f3c..86643702e73ef2398b7495faa81f3a68de670c23 100644 --- a/selftest/test.sh +++ b/selftest/test.sh @@ -1,43 +1,270 @@ #!/bin/bash # Copyright (c), 2023-2024, Huawei Tech. Co., Ltd. -source ./libs/expect.sh -export SYS_PATH=$(pwd) -tmp_log="result.log" +testcase_is_successful="yes" +testcase_error_output_mode="console" +test_error_log_dir="./error_log/" + testcase_success=0 testcase_fail=0 +testcase_timeout=0 success_cases=() fail_cases=() +timeout_cases=() + +# skip test cases +test_skip_status=222 +current_arch=$(uname -m) +test_skip_cases=() + +actual_skip_cases=() +actual_skip_nums=0 + +# timeout exit code +test_timeout_status=137 + +function read_skip_cases() +{ + file=$1 + while IFS= read -r line + do + # skip lines starting with '#' + if [[ "$line" =~ ^# ]]; then + continue + fi + # remove the blanks + line=$(echo "$line" | xargs) + # skip blank line + if [[ -z "$line" ]]; then + continue + fi + if [[ "$line" == *":"* ]]; then + testcase=$(echo "$line" |cut -d':' -f1) + arch=$(echo "$line" |cut -d':' -f2-) + if [ $arch == $current_arch ]; then + test_file=$(find ./ -type f \( -name "$testcase.sh" -o -name "$testcase.py" \)) + test_skip_cases+=("$test_file") + fi + else + test_file=$(find ./ -type f \( -name "$line.sh" -o -name "$line.py" \)) + test_skip_cases+=("$test_file") + fi + + done < $file +} + +function get_file_name_without_extension() +{ + local file_path=$1 + # file name with extension + local filename=$(basename "$file_path") + # file name without extension + local filename_no_ext="${filename%.*}" + echo "$filename_no_ext" +} + +function do_test_file() +{ + testfile="$1" + if echo "${test_skip_cases[@]}" | grep -qw "$testfile"; then + ((++actual_skip_nums)) + actual_skip_cases+=("$testfile") + return $test_skip_status + fi + + extension="${testfile##*.}" + test_name="$(get_file_name_without_extension $testfile)" + + if [ "$extension" == "sh" ]; then + timeout --signal=KILL 300s sh $testfile > "${test_name}.log" 2>&1 + elif [ "$extension" == "py" ]; then + pytest-3 $testfile > "${test_name}.log" 2>&1 + fi + ret=$? + + if [ $ret -eq 0 ]; then + ((++testcase_success)) + success_cases+=("$testfile") + rm -rf "${test_name}.log" + elif [ $ret -eq $test_timeout_status ]; then + testcase_is_successful="no" + ((++testcase_timeout)) + timeout_cases+=("$testfile") + if [ $testcase_error_output_mode == "console" ]; then + cat "${test_name}.log" + rm -rf "${test_name}.log" + else + mv "${test_name}.log" $test_error_log_dir"${test_name}.log" + fi + else + testcase_is_successful="no" + ((++testcase_fail)) + fail_cases+=("$testfile") + if [ $testcase_error_output_mode == "console" ]; then + cat "${test_name}.log" + rm -rf "${test_name}.log" + else + mv "${test_name}.log" $test_error_log_dir"${test_name}.log" + fi + fi + return $ret +} + +function print_test_log_format() +{ + current_test_index=$1 + test_total_count=$2 + test_case_file=$3 + test_status_string=$4 + test_cost_time=$5 + if [ -n "$test_cost_time" ]; then + printf "%3d/%-3d %-60s %7s %.2fs\n" $current_test_index $test_total_count $(basename $test_case_file) $test_status_string $test_cost_time + else + printf "%3d/%-3d %-60s %7s\n" $current_test_index $test_total_count $(basename $test_case_file) $test_status_string + fi +} + +function output_test_result_detail() +{ + current_test_index=$1 + test_total_count=$2 + test_case_file=$3 + test_status_code=$4 + test_cost_time=$5 + if [ $test_status_code -eq 0 ]; then + print_test_log_format $current_test_index $test_total_count $test_case_file "SUCCESS" $test_cost_time + elif [ $test_status_code -eq 137 ]; then + print_test_log_format $current_test_index $test_total_count $test_case_file "TIMEOUT" $test_cost_time + elif [ $test_status_code -eq $test_skip_status ]; then + print_test_log_format $current_test_index $test_total_count $test_case_file "SKIPPED" $test_cost_time + else + print_test_log_format $current_test_index $test_total_count $test_case_file " ERROR " $test_cost_time + fi +} + +function do_all_test() +{ + test_count=0 + test_files=$(find test/ -type f \( -name "test_*.sh" -o -name "test_*.py" \)) + test_total_count=$(echo "$test_files" | wc -l) + for testfile in $test_files + do + test_count=$((test_count+1)) + print_test_log_format $test_count $test_total_count $testfile "RUNNING" + + start_time_tmp=$(date +%s) + do_test_file $testfile + ret=$? + end_time_tmp=$(date +%s) + + # move the cursor to the previous line + echo -en "\033[1A\033[K" + output_test_result_detail $test_count $test_total_count $testfile $ret $((end_time_tmp - start_time_tmp)) + done + +} + +function do_one_test() +{ + testfile=$1 + + print_test_log_format 1 1 $testfile "RUNNING" + + start_time_tmp=$(date +%s) + do_test_file $testfile + ret=$? + end_time_tmp=$(date +%s) + + # move the cursor to the previous line + echo -en "\033[1A\033[K" + output_test_result_detail 1 1 $testfile $ret $((end_time_tmp - start_time_tmp)) +} + +function output_unsuccessful_test_cases() +{ + if [ $testcase_fail -gt 0 ]; then + printf "============== FAILED TEST ==============\n" + for file_name in "${fail_cases[@]}"; do + printf "$(basename $file_name)\n" + done + fi + + if [ $testcase_timeout -gt 0 ]; then + printf "============== TIMEOUT TEST ==============\n" + for file_name in "${timeout_cases[@]}"; do + printf "$(basename $file_name)\n" + done + fi + + if [ $actual_skip_nums -gt 0 ]; then + printf "============== SKIPPED TEST ==============\n" + for file_name in "${actual_skip_cases[@]}"; do + printf "$(basename $file_name)\n" + done + fi +} + +function output_test_cases_result() +{ + printf "============== TEST RESULT ==============\n" + printf "success: $testcase_success\n" + printf "skipped: $actual_skip_nums\n" + printf "timeout: $testcase_timeout\n" + printf "failed: $testcase_fail\n" + printf "total duration: ${total_time}s\n" + printf "=============== TEST END ================\n" +} + +function do_test() +{ + if [ "$2" == "file" ]; then + testcase_error_output_mode="file" + if [ ! -d "${test_error_log_dir}" ];then + mkdir ${test_error_log_dir} + fi + fi + + # read whitelist + read_skip_cases "testsuite_skip_list" + + if [ "$1" == "all" ] || [ $# -eq 0 ]; then + # start to test + start_time=$(date +%s) + do_all_test + end_time=$(date +%s) + total_time=$((end_time - start_time)) + + # print test result info + output_unsuccessful_test_cases + output_test_cases_result + else + test_file=$(find ./ -type f \( -name "$1.sh" -o -name "$1.py" \)) + if [ ! -f "$test_file" ]; then + printf "testsuite $1 not exist, check whether the testname is corrent, we need to use $1 to match test/$1.py or test/$1.sh\n" + exit 1 + else + do_one_test $test_file + fi + fi + + # remove .pyc file + find . -name "*.pyc" | xargs rm -rf + + if [ "$testcase_is_successful" == "no" ]; then + printf "test failed!!!\n" + if [ $testcase_error_output_mode == "file" ]; then + printf "=============== ERROR INFO ==============\n" + printf "the execution log of the failed case refers to the following file:\n" + for file in "$test_error_log_dir"*; do + if [ -f "$file" ]; then + printf "%s\n" $file + fi + done + printf "=============== ERROR END ===============\n" + fi + exit 1 + fi +} -for file in $(find test/ -name test_\*\.sh) -do - echo "=== run test $file start ===" - sh $file > ${tmp_log} 2>&1 - - if [ $? -eq 0 ]; then - ((++testcase_success)) - success_cases+=("$file") - else - ((++testcase_fail)) - fail_cases+=("$file") - echo "test $file failed!" - cat ${tmp_log} - fi - echo "=== run test $file end ===" -done - -echo "----------Success cases:----------" -for file_name in "${success_cases[@]}"; do - echo "$file_name" -done - -echo "----------Fail cases:----------" -for file_name in "${fail_cases[@]}"; do - echo "$file_name" -done - -rm -rf ${tmp_log} - -echo "============ TOTAL RESULT ============" -echo "[result] success:$testcase_success failed:$testcase_fail" +do_test $1 $2 diff --git a/selftest/mod/test_task.c b/selftest/test/sysSentry/test_task.c similarity index 100% rename from selftest/mod/test_task.c rename to selftest/test/sysSentry/test_task.c diff --git a/selftest/test/test_sentryctl_end_exception.sh b/selftest/test/test_sentryctl_end_exception.sh index 0b1e61eaabde7ccbadb0809391bc048320f8fe9b..e0fc8e0ed414e3e7004ba679fb0b0008c93ac82d 100644 --- a/selftest/test/test_sentryctl_end_exception.sh +++ b/selftest/test/test_sentryctl_end_exception.sh @@ -3,7 +3,7 @@ source "libs/expect.sh" source "libs/lib.sh" -source "test/common.sh" +source "libs/common.sh" set +e tmp_log="tmp_log" @@ -42,7 +42,7 @@ function post_test() { kill -9 `pgrep -w test_task` sleep 1 done - rm -rf ${tmp_log} test_task + rm -rf ${tmp_log} test/sysSentry/test_task rm -rf /usr/bin/test_task /etc/sysSentry/tasks/test_end_exception.mod } set -x diff --git a/selftest/test/test_sentryctl_exception.sh b/selftest/test/test_sentryctl_exception.sh index f1d21e1f2709e979c5f0275f07de15eb7e2321e6..c8e3107ee4f5d1350d927359b3c894afec67210a 100644 --- a/selftest/test/test_sentryctl_exception.sh +++ b/selftest/test/test_sentryctl_exception.sh @@ -3,7 +3,7 @@ source "libs/expect.sh" source "libs/lib.sh" -source "test/common.sh" +source "libs/common.sh" set +e tmp_log="tmp_log" @@ -19,10 +19,9 @@ function pre_test() { kill -9 `ps aux|grep syssentry|grep -v grep|awk '{print $2}'` kill -9 `ps aux|grep test_task|grep -v grep|awk '{print $2}'` - update_test_config "test_task" "pkill test_task" "oneshot" 60 3600 - gcc mod/test_task.c -o test_task - cp test_task /usr/bin - cp mod/test_config.mod /etc/sysSentry/tasks/test_sentryctl_exception.mod + add_test_config "test_task" "pkill test_task" "oneshot" 60 3600 "test_sentryctl_exception" + gcc test/sysSentry/test_task.c -o test/sysSentry/test_task + cp test/sysSentry/test_task /usr/bin } function do_test() { @@ -59,8 +58,8 @@ function do_test() { sentryctl aaa test_sentryctl_exception 2>&1 | tee ${tmp_log} | cat expect_true "grep -E '(sentryctl: error: argument cmd_type: invalid choice:)' ${tmp_log}" - update_test_config "test_task" "pkill test_task" "period" 60 3600 - cp mod/test_config.mod /etc/sysSentry/tasks/test_sentryctl_exception.mod + add_test_config "test_task" "pkill test_task" "period" 60 3600 "test_sentryctl_exception" + expect_eq $? 0 sentryctl reload test_sentryctl_exception 2>&1 | tee ${tmp_log} | cat expect_true "grep -E '(type of mod is different from old type, reload failed)' ${tmp_log}" @@ -76,7 +75,7 @@ function post_test() { kill -9 `pgrep -w test_task` sleep 1 done - rm -rf ${tmp_log} test_task + rm -rf ${tmp_log} test/sysSentry/test_task rm -rf /usr/bin/test_task /etc/sysSentry/tasks/test_sentryctl_exception.mod } set -x diff --git a/selftest/test/test_sentryctl_heartbeat_exception.sh b/selftest/test/test_sentryctl_heartbeat_exception.sh index 91d54327a3ae4a8e20e2433639c3354ad27fc488..37cae104f8ba774dfc70b6d51abf5d5fc7eadf0e 100644 --- a/selftest/test/test_sentryctl_heartbeat_exception.sh +++ b/selftest/test/test_sentryctl_heartbeat_exception.sh @@ -3,7 +3,7 @@ source "libs/expect.sh" source "libs/lib.sh" -source "test/common.sh" +source "libs/common.sh" set +e tmp_log="tmp_log" @@ -48,7 +48,7 @@ function post_test() { kill -9 `pgrep -w test_task` sleep 1 done - rm -rf ${tmp_log} test_task + rm -rf ${tmp_log} test/sysSentry/test_task rm -rf /usr/bin/test_task /etc/sysSentry/tasks/test_heartbeat_exception.mod } set -x diff --git a/selftest/test/test_sentryctl_interval_exception.sh b/selftest/test/test_sentryctl_interval_exception.sh index 3cd83c124be61f6a4381d2a43ad3417111a2ba89..9066ff84d6532bc9103634a969f9febc735e4958 100644 --- a/selftest/test/test_sentryctl_interval_exception.sh +++ b/selftest/test/test_sentryctl_interval_exception.sh @@ -3,7 +3,7 @@ source "libs/expect.sh" source "libs/lib.sh" -source "test/common.sh" +source "libs/common.sh" set +e tmp_log="tmp_log" @@ -50,7 +50,7 @@ function post_test() { kill -9 `pgrep -w test_task` sleep 1 done - rm -rf ${tmp_log} test_task + rm -rf ${tmp_log} test/sysSentry/test_task rm -rf /usr/bin/test_task /etc/sysSentry/tasks/test_interval_exception.mod } set -x diff --git a/selftest/test/test_sentryctl_modname_long_length_exception.sh b/selftest/test/test_sentryctl_modname_long_length_exception.sh index 837b6fb2b35dee7939b62b5a678ba138eb9fc325..c91af59be9fc7e30e0844308e92a8adce4757410 100644 --- a/selftest/test/test_sentryctl_modname_long_length_exception.sh +++ b/selftest/test/test_sentryctl_modname_long_length_exception.sh @@ -3,28 +3,30 @@ source "libs/expect.sh" source "libs/lib.sh" -source "test/common.sh" +source "libs/common.sh" set +e tmp_log="tmp_log" # 测试子任务名过长的测试用例 -# length:256 -str="a" -result1="" -for i in {1..256}; do - result+="$str" -done - function pre_test() { + gcc test/sysSentry/test_task.c -o test/sysSentry/test_task + cp test/sysSentry/test_task /usr/bin + syssentry & sleep 1 } function do_test() { + # length:256 + str="a" + result1="" + for i in {1..256}; do + result1+="$str" + done - sentryctl status $result 2>&1 | tee ${tmp_log} | cat + sentryctl status $result1 2>&1 | tee ${tmp_log} | cat expect_true "grep -E '(status: cannot find task by name)' ${tmp_log}" @@ -32,7 +34,8 @@ function do_test() { for i in {1..251}; do result2+="$str" done - add_test_config "test_task" "pkill test_task" "oneshot" 60 3600 "$result2.mod" + add_test_config "test_task" "pkill test_task" "oneshot" 60 3600 "$result2" + expect_eq $? 0 sentryctl reload $result2 expect_eq $? 0 diff --git a/selftest/test/test_sentryctl_modname_valid.sh b/selftest/test/test_sentryctl_modname_valid.sh index b2a4c65d41984485012ab3b056182153e3d9e344..98239cf1cb4eb8854e7f5b39ac58fc0176346841 100644 --- a/selftest/test/test_sentryctl_modname_valid.sh +++ b/selftest/test/test_sentryctl_modname_valid.sh @@ -3,7 +3,7 @@ source "libs/expect.sh" source "libs/lib.sh" -source "test/common.sh" +source "libs/common.sh" set +e tmp_log="tmp_log" @@ -29,14 +29,14 @@ function do_test() { } function post_test() { - while [[ -n "`ps aux|grep -w syssentry|grep -v grep`" ]]; do - kill -9 `pgrep -w syssentry` - kill -9 `pgrep -w test_task` - sleep 1 - done + while [[ -n "`ps aux|grep -w syssentry|grep -v grep`" ]]; do + kill -9 `pgrep -w syssentry` + kill -9 `pgrep -w test_task` + sleep 1 + done rm -rf ${tmp_log} - rm -rf test_task /usr/bin/test_task /etc/sysSentry/tasks/"$result1".mod - rm -rf /etc/sysSentry/tasks/"$result2".mod + rm -rf test/sysSentry/test_task /usr/bin/test_task + rm -rf /etc/sysSentry/tasks/this*.mod } set -x run_testcase diff --git a/selftest/test/test_sentryctl_normal.sh b/selftest/test/test_sentryctl_normal.sh index b2eafcc32a34382f0cd3efce35a7834df9cc9989..efd9f29aaf8379fda87eeca9b9b06241f524b937 100644 --- a/selftest/test/test_sentryctl_normal.sh +++ b/selftest/test/test_sentryctl_normal.sh @@ -3,7 +3,7 @@ source "libs/expect.sh" source "libs/lib.sh" -source "test/common.sh" +source "libs/common.sh" set +e tmp_log="tmp_log" @@ -45,7 +45,7 @@ function post_test() { sleep 1 done rm -rf ${tmp_log} - rm -rf test_task /usr/bin/test_task /etc/sysSentry/tasks/test_normal.mod + rm -rf test/sysSentry/test_task /usr/bin/test_task /etc/sysSentry/tasks/test_normal.mod } set -x run_testcase diff --git a/selftest/test/test_sentryctl_reload.sh b/selftest/test/test_sentryctl_reload.sh index bc33809a5e1977932c961a90607a90884dbdc1ef..85a541824105c1beb6f866e27e9964fbd558c753 100644 --- a/selftest/test/test_sentryctl_reload.sh +++ b/selftest/test/test_sentryctl_reload.sh @@ -3,7 +3,7 @@ source "libs/expect.sh" source "libs/lib.sh" -source "test/common.sh" +source "libs/common.sh" set +e tmp_log="tmp_log" @@ -22,14 +22,15 @@ function do_test() { sentryctl start test_sentryctl_reload expect_eq $? 0 - update_test_config "test_task" "pkill test_task" "period" 60 5 - cp mod/test_config.mod /etc/sysSentry/tasks/test_sentryctl_reload.mod + add_test_config "test_task" "pkill test_task" "period" 60 5 "test_sentryctl_reload" + expect_eq $? 0 sentryctl reload test_sentryctl_reload expect_eq $? 0 sentryctl stop test_sentryctl_reload expect_eq $? 0 + sleep 1 sentryctl start test_sentryctl_reload expect_eq $? 0 @@ -44,14 +45,15 @@ function do_test() { expect_true "grep -E '(status: FAILED)' ${tmp_log}" fi - update_test_config "test_task" "pkill test_task" "period" 20 3600 - cp mod/test_config.mod /etc/sysSentry/tasks/test_sentryctl_reload.mod + add_test_config "test_task" "pkill test_task" "period" 20 3600 "test_sentryctl_reload" + expect_eq $? 0 sentryctl reload test_sentryctl_reload expect_eq $? 0 sentryctl stop test_sentryctl_reload expect_eq $? 0 + sleep 1 sentryctl start test_sentryctl_reload expect_eq $? 0 @@ -76,7 +78,7 @@ function post_test() { kill -9 `pgrep -w test_task` sleep 1 done - rm -rf ${tmp_log} test_task /usr/bin/test_task /etc/sysSentry/tasks/test_sentryctl_reload.mod + rm -rf ${tmp_log} test/sysSentry/test_task /usr/bin/test_task /etc/sysSentry/tasks/test_sentryctl_reload.mod } set -x run_testcase diff --git a/selftest/test/test_sentryctl_start_exception.sh b/selftest/test/test_sentryctl_start_exception.sh index 0b12f5f6bbba81f781e3d30f140a8a0aa55dcfc1..b6611aa93c00710d5f2437b997627e0fc6e54831 100644 --- a/selftest/test/test_sentryctl_start_exception.sh +++ b/selftest/test/test_sentryctl_start_exception.sh @@ -3,7 +3,7 @@ source "libs/expect.sh" source "libs/lib.sh" -source "test/common.sh" +source "libs/common.sh" set +e tmp_log="tmp_log" @@ -33,7 +33,7 @@ function post_test() { kill -9 `pgrep -w test_task` sleep 1 done - rm -rf ${tmp_log} test_task + rm -rf ${tmp_log} test/sysSentry/test_task rm -rf /usr/bin/test_task /etc/sysSentry/tasks/test_start_exception.mod } set -x diff --git a/selftest/test/test_sentryctl_type_exception.sh b/selftest/test/test_sentryctl_type_exception.sh index 35e624b04075556915279ce6cf43c78413a2f1e8..df1ad4d342c237150ab1e9d145fd374bdb09753d 100644 --- a/selftest/test/test_sentryctl_type_exception.sh +++ b/selftest/test/test_sentryctl_type_exception.sh @@ -3,7 +3,7 @@ source "libs/expect.sh" source "libs/lib.sh" -source "test/common.sh" +source "libs/common.sh" set +e tmp_log="tmp_log" @@ -38,7 +38,7 @@ function post_test() { kill -9 `pgrep -w test_task` sleep 1 done - rm -rf ${tmp_log} test_task /usr/bin/test_task /etc/sysSentry/tasks/test_type_exception.mod + rm -rf ${tmp_log} test/sysSentry/test_task /usr/bin/test_task /etc/sysSentry/tasks/test_type_exception.mod } set -x run_testcase diff --git a/selftest/test/test_sentryctl_type_oneshot.sh b/selftest/test/test_sentryctl_type_oneshot.sh index 74c113cb1d400c314952e4c56e72506214498cc9..500aba40f067ad9cff368d05bbd70bcb5d7dd09b 100644 --- a/selftest/test/test_sentryctl_type_oneshot.sh +++ b/selftest/test/test_sentryctl_type_oneshot.sh @@ -3,7 +3,7 @@ source "libs/expect.sh" source "libs/lib.sh" -source "test/common.sh" +source "libs/common.sh" set +e tmp_log="tmp_log" @@ -66,7 +66,7 @@ function post_test() { kill -9 `pgrep -w test_task` sleep 1 done - rm -rf ${tmp_log} test_task /usr/bin/test_task /etc/sysSentry/tasks/test_type_oneshot.mod + rm -rf ${tmp_log} test/sysSentry/test_task /usr/bin/test_task /etc/sysSentry/tasks/test_type_oneshot.mod } set -x run_testcase diff --git a/selftest/test/test_sentryctl_type_period.sh b/selftest/test/test_sentryctl_type_period.sh index 635fc8e965d035086cd8f3682ba622c3f954e603..e6a1d8f6b8fdc5aac0dcbb18aba7b4b33c8c5a19 100644 --- a/selftest/test/test_sentryctl_type_period.sh +++ b/selftest/test/test_sentryctl_type_period.sh @@ -3,7 +3,7 @@ source "libs/expect.sh" source "libs/lib.sh" -source "test/common.sh" +source "libs/common.sh" set +e tmp_log="tmp_log" @@ -68,7 +68,7 @@ function post_test() { kill -9 `pgrep -w test_task` sleep 1 done - rm -rf ${tmp_log} test_task /usr/bin/test_task /etc/sysSentry/tasks/test_type_period.mod + rm -rf ${tmp_log} test/sysSentry/test_task /usr/bin/test_task /etc/sysSentry/tasks/test_type_period.mod } set -x run_testcase diff --git a/selftest/test/test_xalarm_register_and_unregister_exception.sh b/selftest/test/test_xalarm_register_and_unregister_exception.sh index 6d41fe75d3b69730df3d061e42b7330358286d0d..5e909951089f3ef7ccaef68f7a97aeeb643ee33d 100644 --- a/selftest/test/test_xalarm_register_and_unregister_exception.sh +++ b/selftest/test/test_xalarm_register_and_unregister_exception.sh @@ -10,23 +10,23 @@ set +e #测试unregister的场景,其他用户解注册已有clientId和没出现的clientId,重复注册 function pre_test() { - rm -rf ./checklog xalarm/unreg_demo xalarm/send_demo xalarm/reg_demo - gcc xalarm/reg_demo.c -o xalarm/reg_demo -lxalarm - gcc xalarm/unreg_demo.c -o xalarm/unreg_demo -lxalarm + rm -rf ./checklog test/xalarm/unreg_demo test/xalarm/send_demo test/xalarm/reg_demo + gcc test/xalarm/reg_demo.c -o test/xalarm/reg_demo -lxalarm + gcc test/xalarm/unreg_demo.c -o test/xalarm/unreg_demo -lxalarm systemctl start xalarmd.service } function do_test() { - ./xalarm/reg_demo 2 >> checklog 2>&1 & + ./test/xalarm/reg_demo 2 >> checklog 2>&1 & wait_cmd_ok "grep \"xalarm_Register: alarm has registered\" ./checklog" 1 3 expect_eq $? 0 "register twice" - ./xalarm/reg_demo >> checklog 2>&1 & - ./xalarm/unreg_demo 0 >> checklog 2>&1 & + ./test/xalarm/reg_demo >> checklog 2>&1 & + ./test/xalarm/unreg_demo 0 >> checklog 2>&1 & wait_cmd_ok "grep \"unregister xalarm, client id is 0.xalarm_UnRegister: alarm has not registered\" ./checklog" 1 3 expect_eq $? 0 "unregister available client id of xalarm" - ./xalarm/unreg_demo 100 >> checklog 2>&1 & + ./test/xalarm/unreg_demo 100 >> checklog 2>&1 & wait_cmd_ok "grep \"unregister xalarm, client id is 100.xalarm_UnRegister: alarm has not registered\" ./checklog" 1 3 expect_eq $? 0 "unregister unavailable client id of xalarm" @@ -35,7 +35,7 @@ function do_test() { function post_test() { kill -9 $(pgrep -w unreg_demo) cat ./checklog - rm -rf ./checklog xalarm/unreg_demo xalarm/reg_demo + rm -rf ./checklog test/xalarm/unreg_demo test/xalarm/reg_demo systemctl stop xalarmd.service } diff --git a/selftest/test/test_xalarm_send_message.sh b/selftest/test/test_xalarm_send_message.sh index 4c8c687dcde4c6bbd0daa30bc9f688a350d95f11..310fa530117db8c3bf820fa54895267a8f859243 100644 --- a/selftest/test/test_xalarm_send_message.sh +++ b/selftest/test/test_xalarm_send_message.sh @@ -10,19 +10,19 @@ set +e #测试发送消息的场景,参数合法性校验以及关闭xalarmd之后的场景 function pre_test() { - rm -rf ./checklog ./tmp_log xalarm/send_demo xalarm/reg_demo - gcc xalarm/send_demo.c -o xalarm/send_demo -lxalarm - gcc xalarm/reg_demo.c -o xalarm/reg_demo -lxalarm + rm -rf ./checklog ./tmp_log test/xalarm/send_demo test/xalarm/reg_demo + gcc test/xalarm/send_demo.c -o test/xalarm/send_demo -lxalarm + gcc test/xalarm/reg_demo.c -o test/xalarm/reg_demo -lxalarm systemctl start xalarmd.service } function do_test() { - ./xalarm/reg_demo >> checklog 2>&1 & + ./test/xalarm/reg_demo >> checklog 2>&1 & wait_cmd_ok "grep \"register success\" ./checklog" 1 3 expect_eq $? 0 "xalarm register success" # 发送用户注册的alarm id消息 - ./xalarm/send_demo 1001 1 2 "cpu usage high warning" >> checklog 2>&1 & + ./test/xalarm/send_demo 1001 1 2 "cpu usage high warning" >> checklog 2>&1 & wait_cmd_ok "grep \"id:1001\" ./checklog" 1 3 expect_eq $? 0 "alarm id check" @@ -37,27 +37,27 @@ function do_test() { # 发送用户未注册的alarm id消息 start_line=$(wc -l < ./checklog) - ./xalarm/send_demo 1007 1 2 "cpu usage high warning" >> checklog 2>&1 & + ./test/xalarm/send_demo 1007 1 2 "cpu usage high warning" >> checklog 2>&1 & end_line=$(wc -l < ./checklog) expect_eq $end_line $start_line "send unregistered alarm id to xalarm" # 验证不合法参数 start_line=$(expr $(wc -l < ./checklog) + 1) - ./xalarm/send_demo 9000 2 1 "cpu usage high" >> checklog 2>&1 & + ./test/xalarm/send_demo 9000 2 1 "cpu usage high" >> checklog 2>&1 & end_line=$(wc -l < ./checklog) sed -n "${start_line}, ${end_line}p" ./checklog > ./tmp_log wait_cmd_ok "grep \"xalarm_Report: alarm info invalid\" ./tmp_log" 1 3 expect_eq $? 0 "alarm id check" start_line=$(expr $(wc -l < ./checklog) + 1) - ./xalarm/send_demo 1002 7 -1 "cpu usage high" >> checklog 2>&1 & + ./test/xalarm/send_demo 1002 7 -1 "cpu usage high" >> checklog 2>&1 & end_line=$(wc -l < ./checklog) sed -n "${start_line}, ${end_line}p" ./checklog > ./tmp_log wait_cmd_ok "grep \"xalarm_Report: alarm info invalid\" ./tmp_log" 1 3 expect_eq $? 0 "alarm type check" start_line=$(expr $(wc -l < ./checklog) + 1) - ./xalarm/send_demo 1002 2 -1 "cpu usage high" >> checklog 2>&1 & + ./test/xalarm/send_demo 1002 2 -1 "cpu usage high" >> checklog 2>&1 & end_line=$(wc -l < ./checklog) sed -n "${start_line}, ${end_line}p" ./checklog > ./tmp_log wait_cmd_ok "grep \"xalarm_Report: alarm info invalid\" ./tmp_log" 1 3 @@ -65,14 +65,14 @@ function do_test() { # 验证解注册 sleep 10 - ./xalarm/send_demo 1001 1 2 "cpu usage high warning" >> checklog 2>&1 & + ./test/xalarm/send_demo 1001 1 2 "cpu usage high warning" >> checklog 2>&1 & wait_cmd_ok "grep \"unregister xalarm success\" ./checklog" 1 3 expect_eq $? 0 "check unregister xalarm" # 停止xalarmd服务后发消息 systemctl stop xalarmd.service - ./xalarm/send_demo 1001 1 2 "cpu usage high warning" >> checklog 2>&1 & + ./test/xalarm/send_demo 1001 1 2 "cpu usage high warning" >> checklog 2>&1 & wait_cmd_ok "grep \"xalarm_Report: sendto failed errno: 2\" ./checklog" 1 3 expect_eq $? 0 "xalarm send message while stop xalarmd service" } @@ -80,7 +80,7 @@ function do_test() { function post_test() { kill -9 $(pgrep -w reg_demo) cat ./checklog - rm -rf ./checklog ./tmp_log xalarm/send_demo xalarm/reg_demo + rm -rf ./checklog ./tmp_log test/xalarm/send_demo test/xalarm/reg_demo systemctl stop xalarmd.service } diff --git a/selftest/test/test_xalarm_upgrade_exception.sh b/selftest/test/test_xalarm_upgrade_exception.sh index 045df3bad66e53e1082a47354c752edea03c1d56..61aa911309c961db550e417ab02a2fe3d15744f4 100644 --- a/selftest/test/test_xalarm_upgrade_exception.sh +++ b/selftest/test/test_xalarm_upgrade_exception.sh @@ -10,28 +10,28 @@ set +e #测试upgrade场景:更新生效的场景、错误的clientId、错误的alarm id function pre_test() { - rm -rf ./checklog xalarm/upgrade_demo xalarm/send_demo - gcc xalarm/upgrade_demo.c -o xalarm/upgrade_demo -lxalarm - gcc xalarm/send_demo.c -o xalarm/send_demo -lxalarm + rm -rf ./checklog test/xalarm/upgrade_demo test/xalarm/send_demo + gcc test/xalarm/upgrade_demo.c -o test/xalarm/upgrade_demo -lxalarm + gcc test/xalarm/send_demo.c -o test/xalarm/send_demo -lxalarm systemctl start xalarmd.service } function do_test() { - ./xalarm/upgrade_demo 4 0 1001 1002 1003 1004 >> checklog 2>&1 & - ./xalarm/send_demo 1004 1 2 "cpu usage high warning" + ./test/xalarm/upgrade_demo 4 0 1001 1002 1003 1004 >> checklog 2>&1 & + ./test/xalarm/send_demo 1004 1 2 "cpu usage high warning" wait_cmd_ok "grep \"id:1004\" ./checklog" 1 3 expect_eq $? 0 "check upgrade take effect" kill -9 $(pgrep -w upgrade_demo) rm -rf checklog - ./xalarm/upgrade_demo 4 0 1001 1002 1003 4004 >> checklog 2>&1 & + ./test/xalarm/upgrade_demo 4 0 1001 1002 1003 4004 >> checklog 2>&1 & wait_cmd_ok "grep \"xalarm_Upgrade: invalid args\" ./checklog" 1 3 expect_eq $? 0 "upgrade with invalid alarm id" rm -rf checklog - ./xalarm/upgrade_demo 4 999 1001 1002 1003 1004 >> checklog 2>&1 & + ./test/xalarm/upgrade_demo 4 999 1001 1002 1003 1004 >> checklog 2>&1 & wait_cmd_ok "grep \"xalarm_Upgrade: invalid args\" ./checklog" 1 3 expect_eq $? 0 "upgrade with invalid client id" @@ -40,7 +40,7 @@ function do_test() { function post_test() { kill -9 $(pgrep -w upgrade_demo) cat ./checklog - rm -rf ./checklog xalarm/upgrade_demo xalarm/send_demo + rm -rf ./checklog test/xalarm/upgrade_demo test/xalarm/send_demo systemctl stop xalarmd.service } diff --git a/selftest/xalarm/CMakeLists.txt b/selftest/test/xalarm/CMakeLists.txt similarity index 100% rename from selftest/xalarm/CMakeLists.txt rename to selftest/test/xalarm/CMakeLists.txt diff --git a/selftest/xalarm/reg_demo.c b/selftest/test/xalarm/reg_demo.c similarity index 100% rename from selftest/xalarm/reg_demo.c rename to selftest/test/xalarm/reg_demo.c diff --git a/selftest/xalarm/send_demo.c b/selftest/test/xalarm/send_demo.c similarity index 100% rename from selftest/xalarm/send_demo.c rename to selftest/test/xalarm/send_demo.c diff --git a/selftest/xalarm/unreg_demo.c b/selftest/test/xalarm/unreg_demo.c similarity index 100% rename from selftest/xalarm/unreg_demo.c rename to selftest/test/xalarm/unreg_demo.c diff --git a/selftest/xalarm/upgrade_demo.c b/selftest/test/xalarm/upgrade_demo.c similarity index 100% rename from selftest/xalarm/upgrade_demo.c rename to selftest/test/xalarm/upgrade_demo.c diff --git a/selftest/testsuite_skip_list b/selftest/testsuite_skip_list new file mode 100644 index 0000000000000000000000000000000000000000..acfc3d9840491ef71101c6c9e70022d6f0a74b84 --- /dev/null +++ b/selftest/testsuite_skip_list @@ -0,0 +1,8 @@ +# USAGE: +# if it's skipped on all of the arch: +# testsuite +# +# if it's skipped on part of the arch: +# testsuite:arch1 +# testsuite:arch2 +test_cpu_sentry