Tests autogen'd by CMake allows conditional tests
[platform/core/uifw/dali-toolkit.git] / automated-tests / scripts / retriever.sh
1 #!/bin/bash
2
3 USAGE=$(cat <<EOF
4 Usage note: retriever.sh [option] [directory] test-files
5 Options:
6   none    retrieve TC names with corresponding startup and cleanup functions
7   -f      retrieve TC name with corresponding "set" and "purpose" clauses
8   -anum   retrieve automatic TC number
9   -mnum   retrieve manual TC number
10
11 In case of TC in form of "int tc_name()" script will abort.
12 ("int tc_name(void)" is a proper function signature)
13 EOF
14 )
15
16 function get_tc_files {
17     CMAKE_FILE="$DIR/CMakeLists.txt"
18     if [ ! -e $CMAKE_FILE ]; then
19         echo "File $CMAKE_FILE not found. Aborting..."
20         exit 1
21     fi
22
23     TC_FILES=$(cat $CMAKE_FILE | awk -vDIR="$DIR" '
24     BEGIN {
25         flag = 0;
26         files = "";
27     }
28     /^SET\(TC_SOURCES/ {
29         flag = 1;
30         next;
31     }
32     /\)/ {
33         if (flag == 1)
34             exit;
35     }
36     !/^ *#/ {
37         if (flag == 1) {
38             if (files == "")
39                 files = DIR "/" $1;
40             else
41                 files = files " " DIR "/" $1;
42         }
43     }
44     END {
45         print files;
46     }')
47 }
48
49
50
51 function tc_names {
52     if [[ -z "$1" ]]; then
53         exit
54     fi
55
56     awk '
57     BEGIN {
58         OFS = ",";
59         start_fun = "NULL";
60         clean_fun = "NULL";
61         err_flag = 0;
62         tc_list = "";
63     }
64     BEGINFILE {
65         start_fun = "NULL";
66         clean_fun = "NULL";
67     }
68     /^void .*startup\(void\)/ {
69         gsub(/^void /, "");
70         gsub(/\(void\)$/,"");
71         start_fun = $0
72     }
73     /^void .*cleanup\(void\)/ {
74         gsub(/^void /, "");
75         gsub(/\(void\)$/,"");
76         clean_fun = $0
77     }
78     /^int .*\(\)/ {
79         print "Warning: function with empty argument list -- \"" $0 "\" in " FILENAME ":" FNR;
80         err_flag = 1;
81     }
82     /^int .*\(void\)/ {
83         gsub(/^int /, "");
84         gsub(/\(void\).*/,"");
85         if (tc_list != "") tc_list = tc_list "\n";
86         tc_list = tc_list $0 OFS start_fun OFS clean_fun
87     }
88     END {
89         if (err_flag) {
90             exit 1
91         } else {
92             print tc_list
93         }
94     }
95     ' $*
96 }
97
98 function tc_anum {
99     awk '
100     BEGIN {
101         count = 0;
102         err_flag = 0;
103     }
104     /^int .*\(\)/ {
105         print "Warning: function with empty argument list -- \"" $0 "\" in " FILENAME ":" FNR;
106         err_flag = 1;
107     }
108     /^int .*\(void\)$/ {
109         count++;
110     }
111     END {
112         if (err_flag) {
113             exit 1
114         } else {
115             print count
116         }
117     }
118     ' $*
119 }
120
121 function tc_mnum {
122     # TODO: fix this hardcoded value
123     echo 0
124 }
125
126 function tc_fullinfo {
127     awk '
128     BEGIN {
129         OFS=",";
130         purpose = "";
131         set = "default";
132         err_flag = 0;
133         tc_list = "";
134     }
135     /^\/\/& set:/ {
136         set = $3;
137         next;
138     }
139     /^\/\/& purpose:/ {
140         purpose = $3;
141         for (i = 4; i <= NF; i++) {
142             purpose = purpose " " $i;
143         }
144         next;
145     }
146     /^int .*\(\)/ {
147         print "Warning: function with empty argument list -- \"" $0 "\" in " FILENAME ":" FNR;
148         err_flag = 1;
149     }
150     /^int .*\(void\)$/ {
151         gsub(/^int /, "");
152         gsub(/\(void\)$/,"");
153         if (tc_list != "") tc_list = tc_list "\n";
154         tc_list = tc_list $0 OFS set OFS purpose;
155         purpose = "";
156         next
157     }
158     END {
159         if (err_flag) {
160             exit 1
161         } else {
162             print tc_list
163         }
164     }
165     ' $*
166 }
167
168 TEMP=`getopt -o f,a:,m: --long full,anum:,mnum: \
169      -n 'genmake' -- "$@"`
170
171 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
172
173 # Note the quotes around `$TEMP': they are essential!
174 eval set -- "$TEMP"
175
176 opt_full=false
177 opt_anum=
178 opt_mnum=
179
180 while true ; do
181     case "$1" in
182         -f|--full) opt_full=true ; shift ;;
183         -a|--anum) opt_anum="$2" ; shift 2 ;;
184         -m|--mnum) opt_mnum="$2" ; shift 2 ;;
185         --) shift ; break ;;
186         *) echo -e $USAGE ; exit 1 ;;
187     esac
188 done
189
190 DIR=.
191 if [ -n "$opt_anum" ] ; then
192     DIR=$opt_anum
193     echo opt_anum: DIR=$DIR >& 2
194 elif [ -n "$opt_mnum" ] ; then
195     DIR=$opt_mnum
196     echo opt_mnum: DIR=$DIR >& 2
197 fi
198
199 # get filename from first argument
200 if [[ $# == 1 && -f $DIR/$1 ]] ; then
201     FILE=$1
202     shift;
203 fi
204
205 #echo "Dir: $DIR  File: $FILE" >& 2
206
207 # populate $TC_FILES with files declared in CMakeLists.txt
208 if [[ -z $FILE ]]; then
209     if [[ ! $DIR == "." || $# == 0 ]] ; then
210         #echo Get tc files: DIR=$DIR >& 2
211         get_tc_files $DIR
212     else
213         TC_FILES=$(
214             for i in $* ; do
215                 echo $DIR/$i
216             done
217             )
218     fi
219     if [ $? != 0 ]; then
220         exit 1
221     fi
222     echo "Got all files in `pwd`" >& 2
223     #echo "TC_FILES: $TC_FILES" >& 2
224 else
225     TC_FILES="$DIR/$FILE"
226     echo "TC_FILES: $TC_FILES" >& 2
227 fi
228
229
230
231 # run appropriate subcommand
232 if [ $opt_full == "true" ] ; then
233     tc_fullinfo $TC_FILES
234 elif [ -n "$opt_anum" ] ; then
235     tc_anum $TC_FILES
236 elif [ -n "$opt_mnum" ] ; then
237     tc_mnum $TC_FILES
238 else
239     tc_names $TC_FILES
240 fi