[dali_2.3.38] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / automated-tests / scripts / retriever.sh
1 #!/bin/bash
2
3 USAGE=$(cat <<EOF
4 Usage note: retriever.sh [option] [directory]
5 Options:
6   none    retrieve TC names with corresponding startup and cleanup functions
7   -f      retrieveve 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_old {
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 function get_tc_files {
50     TC_FILES=$(cd ../../build; cmake -LA -N 2>/dev/null | grep TC_SOURCE_LIST | perl -n -e 'my ($blah, $vars)=split(/=/,$_);my @files=split(/;/, $vars); print join("\n", @files) ;' )
51 }
52
53 function tc_names {
54     if [[ -z "$1" ]]; then
55         exit
56     fi
57
58     awk '
59     BEGIN {
60         OFS = ",";
61         start_fun = "NULL";
62         clean_fun = "NULL";
63         err_flag = 0;
64         tc_list = "";
65     }
66     /^void .*startup\(void\)/ {
67         gsub(/^void /, "");
68         gsub(/\(void\)$/,"");
69         start_fun = $0
70     }
71     /^void .*cleanup\(void\)/ {
72         gsub(/^void /, "");
73         gsub(/\(void\)$/,"");
74         clean_fun = $0
75     }
76     /^int .*\(\)/ {
77         print "Warning: function with empty argument list -- \"" $0 "\" in " FILENAME ":" FNR;
78         err_flag = 1;
79     }
80     /^int .*\(void\)/ {
81         gsub(/^int /, "");
82         gsub(/\(void\).*/,"");
83         if (tc_list != "") tc_list = tc_list "\n";
84         tc_list = tc_list $0 OFS start_fun OFS clean_fun
85     }
86     END {
87         if (err_flag) {
88             exit 1
89         } else {
90             print tc_list
91         }
92     }
93     ' $*
94 }
95
96 function tc_anum {
97     awk '
98     BEGIN {
99         count = 0;
100         err_flag = 0;
101     }
102     /^int .*\(\)/ {
103         print "Warning: function with empty argument list -- \"" $0 "\" in " FILENAME ":" FNR;
104         err_flag = 1;
105     }
106     /^int .*\(void\)$/ {
107         count++;
108     }
109     END {
110         if (err_flag) {
111             exit 1
112         } else {
113             print count
114         }
115     }
116     ' $*
117 }
118
119 function tc_mnum {
120     # TODO: fix this hardcoded value
121     echo 0
122 }
123
124 function tc_fullinfo {
125     awk '
126     BEGIN {
127         OFS=",";
128         purpose = "";
129         set = "default";
130         err_flag = 0;
131         tc_list = "";
132     }
133     /^\/\/& set:/ {
134         set = $3;
135         next;
136     }
137     /^\/\/& purpose:/ {
138         purpose = $3;
139         for (i = 4; i <= NF; i++) {
140             purpose = purpose " " $i;
141         }
142         next;
143     }
144     /^int .*\(\)/ {
145         print "Warning: function with empty argument list -- \"" $0 "\" in " FILENAME ":" FNR;
146         err_flag = 1;
147     }
148     /^int .*\(void\)$/ {
149         gsub(/^int /, "");
150         gsub(/\(void\)$/,"");
151         if (tc_list != "") tc_list = tc_list "\n";
152         tc_list = tc_list $0 OFS set OFS purpose;
153         purpose = "";
154         next
155     }
156     END {
157         if (err_flag) {
158             exit 1
159         } else {
160             print tc_list
161         }
162     }
163     ' $*
164 }
165
166
167 # usage note and exit:
168 # - argument begin with '-' but is not recognised or number of arguments is > 3,
169 # - argument doesn't begin with '-' and number of arguments is > 2
170 if [[ ( "$1" == -* && ( ! "$1" =~ ^-(anum|mnum|f|l)$ || $# > 3 ) ) || ( "$1" != -* && $# > 2 ) ]]; then
171     echo -e "$USAGE"
172     exit 1
173 fi
174
175 # get directory from last argument (or assume current one)
176 if [[ ! "$1" =~ ^-(anum|mnum|f|l)$ ]]; then
177     DIR=${1:-.}
178 else
179     DIR=${2:-.}
180 fi
181
182 # get filename from last argument
183 if [[ $# == 3 && -f $DIR/$3 ]] ; then
184     FILE=$3
185 elif [[ $# == 2 && -f $DIR/$2 ]] ; then
186     FILE=$2
187 fi
188
189 #echo "Dir: $DIR  File: $FILE" >& 2
190
191
192 # populate $TC_FILES with files declared in CMakeLists.txt
193 if [[ -z $FILE ]]; then
194     get_tc_files $DIR
195     if [ $? != 0 ]; then
196         exit 1
197     fi
198     echo "Got all files" >& 2
199 else
200     TC_FILES="$DIR/$FILE"
201     echo "TC_FILES: $TC_FILES" >& 2
202 fi
203
204
205
206 # run appropriate subcommand
207 case "$1" in
208     -anum)
209         tc_anum $TC_FILES ;;
210     -mnum)
211         tc_mnum $TC_FILES ;;
212     -f)
213         tc_fullinfo $TC_FILES ;;
214     -l)
215         echo $TC_FILES ;;
216     *)
217         tc_names $TC_FILES ;;
218 esac