Merge remote-tracking branch 'qemu/master'
[qemu/ar7.git] / test-fvd.sh
blobadf4e1f60454f38e7ffd53cc5e2c0deeb35c60cd
1 #!/bin/bash
3 if [ $USER != "root" ]; then
4 echo "This command must be run by root in order to mount tmpfs."
5 exit 1
6 fi
8 QEMU_DIR=.
9 QEMU_IMG=$QEMU_DIR/qemu-img
10 QEMU_TEST=$QEMU_DIR/qemu-test
12 if [ ! -e $QEMU_IMG ]; then
13 echo "$QEMU_IMG does not exist."
14 exit 1;
17 if [ ! -e $QEMU_TEST ]; then
18 echo "$QEMU_TEST does not exist."
19 exit 1;
22 DATA_DIR=/var/ramdisk
23 TRUTH_IMG=$DATA_DIR/truth.raw
24 TEST_IMG=$DATA_DIR/test.fvd
25 TEST_BASE=$DATA_DIR/zero-500M.raw
26 TEST_IMG_DATA=$DATA_DIR/test.dat
27 CMD_LOG=/tmp/test-fvd.log
29 mount | grep $DATA_DIR > /dev/null
30 if [ $? -ne 0 ]; then
31 echo "Create tmpfs at $DATA_DIR to store testing images."
32 if [ ! -e $DATA_DIR ]; then mkdir -p $DATA_DIR ; fi
33 mount -t tmpfs none $DATA_DIR -o size=4G
34 if [ $? -ne 0 ]; then exit 1; fi
37 G1=1073741824
38 MAX_MEM=536870912
39 MAX_ROUND=1000000
40 MAX_IO_SIZE=100000000
41 fail_prob=0.1
42 cancel_prob=0.1
43 flush_prob=0.01
44 seed=$RANDOM$RANDOM
45 count=0
47 function invoke() {
48 echo "$*" >> $CMD_LOG
49 sync
51 ret=$?
52 if [ $ret -ne 0 ]; then
53 echo "$Exit with error code $ret: $*"
54 exit $ret;
58 /bin/rm -f $CMD_LOG
59 touch $CMD_LOG
61 while [ -t ]; do
62 for compact_image in on off ; do
63 for prefetch_delay in 1 0; do
64 for copy_on_read in on off; do
65 for block_size in 7680 512 1024 15872 65536 65024 1048576 1048064; do
66 for chunk_mult in 5 1 2 3 7 9 12 16 33 99 ; do
67 for base_img in "" "-b $TEST_BASE"; do
68 chunk_size=$[$block_size * $chunk_mult]
69 large_io_size=$[$chunk_size * 5]
70 if [ $large_io_size -gt $MAX_IO_SIZE ]; then large_io_size=$MAX_IO_SIZE; fi
71 for io_size in $large_io_size 1048576 ; do
72 for use_data_file in "" "data_file=$TEST_IMG_DATA," ; do
74 # FVD image is about 1G
75 img_size=$[(1073741824 + ($RANDOM$RANDOM$RANDOM % 104857600)) / 512 * 512]
77 # base image is about 500MB
78 base_size=$[(536870912 + ($RANDOM$RANDOM$RANDOM % 104857600)) / 512 * 512]
80 count=$[$count + 1]
81 echo "Round $count" >> $CMD_LOG
83 invoke "/bin/rm -rf $TRUTH_IMG $TEST_IMG $TEST_BASE $TEST_IMG_DATA"
84 invoke "dd if=/dev/zero of=$TRUTH_IMG count=0 bs=1 seek=$img_size"
85 invoke "dd if=/dev/zero of=$TEST_BASE count=0 bs=1 seek=$base_size"
86 if [ ! -z $use_data_file ]; then invoke "touch $TEST_IMG_DATA"; fi
88 mixed_records_per_journal_sector=121
89 journal_size=$[(((($io_size / $chunk_size ) + 1 ) / $mixed_records_per_journal_sector ) + 1) * 512 * 100]
91 invoke "$QEMU_IMG create -f fvd $base_img -o${use_data_file}data_file_fmt=blksim,compact_image=$compact_image,copy_on_read=$copy_on_read,block_size=$block_size,chunk_size=$chunk_size,journal_size=$journal_size,prefetch_start_delay=$prefetch_delay $TEST_IMG $img_size"
92 if [ $prefetch_delay -eq 1 ]; then $QEMU_IMG update $TEST_IMG prefetch_over_threshold_throttle_time=0; fi
94 # Use no more 1GB memory.
95 mem=$[$io_size * 1000]
96 if [ $mem -gt $MAX_MEM ]; then
97 parallel=$[$MAX_MEM / $io_size]
98 else
99 parallel=1000
101 parallel=$[${RANDOM}${RANDOM} % $parallel]
103 round=$[$G1 * 10 / $io_size]
104 if [ $round -gt $MAX_ROUND ]; then round=$MAX_ROUND; fi
106 b3=$[$round * 2 / 3]
107 [ $b3 -eq 0 ] && b3=1
108 for rep in 0 1 2 ; do
109 if [ $rep -eq 0 ]; then
110 compare_before=false
111 else
112 compare_before=true
114 r=$[${RANDOM}${RANDOM} % $b3]
115 seed=$[$seed + 1]
116 invoke "$QEMU_TEST --truth=$TRUTH_IMG --format=fvd --test="blksim:$TEST_IMG" --verify_write=true --parallel=$parallel --io_size=$io_size --fail_prob=$fail_prob --cancel_prob=$cancel_prob --flush_prob=$flush_prob --compare_after=true --round=$r --compare_before=$compare_before --seed=$seed"
117 done
119 /bin/rm -rf /tmp/fvd.log*
120 done; done; done; done; done; done; done; done; done