Compare commits
No commits in common. "3a66d3557be937be96e6b3c7087f67d44ae51b47" and "8119bf1b699f4eb6051de22ab6b4bf6030c6b31f" have entirely different histories.
3a66d3557b
...
8119bf1b69
112
nicsensor.sh
112
nicsensor.sh
@ -1,6 +1,5 @@
|
||||
#!/bin/sh
|
||||
set -eo pipefail
|
||||
SCRIPT_VERSION="1.9.7"
|
||||
SCRIPT_VERSION="1.9.4"
|
||||
# ---------------------------------------------------------
|
||||
# Project Feature Varible (Change if need)
|
||||
# ---------------------------------------------------------
|
||||
@ -159,22 +158,16 @@ 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
|
||||
@ -261,29 +254,6 @@ 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(){
|
||||
@ -371,16 +341,16 @@ parse_nic_slot(){
|
||||
|
||||
get_set_properties(){
|
||||
if [ "$Param2" = "server" ];then
|
||||
target_file="${CONFIG_DIR}ns_servertype"
|
||||
target_file="/tmp/ns_servertype"
|
||||
default_data=$server_type
|
||||
elif [ "$Param2" = "debug" ];then
|
||||
target_file="${CONFIG_DIR}ns_debugmode"
|
||||
target_file="/tmp/ns_debugmode"
|
||||
default_data=$DEBUG_MODE
|
||||
elif [ "$Param2" = "n_detect" ];then
|
||||
target_file="${CONFIG_DIR}ns_disabledetect"
|
||||
target_file="/tmp/ns_disabledetect"
|
||||
default_data=$DISABLE_DETECT
|
||||
elif [ "$Param2" = "fru_size" ];then
|
||||
target_file="${CONFIG_DIR}ns_frusize"
|
||||
target_file="/tmp/ns_frusize"
|
||||
default_data=$fru_size
|
||||
else
|
||||
fmt_print "console" $ERROR "Invalid Property : $Param2"
|
||||
@ -403,27 +373,27 @@ get_set_properties(){
|
||||
}
|
||||
|
||||
load_properties_from_cache(){
|
||||
if [ -e "${CONFIG_DIR}ns_servertype" ];then
|
||||
server_type=`cat ${CONFIG_DIR}ns_servertype`
|
||||
if [ -e "/tmp/ns_servertype" ];then
|
||||
server_type=`cat /tmp/ns_servertype`
|
||||
fi
|
||||
|
||||
if [ -e "${CONFIG_DIR}ns_debugmode" ];then
|
||||
DEBUG_MODE=`cat ${CONFIG_DIR}ns_debugmode`
|
||||
if [ -e "/tmp/ns_debugmode" ];then
|
||||
DEBUG_MODE=`cat /tmp/ns_debugmode`
|
||||
fi
|
||||
|
||||
if [ -e "${CONFIG_DIR}ns_disabledetect" ];then
|
||||
DISABLE_DETECT=`cat ${CONFIG_DIR}ns_disabledetect`
|
||||
if [ -e "/tmp/ns_disabledetect" ];then
|
||||
DISABLE_DETECT=`cat /tmp/ns_disabledetect`
|
||||
fi
|
||||
|
||||
if [ -e "${CONFIG_DIR}ns_frusize" ];then
|
||||
fru_size=`cat ${CONFIG_DIR}ns_frusize`
|
||||
if [ -e "/tmp/ns_frusize" ];then
|
||||
fru_size=`cat /tmp/ns_frusize`
|
||||
fi
|
||||
}
|
||||
|
||||
# According to boardid, parse server_type
|
||||
try_get_server_type(){
|
||||
if [ -e "${CONFIG_DIR}ns_servertype" ];then
|
||||
server_type=`cat ${CONFIG_DIR}ns_servertype`
|
||||
if [ -e "/tmp/ns_servertype" ];then
|
||||
server_type=`cat /tmp/ns_servertype`
|
||||
else
|
||||
boardid=`cat /proc/cmdline | awk -F 'boardid=' '{split($2, a," "); print a[1]}'`
|
||||
|
||||
@ -446,7 +416,7 @@ try_get_server_type(){
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo $server_type > ${CONFIG_DIR}ns_servertype
|
||||
echo $server_type > /tmp/ns_servertype
|
||||
fi
|
||||
}
|
||||
|
||||
@ -455,11 +425,6 @@ 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"
|
||||
@ -540,7 +505,6 @@ 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
|
||||
@ -596,17 +560,6 @@ 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
|
||||
@ -969,7 +922,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: 0x$merge_value"
|
||||
fmt_print "log" $INFO "$3 - Hex data: $upper_hex_value"
|
||||
echo "$3 : $format_volt V"
|
||||
}
|
||||
|
||||
@ -1030,17 +983,6 @@ 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 }')
|
||||
@ -1193,16 +1135,6 @@ 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)
|
||||
@ -1288,7 +1220,7 @@ process_ina226(){
|
||||
# @Param1 lm95241 data high 8bit
|
||||
# @Param2 lm95241 data low 8bit
|
||||
# @Param3 customization sensor name
|
||||
convert_lm95241_data(){
|
||||
convert_lms95241_data(){
|
||||
if [ "$3" = "disable" ];then
|
||||
return
|
||||
fi
|
||||
@ -1319,9 +1251,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_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"
|
||||
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"
|
||||
}
|
||||
|
||||
process_lm95241(){
|
||||
@ -1738,6 +1670,8 @@ 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
|
||||
|
||||
1212
nicsensor_s.sh
Normal file
1212
nicsensor_s.sh
Normal file
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,7 +27,6 @@ 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
208
stress_test.sh
@ -1,208 +0,0 @@
|
||||
#!/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
|
||||
Loading…
Reference in New Issue
Block a user