用 Shell 快速写一个嵌入式测试框架
嵌入式Linux
共 2069字,需浏览 5分钟
·
2022-02-12 21:28
查找表
declare -gA fct_table=(['Test 1']="do_test1"
['Test 2']="do_test2"
['Test 3']="do_test3"
['Test 4']="do_empty_handler"
['Test 5']="do_empty_handler"
['Test6']="do_empty_handler"
)
declare -gA res_table=(['Test 1']="N/A"
['Test 2']="N/A"
['Test 3']="N/A"
['Test 4']="N/A"
['Test 5']="N/A"
['Test 6']="N/A"
)
测试函数
function do_empty_handler()
{
echo "Test Not Implemented: $1"
return 2
}
function do_test1
{
echo "Test 1"
ret=0
return $ret
}
function do_test2
{
echo "Test 2"
ret=0
return $ret
}
function do_test3
{
echo "Test 1"
ret=0
return $ret
}
调度代码
function validate_system()
{
for i in "${!fct_table[@]}"; do
echo "Test : $i"
${fct_table[$i]}
res=$?
__update_result_table $res "$i" res_table
done
}
# Main entry point
validate_system
print_result
运行效果
wwd@think:~/Desktop$ ./board_test.sh
Test : Test 1
Test 1
>>>>> SUCCESS
Test : Test 3
Test 1
>>>>> SUCCESS
Test : Test 2
Test 2
>>>>> SUCCESS
Test : Test 5
Test Not Implemented:
>>>>> N/A
Test : Test 4
Test Not Implemented:
>>>>> N/A
Test : Test6
Test Not Implemented:
>>>>> N/A
TEST RESULTS:
============
Test: Test 1 Result: PASS
Test: Test 3 Result: PASS
Test: Test 2 Result: PASS
Test: Test 5 Result: N/A
Test: Test 4 Result: N/A
Test: Test 6 Result: N/A
Test: Test6 Result: N/A
总结
—— The End ——
评论