外设测试 - SD 、eMMC 测试

在 Linux 中,SD 卡、eMMC 设备都使用 mmc 总线,所以可以采用统一的测试方法。

这里的思路是,先生成一个 1MB 大小的文件,写入设备,然后读取出来存到另一个文件。再使用 cmp 命令对比两个文件的内容是否一致。存储设备可能存在多个分区,所以对每一个分区都进行一次以上测试。

mmc_test.sh:

#!/bin/bash
# Description:
#   Test SD or eMMC device with mount point. Get mount point from /proc/mounts.

if [ $# -ne 1 ]
then
    echo "Usage $0 <mmc device>"
    echo "e.g. $0 mmcblk0"
    exit 2
fi

MMC_DEVICE=$1
WRITE_TEST_FILE=/tmp/solid_disk_test.write
READ_TEST_FILE=/tmp/solid_disk_test.read

# get all mount points
MOUNT_POINTS=(`cat /proc/mounts | grep media | grep ${MMC_DEVICE} | awk '{print $2}'`)

dd if=/dev/zero of=${WRITE_TEST_FILE} bs=1024k count=1 > /dev/null 2>&1

for i in ${MOUNT_POINTS[@]}
do
    # Write, read and compare.
    dd if=${WRITE_TEST_FILE} of=$i/RW_TEST bs=1024k count=1 > /dev/null 2>&1
    dd if=$i/RW_TEST of=${READ_TEST_FILE} > /dev/null 2>&1
    cmp ${WRITE_TEST_FILE} ${READ_TEST_FILE}
    if [ $? -eq 0 ]
    then
        echo "Test pass!"
        exit 0
    fi
done

echo "Can not find $1, test failed!"
exit 3

考虑到全新生产的板卡上 eMMC 可能还没分区,也就没有挂载,故对上面测试程序进行了改进。先检测是否存在 p1 分区。同时把全零的测试数据改为了使用随机数。

emmc_test.sh:

#!/bin/bash
# Description:
#   Test eMMC device.

MMC_DEVICE=/dev/mmcblk1
WRITE_TEST_FILE=/tmp/solid_disk_test.write
READ_TEST_FILE=/tmp/solid_disk_test.read

# generate file to write.
dd if=/dev/urandom of=${WRITE_TEST_FILE} bs=1024k count=1 > /dev/null 2>&1

if [[ ! -e ${MMC_DEVICE}p1 ]];then  # there is no partition in emmc yet.
    dd if=${WRITE_TEST_FILE} of=${MMC_DEVICE} bs=1024k count=1 > /dev/null 2>&1
    dd if=${MMC_DEVICE} of=${READ_TEST_FILE} bs=1024k count=1 > /dev/null 2>&1
    cmp ${WRITE_TEST_FILE} ${READ_TEST_FILE}
    if [ $? -eq 0 ];then
        echo "Test pass!"
        exit 0
    else
        echo "Test failed!"
        exit 3
    fi
else
    # get all mount points
    MOUNT_POINTS=(`cat /proc/mounts | grep media | grep ${MMC_DEVICE} | awk '{print $2}'`)

    for i in ${MOUNT_POINTS[@]}
    do
        # Write, read and compare.
        dd if=${WRITE_TEST_FILE} of=$i/RW_TEST bs=1024k count=1 > /dev/null 2>&1
        dd if=$i/RW_TEST of=${READ_TEST_FILE} > /dev/null 2>&1
        cmp ${WRITE_TEST_FILE} ${READ_TEST_FILE}
        if [ $? -ne 0 ];then
            echo "Test failed!"
            exit 3
        fi
    done
    echo "Test pass!"
    exit 0
fi

参考

《存储设备与总线性能测试工具 Fio》:https://blog.csdn.net/engrossment/article/details/100033300

2020年10月20日

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页