summaryrefslogtreecommitdiff
path: root/tools/run-threadreadtest.sh
blob: 4bd847852ee03bfa0d284cac0b187a22cc61ec48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash

dir=/tmp
filesize=100 # megabytes
numfiles=128
nocache=
interleave=
needfiles=1
write_blocksize=262144
args=

if uname -a | grep --silent arwin ; then
    ddmega=m
else
    ddmega=M
fi

while [ $# -gt 1 ] ; do
    case $1 in
	-d) dir=$2; shift; shift ;;
	-f) filesize=$2; shift; shift ;;
	-n) numfiles=$2; shift; shift ;;
	-M) args="$args -M"; shift ;;
	-D) args="$args -D"; shift ;;
	-R) args="$args -R"; shift ;;
        *) break ;;
    esac
done

if [ -d $dir -a -f $dir/testfile_1 ] ; then
    # dir exists and has a testfile within it - reuse to avoid
    # recreating files
    echo "# Re-using files in $dir"
    needfiles=
else
    dir=$dir/readtest_$$
    mkdir $dir
    
    if [ $? != 0 ] ; then
	echo "Cannot create testfile directory $dir"
	exit 1
    fi
fi

if [ x$needfiles != x ] ; then
    echo "# Building files for test..."
    if [ x$interleave = x ] ; then
	
	#
	# Create all files sequentially
	#
	
	for i in `seq 1 $numfiles` ; do
	    dd of=$dir/testfile_$i if=/dev/zero bs=1$ddmega count=$filesize >/dev/null 2>&1
	done
    else
	
	#
	# Create files interleaved, adding $write_blocksize to each
	# file in turn.
	#
	
	size=0
	limit=`expr $filesize * 1048576`
	while [ $size -lt $limit ] ; do
	    for i in `seq 1 $numfiles` ; do
		dd if=/dev/zero bs=$write_blocksize count=1 >> $dir/testfile_$i 2>/dev/null
	    done
	    size=`expr $size + $write_blocksize`
	done
    fi
fi

for bs in $@ ; do

    if uname -a | grep --silent arwin ; then
        # clears cache on OS X
        sudo purge
    elif [ -f /proc/sys/vm/drop_caches ] ; then
        # Linux cache clearing
        echo 3 | sudo tee /proc/sys/vm/drop_caches >/dev/null
    else       
        # need an alternative for other operating systems
        :
    fi
    
    echo "# Blocksize $bs"
    ./thread_readtest $args -b $bs -q $dir/testfile_%d
done