-
Notifications
You must be signed in to change notification settings - Fork 36
/
test_image_mgmt.sh
executable file
·103 lines (83 loc) · 3.58 KB
/
test_image_mgmt.sh
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/sh
DELIMITER="echo -e \n##############################################"
groups | grep '\<docker\>' > /dev/null
NEED_SUDO=$?
if [ $NEED_SUDO -eq 1 ]; then
echo "The user running this test is NOT in the docker group (will need sudo)"
SUDO_CMD="sudo"
else
echo "The user running this test is in the docker group"
SUDO_CMD=""
fi
set -eux
$DELIMITER
echo "Clearing the state before the test..."
python3 manage_images.py -r
python3 -m coverage erase
$DELIMITER
echo "Testing help message printing..."
python3 -m coverage run -a --branch manage_images.py -h
$DELIMITER
echo "Testing image building..."
python3 -m coverage run -a --branch manage_images.py -b gcc-8
python3 -m coverage run -a --branch manage_images.py -b clang-11
$DELIMITER
echo "Testing quiet image building..."
python3 -m coverage run -a --branch manage_images.py -b gcc-12 -q
python3 -m coverage run -a --branch manage_images.py -b clang-15 -q
$DELIMITER
echo "Testing image listing..."
python3 -m coverage run -a --branch manage_images.py -l
$DELIMITER
echo "Testing image removal..."
python3 -m coverage run -a --branch manage_images.py -r
$DELIMITER
echo "Testing building all images..."
python3 -m coverage run -a --branch manage_images.py -b all
$DELIMITER
echo "Testing building an existing image..."
python3 -m coverage run -a --branch manage_images.py -b gcc-6
python3 -m coverage run -a --branch manage_images.py -b clang-10
$DELIMITER
echo "Testing image removal when containers are running..."
$SUDO_CMD docker run -d --rm --name test-running-1 kernel-build-container:gcc-12 tail -f /dev/null
$SUDO_CMD docker run -d --rm --name test-running-2 kernel-build-container:gcc-14 tail -f /dev/null
python3 -m coverage run -a --branch manage_images.py -r
$SUDO_CMD docker stop test-running-1
python3 -m coverage run -a --branch manage_images.py -r
$SUDO_CMD docker stop test-running-2
python3 -m coverage run -a --branch manage_images.py -r
$DELIMITER
echo "Testing the error handling..."
$DELIMITER
echo "Testing without any options..."
python3 -m coverage run -a --branch manage_images.py && exit 1
$DELIMITER
echo "Testing invalid arguments..."
python3 -m coverage run -a --branch manage_images.py -b strange-compiler && exit 1
python3 -m coverage run -a --branch manage_images.py -r invalid-option && exit 1
$DELIMITER
echo "Testing invalid combinations..."
python3 -m coverage run -a --branch manage_images.py -q && exit 1
python3 -m coverage run -a --branch manage_images.py -q -r && exit 1
python3 -m coverage run -a --branch manage_images.py -l -r && exit 1
python3 -m coverage run -a --branch manage_images.py -l -q && exit 1
python3 -m coverage run -a --branch manage_images.py -l -q -r && exit 1
python3 -m coverage run -a --branch manage_images.py -b gcc-10 -r && exit 1
python3 -m coverage run -a --branch manage_images.py -b gcc-10 -q -r && exit 1
python3 -m coverage run -a --branch manage_images.py -b all -l && exit 1
python3 -m coverage run -a --branch manage_images.py -b all -l -r && exit 1
python3 -m coverage run -a --branch manage_images.py -b all -l -q && exit 1
python3 -m coverage run -a --branch manage_images.py -b all -l -q -r && exit 1
$DELIMITER
echo "Testing containers with missing GCC tags..."
python3 -m coverage run -a --branch manage_images.py -b gcc-12
$SUDO_CMD docker rmi -f kernel-build-container:gcc-12
python3 -m coverage run -a --branch manage_images.py -l && exit 1
$SUDO_CMD docker rmi -f kernel-build-container:clang-13
python3 -m coverage run -a --branch manage_images.py -l
$DELIMITER
echo "All tests completed. Creating the coverage report..."
python3 -m coverage report
python3 -m coverage html
echo "Well done!"