root/trunk/bin/do_unittests.sh

Revision 1161, 2.7 kB (checked in by frisco, 15 months ago)

Major updates to scripts for unit tests and pydoc

  • Property svn:executable set to *
Line 
1#!/bin/sh
2#do_unittests.sh
3#
4# run this script _before_ you do a commit and fix errors before uploading
5#
6# preparations:
7#       - add the following lines to /etc/super.tab:
8#               :global_options relative_path=y
9#               CryptoBoxRootActionsLocal       ./CryptoBoxRootActions  cryptobox
10#
11
12GETOPT="getopt"
13BASE_DIR=$(cd "$(dirname $0)/.."; pwd)
14
15export PYTHONPATH=$BASE_DIR/src
16
17disable_filecheck()
18{
19        sed -i "s/^OVERRIDE_FILECHECK = .*$/OVERRIDE_FILECHECK = True/" "$BASE_DIR/bin/CryptoBoxRootActions"
20}
21
22enable_filecheck()
23{
24        sed -i "s/^OVERRIDE_FILECHECK = .*$/OVERRIDE_FILECHECK = False/" "$BASE_DIR/bin/CryptoBoxRootActions"
25}
26
27
28run_tests()
29{
30    # chdir to 'bin' - all config settings depend on this
31    cd "${BASE_DIR}/bin"
32   
33    disable_filecheck
34   
35    if test -n "$files"
36        then    # do the specified tests
37        ##The use of "eval", plus not using double quotes for
38        ##$a below are
39        ##required because getopt already puts argument names in
40        ##single-quotes, and the script will not work with both sets
41        ##of quotes.
42        for a in $files
43          do    eval testoob -v $a
44        done
45    else        # do all tests
46        for a in ${BASE_DIR}/src/cryptobox/tests/test.*.py
47          do    testoob -v "$a"
48        done
49    fi
50   
51    enable_filecheck
52   
53    return 0
54}
55
56
57usage()
58{
59    echo -e "Usage:"
60    echo -e "\tbin/do_unittests.sh --clobber=foo [ files... ]"
61    echo -e "\t"
62    echo -e "\t(Where \"files\", if given, are absolute pathnames)"
63    echo -e "\t(Example: bin/do_unittests.sh --clobber=sdX)"
64    echo -e "***Warning: All data on /dev/foo will be DESTROYED!"
65    echo -e "\t"
66    exit 1
67}
68
69
70##### main() section #####
71
72##Declare global variables with empty contents
73CNAS_UTEST_CLOBBER=""
74files=""
75clobber_dev_arg=""
76
77
78##Use the getopt command line utility to simplify parsing
79getopt_str=`${GETOPT} -o c: --long clobber: \
80-n do_unittests.sh -- "$@"`
81#echo $getopt_str
82##Assign the tokens to an array
83getopt_arr=($getopt_str)
84
85##Note: Output of getopt in this script should look like:
86## --clobber 'sdX' -- file1 file2 file3 ...
87##Read the following code with that in mind.
88
89##If there is exactly one option, and it has an argument
90if [ "${getopt_arr[0]}" == "--clobber" ] \
91    && [ "${getopt_arr[2]}" == "--" ]; then
92    clobber_dev_arg="${getopt_arr[1]}"
93    ##Strip any single quotes from the device name
94    clobber_dev_arg="${clobber_dev_arg//\'/}"
95    #echo ${clobber_dev_arg}
96    ##Grab the part of $getopt_str that follows "--"
97    files="`expr match \"${getopt_str}\" '.*--\(.*\)'`"
98    #echo $files
99    if [ -b "/dev/${clobber_dev_arg}" ]; then
100        export CNAS_UTEST_CLOBBER="${clobber_dev_arg}"
101        ##Run the tests using testoob...
102        run_tests
103    else
104        echo "Error: /dev/${clobber_dev_arg} is not a valid block device"
105        exit 2
106    fi
107else
108    usage
109fi
110
111
Note: See TracBrowser for help on using the browser.