summaryrefslogtreecommitdiffstats
path: root/sanity/system_light/run.sh
blob: b8061c86347c19ab0a36af10c6aeaf35248c338f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash

_init ()
{
    ulimit -c unlimited
    set +x
    set -u;
    basedir=$(dirname $0);
    name=$(basename $0);
    abs=$(cd "$(dirname "$0")"; pwd)
    SCRIPTS_PATH=$abs/scripts;
    echo $abs;
    #SCRIPTS_PATH="/opt/qa/tools/system_light/scripts"
    CNT=0
    . $basedir/config;
    #. /opt/qa/tools/system_light/config
}

function run_tests ()
{
    local tool=;
    if [ $# -eq 1 ]; then
        tool=$1;
    fi

    export global_test=;

    if [ $tool ]; then
        global_test=$tool;
        export TOOLDIR=$SCRIPTS_PATH/$global_test;

        if [ -f $SCRIPTS_PATH/$tool/$tool.sh ]; then

            echo "executing $tool" && sleep 2;
            set +x;
            $SCRIPTS_PATH/$tool/$tool.sh;
            if [ "${?}" -eq 0 ]; then
                CNT=$((CNT+1))
                echo $CNT
            else
                echo "$tool failed" | tee -a $TEST_FAIL
                echo $CNT
            fi
            return 0;
        else
            echo "tool $tool is not there in the script directory $SCRIPTS_PATH. Exiting";
            return 22;
        fi
    fi

    for i in $(ls $SCRIPTS_PATH | sort -n)
    do
        if [ -f $SCRIPTS_PATH/$i/$i.sh ]; then
            run_tests $i;
            sleep 1;
        fi
    done
}

main ()
{
    echo "Tests available:"
    ls $SCRIPTS_PATH | sort -n && sleep 1;

    old_PWD=$PWD;

    echo "===========================TESTS RUNNING===========================";
    echo "Changing to the specified mountpoint";
    cd $THIS_TEST_DIR;
    pwd;
    sleep 1;

    if [ $TEST == "all" ]; then
        run_tests;
    else
        run_tests $TEST;
        if [ $? -ne 0 ]; then
            cd $old_PWD;
            rmdir $THIS_TEST_DIR;
            exit 22;
        fi
    fi

    echo "Total $CNT tests were successful" | tee -a $TEST_FAIL

    if [ "$INVOKEDIR" == "$THIS_TEST_DIR" ]; then
        echo "moving to the parent directory"
        cd ..
        echo "Removing $THIS_TEST_DIR"
        rmdir $THIS_TEST_DIR
        if [ "${?}" -ne 0 ]; then
            echo "rmdir failed:Directory not empty"
        fi
    else
        echo "Switching over to the previous working directory"
        cd $INVOKEDIR
        echo "Removing $THIS_TEST_DIR"
        rmdir $THIS_TEST_DIR
        if [ "${?}" -ne 0 ]; then
            echo "rmdir failed:Directory not empty"
        fi
    fi
}

_init "$@" && main "$@"