]> git.notmuchmail.org Git - notmuch/blob - performance-test/perf-test-lib.sh
53ef96dae8b28d1afd3a609000719d01695b1daa
[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 "$corpus_size" in
43         small)
44             mail_subdir="mail/enron/bailey-s"
45             check_for="${TEST_DIRECTORY}/corpus/$mail_subdir"
46             ;;
47         medium)
48             mail_subdir="mail/notmuch-archive"
49             check_for="${TEST_DIRECTORY}/corpus/$mail_subdir"
50             ;;
51         *)
52             mail_subdir=mail
53             check_for="${TEST_DIRECTORY}/corpus/$mail_subdir/enron/wolfe-j"
54     esac
55
56     MAIL_CORPUS="${TEST_DIRECTORY}/corpus/$mail_subdir"
57     args=()
58     if [ ! -d "$check_for" ] ; then
59         args+=("notmuch-email-corpus/$mail_subdir")
60     fi
61
62     if [[ ${#args[@]} > 0 ]]; then
63         if command -v pixz > /dev/null; then
64             XZ=pixz
65         else
66             XZ=xz
67         fi
68
69         printf "Unpacking corpus\n"
70         mkdir -p "${TEST_DIRECTORY}/corpus"
71
72         tar --checkpoint=.5000 --extract --strip-components=1 \
73             --directory ${TEST_DIRECTORY}/corpus \
74             --use-compress-program ${XZ} \
75             --file ../download/notmuch-email-corpus-${PERFTEST_VERSION}.tar.xz \
76             "${args[@]}"
77
78         printf "\n"
79
80     fi
81
82     cp -lr $MAIL_CORPUS $MAIL_DIR
83 }
84
85
86 print_header () {
87     printf "[v%4s %6s]          Wall(s)\tUsr(s)\tSys(s)\tRes(K)\tIn/Out(512B)\n" \
88            ${PERFTEST_VERSION} ${corpus_size}
89 }
90
91 time_run () {
92     printf "  %-22s" "$1"
93     if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
94     if ! eval >&3 "/usr/bin/time -f '%e\t%U\t%S\t%M\t%I/%O' $2" ; then
95         test_failure=$(($test_failure + 1))
96         return 1
97     fi
98     return 0
99 }
100
101 time_done () {
102     if [ "$test_failure" = "0" ]; then
103         rm -rf "$remove_tmp"
104         exit 0
105     else
106         exit 1
107     fi
108 }
109
110 cd -P "$test" || error "Cannot setup test environment"
111 test_failure=0
112
113 echo
114 echo $(basename "$0"): "Testing ${test_description:-notmuch performance}"