325 lines
11 KiB
Diff
325 lines
11 KiB
Diff
From eb0e130cc72a9d5d6f6e53fa96d74a11a3b8f6eb Mon Sep 17 00:00:00 2001
|
|
From: LHesperus <2639350497@qq.com>
|
|
Date: Sat, 25 Nov 2023 15:45:14 +0800
|
|
Subject: [PATCH] add command check, config check , test case
|
|
|
|
---
|
|
extra-tools/da-tool/script/da-tool.sh | 68 +++++++++++++++++-
|
|
.../da-tool/test/config_check/config_check.sh | 70 +++++++++++++++++++
|
|
.../test/config_check/config_test1.conf | 2 +
|
|
.../test/config_check/config_test2.conf | 2 +
|
|
.../test/config_check/config_test3.conf | 2 +
|
|
.../test/config_check/config_test4.conf | 2 +
|
|
.../test/config_check/config_test5.conf | 2 +
|
|
.../test/config_check/config_test6.conf | 2 +
|
|
.../test/config_check/config_test7.conf | 2 +
|
|
extra-tools/da-tool/test/opt_test/opt_test.sh | 49 +++++++++++++
|
|
10 files changed, 198 insertions(+), 3 deletions(-)
|
|
create mode 100755 extra-tools/da-tool/test/config_check/config_check.sh
|
|
create mode 100644 extra-tools/da-tool/test/config_check/config_test1.conf
|
|
create mode 100644 extra-tools/da-tool/test/config_check/config_test2.conf
|
|
create mode 100644 extra-tools/da-tool/test/config_check/config_test3.conf
|
|
create mode 100644 extra-tools/da-tool/test/config_check/config_test4.conf
|
|
create mode 100644 extra-tools/da-tool/test/config_check/config_test5.conf
|
|
create mode 100644 extra-tools/da-tool/test/config_check/config_test6.conf
|
|
create mode 100644 extra-tools/da-tool/test/config_check/config_test7.conf
|
|
create mode 100644 extra-tools/da-tool/test/opt_test/opt_test.sh
|
|
|
|
diff --git a/extra-tools/da-tool/script/da-tool.sh b/extra-tools/da-tool/script/da-tool.sh
|
|
index efc9592..a25c347 100755
|
|
--- a/extra-tools/da-tool/script/da-tool.sh
|
|
+++ b/extra-tools/da-tool/script/da-tool.sh
|
|
@@ -96,7 +96,7 @@ while getopts "t:h" opt; do
|
|
is_sample_with_analysis=false
|
|
;;
|
|
t)
|
|
- if [[ $OPTARG =~ ^[0-9]+$ ]]; then
|
|
+ if [[ $OPTARG =~ ^[0-9]{1,3}$ ]]; then
|
|
sleep_time=$OPTARG
|
|
else
|
|
usage
|
|
@@ -122,6 +122,13 @@ while getopts "t:h" opt; do
|
|
esac
|
|
done
|
|
|
|
+shift $((OPTIND - 1))
|
|
+if [[ $# -ne 0 ]]; then
|
|
+ echo "Illegal parameter :$@"
|
|
+ usage
|
|
+ exit 1
|
|
+fi
|
|
+
|
|
function config_display() {
|
|
echo "kernel_symbols:" >>$sample_log
|
|
for item in "${kernel_symbols[@]}"; do
|
|
@@ -154,7 +161,57 @@ function arr_repet_ele_check() {
|
|
for element in "${arr[@]}"; do
|
|
count=$(printf '%s\n' "${arr[@]}" | grep -c -w "$element")
|
|
if [ $count -ge 2 ]; then
|
|
- echo " '$element' duplicate configuration, please check '$config_file'"
|
|
+ echo " '$element' duplicate configuration, please check '$config_file'!!!"
|
|
+ exit 1
|
|
+ fi
|
|
+ done
|
|
+}
|
|
+
|
|
+# function names cannot contain '.'
|
|
+function arr_check_function_support() {
|
|
+ local symbols_tmp=("$@")
|
|
+ for symbol in "${symbols_tmp[@]}"; do
|
|
+ if [[ $symbol =~ \. ]]; then
|
|
+ echo "$symbol have '.', not support, please check '$config_file!!!'" | tee -a $sample_log
|
|
+ exit 1
|
|
+ fi
|
|
+ done
|
|
+}
|
|
+
|
|
+# kernel symbols should be found in '/proc/kallsyms'
|
|
+function arr_check_kernel_symbols_exist() {
|
|
+ local symbols_tmp=("$@")
|
|
+ for symbol in "${symbols_tmp[@]}"; do
|
|
+ if grep "\<$symbol\>" /proc/kallsyms >/dev/null; then
|
|
+ echo "$symbol exist in /proc/kallsyms" >>$sample_log
|
|
+ else
|
|
+ echo "$symbol does not exist in /proc/kallsyms, please check '$config_file'!!!" | tee -a $sample_log
|
|
+ exit 1
|
|
+ fi
|
|
+ done
|
|
+}
|
|
+
|
|
+# user symbols should be found by 'nm bin'
|
|
+function arr_check_user_symbols_exist() {
|
|
+ binary=$1
|
|
+ local symbols_tmp=("${@:2}")
|
|
+ for symbol in "${symbols_tmp[@]}"; do
|
|
+ if nm "$binary" | grep -q "\<$symbol\>"; then
|
|
+ echo "$symbol dost exist in $binary" >>$sample_log
|
|
+ else
|
|
+ echo "$symbol does not exist in $binary, please check '$config_file'!!!" | tee -a $sample_log
|
|
+ exit 1
|
|
+ fi
|
|
+ done
|
|
+}
|
|
+
|
|
+function arr_check_sched() {
|
|
+ local sched_tmp=("$@")
|
|
+ for sched in "${sched_tmp[@]}"; do
|
|
+ if [[ $sched == "sched_switch" ]]; then
|
|
+ echo "sched_switch match" >>$sample_log
|
|
+ else
|
|
+ echo "s only support sched_switch, please check '$config_file'!!!" | tee -a $sample_log
|
|
exit 1
|
|
fi
|
|
done
|
|
@@ -162,7 +219,10 @@ function arr_repet_ele_check() {
|
|
|
|
function config_file_check() {
|
|
arr_repet_ele_check ${kernel_symbols[@]} # check kernel
|
|
- arr_repet_ele_check ${sched_symbols[@]} # check sched
|
|
+ arr_check_kernel_symbols_exist ${kernel_symbols[@]}
|
|
+ arr_check_function_support ${kernel_symbols[@]}
|
|
+ arr_repet_ele_check ${sched_symbols[@]} # check sched
|
|
+ arr_check_sched ${sched_symbols[@]}
|
|
|
|
spl_begin=0
|
|
declare -a target_path_tmp
|
|
@@ -176,6 +236,8 @@ function config_file_check() {
|
|
done
|
|
spl_begin=${spl_end}
|
|
arr_repet_ele_check ${user_symbols_arr_tmp[@]} # check user symbol of same bin
|
|
+ arr_check_function_support ${user_symbols_arr_tmp[@]}
|
|
+ arr_check_user_symbols_exist ${target_path_tmp[-1]} ${user_symbols_arr_tmp[@]}
|
|
done
|
|
arr_repet_ele_check "${target_path_tmp[@]}" # check bin
|
|
}
|
|
diff --git a/extra-tools/da-tool/test/config_check/config_check.sh b/extra-tools/da-tool/test/config_check/config_check.sh
|
|
new file mode 100755
|
|
index 0000000..20c06a1
|
|
--- /dev/null
|
|
+++ b/extra-tools/da-tool/test/config_check/config_check.sh
|
|
@@ -0,0 +1,70 @@
|
|
+#!/bin/bash
|
|
+
|
|
+script_dir=$(
|
|
+ cd $(dirname $0)
|
|
+ pwd
|
|
+)
|
|
+cd $script_dir/
|
|
+
|
|
+datool="../../script/da-tool.sh"
|
|
+case1_path="../../test"
|
|
+config_file="/etc/da-tool.conf"
|
|
+config_tmp="config.tmp"
|
|
+output_file="config_test.log"
|
|
+
|
|
+err_config=(
|
|
+ ./"config_test1.conf"
|
|
+ ./"config_test2.conf"
|
|
+ ./"config_test3.conf"
|
|
+ ./"config_test4.conf"
|
|
+ ./"config_test5.conf"
|
|
+ ./"config_test6.conf"
|
|
+ ./"config_test7.conf"
|
|
+)
|
|
+
|
|
+cat $config_file >$config_tmp
|
|
+
|
|
+echo >$output_file
|
|
+
|
|
+# loop test config
|
|
+echo "=========================================================================================" >>$output_file
|
|
+echo "===================================== err_configs ======================================" >>$output_file
|
|
+echo "=========================================================================================" >>$output_file
|
|
+for config_test in "${err_config[@]}"; do
|
|
+ echo >$config_file
|
|
+ echo "================================" "$config_test" "================================" >>$output_file
|
|
+ cat $config_test >$config_file
|
|
+ echo "#config start" >>$output_file
|
|
+ cat $config_test >>$output_file
|
|
+ echo "#config end" >>$output_file
|
|
+ $datool -t 1 >>$output_file 2>&1
|
|
+done
|
|
+
|
|
+# user check
|
|
+g++ $case1_path/case/case1/case1.cpp -o case1_test
|
|
+
|
|
+err_user_config=(
|
|
+ ./"config_user_test1.conf"
|
|
+ ./"config_user_test2.conf"
|
|
+ ./"config_user_test3.conf"
|
|
+)
|
|
+
|
|
+echo "u,$script_dir/,case1_test,_Z5funcAv,aaaa" >./"config_user_test1.conf"
|
|
+echo "u,$script_dir/,case1_test,_Z5funcAv,_Z5funcAv" >./"config_user_test2.conf"
|
|
+echo "u,$script_dir/,case1_test,_Z5funcAv.a" >./"config_user_test3.conf"
|
|
+
|
|
+# loop test config
|
|
+echo "=========================================================================================" >>$output_file
|
|
+echo "===================================== user err_configs ======================================" >>$output_file
|
|
+echo "=========================================================================================" >>$output_file
|
|
+for config_test in "${err_user_config[@]}"; do
|
|
+ echo >$config_file
|
|
+ echo "================================" "$config_test" "================================" >>$output_file
|
|
+ cat $config_test >$config_file
|
|
+ echo "#config start" >>$output_file
|
|
+ cat $config_test >>$output_file
|
|
+ echo "#config end" >>$output_file
|
|
+ $datool -t 1 >>$output_file 2>&1
|
|
+done
|
|
+
|
|
+cat $config_tmp >$config_file
|
|
diff --git a/extra-tools/da-tool/test/config_check/config_test1.conf b/extra-tools/da-tool/test/config_check/config_test1.conf
|
|
new file mode 100644
|
|
index 0000000..cc75ca7
|
|
--- /dev/null
|
|
+++ b/extra-tools/da-tool/test/config_check/config_test1.conf
|
|
@@ -0,0 +1,2 @@
|
|
+# kernel repet config
|
|
+k,udp_recvmsg,udp_recvmsg
|
|
diff --git a/extra-tools/da-tool/test/config_check/config_test2.conf b/extra-tools/da-tool/test/config_check/config_test2.conf
|
|
new file mode 100644
|
|
index 0000000..9b1951d
|
|
--- /dev/null
|
|
+++ b/extra-tools/da-tool/test/config_check/config_test2.conf
|
|
@@ -0,0 +1,2 @@
|
|
+# u config err
|
|
+u,udp_recvmsg
|
|
diff --git a/extra-tools/da-tool/test/config_check/config_test3.conf b/extra-tools/da-tool/test/config_check/config_test3.conf
|
|
new file mode 100644
|
|
index 0000000..dd8004d
|
|
--- /dev/null
|
|
+++ b/extra-tools/da-tool/test/config_check/config_test3.conf
|
|
@@ -0,0 +1,2 @@
|
|
+# kenrel config error symbols
|
|
+k,udp_recvmsg,aaaaaa
|
|
diff --git a/extra-tools/da-tool/test/config_check/config_test4.conf b/extra-tools/da-tool/test/config_check/config_test4.conf
|
|
new file mode 100644
|
|
index 0000000..4afb295
|
|
--- /dev/null
|
|
+++ b/extra-tools/da-tool/test/config_check/config_test4.conf
|
|
@@ -0,0 +1,2 @@
|
|
+# s config error
|
|
+s,sched_switch2
|
|
diff --git a/extra-tools/da-tool/test/config_check/config_test5.conf b/extra-tools/da-tool/test/config_check/config_test5.conf
|
|
new file mode 100644
|
|
index 0000000..4afb295
|
|
--- /dev/null
|
|
+++ b/extra-tools/da-tool/test/config_check/config_test5.conf
|
|
@@ -0,0 +1,2 @@
|
|
+# s config error
|
|
+s,sched_switch2
|
|
diff --git a/extra-tools/da-tool/test/config_check/config_test6.conf b/extra-tools/da-tool/test/config_check/config_test6.conf
|
|
new file mode 100644
|
|
index 0000000..4945653
|
|
--- /dev/null
|
|
+++ b/extra-tools/da-tool/test/config_check/config_test6.conf
|
|
@@ -0,0 +1,2 @@
|
|
+# s config repet
|
|
+s,sched_switch,sched_switch
|
|
diff --git a/extra-tools/da-tool/test/config_check/config_test7.conf b/extra-tools/da-tool/test/config_check/config_test7.conf
|
|
new file mode 100644
|
|
index 0000000..6b4088b
|
|
--- /dev/null
|
|
+++ b/extra-tools/da-tool/test/config_check/config_test7.conf
|
|
@@ -0,0 +1,2 @@
|
|
+# not support function check
|
|
+k,udp_recvmsg,set_bringup_idt_handler.constprop.0
|
|
diff --git a/extra-tools/da-tool/test/opt_test/opt_test.sh b/extra-tools/da-tool/test/opt_test/opt_test.sh
|
|
new file mode 100644
|
|
index 0000000..ab7dd65
|
|
--- /dev/null
|
|
+++ b/extra-tools/da-tool/test/opt_test/opt_test.sh
|
|
@@ -0,0 +1,49 @@
|
|
+#!/bin/bash
|
|
+
|
|
+script_dir=$(
|
|
+ cd $(dirname $0)
|
|
+ pwd
|
|
+)
|
|
+cd $script_dir/
|
|
+
|
|
+datool_path="../../script/"
|
|
+
|
|
+err_commands=(
|
|
+ "./da-tool.sh -t 0"
|
|
+ "./da-tool.sh -t 101"
|
|
+ "./da-tool.sh -t 1000000000000000000000000000"
|
|
+ "./da-tool.sh -t -10"
|
|
+ "./da-tool.sh -t 0.12345"
|
|
+ "./da-tool.sh -t abc"
|
|
+ "./da-tool.sh -t ~"
|
|
+ "./da-tool.sh -t -m 5"
|
|
+ "./da-tool.sh -a"
|
|
+ "./da-tool.sh -x 1"
|
|
+ "./da-tool.sh -"
|
|
+ "./da-tool.sh 1"
|
|
+)
|
|
+
|
|
+right_commands=(
|
|
+ "./da-tool.sh -h"
|
|
+ #"./da-tool.sh -t 1"
|
|
+ #"./da-tool.sh"
|
|
+)
|
|
+
|
|
+output_file="opt_test.log"
|
|
+echo >$output_file
|
|
+
|
|
+echo "=========================================================================================" >>$output_file
|
|
+echo "===================================== err_commands ======================================" >>$output_file
|
|
+echo "=========================================================================================" >>$output_file
|
|
+for command in "${err_commands[@]}"; do
|
|
+ echo "================================" "$command" "================================" >>$output_file
|
|
+ $datool_path$command >>$output_file 2>&1
|
|
+done
|
|
+
|
|
+echo "=========================================================================================" >>$output_file
|
|
+echo "===================================== right_commands ====================================" >>$output_file
|
|
+echo "=========================================================================================" >>$output_file
|
|
+for command in "${right_commands[@]}"; do
|
|
+ echo "================================" "$command" "================================" >>$output_file
|
|
+ $datool_path$command >>$output_file 2>&1
|
|
+done
|
|
--
|
|
2.33.0
|
|
|