#!/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