perf-test: add argument parsing for performance tests
[notmuch] / performance-test / perf-test-lib.sh
1 . ./version.sh
2
3 corpus_size=large
4
5 while test "$#" -ne 0
6 do
7         case "$1" in
8         -d|--debug)
9                 debug=t;
10                 shift
11                 ;;
12         -s|--small)
13                 corpus_size=small;
14                 shift
15                 ;;
16         -m|--medium)
17                 corpus_size=medium;
18                 shift
19                 ;;
20         -l|--large)
21                 corpus_size=large;
22                 shift
23                 ;;
24         *)
25                 echo "error: unknown performance test option '$1'" >&2; exit 1 ;;
26         esac
27 done
28 . ../test/test-lib-common.sh
29
30 set -e
31
32 if ! test -x ../notmuch
33 then
34         echo >&2 'You do not seem to have built notmuch yet.'
35         exit 1
36 fi
37
38 add_email_corpus ()
39 {
40     rm -rf ${MAIL_DIR}
41
42     case "$1" in
43         --small)
44             arg="mail/enron/bailey-s"
45             ;;
46         --medium)
47             arg="mail/notmuch-archive"
48             ;;
49         *)
50             arg=mail
51     esac
52
53     if command -v pixz > /dev/null; then
54         XZ=pixz
55     else
56         XZ=xz
57     fi
58
59     printf "Unpacking corpus\n"
60     tar --checkpoint=.5000 --extract --strip-components=1 \
61         --directory ${TMP_DIRECTORY} \
62         --use-compress-program ${XZ} \
63         --file ../download/notmuch-email-corpus-${PERFTEST_VERSION}.tar.xz \
64         notmuch-email-corpus/"$arg"
65
66     printf "\n"
67 }
68
69 print_header () {
70     printf "[v%4s]               Wall(s)\tUsr(s)\tSys(s)\tRes(K)\tIn(512B)\tOut(512B)\n" \
71            ${PERFTEST_VERSION}
72 }
73
74 time_run () {
75     printf "%-22s" "$1"
76     if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
77     if ! eval >&3 "/usr/bin/time -f '%e\t%U\t%S\t%M\t%I\t%O' $2" ; then
78         test_failure=$(($test_failure + 1))
79         return 1
80     fi
81     return 0
82 }
83
84 time_done () {
85     if [ "$test_failure" = "0" ]; then
86         rm -rf "$remove_tmp"
87         exit 0
88     else
89         exit 1
90     fi
91 }
92
93 cd -P "$test" || error "Cannot setup test environment"
94 test_failure=0