feat(test): update oe_test_hdparam
This commit is contained in:
@@ -22,26 +22,65 @@ source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
function pre_test() {
|
||||
LOG_INFO "Start environment preparation."
|
||||
DNF_INSTALL "hdparm util-linux"
|
||||
disk=$(lsblk -a -o NAME,TYPE | grep -v NAME | grep disk | head -1 | awk '{print $1}')
|
||||
|
||||
# 获取第一个物理磁盘,排除虚拟设备(ram, loop, dm等)
|
||||
disk=$(lsblk -a -o NAME,TYPE | grep -v NAME | grep disk | grep -v -E '(ram|loop|dm|nbd)' | head -1 | awk '{print $1}')
|
||||
|
||||
if [ -z "${disk}" ]; then
|
||||
LOG_ERROR "No physical disk found for testing"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
LOG_INFO "Selected disk for testing: ${disk}"
|
||||
LOG_INFO "End of environmental preparation!"
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
LOG_INFO "Start testing..."
|
||||
|
||||
# 测试读取预读缓冲设置
|
||||
hdparm -a /dev/"${disk}" | grep readahead
|
||||
CHECK_RESULT $?
|
||||
|
||||
# 测试只读状态查询
|
||||
hdparm -r /dev/"${disk}" | grep readonly
|
||||
CHECK_RESULT $?
|
||||
if lsblk | grep sd; then
|
||||
hdparm -F /dev/"${disk}"
|
||||
CHECK_RESULT $?
|
||||
|
||||
# 仅对SCSI/SATA磁盘执行flush cache测试
|
||||
# 检查是否为sd设备且支持flush cache操作
|
||||
if echo "${disk}" | grep -q "^sd"; then
|
||||
LOG_INFO "Executing flush cache test on SCSI/SATA disk: ${disk}"
|
||||
hdparm -F /dev/"${disk}" 2>&1 | tee /tmp/hdparm_flush_result.log
|
||||
flush_result=${PIPESTATUS[0]}
|
||||
|
||||
# 检查执行结果
|
||||
if [ ${flush_result} -ne 0 ]; then
|
||||
# 如果失败,检查是否是ioctl不支持的错误
|
||||
if grep -q "Inappropriate ioctl" /tmp/hdparm_flush_result.log; then
|
||||
LOG_WARN "Device /dev/${disk} does not support flush cache operation, skipping this test"
|
||||
rm -f /tmp/hdparm_flush_result.log
|
||||
return 0
|
||||
else
|
||||
LOG_ERROR "hdparm -F failed with unexpected error"
|
||||
cat /tmp/hdparm_flush_result.log
|
||||
rm -f /tmp/hdparm_flush_result.log
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
rm -f /tmp/hdparm_flush_result.log
|
||||
LOG_INFO "Flush cache test passed"
|
||||
else
|
||||
LOG_INFO "Disk ${disk} is not a SCSI/SATA device (sd*), skipping flush cache test"
|
||||
fi
|
||||
|
||||
LOG_INFO "Finish test!"
|
||||
}
|
||||
|
||||
function post_test() {
|
||||
LOG_INFO "start environment cleanup."
|
||||
DNF_REMOVE
|
||||
rm -f /tmp/hdparm_flush_result.log
|
||||
LOG_INFO "Finish environment cleanup!"
|
||||
}
|
||||
main $@
|
||||
|
||||
Reference in New Issue
Block a user