1#!/bin/bash
2#
3# Script to test srm performance
4#
5# (Note: we use bash since it honors 'echo -n', unlike sh)
6
7# ----------------------------------------------------------------------
8
9# Location of standard srm command (as a baseline control)
10STDSRM=/usr/bin/srm
11
12# Location of srm command we are testing
13BASEDIR=`pwd`
14TSTSRM="${BASEDIR}/srm"
15
16# Location of temporary directory (warning: this directory will be wiped!)
17TMPDIR="${BASEDIR}/temp"
18
19# Strings to identify hardware & software (note: this is OS-specific)
20SW_VERS="`sw_vers -productVersion` (`sw_vers -buildVersion`)"
21HW_VERS="`system_profiler SPHardwareDataType | grep Name | sed 's/^[ ]*//'`"
22
23# ----------------------------------------------------------------------
24# Subroutines
25
26TAB="	"
27csh_time () {
28/bin/csh -sf << EOF
29  time $* >& /dev/null
30EOF
31}
32
33createLargeFiles () {
34	if [ ! -d "${TMPDIR}" ] ; then mkdir -p "${TMPDIR}" ; fi
35	if [ ! -f "${TMPDIR}/284mb" ] ; then
36	    # Make a 284MB file
37	    /bin/dd if=/dev/zero of="${TMPDIR}/284mb" bs=1k count=290816
38	    sync
39	    echo "Created ${TMPDIR}/284mb"
40	    ls -la "${TMPDIR}/284mb"
41    	fi
42   	if [ ! -f "${TMPDIR}/100mb" ] ; then
43	    # Make a 100MB file
44	    /bin/dd if=/dev/zero of="${TMPDIR}/100mb" bs=1k count=102400
45	    sync
46	    echo "Created ${TMPDIR}/100mb"
47	    ls -la "${TMPDIR}/100mb"
48    	fi
49}
50
51createSmallFiles () {
52	if [ ! -d "${TMPDIR}" ] ; then mkdir -p "${TMPDIR}" ; fi
53	if [ ! -d "${TMPDIR}/smallfiles" ] ; then
54		# Create a directory containing many small files
55		# (in this case, a copy of /usr/include/sys)
56		/bin/cp -r /usr/include/sys "${TMPDIR}/smallfiles"
57		sync
58		echo "Created ${TMPDIR}/smallfiles"
59		du -h "${TMPDIR}/smallfiles"
60	fi
61}
62
63doForN () {
64	# $1 = command to execute
65	# $2 = string to print on first iteration
66	# $3 = number of times to execute command
67	i=1
68	q=${3-1}
69	echo -n "$2"
70	
71	while [ $i -le $q ] ; do
72		echo -n "${TAB}"
73		if [ $i -gt 1 ] ; then echo -n "${TAB}${TAB}" ; fi
74		csh_time "$1"
75		i=$((i+1))
76		if [ ! -d "${TMPDIR}/smallfiles" ] ; then
77			# srm incorrectly renamed the folder [4498712]
78			createSmallFiles
79		fi
80	done
81}
82
83doTest () {
84	# $1 = command-line options
85	# $2 = number of times to execute command
86	doForN "${STDSRM}""$1" "baseline time${TAB}" "$2"
87	doForN "${TSTSRM}"' --bsize=4096 '"$1" "buffsize=4096${TAB}" "$2"
88	doForN "${TSTSRM}"' --bsize=65536 '"$1" "buffsize=65536${TAB}" "$2"
89	doForN "${TSTSRM}"' --bsize=131072 '"$1" "buffsize=131072${TAB}" "$2"
90	doForN "${TSTSRM}"' --bsize=1048576 '"$1" "buffsize=1048576" "$2"
91	doForN "${TSTSRM}"' --bsize=4194304 '"$1" "buffsize=4194304" "$2"
92	doForN "${TSTSRM}"' --bsize=8388608 '"$1" "buffsize=8388608" "$2"
93}
94
95# ----------------------------------------------------------------------
96# Begin script
97
98echo "`date`: ${HW_VERS}"
99echo "`date`: Current system is ${SW_VERS}"
100echo "`date`: Current directory is ${BASEDIR}"
101echo "`date`: Starting tests"
102
103if [ -d "${TMPDIR}" ] ; then rm -rf "${TMPDIR}" ; fi
104createLargeFiles
105createSmallFiles
106
107echo
108echo "### 1-pass tests ###"
109echo
110echo "file: ${TMPDIR}/284mb"
111doTest ' -s -n '"${TMPDIR}/284mb" 3
112echo
113echo "folder: ${TMPDIR}/smallfiles"
114doTest ' -s -r -f -n '"${TMPDIR}/smallfiles" 3
115
116echo
117echo "### 7-pass tests ###"
118echo
119echo "file: ${TMPDIR}/284mb"
120doTest ' -m -n '"${TMPDIR}/284mb" 3
121echo
122echo "folder: ${TMPDIR}/smallfiles"
123doTest ' -m -r -f -n '"${TMPDIR}/smallfiles" 3
124
125echo
126echo "### 35-pass tests ###"
127echo
128echo "file: ${TMPDIR}/100mb"
129doTest ' -n '"${TMPDIR}/100mb" 3
130echo
131echo "folder: ${TMPDIR}/smallfiles"
132doTest ' -r -f -n '"${TMPDIR}/smallfiles" 3
133
134if [ -d "${TMPDIR}" ] ; then rm -rf "${TMPDIR}" ; fi
135
136echo
137echo "`date`: Completed tests"
138
139exit 0
140