Compare commits

..

6 Commits

Author SHA1 Message Date
leimingsheng
3a66d3557b Merge branch 'master' of 121.36.59.21:Marcin/nicsensor 2026-03-10 18:35:44 +08:00
leimingsheng
e5a4a4e28d 移除 nicsensor_s.sh 2026-03-10 18:34:39 +08:00
leimingsheng
27ae0a4dc4 feat(master : nicsensor) update to 1.9.7 【重要】
1.原生支持 stress 压力测试
2.新增stress_test插件
2026-03-10 18:22:38 +08:00
leimingsheng
c7730923a1 fix(master : nicsensor) 修复 1.9.4 引入的执行时语法错误 2026-03-10 15:57:18 +08:00
leimingsheng
04c0342367 feat(master : nicsensor.sh) update to 1.9.6
1.增加安全性检查内容
2.pmbus_cmd_list 引入版本号
2026-03-10 15:27:18 +08:00
leimingsheng
f526fa8190 fix(master : nicsensor) update to 1.9.5
修正拼写错误
2026-03-09 09:39:19 +08:00
4 changed files with 299 additions and 1236 deletions

@ -1,5 +1,6 @@
#!/bin/sh
SCRIPT_VERSION="1.9.4"
set -eo pipefail
SCRIPT_VERSION="1.9.7"
# ---------------------------------------------------------
# Project Feature Varible (Change if need)
# ---------------------------------------------------------
@ -158,16 +159,22 @@ log="/tmp/nicsensor_debug.log"
pmbus_op="get"
hex_pmbus_cmd=0xff
hex_pmbus_size=0
CONFIG_DIR="/tmp/nicsensor_config/"
# ---------------------------------------------------------
# Script Function Defination
# ---------------------------------------------------------
search_plugin_help(){
PMBUS_PLUGIN="./pmbus_cmd_list.sh"
STRESS_PLUGIN="./stress_test.sh"
plugin_flag=0
if [ -e ${PMBUS_PLUGIN} ];then
$PMBUS_PLUGIN "help"
plugin_flag=1
fi
if [ -e ${STRESS_PLUGIN} ];then
$STRESS_PLUGIN "help"
plugin_flag=1
fi
if [ $plugin_flag -eq 0 ];then
echo " No Plugin found in file system"
fi
@ -254,6 +261,29 @@ print_usage(){
fi
}
systemtool_check(){
systemtool_exist_flag="${CONFIG_DIR}systemtool_exist_flag"
# Check system tools exist flag file, if exists, skip check
if [ -e $systemtool_exist_flag ];then
fmt_print "log" $INFO "System tools found in file system"
return
fi
# Check system tools exist
systemtool_list="i2ctransfer i2cdetect i2cget bc"
for tool in $systemtool_list;do
if ! command -v $tool &> /dev/null;then
fmt_print "console" $ERROR "System tool $tool not found in file system"
fmt_print "console" $INFO "Please Check BMC Version, Only Support on AMI BMC!"
exit 1
fi
done
# Create system tools exist flag file
touch $systemtool_exist_flag
}
# Convert a hexadecimal number to a decimal number
# @Param1 hex data
hex_to_dec(){
@ -341,16 +371,16 @@ parse_nic_slot(){
get_set_properties(){
if [ "$Param2" = "server" ];then
target_file="/tmp/ns_servertype"
target_file="${CONFIG_DIR}ns_servertype"
default_data=$server_type
elif [ "$Param2" = "debug" ];then
target_file="/tmp/ns_debugmode"
target_file="${CONFIG_DIR}ns_debugmode"
default_data=$DEBUG_MODE
elif [ "$Param2" = "n_detect" ];then
target_file="/tmp/ns_disabledetect"
target_file="${CONFIG_DIR}ns_disabledetect"
default_data=$DISABLE_DETECT
elif [ "$Param2" = "fru_size" ];then
target_file="/tmp/ns_frusize"
target_file="${CONFIG_DIR}ns_frusize"
default_data=$fru_size
else
fmt_print "console" $ERROR "Invalid Property : $Param2"
@ -373,27 +403,27 @@ get_set_properties(){
}
load_properties_from_cache(){
if [ -e "/tmp/ns_servertype" ];then
server_type=`cat /tmp/ns_servertype`
if [ -e "${CONFIG_DIR}ns_servertype" ];then
server_type=`cat ${CONFIG_DIR}ns_servertype`
fi
if [ -e "/tmp/ns_debugmode" ];then
DEBUG_MODE=`cat /tmp/ns_debugmode`
if [ -e "${CONFIG_DIR}ns_debugmode" ];then
DEBUG_MODE=`cat ${CONFIG_DIR}ns_debugmode`
fi
if [ -e "/tmp/ns_disabledetect" ];then
DISABLE_DETECT=`cat /tmp/ns_disabledetect`
if [ -e "${CONFIG_DIR}ns_disabledetect" ];then
DISABLE_DETECT=`cat ${CONFIG_DIR}ns_disabledetect`
fi
if [ -e "/tmp/ns_frusize" ];then
fru_size=`cat /tmp/ns_frusize`
if [ -e "${CONFIG_DIR}ns_frusize" ];then
fru_size=`cat ${CONFIG_DIR}ns_frusize`
fi
}
# According to boardid, parse server_type
try_get_server_type(){
if [ -e "/tmp/ns_servertype" ];then
server_type=`cat /tmp/ns_servertype`
if [ -e "${CONFIG_DIR}ns_servertype" ];then
server_type=`cat ${CONFIG_DIR}ns_servertype`
else
boardid=`cat /proc/cmdline | awk -F 'boardid=' '{split($2, a," "); print a[1]}'`
@ -416,7 +446,7 @@ try_get_server_type(){
exit 1
fi
echo $server_type > /tmp/ns_servertype
echo $server_type > ${CONFIG_DIR}ns_servertype
fi
}
@ -425,6 +455,11 @@ init_debuglog(){
rm $log
fi
# create config dir if not exists
if [ ! -d $CONFIG_DIR ];then
mkdir -p $CONFIG_DIR
fi
res_date=`date +%Y-%m-%dT%H:%M:%S`
fmt_print "log" $INFO "Start Time : $res_date"
fmt_print "log" $INFO "Script Version : $SCRIPT_VERSION"
@ -505,6 +540,7 @@ switch_pca9548_channel(){
# Function 4 : Implementation of Parameter Setting Function
pre_exec_hook(){
init_debuglog
systemtool_check
if [ "$Param1" = "help" ] && [ $param_num -eq 2 ];then
print_usage $Param2
@ -560,6 +596,17 @@ pre_exec_hook(){
fi
fi
if [ "$Param2" = "stress" ];then
STRESS_PLUGIN="./stress_test.sh"
if [ -e ${STRESS_PLUGIN} ];then
${STRESS_PLUGIN} $Param3 $option_data
exit 0
else
fmt_print "console" $ERROR "Can't find stress plugin file, please copy stress_test.sh to here!"
exit 1
fi
fi
# if the action is fru write, need pre-process fru data
if [ "$Param2" = "fru" ];then
if [ "$option_data" = "write" ];then
@ -922,7 +969,7 @@ convert_adc128_data(){
volt=$(echo "scale=4; $dec_val / 16 / 4096 * 2.65 / $4" | bc)
format_volt=$(echo "$volt" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }')
fmt_print "log" $INFO "$3 - Hex data: $upper_hex_value"
fmt_print "log" $INFO "$3 - Hex data: 0x$merge_value"
echo "$3 : $format_volt V"
}
@ -983,6 +1030,17 @@ convert_ina3221_data(){
merge_value="${hex_value1}${hex_value2}"
dec_val=$(hex_to_dec $merge_value)
# bc calculator recognized upper case only, change data to upper case
upper_hex_value=$(echo "$merge_value" | awk '{
for(i=1; i<=length($0); i++){
if(tolower(substr($0,i,1)) ~ /^[a-f]$/)
printf toupper(substr($0,i,1));
else
printf substr($0,i,1);
}
print ""
}')
if [ $4 -eq $INA3221_BUS_VOLT ];then
volt=$(echo "scale=4; $dec_val / 8 * 40 / 10000 * 2" | bc)
format_volt=$(echo "$volt" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }')
@ -1135,6 +1193,16 @@ convert_tmp112_data(){
merge_value="${hex_value1}${hex_value2}"
dec_val=$(hex_to_dec $merge_value)
upper_hex_value=$(echo "$merge_value" | awk '{
for(i=1; i<=length($0); i++){
if(tolower(substr($0,i,1)) ~ /^[a-f]$/)
printf toupper(substr($0,i,1));
else
printf substr($0,i,1);
}
print ""
}')
binary_number=$(echo "ibase=16;obase=2;$upper_hex_value" | bc)
bin_length=$(echo $binary_number | awk '{print length($0)}')
last_digit=$(echo $binary_number | cut -c $bin_length)
@ -1220,7 +1288,7 @@ process_ina226(){
# @Param1 lm95241 data high 8bit
# @Param2 lm95241 data low 8bit
# @Param3 customization sensor name
convert_lms95241_data(){
convert_lm95241_data(){
if [ "$3" = "disable" ];then
return
fi
@ -1251,9 +1319,9 @@ read_lm95241_value(){
fmt_print "log" $INFO "LM95241 remote2 data: $res_lm95241_remote2_h $res_lm95241_remote2_l"
fmt_print "console" $INFO "LM95241 read result:"
convert_lms95241_data $res_lm95241_local_h $res_lm95241_local_l "$LM95241_Local_name"
convert_lms95241_data $res_lm95241_remote1_h $res_lm95241_remote1_l "$LM95241_Remote1_name"
convert_lms95241_data $res_lm95241_remote2_h $res_lm95241_remote2_l "$LM95241_Remote2_name"
convert_lm95241_data $res_lm95241_local_h $res_lm95241_local_l "$LM95241_Local_name"
convert_lm95241_data $res_lm95241_remote1_h $res_lm95241_remote1_l "$LM95241_Remote1_name"
convert_lm95241_data $res_lm95241_remote2_h $res_lm95241_remote2_l "$LM95241_Remote2_name"
}
process_lm95241(){
@ -1670,8 +1738,6 @@ start_detect_device(){
pre_exec_hook
if [ "$1" = "version" ];then
echo "Script Version : $SCRIPT_VERSION"
echo "Debug Mode : $DEBUG_MODE"
echo "Disable Detect : $DISABLE_DETECT"
exit 0
fi
if [ "$1" = "detect" ];then

File diff suppressed because it is too large Load Diff

@ -8,7 +8,7 @@
# How to use this pmbus plugin?
# Copy this file to the dir as same as nicsensor.sh
EXTENSION_VERSION="v1.0"
# ---------------------------------------------------------
# Varible Define
# ---------------------------------------------------------
@ -27,6 +27,7 @@ PMBUS_RAW=4
# ---------------------------------------------------------
pmbus_command_help(){
echo " Extend Function - PMBUS command test"
echo " Version : $EXTENSION_VERSION"
echo " 1) Command Format : ./nicsensor.sh [slot] pmbus [slave] [command]"
echo " 2) Option Detail"
echo " - [slot] : 0 1 2 3 4 5 ..."

208
stress_test.sh Normal file

@ -0,0 +1,208 @@
#!/bin/sh
# Desc: Stress test script for nicsensor
# Detail: This script will stress test the nicsensor by reading the sensor data
# and print the result to the console.
EXTENSION_VERSION="v1.0"
# ---------------------------------------------------------
# Varible Define
# ---------------------------------------------------------
Param1=$1
Param2=$2
CONFIG_DIR="/tmp/nicsensor_config"
CONFIG_NICSENSOR="${CONFIG_DIR}/stress_tool"
CONFIG_SLOT="${CONFIG_DIR}/stress_slot"
CONFIG_SENSOR="${CONFIG_DIR}/stress_sensor"
CONFIG_ROUND="${CONFIG_DIR}/stress_round"
CONFIG_INTERVAL="${CONFIG_DIR}/stress_interval"
CONFIG_SLAVE="${CONFIG_DIR}/stress_slave"
config_tool=""
# ---------------------------------------------------------
# Function Define
# ---------------------------------------------------------
print_usage(){
echo " Extend Function - Stress Test"
echo " Version: $EXTENSION_VERSION"
echo " 1) Description"
echo " This plugin will stress test the nicsensor by reading the sensor data"
echo " and print the result to the console."
echo " 2) Command Format : ./nicsensor.sh [slot] stress [option] [data]"
echo " 3) Option Detail"
echo " - [slot] : The nicsensor slot number"
echo " - [option] : start|show|round|tool|interval|slot|sensor|slave"
echo " - [data] : The option data"
echo " 4) Example"
echo " Case: Test PCIe1 Nic's INA3221, slave=0x42, round=1000, interval=3s"
echo " Step 1 : Set the stress test parameter"
echo " ./nicsensor.sh pcie1 stress slot pcie1"
echo " ./nicsensor.sh pcie1 stress round 1000"
echo " ./nicsensor.sh pcie1 stress interval 3"
echo " ./nicsensor.sh pcie1 stress sensor ina3221"
echo " ./nicsensor.sh pcie1 stress slave 0x42"
echo " Step 2 : Check the stress test configuration"
echo " ./nicsensor.sh pcie1 stress show"
echo " Step 3 : Start the stress test"
echo " ./nicsensor.sh pcie1 stress start"
}
set_stress_config(){
case ${Param1} in
"round")
echo "Set the stress test round to ${Param2}"
echo ${Param2} > ${CONFIG_ROUND}
;;
"interval")
echo "Set the stress test interval to ${Param2}s"
echo ${Param2} > ${CONFIG_INTERVAL}
;;
"sensor")
echo "Set the stress test sensor to ${Param2}"
echo ${Param2} > ${CONFIG_SENSOR}
;;
"slave")
echo "Set the stress test slave to ${Param2}"
echo ${Param2} > ${CONFIG_SLAVE}
;;
"slot")
echo "Set the stress test slot to ${Param2}"
echo ${Param2} > ${CONFIG_SLOT}
;;
"tool")
echo "Set the stress test tool to ${Param2}"
echo ${Param2} > ${CONFIG_NICSENSOR}
;;
*)
echo "Invalid option: ${Param1}"
;;
esac
}
get_stress_all_config(){
echo "Stress Test Config:"
if [ -f ${CONFIG_NICSENSOR} ]; then
echo " Tool : $(cat ${CONFIG_NICSENSOR})"
else
echo " Tool : nicsensor.sh"
fi
if [ -f ${CONFIG_ROUND} ]; then
echo " Round : $(cat ${CONFIG_ROUND})"
else
echo " Round : Not Set"
fi
if [ -f ${CONFIG_INTERVAL} ]; then
echo " Interval: $(cat ${CONFIG_INTERVAL})s"
else
echo " Interval: Not Set"
fi
if [ -f ${CONFIG_SLOT} ]; then
echo " Slot : $(cat ${CONFIG_SLOT})"
else
echo " Slot : Not Set"
fi
if [ -f ${CONFIG_SENSOR} ]; then
echo " Sensor : $(cat ${CONFIG_SENSOR})"
else
echo " Sensor : Not Set"
fi
if [ -f ${CONFIG_SLAVE} ]; then
echo " Slave : $(cat ${CONFIG_SLAVE})"
else
echo " Slave : Not Set"
fi
}
start_stress_test(){
# nicsensor tool check
if [ -f ${CONFIG_NICSENSOR} ]; then
config_tool=$(cat ${CONFIG_NICSENSOR})
else
config_tool="nicsensor.sh"
fi
if [ ! -f "./${config_tool}" ]; then
echo "Error: ${config_tool} tool not found"
echo "Info : Please check the nicsensor tool path and name"
return 1
fi
# option check
if [ ! -f ${CONFIG_ROUND} ]; then
echo "Error: Round is not set"
echo "Info : Please set the stress test round first, use command: ./nicsensor.sh [slot] stress round [data]"
return 1
fi
if [ ! -f ${CONFIG_INTERVAL} ]; then
echo "Error: Interval is not set"
echo "Info : Please set the stress test interval first, use command: ./nicsensor.sh [slot] stress interval [data]"
return 1
fi
if [ ! -f ${CONFIG_SLOT} ]; then
echo "Error: Slot is not set"
echo "Info : Please set the stress test slot first, use command: ./nicsensor.sh [slot] stress slot [data]"
return 1
fi
if [ ! -f ${CONFIG_SENSOR} ]; then
echo "Error: Sensor is not set"
echo "Info : Please set the stress test sensor first, use command: ./nicsensor.sh [slot] stress sensor [data]"
return 1
fi
if [ ! -f ${CONFIG_SLAVE} ]; then
echo "Error: Slave is not set"
echo "Info : Please set the stress test slave first, use command: ./nicsensor.sh [slot] stress slave [data]"
return 1
fi
# start stress test
echo "Stress Test Config Info:"
config_round=$(cat ${CONFIG_ROUND})
config_interval=$(cat ${CONFIG_INTERVAL})
config_slot=$(cat ${CONFIG_SLOT})
config_sensor=$(cat ${CONFIG_SENSOR})
config_slave=$(cat ${CONFIG_SLAVE})
echo " Round : ${config_round}"
echo " Interval: ${config_interval}s"
echo " Slot : ${config_slot}"
echo " Sensor : ${config_sensor}"
echo " Slave : ${config_slave}"
run_count=1
while [ ${run_count} -le ${config_round} ]; do
timestamp=$(date +"%Y-%m-%dT%H:%M:%S")
echo "====== ${timestamp}, Run Count: ${run_count}"
exec_cmd="./${config_tool} ${config_slot} ${config_sensor} ${config_slave}"
${exec_cmd}
sleep ${config_interval}
run_count=$((run_count+1))
done
echo "==========================================="
echo " Stress Test Completed"
}
main(){
cmd=${Param1}
case ${cmd} in
"start")
echo "Start the stress test"
start_stress_test
;;
"show")
echo "Show the stress test configuration"
get_stress_all_config
;;
"help")
print_usage
;;
*)
echo "Set Stress Config"
set_stress_config
;;
esac
}
# ---------------------------------------------------------
# Start Execute Script(main)
# ---------------------------------------------------------
main