Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 94CAE431FBF for ; Sun, 25 Nov 2012 07:02:46 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hQtPiRMKMQ9z for ; Sun, 25 Nov 2012 07:02:43 -0800 (PST) Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id E77FD431FB6 for ; Sun, 25 Nov 2012 07:02:40 -0800 (PST) Received: from fctnnbsc30w-156034089108.dhcp-dynamic.fibreop.nb.bellaliant.net ([156.34.89.108] helo=zancas.localnet) by tesseract.cs.unb.ca with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1TcdjD-0007HQ-8n; Sun, 25 Nov 2012 11:02:40 -0400 Received: from bremner by zancas.localnet with local (Exim 4.80) (envelope-from ) id 1Tcdj7-00034q-Op; Sun, 25 Nov 2012 11:02:33 -0400 From: david@tethera.net To: notmuch@notmuchmail.org Subject: [Patch v4 1/2] test: factor out part of test-lib.sh into test-lib-common.sh Date: Sun, 25 Nov 2012 11:02:23 -0400 Message-Id: <1353855745-11697-2-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1353855745-11697-1-git-send-email-david@tethera.net> References: <1353855745-11697-1-git-send-email-david@tethera.net> X-Spam_bar: - Cc: David Bremner X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 25 Nov 2012 15:02:46 -0000 From: David Bremner The idea is to use some of the simpler parts of the test suite infrastructure to help run performance tests. --- test/test-lib-common.sh | 147 +++++++++++++++++++++++++++++++++++++++++++++++ test/test-lib.sh | 129 +---------------------------------------- 2 files changed, 148 insertions(+), 128 deletions(-) create mode 100644 test/test-lib-common.sh diff --git a/test/test-lib-common.sh b/test/test-lib-common.sh new file mode 100644 index 0000000..e1eaa5a --- /dev/null +++ b/test/test-lib-common.sh @@ -0,0 +1,147 @@ +# +# Copyright (c) 2005 Junio C Hamano +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/ . + +# This file contains common code to be used by both the regular +# (correctness) tests and the performance tests. + +find_notmuch_path () +{ + dir="$1" + + while [ -n "$dir" ]; do + bin="$dir/notmuch" + if [ -x "$bin" ]; then + echo "$dir" + return + fi + dir="$(dirname "$dir")" + if [ "$dir" = "/" ]; then + break + fi + done +} + +# Test the binaries we have just built. The tests are kept in +# test/ subdirectory and are run in 'trash directory' subdirectory. +TEST_DIRECTORY=$(pwd) +notmuch_path=`find_notmuch_path "$TEST_DIRECTORY"` +if test -n "$valgrind" +then + make_symlink () { + test -h "$2" && + test "$1" = "$(readlink "$2")" || { + # be super paranoid + if mkdir "$2".lock + then + rm -f "$2" && + ln -s "$1" "$2" && + rm -r "$2".lock + else + while test -d "$2".lock + do + say "Waiting for lock on $2." + sleep 1 + done + fi + } + } + + make_valgrind_symlink () { + # handle only executables + test -x "$1" || return + + base=$(basename "$1") + symlink_target=$TEST_DIRECTORY/../$base + # do not override scripts + if test -x "$symlink_target" && + test ! -d "$symlink_target" && + test "#!" != "$(head -c 2 < "$symlink_target")" + then + symlink_target=$TEST_DIRECTORY/valgrind.sh + fi + case "$base" in + *.sh|*.perl) + symlink_target=$TEST_DIRECTORY/unprocessed-script + esac + # create the link, or replace it if it is out of date + make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit + } + + # override notmuch executable in TEST_DIRECTORY/.. + GIT_VALGRIND=$TEST_DIRECTORY/valgrind + mkdir -p "$GIT_VALGRIND"/bin + make_valgrind_symlink $TEST_DIRECTORY/../notmuch + OLDIFS=$IFS + IFS=: + for path in $PATH + do + ls "$path"/notmuch 2> /dev/null | + while read file + do + make_valgrind_symlink "$file" + done + done + IFS=$OLDIFS + PATH=$GIT_VALGRIND/bin:$PATH + GIT_EXEC_PATH=$GIT_VALGRIND/bin + export GIT_VALGRIND + test -n "$notmuch_path" && MANPATH="$notmuch_path/man:$MANPATH" +else # normal case + if test -n "$notmuch_path" + then + PATH="$notmuch_path:$PATH" + MANPATH="$notmuch_path/man:$MANPATH" + fi +fi +export PATH MANPATH + +# Test repository +test="tmp.$(basename "$0" .sh)" +test -n "$root" && test="$root/$test" +case "$test" in +/*) TMP_DIRECTORY="$test" ;; + *) TMP_DIRECTORY="$TEST_DIRECTORY/$test" ;; +esac +test ! -z "$debug" || remove_tmp=$TMP_DIRECTORY +rm -fr "$test" || { + GIT_EXIT_OK=t + echo >&5 "FATAL: Cannot prepare test area" + exit 1 +} + +# A temporary home directory is needed by at least: +# - emacs/"Sending a message via (fake) SMTP" +# - emacs/"Reply within emacs" +# - crypto/emacs_deliver_message +export HOME="${TMP_DIRECTORY}/home" +mkdir -p "${HOME}" + +MAIL_DIR="${TMP_DIRECTORY}/mail" +export GNUPGHOME="${TMP_DIRECTORY}/gnupg" +export NOTMUCH_CONFIG="${TMP_DIRECTORY}/notmuch-config" + +mkdir -p "${test}" +mkdir -p "${MAIL_DIR}" + +cat <"${NOTMUCH_CONFIG}" +[database] +path=${MAIL_DIR} + +[user] +name=Notmuch Test Suite +primary_email=test_suite@notmuchmail.org +other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org +EOF diff --git a/test/test-lib.sh b/test/test-lib.sh index e7638be..467b83c 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -1070,134 +1070,7 @@ test_init_ () { } -find_notmuch_path () -{ - dir="$1" - - while [ -n "$dir" ]; do - bin="$dir/notmuch" - if [ -x "$bin" ]; then - echo "$dir" - return - fi - dir="$(dirname "$dir")" - if [ "$dir" = "/" ]; then - break - fi - done -} - -# Test the binaries we have just built. The tests are kept in -# test/ subdirectory and are run in 'trash directory' subdirectory. -TEST_DIRECTORY=$(pwd) -notmuch_path=`find_notmuch_path "$TEST_DIRECTORY"` -if test -n "$valgrind" -then - make_symlink () { - test -h "$2" && - test "$1" = "$(readlink "$2")" || { - # be super paranoid - if mkdir "$2".lock - then - rm -f "$2" && - ln -s "$1" "$2" && - rm -r "$2".lock - else - while test -d "$2".lock - do - say "Waiting for lock on $2." - sleep 1 - done - fi - } - } - - make_valgrind_symlink () { - # handle only executables - test -x "$1" || return - - base=$(basename "$1") - symlink_target=$TEST_DIRECTORY/../$base - # do not override scripts - if test -x "$symlink_target" && - test ! -d "$symlink_target" && - test "#!" != "$(head -c 2 < "$symlink_target")" - then - symlink_target=$TEST_DIRECTORY/valgrind.sh - fi - case "$base" in - *.sh|*.perl) - symlink_target=$TEST_DIRECTORY/unprocessed-script - esac - # create the link, or replace it if it is out of date - make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit - } - - # override notmuch executable in TEST_DIRECTORY/.. - GIT_VALGRIND=$TEST_DIRECTORY/valgrind - mkdir -p "$GIT_VALGRIND"/bin - make_valgrind_symlink $TEST_DIRECTORY/../notmuch - OLDIFS=$IFS - IFS=: - for path in $PATH - do - ls "$path"/notmuch 2> /dev/null | - while read file - do - make_valgrind_symlink "$file" - done - done - IFS=$OLDIFS - PATH=$GIT_VALGRIND/bin:$PATH - GIT_EXEC_PATH=$GIT_VALGRIND/bin - export GIT_VALGRIND - test -n "$notmuch_path" && MANPATH="$notmuch_path/man:$MANPATH" -else # normal case - if test -n "$notmuch_path" - then - PATH="$notmuch_path:$PATH" - MANPATH="$notmuch_path/man:$MANPATH" - fi -fi -export PATH MANPATH - -# Test repository -test="tmp.$(basename "$0" .sh)" -test -n "$root" && test="$root/$test" -case "$test" in -/*) TMP_DIRECTORY="$test" ;; - *) TMP_DIRECTORY="$TEST_DIRECTORY/$test" ;; -esac -test ! -z "$debug" || remove_tmp=$TMP_DIRECTORY -rm -fr "$test" || { - GIT_EXIT_OK=t - echo >&5 "FATAL: Cannot prepare test area" - exit 1 -} - -# A temporary home directory is needed by at least: -# - emacs/"Sending a message via (fake) SMTP" -# - emacs/"Reply within emacs" -# - crypto/emacs_deliver_message -export HOME="${TMP_DIRECTORY}/home" -mkdir -p "${HOME}" - -MAIL_DIR="${TMP_DIRECTORY}/mail" -export GNUPGHOME="${TMP_DIRECTORY}/gnupg" -export NOTMUCH_CONFIG="${TMP_DIRECTORY}/notmuch-config" - -mkdir -p "${test}" -mkdir -p "${MAIL_DIR}" - -cat <"${NOTMUCH_CONFIG}" -[database] -path=${MAIL_DIR} - -[user] -name=Notmuch Test Suite -primary_email=test_suite@notmuchmail.org -other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org -EOF +. ./test-lib-common.sh emacs_generate_script -- 1.7.10.4