[dali_2.3.20] Merge branch 'devel/master'
[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     /LIST\(APPEND TC_SOURCES/ {
33         flag = 1;
34         next;
35     }
36     /\)/ {
37         flag = 0;
38     }
39     !/^ *#/ {
40         if (flag == 1) {
41             if (files == "")
42                 files = DIR "/" $1;
43             else
44                 files = files " " DIR "/" $1;
45         }
46     }
47     END {
48         print files;
49     }')
50 }
51
52
53
54 function tc_names {
55     if [[ -z "$1" ]]; then
56         exit
57     fi
58
59     awk '
60     BEGIN {
61         OFS = ",";
62         start_fun = "NULL";
63         clean_fun = "NULL";
64         err_flag = 0;
65         tc_list = "";
66     }
67     BEGINFILE {
68         start_fun = "NULL";
69         clean_fun = "NULL";
70     }
71     /^void .*startup\(void\)/ {
72         gsub(/^void /, "");
73         gsub(/\(void\)$/,"");
74         start_fun = $0
75     }
76     /^void .*cleanup\(void\)/ {
77         gsub(/^void /, "");
78         gsub(/\(void\)$/,"");
79         clean_fun = $0
80     }
81     /^int .*\(\)/ {
82         print "Warning: function with empty argument list -- \"" $0 "\" in " FILENAME ":" FNR;
83         err_flag = 1;
84     }
85     /^int .*\(void\)/ {
86         gsub(/^int /, "");
87         gsub(/\(void\).*/,"");
88         if (tc_list != "") tc_list = tc_list "\n";
89         tc_list = tc_list $0 OFS start_fun OFS clean_fun
90     }
91     END {
92         if (err_flag) {
93             exit 1
94         } else {
95             print tc_list
96         }
97     }
98     ' $*
99 }
100
101 function tc_anum {
102     awk '
103     BEGIN {
104         count = 0;
105         err_flag = 0;
106     }
107     /^int .*\(\)/ {
108         print "Warning: function with empty argument list -- \"" $0 "\" in " FILENAME ":" FNR;
109         err_flag = 1;
110     }
111     /^int .*\(void\)$/ {
112         count++;
113     }
114     END {
115         if (err_flag) {
116             exit 1
117         } else {
118             print count
119         }
120     }
121     ' $*
122 }
123
124 function tc_mnum {
125     # TODO: fix this hardcoded value
126     echo 0
127 }
128
129 function tc_fullinfo {
130     awk '
131     BEGIN {
132         OFS=",";
133         purpose = "";
134         set = "default";
135         err_flag = 0;
136         tc_list = "";
137     }
138     /^\/\/& set:/ {
139         set = $3;
140         next;
141     }
142     /^\/\/& purpose:/ {
143         purpose = $3;
144         for (i = 4; i <= NF; i++) {
145             purpose = purpose " " $i;
146         }
147         next;
148     }
149     /^int .*\(\)/ {
150         print "Warning: function with empty argument list -- \"" $0 "\" in " FILENAME ":" FNR;
151         err_flag = 1;
152     }
153     /^int .*\(void\)$/ {
154         gsub(/^int /, "");
155         gsub(/\(void\)$/,"");
156         if (tc_list != "") tc_list = tc_list "\n";
157         tc_list = tc_list $0 OFS set OFS purpose;
158         purpose = "";
159         next
160     }
161     END {
162         if (err_flag) {
163             exit 1
164         } else {
165             print tc_list
166         }
167     }
168     ' $*
169 }
170
171 TEMP=`getopt -o f::,a:,m: --long full::,anum:,mnum: \
172      -n 'retriever.sh' -- "$@"`
173
174 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
175
176 # Note the quotes around `$TEMP': they are essential!
177 eval set -- "$TEMP"
178
179 opt_full=false
180 opt_full_dir=
181 opt_anum=
182 opt_mnum=
183
184 while true ; do
185     case "$1" in
186         -f|--full) opt_full_dir="$2" ; opt_full="true" ; shift 2 ;;
187         -a|--anum) opt_anum="$2" ; shift 2 ;;
188         -m|--mnum) opt_mnum="$2" ; shift 2 ;;
189         --) shift ; break ;;
190         *) echo -e $USAGE ; exit 1 ;;
191     esac
192 done
193
194 #echo "###Retriever" >& 2
195 #echo opt_full: {$opt_full} >& 2
196 #echo opt_full_dir: {$opt_full_dir} >& 2
197
198 DIR=.
199 if [ -n "$opt_anum" ] ; then
200     DIR=$opt_anum
201     echo opt_anum: DIR=$DIR >& 2
202 elif [ -n "$opt_mnum" ] ; then
203     DIR=$opt_mnum
204     echo opt_mnum: DIR=$DIR >& 2
205 elif [ "$opt_full" == "true" ] ; then
206     if [ -n $opt_full_dir ] ; then
207         DIR=$opt_full_dir
208         echo opt_full: DIR=$DIR >& 2
209     fi
210 fi
211
212
213 # get filename from first argument
214 if [[ $# == 1 && -f $DIR/$1 ]] ; then
215     FILE=$1
216     shift;
217 fi
218
219 #echo "Dir: $DIR  File: $FILE" >& 2
220
221 # populate $TC_FILES with files declared in CMakeLists.txt
222 if [[ -z $FILE ]]; then
223     if [[ ! $DIR == "." || $# == 0 ]] ; then
224         #echo Get tc files: DIR=$DIR >& 2
225         get_tc_files $DIR
226     else
227         TC_FILES=$(
228             for i in $* ; do
229                 echo $DIR/$i
230             done
231             )
232     fi
233     if [ $? != 0 ]; then
234         exit 1
235     fi
236     echo "Got all files in `pwd`" >& 2
237     #echo "TC_FILES: $TC_FILES" >& 2
238 else
239     TC_FILES="$DIR/$FILE"
240     echo "TC_FILES: $TC_FILES" >& 2
241 fi
242
243
244
245 # run appropriate subcommand
246 if [ "$opt_full" == "true" ] ; then
247     tc_fullinfo $TC_FILES
248 elif [ -n "$opt_anum" ] ; then
249     tc_anum $TC_FILES
250 elif [ -n "$opt_mnum" ] ; then
251     tc_mnum $TC_FILES
252 else
253     tc_names $TC_FILES
254 fi