summaryrefslogtreecommitdiffstats
path: root/helper_scripts/untar-remove.sh
blob: 3b7bad31365e4d9d7cd83655ca39ba8cf8b7f2f3 (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
#!/bin/bash

function _init ()
{
    set -e;

    if [ $# -lt 2 ]; then
	echo "Continuing tests with current working directory."
        M=$PWD;
    else
	if [ ! -d $2 ]; then
	    echo "2nd argument needs to be a valid directory."
	    exit 42;
	else
            M=$2;
	fi
    fi

    if echo $1 | egrep -q '^[0-9]+$'; then
	T=$1;
    else
	echo "First argument was not a number, continuing with default"
	T=600;
    fi
    echo $T
    export pid_untar;
    export pid_remove;
}

function run_tests()
{
    old_PWD=$PWD;
    cd $M;

    sleep 1;
    untar &
    sleep 2;
    remove_kernel &

    sleep $T;

    cd $old_PWD;
}

function untar ()
{
    cd $M;
    while true
    do
       tar -xjf /opt/qa/tools/linux-2.6.31.1.tar.bz2 &
       pid_untar=$!;
       wait $pid_untar;
    done
}

function remove_kernel ()
{
    while true
    do
        rm -rf $M/linux-2.6.31.1 &
	pid_remove=$!;
	wait $pid_remove;
    done
}

function watchdog ()
{
    # insurance against hangs during the test

    sleep $1;

    echo "Kicking in watchdog after $1 secs";
}


function finish ()
{
    for i in $(jobs -pr)
    do
	echo "killing jobs"
    	kill -KILL $i;
	sleep 2;
    done

    sleep 10;

    rm -rf $M/linux-2.6.31.1 &
    cleanup_remove=$!;
    wait $cleanup_remove;
}

function main ()
{
    watchdog $T &

    trap finish INT EXIT;

    set -x;

    run_tests;
}

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