From d480139f1dc76cb0d0b3c9da721237105c8bdf73 Mon Sep 17 00:00:00 2001 From: leimingsheng Date: Fri, 27 Jun 2025 14:29:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(master=20:=20test=5Ftool)=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=98=88=E5=80=BC=E5=88=A4=E6=96=AD=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_plugin/check_threhold.sh | 45 +++++++++++++++++++++++++++++++++++ test_plugin/readme.md | 19 +++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 test_plugin/check_threhold.sh create mode 100644 test_plugin/readme.md diff --git a/test_plugin/check_threhold.sh b/test_plugin/check_threhold.sh new file mode 100644 index 0000000..3938027 --- /dev/null +++ b/test_plugin/check_threhold.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +# 20250627 +# A tool script to test a value greater or less than threhold + +data=$1 +direction=$2 +threhold=$3 +param_num=$# + +print_usage(){ + echo " Script Usage" + echo " ./check_threhold.sh " + echo " @Param direction : greater , >" + echo " less , <" + echo " equal , =" + echo "" + echo " E.G. ./check_threhold.sh 500 > 1000" + echo " +--> Result : 0" + echo "" + echo " About Result: 1 means true, 0 means fault" + echo "" +} + +main(){ + if [ ${param_num} -ne 3 ];then + print_usage + exit 0 + fi + + if [ "${direction}" = "great" ] || [ "${direction}" = ">" ];then + res= `echo " $data > $threhold" | bc -l` + elif [ "${direction}" = "less" ] || [ "${direction}" = "<" ];then + res= `echo " $data < $threhold" | bc -l` + elif [ "${direction}" = "equal" ] || [ "${direction}" = "=" ];then + res= `echo " $data = $threhold" | bc -l` + else + echo "Invalid direction" + print_usage + fi + + echo $res +} + +main \ No newline at end of file diff --git a/test_plugin/readme.md b/test_plugin/readme.md new file mode 100644 index 0000000..e2a7117 --- /dev/null +++ b/test_plugin/readme.md @@ -0,0 +1,19 @@ +# 测试治具说明 + +> [!info] +> nicsensor提供了一部分测试治具脚本用于辅助编写测试脚本 + +## 阈值校验脚本-check_threhold.sh + +阈值校验脚本提供了判断数值是否大于目标阈值的方法, 可进行整数和小数的比较。使用方法如下: + +```shell +# 测试数据大于阈值 +# 例如测试数据是否大于100,有如下使用方法 +res=`./check_threhold.sh ${data} > 100` +if [ $res -eq 1 ];then + echo "data is greater than threholds" +else + echo "data isn't greater than threholds" +fi +``` \ No newline at end of file