summaryrefslogtreecommitdiff
path: root/rtems-test-template/mktest
blob: 136838efad83c69acbf2b7c45f9c87b153cc00b2 (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
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
#! /bin/sh
#
#  Process a test template directory into the baseline for a new test
#

toggle()
{
  case $1 in
    no)  echo "yes" ;;
    yes) echo "no" ;;
    *)   fatal "Unknown value to toggle ($1)" ;;
  esac
}

check_status()
{
  if [ $1 -ne 0 ] ; then
    shift 
    echo "FAILED: " "$*" >&2
    exit 1
  fi
}

usage()
{
  echo "$progname -s SOURCE -d DEST -D description -n NUMBER [-v]"
  echo "                   OR"
  echo "$progname -c -d DEST"
cat <<EOF

The first form is to generate a new test.
The second form is to add the new test to CVS.
EOF
  exit 1
}

addToCVS=no
source=
dest=
desc=
testNum=
verbose=no
while getopts cd:D:s:n:v OPT
do
  case "$OPT" in 
    c) addToCVS=`toggle ${addToCVS}` ;;
    d) dest=$OPTARG ;; 
    D) desc=$OPTARG ;; 
    s) source=$OPTARG ;; 
    n) testNum=$OPTARG ;; 
    v) verbose=`toggle ${verbose}` ;;
    *) usage ;;
  esac
done

# Error check
test "X${dest}" != "X"
check_status $? No destination provided
test -r configure.ac
check_status $? Not in test suite directory


if [ ${addToCVS} == yes ] ; then
  test -d ${dest}
  check_status $? "Cannot add ${dest} -- does not exist"

  cvs add ${dest}
  cd ${dest}
  for f in `ls -1 .cvsignore Makefile.am *.doc *.scn *.[ch] 2>/dev/null`
  do
     cvs add -kkv ${f}
  done
  exit 0
fi

test "X${source}" != "X"
check_status $? No source provided
test -d "${source}" 
check_status $? Source directory not present 
test "X${testNum}" != "X"
check_status $? No test number provided

test ! -d ${dest}/CVS
check_status $? "Are you sure about ${dest}? Already a CVS directory in it"

let $((shiftcount = $OPTIND - 1))
shift #shiftcount

args=$*

destCaps=`echo ${dest} | tr [:lower:] [:upper:]`
echo ${destCaps}

# Process the test
rm -rf ${dest}
check_status $? "Unable to remove ${dest}"

mkdir ${dest}
check_status $? "Unable to make ${dest}"

# all the source code we know about
for s in ${source}/*
do
  if [ -r ${s} -a ! -d ${s} ] ; then
    b=`basename ${s}`
    d=`echo ${dest}/${b} | sed "s/TEST\./${dest}\./"`
    echo Processing ${s} to ${d}
    sed -e "s/@LOWER@/${dest}/g" \
        -e "s/@UPPER@/${destCaps}/g" \
        -e "s/@DESC@/${desc}/g" \
        -e "s/@TESTNUM@/${testNum}/g" \
    <${s} >${d}
   check_status $? "Unable to process ${d}"
  fi
done

cat <<EOF >${dest}/.cvsignore
Makefile
Makefile.in
EOF

cat <<EOF
You need to add the test to the Makefile.am and configure.ac by hand
before you can build.

You will have to add content to the test itself including screen
and doc files.

EOF

exit 0