1#!/bin/bash 2#/******************************************************************/ 3#/* Copyright (C) ROCK-CHIPS . All Rights Reserved. */ 4#/******************************************************************* 5#File : flash_stress_test.sh 6#Desc : flash write and read stress test tools 7#Author : ZYF 8#Date : 2020-07-16 9#Notes : 10# Revision Data Author Note. 11# 1.00 2017/05/05 Zhaoyifeng 1.First version 12# 1.10 2020/06/28 Dingqiang Lin(jon.lin@rock-chips.com) 1.Simplify test_log 2.Add more introduction 13# 1.20 2020/07/16 Hans Yang 1.use /dev/urandom to generate test data 14#Introduction. 15#********************************************************************/ 16# usage�� 17# sudo flash_stress_test.sh dirnum testcount 18# example �� 19# count for script command: 20# SLC Nand 128MB, 100K P/E cycles, normaly we test 5K P/E ���� 128MB * 5000 21# src file size 5MB, totle test data 128MB * 5000, testcount = 128MB * 5000 / 5MB * 5(dirnum) = 20600 22# command: 23# sudo flash_stress_test.sh 5 20000 24# available space need: 25# src file size: 5MB 26# des file size: 5MB * dirnum = 25MB 27# log file size: 189B(log item size) * 20000 = 3691KB 28# total: about 34MB 29# result analyze: 30# success: 31# 1. shell progress stop; 32# 2. print "-------copy and check success------------" 33# fail: 34# 1. shell progress stop; 35# 2. any printing with "error" tag 36# 37#********************************************************************/ 38 39test_dir=/data/rockchip-test/flash_test 40source_dir=$test_dir/src_test_data 41dest_dir=$test_dir/des_test_data 42md5_dir=$test_dir/md5_data 43 44usage() 45{ 46echo "Usage: flash_stress_test.sh [dirnum] [looptime]" 47echo "flash_stress_test.sh 5 20000" 48} 49 50test_max_count=200 51test_max_dir=5 52if [ $1 -ne 0 ] ;then 53 test_max_dir=$1 54fi 55 56if [ $2 -ne 0 ] ;then 57 test_max_count=$2 58fi 59 60echo "Test Max dir Num = ${test_max_dir}" 61echo "Test Max count = ${test_max_count}" 62 63count=0 64dir_loop=0 65rm -rf $test_dir/test_log.txt 66mkdir -p $dest_dir 67mkdir -p $md5_dir 68mkdir -p $source_dir 69 70#generate 5MB random file 71rm -rf $source_dir/* 72file_path=$source_dir 73file_size=(512 1024 3456 512 1024 3456) 74file_radio=(5 5 5 5 5 5) 75 76function random() 77{ 78 min=$1 79 max=$2 80 num=`date +%s` 81 ((value=$num%($max-$min)+$min+1)) 82 echo $value 83} 84 85file_size_count=${#file_size[*]} 86file_radio_count=${#file_radio[*]} 87 88if [ $file_size_count=$file_radio_count ] 89then 90 for ((i=0;i <$file_size_count;i++)) 91 do 92 for ((n=0;n <${file_radio[$i]};n++)) 93 do 94 if [ $i==0 ] 95 then 96 rand=$(random 0 ${file_size[$i]}) 97 else 98 rand=$(random ${file_size[$i-1]} ${file_size[$i]}) 99 fi 100 dd if=/dev/urandom of=$file_path/test.$i.$rand.bin bs=$rand count=1024 101 done 102 echo =========== 103 done 104fi 105 106cd $source_dir 107 108#find ./ -type f -print0 | xargs -0 md5sum | sort > $md5_dir/source.md5 109md5sum ./* > $md5_dir/source.md5 110cd / 111while [ $count -lt $test_max_count ]; do 112 echo $count 113 echo $count >> $test_dir/test_log.txt 114 dir_loop=0 115 while [ $dir_loop -lt $test_max_dir ]; do 116 echo "$count test $source_dir to $dest_dir/${dir_loop}" 117 rm -rf $dest_dir/$dir_loop 118 if [ $? == 0 ]; then 119 echo "$count clean $dest_dir/${dir_loop} success" 120 echo "$count clean ${dir_loop}" >> $test_dir/test_log.txt 121 else 122 echo "$count clean $dest_dir/${dir_loop} error" 123 echo "$count clean $dest_dir/${dir_loop} error" >> $test_dir/test_log.txt 124 exit 0 125 fi 126 #sync 127 #sleep 1 128 #start copy data 129 echo "$count $dir_loop start copy data" 130 cp -rf $source_dir $dest_dir/$dir_loop 131 if [ $? == 0 ]; then 132 echo "$count cp $source_dir to $dest_dir/${dir_loop} success" 133 echo "$count cp ${dir_loop}" >> $test_dir/test_log.txt 134 else 135 echo "$count cp $source_dir to $dest_dir/${dir_loop} error" 136 echo "$count cp $source_dir to $dest_dir/${dir_loop} error" >> $test_dir/test_log.txt 137 fi 138 #sync 139 #sleep 1 140 dir_loop=$(($dir_loop+1)) 141 done 142 dir_loop=0 143 sync && echo 3 > /proc/sys/vm/drop_caches 144 sleep 5 145 sync 146 echo 3 > /proc/sys/vm/drop_caches 147 sleep 5 148 while [ $dir_loop -lt $test_max_dir ]; do 149 #calc dir md5 150 echo "$count calc $dest_dir/${dir_loop} md5 start" 151 echo "$count calc $dest_dir/${dir_loop} md5 start" >> $test_dir/test_log.txt 152 cd $dest_dir/${dir_loop} 153 #find ./ -type f -print0 | xargs -0 md5sum | sort > $md5_dir/dest${dir_loop}.md5 154 md5sum ./* > $md5_dir/dest${dir_loop}.md5 155 cd / 156 #cmp with src md5 157 diff $md5_dir/source.md5 $md5_dir/dest${dir_loop}.md5 158 if [ $? == 0 ]; then 159 echo "$count check source to $dest_dir/${dir_loop} success" 160 echo "$count check ${dir_loop}" >> $test_dir/test_log.txt 161 rm $md5_dir/dest${dir_loop}.md5 162 rm -rf $dest_dir/$dir_loop 163 else 164 echo "$count check source to $dest_dir/${dir_loop} error" 165 echo "$count check source to $dest_dir/${dir_loop} error" >> $test_dir/test_log.txt 166 exit 0 167 fi 168 dir_loop=$(($dir_loop+1)) 169 done 170 count=$(($count+1)) 171 #if test fail, we can save file for debug 172 #rm -rf $test_dir/$dest_dir/* 173 echo ----------------------------------------- 174 echo "-------========You can see the result at and $test_dir/test_log.txt file=======------------" 175 echo ----------------------------------------- >> $test_dir/test_log.txt 176done 177 178 echo "-------copy and check success------------" 179 echo "-------copy and check success------------" >> $test_dir/test_log.txt 180 echo "-------========You can see the result at and $test_dir/test_log.txt file=======------------" 181 182 183 184 185 186