-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_test_case_info.sh
executable file
·106 lines (83 loc) · 2.87 KB
/
generate_test_case_info.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
104
105
106
#!/usr/bin/env bash
# Script to extract information on the test cases by scanning the directories and files.
# Currently writes the information to a csv file.
# TODO
# - get platform specific grep from framework
# - offer output to text file?
# - add other info to output...
OUTPUT_FILE_NAME="test_info.csv"
generate_test_info() {
test_status="ON"
if [ -a "off" ]; then
test_status="OFF"
fi
# Replace any commas with dashes since we will write to a csv file
test_description=`grep "^#TEST:" test.sh | sed s/#TEST://g | sed s/,/-/g`
test_disabled=`grep "^#DISABLED:" test.sh | sed s/#DISABLED://g | sed s/,/-/g`
# Just extract the issue identifier
test_issues=`grep "^#OPENDNSSEC\|^#SUPPORT" test.sh | sed s/#//g | sed 's/ .*//' `
test_todo=`grep "^#TODO:" test.sh | sed s/#TODO://g | sed s/,/-/g`
echo $1","$test_path","$test_status","$test_disabled","$test_description","$test_issues","$test_todo >> $OUTPUT_FILE
}
if [ -n "$1" ]; then
if [ "$1" == "--help" -o "$1" == "-help" -o "$1" == "-h" ]; then
echo "usage: generate_test_case_info <test directory (optional-default is pwd)>" >&2
exit 0
fi
if [ -d "$1" ]; then
if ! cd "$1" 2>/dev/null; then
echo "generate_test_case_info: unable to change to test directory $1!" >&2
exit 1
fi
else
echo "generate_test_case_info: test directory $1 does not exist" >&2
exit 1
fi
fi
pwd=`pwd`
echo "Searching top level directory "$pwd" for tests"
OUTPUT_FILE=$pwd/$OUTPUT_FILE_NAME
rm $OUTPUT_FILE
echo "Directory,Name,Status,Disabled,Description,Issues,To do" > $OUTPUT_FILE
for LOCAL_TEST_DIR in test-cases.d test-cases-daily.d test-cases-weekly.d; do
if [ -d "$LOCAL_TEST_DIR" ]; then
if ! cd "$LOCAL_TEST_DIR" 2>/dev/null; then
echo "generate_test_case_info: unable to change to test directory $LOCAL_TEST_DIR!" >&2
continue
fi
echo "Searching sub directory " $LOCAL_TEST_DIR " for tests"
test_num=0
ls -1 2>/dev/null | grep '^[0-9]*' 2>/dev/null >"tests.list"
while read entry; do
if [ -d "$entry" -a -f "$entry/test.sh" ]; then
test[test_num]="$entry"
test_num=$(( test_num + 1 ))
fi
done <"tests.list"
rm -f "tests.list" 2>/dev/null
if [ "$test_num" -le 0 ] 2>/dev/null; then
echo "generate_test_case_info: no tests found!" >&2
exit 1
fi
test_iter=0
while [ "$test_iter" -lt "$test_num" ] 2>/dev/null; do
test_path="${test[test_iter]}"
test_iter=$(( test_iter + 1 ))
pwd2=`pwd`
cd "$test_path" 2>/dev/null
echo " Found $test_path... "
generate_test_info $LOCAL_TEST_DIR
if ! cd "$pwd2" 2>/dev/null; then
echo "run_tests: unable to change back to test directory $pwd2 after checking a test!" >&2
exit 1
fi
done
if ! cd "$pwd" 2>/dev/null; then
echo "run_tests: unable to change back to directory $pwd after checking tests!" >&2
exit 1
fi
fi
done
echo "Done."
echo "Output written to: " $OUTPUT_FILE
exit 0