-
Notifications
You must be signed in to change notification settings - Fork 11
/
make-new-test.sh
executable file
·145 lines (119 loc) · 2.37 KB
/
make-new-test.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/sh -e
fail () { echo "$1"; exit 1; }
[ $# -gt 1 ] && fail "Interactive script to create new XTF tests\n Usage: $0 [\$NAME]"
cd $(dirname $(readlink -f $0))
# Test name
if [ $# -eq 1 ]
then
NAME=$1
echo "Test name: $NAME"
else
echo -n "Test name: "
read NAME
fi
NAME_UC=$(echo $NAME | tr a-z A-Z)
[ -z "$NAME" ] && fail "No name given"
[ -e tests/$NAME ] && fail "Test $NAME already exists"
mkdir -p tests/$NAME
# Category - Select default based on test name
if [ ${NAME#xsa-} != ${NAME} ];
then
DEF_CATEGORY="xsa"
else
DEF_CATEGORY="utility"
fi
echo -n "Category [$DEF_CATEGORY]: "
read CATEGORY
CATEGORY=${CATEGORY:-$DEF_CATEGORY}
# Environments
echo -n "Environments [hvm32]: "
read ENVS
ENVS=${ENVS:-"hvm32"}
# Optional extra config
echo -n "Extra xl.cfg? [y/N]: "
read EXTRA
if [ -z "$EXTRA" ];
then
EXTRA=n
fi
if [ "$EXTRA" = "Y" ];
then
EXTRA=y
fi
# Write Makefile
echo "Writing default tests/$NAME/Makefile"
{
cat <<EOF
include \$(ROOT)/build/common.mk
NAME := $NAME
CATEGORY := $CATEGORY
TEST-ENVS := $ENVS
EOF
[ "$EXTRA" = "y" ] && cat <<EOF
TEST-EXTRA-CFG := extra.cfg.in
EOF
cat <<EOF
obj-perenv += main.o
include \$(ROOT)/build/gen.mk
EOF
} > tests/$NAME/Makefile
# Possibly insert an empty extra.cfg file
if [ "$EXTRA" = "y" ];
then
echo "Writing default tests/$NAME/extra.cfg.in"
echo "" > tests/$NAME/extra.cfg.in
fi
# Write main.c
echo "Writing default tests/$NAME/main.c"
{
cat <<EOF
/**
* @file tests/$NAME/main.c
* @ref test-$NAME
*
EOF
if [ $CATEGORY != "xsa" ]
then
cat <<EOF
* @page test-$NAME $NAME
EOF
else
cat <<EOF
* @page test-$NAME $NAME_UC
*
* Advisory: [$NAME_UC](https://xenbits.xen.org/xsa/advisory-${NAME#xsa-}.html)
EOF
fi
cat <<EOF
*
* @todo Docs for test-$NAME
*
* @see tests/$NAME/main.c
*/
#include <xtf.h>
EOF
[ $CATEGORY != "xsa" ] && \
echo 'const char test_title[] = "Test '$NAME'";' || \
echo 'const char test_title[] = "'$NAME_UC' PoC";'
cat <<EOF
void test_main(void)
{
xtf_success(NULL);
}
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
EOF
} > tests/$NAME/main.c
# Update docs/all-tests.dox with a placeholder
echo "Adding placeholder to docs/all-tests.dox"
cat >> docs/all-tests.dox <<EOF
# Placeholder: Merge into the appropriate location above
@subpage test-$NAME - @todo title
EOF