~n3npq/lsb/distribution-checker

« back to all changes in this revision

Viewing changes to webui/public_html/BuildList.pm

  • Committer: biga
  • Date: 2009-04-24 14:16:44 UTC
  • Revision ID: biga@spidey.linux-foundation.org-20090424141644-7evzd6mjocix7e68
init

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# LSB Test Execution Framework
 
2
# Module for Generating Lists of Tests (BuildList.pm)
 
3
#
 
4
# Copyright (C) 2007-2009 The Linux Foundation. All rights reserved.
 
5
#
 
6
# This program has been developed by ISP RAS for LF.
 
7
# The ptyshell tool is originally written by Jiri Dluhos <jdluhos@suse.cz>
 
8
# Copyright (C) 2005-2007 SuSE Linux Products GmbH
 
9
#
 
10
# This program is free software; you can redistribute it and/or
 
11
# modify it under the terms of the GNU General Public License
 
12
# version 2 as published by the Free Software Foundation.
 
13
#
 
14
# This program is distributed in the hope that it will be useful,
 
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
# GNU General Public License for more details.
 
18
#
 
19
# You should have received a copy of the GNU General Public License
 
20
# along with this program; if not, write to the Free Software
 
21
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
22
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 
23
 
 
24
package BuildList;
 
25
use strict;
 
26
use Exporter;
 
27
use Manifest;
 
28
use Packages;
 
29
use Common;
 
30
use Error;
 
31
 
 
32
@BuildList::ISA = 'Exporter';
 
33
@BuildList::EXPORT = (
 
34
        qw(
 
35
                $manifest
 
36
                @supported_archs
 
37
                @all_std_versions
 
38
                &generate_modlist
 
39
                &generate_std_profiles
 
40
                &generate_js_init_data
 
41
                &generate_profile_init
 
42
        ),
 
43
        @Manifest::EXPORT
 
44
);
 
45
 
 
46
# $manifest: reference to the hash containing Manifest data
 
47
our $manifest;
 
48
 
 
49
# List of error messages
 
50
our @buildlist_errors = ();
 
51
 
 
52
# Supported architectures
 
53
our @supported_archs;
 
54
 
 
55
our @all_std_versions;
 
56
 
 
57
# %tests_tree: Categorized list of tests
 
58
# {std_version => {category => {'SUBCAT' => {subcategory => {'TESTS' => [test1, test2, ...] } } } } }
 
59
my %tests_tree;
 
60
 
 
61
# Builds the tree of tests from manifest data
 
62
sub build_tests_tree() {
 
63
        @buildlist_errors = ();
 
64
        %tests_tree = ();
 
65
        if (!$manifest) {
 
66
                push @buildlist_errors, 'Manifest not defined!';
 
67
                return;
 
68
        }
 
69
        foreach my $stdv (keys %{$manifest->{'TREE'}}) {
 
70
                $tests_tree{$stdv} = {} if (!exists($tests_tree{$stdv}));
 
71
                foreach my $ts (keys %{$manifest->{'TREE'}->{$stdv}}) {
 
72
                        my @path_elems = split(m/\//, $manifest->{'TREE'}->{$stdv}->{$ts});
 
73
                        my $root = $tests_tree{$stdv};
 
74
                        my $elem;
 
75
                        while ($elem = shift @path_elems) {
 
76
                                $elem =~ s/^<(.*)>$/$1/;
 
77
                                $root->{$elem} = {} if (!exists($root->{$elem}));
 
78
                                if (scalar(@path_elems) > 0) {
 
79
                                        $root->{$elem}->{'SUBCAT'} = {} if (!exists($root->{$elem}->{'SUBCAT'}));
 
80
                                        $root = $root->{$elem}->{'SUBCAT'};
 
81
                                }
 
82
                                else {
 
83
                                        $root->{$elem}->{'TESTS'} = [] if (!exists($root->{$elem}->{'TESTS'}));
 
84
                                        $root = $root->{$elem}->{'TESTS'};
 
85
                                }
 
86
                        }
 
87
                        push @$root, $ts;
 
88
                }
 
89
        }
 
90
}
 
91
 
 
92
# Arrays for extended sorting:
 
93
# test suite categories
 
94
my @tests_tree_sort1 = ('Certification Tests', 'Unofficial Tests');
 
95
# test suite subcategories
 
96
my @tests_tree_sort2 = ('Command Tests', 'Static Interface Tests', 'Runtime Interface Tests', 'Automated Application Battery Tests', 'Manual Tests');
 
97
# preferrable test suite status
 
98
my @preferred_status_list = ('cert', 'certold', 'noncert', 'beta', 'snapshot');
 
99
 
 
100
 
 
101
# PUBLIC: Generates HTML code with list of test suites, versions, etc.
 
102
sub generate_modlist() {
 
103
        @buildlist_errors = ();
 
104
        if (!$manifest) {
 
105
                push @buildlist_errors, 'Manifest not defined!';
 
106
                return '';
 
107
        }
 
108
        my $res = '';
 
109
        foreach my $arch (@supported_archs) {
 
110
                foreach my $stdv (@all_std_versions) {
 
111
                        my $stdv_id = $stdv;
 
112
                        $stdv_id =~ s/ /:/g;
 
113
                        my @ts_list = ();
 
114
                        $res .= "      <table id=\"arch-$arch-$stdv_id\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: solid 4px white; width: 100%; display: none;\">\n";
 
115
                        $res .= <<DATA;
 
116
        <tr class="list_head">
 
117
          <td style="width: 14.5em;"><input type="checkbox" name="check-all-$arch-$stdv_id" id="check-all-$arch-$stdv_id" onclick="javascript:un_check_all('all');" /></td>
 
118
          <td style="width: 7.5em; padding-left: 1em;"><span class="clickable" onclick="javascript:selectVersionAll(this); return false;" title="Select versions"><b>Version</b></span></td>
 
119
          <td style="width: 1em;"><img src="images/environment-spacer.gif" alt="" style="width: 1em;" /></td>
 
120
          <td style="width: 5em;"><span class="clickable" onclick="javascript:fileOptionsAll(this);" title="Select installation method"><b>Files</b></span></td>
 
121
          <td style="width: 1em;"><img src="images/environment-spacer.gif" alt="" style="width: 1em;" /></td>
 
122
          <td style="width: 5em;"><span class="clickable" onclick="javascript:customizeAll(this);" title="Select installation method"><b>Advanced</b></span></td>
 
123
          <td></td>
 
124
        </tr>
 
125
DATA
 
126
 
 
127
                        foreach my $disp_name1 (sort { sort_cat($a, $b, \@tests_tree_sort1); } keys %{$tests_tree{$stdv}}) {
 
128
                                my $int_name1 = lc($disp_name1);
 
129
                                $int_name1 =~ s/ /_/g;
 
130
                                $res .= <<DATA;
 
131
        <tr class="list_cat">
 
132
          <td colspan="7"><b><label><input type="checkbox" name="check-$int_name1-$arch-$stdv_id" id="check-$int_name1-$arch-$stdv_id" onclick="javascript:un_check_all('$int_name1');" />&nbsp;$disp_name1</label>&nbsp;&nbsp;&nbsp;<span class="active" onclick="javascript:show_hide_tooltip(this, '$int_name1', event);"><img src="images/question.png" width="16" height="17" alt="[?]" title="What's this?" /></span></b></td>
 
133
        </tr>
 
134
DATA
 
135
                                foreach my $disp_name2 (sort { sort_cat($a, $b, \@tests_tree_sort2); } keys %{$tests_tree{$stdv}->{$disp_name1}->{'SUBCAT'}}) {
 
136
                                        my $int_name2 = lc($disp_name2);
 
137
                                        $int_name2 =~ s/ /_/g;
 
138
                                        $res .= <<DATA;
 
139
        <tr class="list_subcat">
 
140
          <td colspan="7"><b><label><input type="checkbox" name="check-$int_name1-$int_name2-$arch-$stdv_id" id="check-$int_name1-$int_name2-$arch-$stdv_id" onclick="javascript:un_check_all('$int_name1-$int_name2');" />&nbsp;&nbsp;&nbsp;$disp_name2</label>&nbsp;&nbsp;&nbsp;<span class="active" onclick="javascript:show_hide_tooltip(this, '$int_name1-$int_name2', event); return false;"><img src="images/question.png" width="16" height="17" alt="[?]" title="What's this?" /></span></b></td>
 
141
        </tr>
 
142
DATA
 
143
                                        my $row_color = 0;
 
144
                                        foreach my $int_name3 (sort @{$tests_tree{$stdv}->{$disp_name1}->{'SUBCAT'}->{$disp_name2}->{'TESTS'}}) {
 
145
                                                push @ts_list, $int_name3;
 
146
                                                $row_color = 1 - $row_color;
 
147
                                                my $mod_descr = $manifest->{'DESCRIPTIONS'}->{$int_name3};
 
148
                                                my $disp_name3 = $int_name3;
 
149
                                                my ($descr_obj) = grep { version_filter($_->{'STANDARD'}, $stdv) } @$mod_descr;
 
150
                                                if ($descr_obj) {
 
151
                                                        $disp_name3 = $descr_obj->{'DISPLAYNAME'};
 
152
                                                }
 
153
                                                my $status_list = $manifest->{'COMPOSITION'}->{$stdv}->{$int_name3}->{$arch};
 
154
                                                my $enabled = 1;
 
155
                                                my $status = '';
 
156
                                                my $version = '';
 
157
                                                if ($status_list) {
 
158
                                                        $status = (sort { sort_cat($a, $b, \@preferred_status_list); } keys %$status_list)[0];
 
159
                                                        $version = (sort { vercmp($a, $b) } keys %{$status_list->{$status}})[0]
 
160
                                                                or next;
 
161
                                                }
 
162
                                                else {
 
163
                                                        $enabled = 0;
 
164
                                                        $status = 'unknown';
 
165
                                                }
 
166
                                                my $td_class = ($enabled ? 'dropdown' : 'dropdown_dis');
 
167
                                                my $color = ($enabled ? 'black' : 'gray');
 
168
                                                my $chkbox_state = ($enabled ? '' : '');
 
169
                                                my $chkbox_handlers = ($enabled ? ' onclick="javascript:update_elements_state();" ondblclick="javascript:setTimeout(\'update_elements_state()\', 500);"' : ' disabled="disabled"');
 
170
                                                my $statver_handlers = ($enabled ? ' onclick="javascript:selectVersion(this, \''.$int_name3.'\');"' : '');
 
171
                                                my $files_handlers = ($enabled ? ' onclick="javascript:selectInstall(this, \''.$int_name3.'\');"' : '');
 
172
                                                my $config_handlers = ($enabled ? ' onclick="javascript:customizeTS(this, \''.$int_name3.'\');"' : '');
 
173
                                                my $files_img = ($enabled ? 'files_normal.png' : 'files_disabled.png');
 
174
                                                my $config_img = ($enabled ? 'configure_answers.png' : 'configure_answers_dis.png');
 
175
                                                my $id_suffix = ($enabled ? '' : '-dis');
 
176
                                                $res .= <<DATA;
 
177
        <tr class="list_item$row_color">
 
178
          <td><label><input type="checkbox" name="mod-$arch-$stdv_id-$int_name3$id_suffix" id="mod-$arch-$stdv_id-$int_name3$id_suffix"$chkbox_handlers />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: $color;">$disp_name3</span></label></td>
 
179
          <td class="$td_class"$statver_handlers><img src="images/status_$status.png" alt="" width="16" height="16" id="stat-$arch-$stdv_id-$int_name3$id_suffix" />&nbsp;<span id="visver-$arch-$stdv_id-$int_name3$id_suffix">$version</span><img src="images/environment-spacer.gif" width="18" height="1" alt="" /><input type="hidden" name="ver-$arch-$stdv_id-$int_name3$id_suffix" id="ver-$arch-$stdv_id-$int_name3$id_suffix" value="$status|$version" /></td>
 
180
          <td></td>
 
181
          <td class="$td_class"$files_handlers><img src="images/$files_img" alt="" width="16" height="16" id="visinst-$arch-$stdv_id-$int_name3$id_suffix" /></td>
 
182
          <td></td>
 
183
          <td class="$td_class"$config_handlers><img src="images/$config_img" alt="" width="16" height="16" id="viscust-$arch-$stdv_id-$int_name3$id_suffix"/></td>
 
184
          <td></td>
 
185
        </tr>
 
186
DATA
 
187
                                                my $opt_list = $manifest->{'OPTIONS'}->{$int_name3};
 
188
                                                if ($opt_list) {
 
189
                                                        my @glob_options = grep { $_->{'GLOBAL'} and version_filter($_->{'STANDARD'}, $stdv) } @$opt_list;
 
190
                                                        foreach my $option (@glob_options) {
 
191
                                                                foreach my $var (@{$option->{'VARIANTS'}}) {
 
192
                                                                        my $check = (($var eq $option->{'DEFAULT'}) ? ' checked="checked"' : '');
 
193
                                                                        my $id = $var;
 
194
                                                                        $id =~ s/[^A-Za-z0-9\-_:\.]/-/g;
 
195
                                                                        $res .= <<DATA;
 
196
        <tr class="list_item$row_color">
 
197
          <td colspan="7">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label><input type="radio" name="modopt-$arch-$stdv_id-$int_name3-$option->{'ID'}$id_suffix" id="modopt-$arch-$stdv_id-$int_name3-$option->{'ID'}-$id$id_suffix" value="$var"$check disabled="disabled" onclick="javascript:update_elements_state();" ondblclick="javascript:setTimeout('update_elements_state()', 500);" />&nbsp;$option->{'DISPLAY'}->{$var}</label></td>
 
198
        </tr>
 
199
DATA
 
200
                                                                }
 
201
                                                        }
 
202
                                                }
 
203
                                        }
 
204
                                }
 
205
                        }
 
206
                        $res .= "      </table>\n";
 
207
                        $res .= "      <input type=\"hidden\" name=\"ts-sort-$arch-$stdv_id\" value=\"".join(';', @ts_list)."\" />\n";
 
208
                }
 
209
        }
 
210
        return $res;
 
211
}
 
212
 
 
213
# PUBLIC: Generates JS code for filling in the stdp_list array (list of profiles present in each standard version).
 
214
sub generate_std_profiles() {
 
215
        @buildlist_errors = ();
 
216
        my $res = "\tstdp_list = new Array();\n";
 
217
        if (!$manifest) {
 
218
                push @buildlist_errors, 'Manifest not defined!';
 
219
                return $res;
 
220
        }
 
221
        foreach my $stdv (sort keys %{$manifest->{'STD_PROFILES'}}) {
 
222
                my $stdv_id = $stdv;
 
223
                $stdv_id =~ s/ /:/g;
 
224
                my $std_profile_list = $manifest->{'STD_PROFILES'}->{$stdv};
 
225
                $res .= "\tstdp_list['$stdv_id'] = new Array();\n";
 
226
                foreach my $id (sort keys %$std_profile_list) {
 
227
                        my $value = $std_profile_list->{$id};
 
228
                        $value =~ s/&lt;/</g;
 
229
                        $value =~ s/&gt;/>/g;
 
230
                        $value =~ s/&amp;/&/g;
 
231
                        $res .= "\tstdp_list['$stdv_id']['$id'] = '$value';\n";
 
232
                }
 
233
        }
 
234
        return $res;
 
235
}
 
236
 
 
237
# List of all the files used by all test suite versions.
 
238
my @used_files = ();
 
239
 
 
240
# Generates JS code for filling in the ts_files array (info about test suite versions, files they use, etc.).
 
241
sub generate_ts_files() {
 
242
        @buildlist_errors = ();
 
243
        my $res = "\tts_files = new Array();\n";
 
244
        if (!$manifest) {
 
245
                push @buildlist_errors, 'Manifest not defined!';
 
246
                return $res;
 
247
        }
 
248
        foreach my $arch (@supported_archs) {
 
249
                foreach my $stdv (@all_std_versions) {
 
250
                        my $stdv_id = $stdv;
 
251
                        $stdv_id =~ s/ /:/g;
 
252
                        $res .= "\tts_files['$arch-$stdv_id'] = new Array();\n";
 
253
                        my $test_list = $manifest->{'COMPOSITION'}->{$stdv};
 
254
                        foreach my $ts (keys %$test_list) {
 
255
                                $res .= "\tts_files['$arch-$stdv_id']['$ts'] = new Array();\n";
 
256
                                my $status_list = $test_list->{$ts}->{$arch};
 
257
                                foreach my $status (keys %$status_list) {
 
258
                                        $res .= "\tts_files['$arch-$stdv_id']['$ts']['$status'] = new Array();\n";
 
259
                                        my $ver_list = $status_list->{$status};
 
260
                                        foreach my $ver (keys %$ver_list) {
 
261
                                                my @fpaths = ();
 
262
                                                foreach my $pkg (@{$ver_list->{$ver}}) {
 
263
                                                        my $pkg_manager = 'rpm';
 
264
                                                        my $files = select_file($manifest, $arch, $pkg_manager, $pkg->{'PACKAGE'}, $pkg->{'PACKAGE_VER'}, $pkg->{'LOCATION'});
 
265
                                                        if (!is_ok($files)) {
 
266
                                                                push @buildlist_errors, $Error::Last->tostring();
 
267
                                                                push @buildlist_errors, "Internal error: file not found for $pkg_manager/$arch/$stdv/$ts/$status/$ver (".$pkg->{'PACKAGE'}."-".$pkg->{'PACKAGE_VER'}."@".$pkg->{'LOCATION'}.")!";
 
268
                                                        }
 
269
                                                        else {
 
270
                                                                if (scalar(@$files) > 1) {
 
271
                                                                        push @buildlist_errors, "Internal error: too many files for $pkg_manager/$arch/$stdv/$ts/$status/$ver (".$pkg->{'PACKAGE'}."-".$pkg->{'PACKAGE_VER'}."@".$pkg->{'LOCATION'}.")!";
 
272
                                                                }
 
273
                                                                my $fname = $files->[0]->{'SRC'}.'/'.$files->[0]->{'FILENAME'};
 
274
                                                                push @fpaths, "'".$fname."'";
 
275
                                                                push @used_files, $fname;
 
276
                                                        }
 
277
                                                }
 
278
                                                $res .= "\tts_files['$arch-$stdv_id']['$ts']['$status']['$ver'] = new Array(".join(", ", @fpaths).");\n";
 
279
                                        }
 
280
                                }
 
281
                        }
 
282
                }
 
283
        }
 
284
        $res .= "\n\tbuild_file_ts();\n";
 
285
        return $res;
 
286
}
 
287
 
 
288
# Generates JS code for filling in the mod_time array (info about test suite estimated execution time).
 
289
sub generate_ts_times() {
 
290
        return "\tmod_time = new Array();\n";
 
291
}
 
292
 
 
293
# Generates JS code for filling in the file_size_full and file_size_disk arrays (sizes of files: remote and in cache).
 
294
# Needs @used_files to be filled by generate_ts_files() call!
 
295
sub generate_file_sizes() {
 
296
        @buildlist_errors = ();
 
297
        my $res = "\tfile_size = new Array();\n\tfile_downloaded = new Array();\n\tfile_installed = new Array();\n\tfile_size[''] = 0;\n";
 
298
        if (!$manifest) {
 
299
                push @buildlist_errors, 'Manifest not defined!';
 
300
                return $res;
 
301
        }
 
302
        if (scalar(@used_files) == 0) {
 
303
                push @buildlist_errors, 'List of files is empty (generate_ts_files() not called)!';
 
304
                return $res;
 
305
        }
 
306
        foreach my $file (@used_files) {
 
307
                $res .= "\tfile_size['$file'] = ".$manifest->{'FILES'}->{$file}->{'SIZE'}.";\n";
 
308
                $res .= "\tfile_downloaded['$file'] = ".$manifest->{'FILES'}->{$file}->{'DOWNLOADED'}.";\n";
 
309
                if ($manifest->{'FILES'}->{$file}->{'KIND'} eq 'file') {
 
310
                        $res .= "\tfile_installed['$file'] = -1;\n";
 
311
                }
 
312
                else {
 
313
                        my $pkg = $manifest->{'FILES'}->{$file}->{'PACKAGE'};
 
314
                        my $ver = $manifest->{'FILES'}->{$file}->{'VERSION'};
 
315
                        $res .= "\tfile_installed['$file'] = ".($manifest->{'PACKAGES'}->{$pkg}->{'VERSIONS'}->{$ver} ? '1' : '0').";\n";
 
316
                }
 
317
        }
 
318
        return $res;
 
319
}
 
320
 
 
321
sub generate_ts_options() {
 
322
        @buildlist_errors = ();
 
323
        my $res = "\tts_options = new Array();\n";
 
324
        if (!$manifest) {
 
325
                push @buildlist_errors, 'Manifest not defined!';
 
326
                return $res;
 
327
        }
 
328
        foreach my $arch (@supported_archs) {
 
329
                foreach my $stdv (@all_std_versions) {
 
330
                        my $stdv_id = $stdv;
 
331
                        $stdv_id =~ s/ /:/g;
 
332
                        $res .= "\tts_options['$arch-$stdv_id'] = new Array();\n";
 
333
                        foreach my $ts (keys %{$manifest->{'TREE'}->{$stdv}}) {
 
334
                                my $id_list = '';
 
335
                                my $opt_list = $manifest->{'OPTIONS'}->{$ts};
 
336
                                if ($opt_list) {
 
337
                                        my @options = grep { $_->{'GLOBAL'} and version_filter($_->{'STANDARD'}, $stdv) } @$opt_list;
 
338
                                        $id_list = join(', ', map { "'$_->{'ID'}'" } @options);
 
339
                                }
 
340
                                $res .= "\tts_options['$arch-$stdv_id']['$ts'] = new Array($id_list);\n";
 
341
                        }
 
342
                }
 
343
        }
 
344
        return $res;
 
345
}
 
346
 
 
347
# Generates JS code for filling in the ts_expect_info array (autoreplies to test suite questions).
 
348
sub generate_ts_expect_info() {
 
349
        @buildlist_errors = ();
 
350
        my $res = "\tts_expect_info = new Array();\n";
 
351
        if (!$manifest) {
 
352
                push @buildlist_errors, 'Manifest not defined!';
 
353
                return $res;
 
354
        }
 
355
        foreach my $arch (@supported_archs) {
 
356
                foreach my $stdv (@all_std_versions) {
 
357
                        my $stdv_id = $stdv;
 
358
                        $stdv_id =~ s/ /:/g;
 
359
                        $res .= "\tts_expect_info['$arch-$stdv_id'] = new Array();\n";
 
360
                        my $test_list = $manifest->{'COMPOSITION'}->{$stdv};
 
361
                        foreach my $ts (keys %$test_list) {
 
362
                                $res .= "\tts_expect_info['$arch-$stdv_id']['$ts'] = new Array();\n";
 
363
                                my $status_list = $test_list->{$ts}->{$arch};
 
364
                                foreach my $status (keys %$status_list) {
 
365
                                        $res .= "\tts_expect_info['$arch-$stdv_id']['$ts']['$status'] = new Array();\n";
 
366
                                        my $ver_list = $status_list->{$status};
 
367
                                        foreach my $ver (keys %$ver_list) {
 
368
                                                $res .= "\tts_expect_info['$arch-$stdv_id']['$ts']['$status']['$ver'] = new Array();\n";
 
369
                                                my $opt_list = $manifest->{'OPTIONS'}->{$ts};
 
370
                                                if ($opt_list) {
 
371
                                                        my @options = grep { !$_->{'GLOBAL'} and version_filter($_->{'STANDARD'}, $stdv) and version_filter($_->{'TEST_VER'}, $ver) } @$opt_list;
 
372
                                                        foreach my $option (@options) {
 
373
                                                                my $def_answer = (defined($option->{'DEFAULT'}) ? $option->{'DEFAULT'} : '[default]');
 
374
                                                                $res .= "\tts_expect_info['$arch-$stdv_id']['$ts']['$status']['$ver']['$option->{'ID'}'] = {question: '$option->{'Q'}', def_answer: '$def_answer', answer: '$def_answer'};\n";
 
375
                                                        }
 
376
                                                }
 
377
                                        }
 
378
                                }
 
379
                        }
 
380
                }
 
381
        }
 
382
        return $res;
 
383
}
 
384
 
 
385
# Generates JS code for filling in the mod_cat_list array (test suites to be selected on checking a category)
 
386
# and in the check_list array (subcategories to be selected on checking a category).
 
387
sub generate_mod_cat_list_check_list() {
 
388
        @buildlist_errors = ();
 
389
        my $res_m = "\tmod_cat_list = new Array();\n";
 
390
        my $res_c = "\tcheck_list = new Array();\n";
 
391
        if (!$manifest) {
 
392
                push @buildlist_errors, 'Manifest not defined!';
 
393
        return "$res_m\n$res_c";
 
394
        }
 
395
        foreach my $arch (@supported_archs) {
 
396
                foreach my $stdv (@all_std_versions) {
 
397
                        my $stdv_id = $stdv;
 
398
                        $stdv_id =~ s/ /:/g;
 
399
                        $res_m .= "\tmod_cat_list['$arch-$stdv_id'] = new Array();\n";
 
400
                        $res_c .= "\tcheck_list['$arch-$stdv_id'] = new Array();\n";
 
401
                        my %mod_list = ('all' => {});
 
402
                        my %cat_list = ('all' => {});
 
403
                        foreach my $cat (keys %{$tests_tree{$stdv}}) {
 
404
                                my $cat_id = lc($cat);
 
405
                                $cat_id =~ s/ /_/g;
 
406
                                $cat_list{'all'}->{$cat_id} = 1;
 
407
                                foreach my $subcat (keys %{$tests_tree{$stdv}->{$cat}->{'SUBCAT'}}) {
 
408
                                        my $subcat_id = lc($subcat);
 
409
                                        $subcat_id =~ s/ /_/g;
 
410
                                        $subcat_id = "$cat_id-$subcat_id";
 
411
                                        $cat_list{'all'}->{$subcat_id} = 1;
 
412
                                        $cat_list{$cat_id}->{$subcat_id} = 1;
 
413
                                        foreach my $ts (@{$tests_tree{$stdv}->{$cat}->{'SUBCAT'}->{$subcat}->{'TESTS'}}) {
 
414
                                                $mod_list{'all'}->{$ts} = 1;
 
415
                                                $mod_list{$cat_id}->{$ts} = 1;
 
416
                                                $mod_list{$subcat_id}->{$ts} = 1;
 
417
                                        }
 
418
                                }
 
419
                        }
 
420
                        foreach my $cat (sort keys %mod_list) {
 
421
                                $res_m .= "\tmod_cat_list['$arch-$stdv_id']['$cat'] = new Array(".join(', ', map("'$_'", keys %{$mod_list{$cat}})).");\n";
 
422
                        }
 
423
                        foreach my $cat (sort keys %cat_list) {
 
424
                                $res_c .= "\tcheck_list['$arch-$stdv_id']['$cat'] = new Array(".join(', ', map("'$_'", keys %{$cat_list{$cat}})).");\n";
 
425
                        }
 
426
                }
 
427
        }
 
428
        return "$res_m\n$res_c";
 
429
}
 
430
 
 
431
# PUBLIC: Generates JS code for initializing all the necessary structures at once.
 
432
sub generate_js_init_data() {
 
433
        return "\tarch_list = new Array(".join(', ', map("'$_'", @supported_archs)).");\n" .
 
434
                   "\tstdv_list = new Array(".join(', ', map { my $tmp = $_; $tmp =~ s/ /:/g; "'$tmp'" } @all_std_versions).");\n" .
 
435
                   "\tmod_list  = new Array(".join(', ', map("'$_'", @{$manifest->{'ALL'}->{'TESTSUITES'}})).");\n" .
 
436
                   "\n" .
 
437
                   generate_ts_files() . "\n" .
 
438
                   generate_ts_times() . "\n" .
 
439
                   generate_file_sizes() . "\n" .
 
440
                   generate_ts_options() . "\n" .
 
441
                   generate_ts_expect_info() . "\n" .
 
442
                   generate_mod_cat_list_check_list();
 
443
}
 
444
 
 
445
# PUBLIC: Generates JS code for setting all options according to profile data.
 
446
# $page specifies the caller page ('cert' for 'Get Certified' or 'conf' for 'Custom Tests').
 
447
sub generate_profile_init($$) {
 
448
        my ($profile, $page) = @_;
 
449
        return '' if (!$profile);
 
450
        my %js_names = (
 
451
                'NAME' => 'tester_name',
 
452
                'ORGANIZATION' => 'organization',
 
453
                'EMAIL' => 'tester_email',
 
454
                'SEND_EMAIL' => 'send_email_report',
 
455
                'VERBOSE_LEVEL' => 'verbose_level',
 
456
                'SHORT_SCENARIOS' => 'short_scen',
 
457
                'ARCHITECTURE' => 'architecture',
 
458
                'USE_INTERNET' => 'use_internet',
 
459
                'STD_VERSION' => 'std_version',
 
460
                'STD_PROFILE' => 'std_profile',
 
461
                'COMMENTS' => 'comments'
 
462
        );
 
463
 
 
464
        my $current_std = $profile->{'GENERAL'}->{'STD_VERSION'};
 
465
        my $current_std_id = $current_std;
 
466
        $current_std_id =~ s/ /:/g;
 
467
        my $current_arch = $profile->{'GENERAL'}->{'ARCHITECTURE'};
 
468
 
 
469
        my $res = <<DATA;
 
470
        var elem;
 
471
        // Reset all values changed by user
 
472
        main_form.reset();
 
473
 
 
474
        elem = document.getElementById('architecture');
 
475
        if (elem) {
 
476
                elem.value = '$current_arch';
 
477
        }
 
478
        elem = document.getElementById('std_version');
 
479
        if (elem) {
 
480
                elem.value = '$current_std';
 
481
        }
 
482
 
 
483
DATA
 
484
 
 
485
        if ($page ne 'cert') {
 
486
                $res .= <<DATA;
 
487
        ts_file_inst = new Array();
 
488
        ts_file_dl = new Array();
 
489
        for (var arch_std in ts_expect_info) {
 
490
                for (var ts in ts_expect_info[arch_std]) {
 
491
                        for (var status in ts_expect_info[arch_std][ts]) {
 
492
                                for (var ver in ts_expect_info[arch_std][ts][status]) {
 
493
                                        for (var id in ts_expect_info[arch_std][ts][status][ver]) {
 
494
                                                var option = ts_expect_info[arch_std][ts][status][ver][id];
 
495
                                                option.answer = option.def_answer;
 
496
                                        }
 
497
                                }
 
498
                        }
 
499
                }
 
500
        }
 
501
        show_modules();
 
502
DATA
 
503
        }
 
504
 
 
505
        $res .= "\tvar to_set_value = new Array();\n";
 
506
        foreach my $name (qw/NAME ORGANIZATION EMAIL VERBOSE_LEVEL STD_PROFILE/) {
 
507
                $res .= "\tto_set_value['".$js_names{$name}."'] = '".$profile->{'GENERAL'}->{$name}."';\n" if (defined($profile->{'GENERAL'}->{$name}));
 
508
        }
 
509
        if (defined($profile->{'GENERAL'}->{'COMMENTS'})) {
 
510
                my $comments = $profile->{'GENERAL'}->{'COMMENTS'};
 
511
                $comments =~ s/\r?\n/\\n/g;
 
512
                $res .= "\tto_set_value['".$js_names{'COMMENTS'}."'] = '".$comments."';\n";
 
513
        }
 
514
 
 
515
        $res .= "\tvar to_set_check = new Array();\n";
 
516
        foreach my $name (qw/SEND_EMAIL SHORT_SCENARIOS USE_INTERNET/) {
 
517
                $res .= "\tto_set_check['".$js_names{$name}."'] = ".($profile->{'GENERAL'}->{$name} ? "1" : "0").";\n" if (defined($profile->{'GENERAL'}->{$name}));
 
518
        }
 
519
 
 
520
        $res .= <<DATA;
 
521
 
 
522
        for (var elem_id in to_set_check) {
 
523
                elem = document.getElementById(elem_id);
 
524
                if (elem) {
 
525
                        elem.checked = to_set_check[elem_id];
 
526
                }
 
527
        }
 
528
        for (var elem_id in to_set_value) {
 
529
                elem = document.getElementById(elem_id);
 
530
                if (elem) {
 
531
                        elem.value = to_set_value[elem_id];
 
532
                }
 
533
        }
 
534
 
 
535
DATA
 
536
 
 
537
        if ($page ne 'cert') {
 
538
                my $set_versions = '';
 
539
                my $expect_info = '';
 
540
                my $check_ts = '';
 
541
                if (defined($profile->{'TEST_SUITES'})) {
 
542
                        foreach my $ts (keys %{$profile->{'TEST_SUITES'}}) {
 
543
                                my $ts_info = $profile->{'TEST_SUITES'}->{$ts};
 
544
                                if ($ts_info->{'RUN'}) {
 
545
                                        $check_ts .= "\tto_check_ts['$ts'] = 1;\n";
 
546
                                }
 
547
                                if ($ts_info->{'OPTIONS'}) {
 
548
                                        my $check_ts_tmp = '';
 
549
                                        foreach (keys %{$ts_info->{'OPTIONS'}}) {
 
550
                                                $check_ts_tmp .= "\tto_check_ts_opt['$ts']['$_'] = '".$ts_info->{'OPTIONS'}->{$_}."';\n";
 
551
                                        }
 
552
                                        if ($check_ts_tmp ne '') {
 
553
                                                $check_ts .= "\tto_check_ts_opt['$ts'] = new Array();\n".$check_ts_tmp;
 
554
                                        }
 
555
                                }
 
556
                                if ($ts_info->{'AUTO_REPLIES'}) {
 
557
                                        $expect_info .= "\tif (check_array_elem(ts_expect_info, '$current_arch-$current_std_id', '$ts')) {\n";
 
558
                                        foreach my $status (keys %{$ts_info->{'AUTO_REPLIES'}}) {
 
559
                                                $expect_info .= "\t\tif (ts_expect_info['$current_arch-$current_std_id']['$ts']['$status']) {\n";
 
560
                                                foreach my $ver (keys %{$ts_info->{'AUTO_REPLIES'}->{$status}}) {
 
561
                                                        $expect_info .= "\t\t\telem = ts_expect_info['$current_arch-$current_std_id']['$ts']['$status']['$ver'];\n\t\t\tif (elem) {\n";
 
562
                                                        my $auto_replies = $ts_info->{'AUTO_REPLIES'}->{$status}->{$ver};
 
563
                                                        foreach my $id (keys %$auto_replies) {
 
564
                                                                $expect_info .= "\t\t\t\tif (elem['$id']) {\n\t\t\t\t\telem['$id'].answer = '".(defined($auto_replies->{$id}) ? $auto_replies->{$id} : '[default]')."';\n\t\t\t\t}\n";
 
565
                                                        }
 
566
                                                        $expect_info .= "\t\t\t}\n";
 
567
                                                }
 
568
                                                $expect_info .= "\t\t}\n";
 
569
                                        }
 
570
                                        $expect_info .= "\t}\n";
 
571
                                }
 
572
                                if ($ts_info->{'STATUS'} and $ts_info->{'VERSION'}) {
 
573
                                        $set_versions .= "\tacceptVersion('$ts', '".$ts_info->{'STATUS'}."', '".$ts_info->{'VERSION'}."', false);\n";
 
574
                                }
 
575
                        }
 
576
                }
 
577
 
 
578
                $set_versions .= "\n" if ($set_versions ne '');
 
579
                $expect_info .= "\n" if ($expect_info ne '');
 
580
 
 
581
                if ($check_ts ne '') {
 
582
                        $res .= <<DATA;
 
583
        var to_check_ts = new Array();
 
584
        var to_check_ts_opt = new Array();
 
585
$check_ts
 
586
        var cat_list = new Array();
 
587
        // Make a copy of the array mod_cat_list (for current arch-std only).
 
588
        for (var cat in mod_cat_list[current_arch_std]) {
 
589
                cat_list[cat] = mod_cat_list[current_arch_std][cat].slice(0);
 
590
        }
 
591
        for (var mod in to_check_ts) {
 
592
                // Remove the test suite from the array cat.
 
593
                for (var cat in cat_list) {
 
594
                        for (var i=0; i<cat_list[cat].length; ++i) {
 
595
                                if (cat_list[cat][i] == mod) {
 
596
                                        cat_list[cat].splice(i, 1);
 
597
                                        break;
 
598
                                }
 
599
                        }
 
600
                }
 
601
                elem = document.getElementById('mod-' + current_arch_std + '-' + mod);
 
602
                if (elem) {
 
603
                        elem.checked = true;
 
604
                }
 
605
                if (to_check_ts_opt[mod]) {
 
606
                        for (var opt_name in to_check_ts_opt[mod]) {
 
607
                                var opt_value = to_check_ts_opt[mod][opt_name];
 
608
                                var elems = document.getElementsByName('modopt-' + current_arch_std + '-' + mod + '-' + opt_name);
 
609
                                if (elems) {
 
610
                                        for (var i=0; i<elems.length; ++i) {
 
611
                                                elems[i].checked = (elems[i].value == opt_value);
 
612
                                        }
 
613
                                }
 
614
                        }
 
615
                }
 
616
        }
 
617
        for (var cat in cat_list) {
 
618
                elem = document.getElementById('check-' + cat + '-' + current_arch_std);
 
619
                if (elem) {
 
620
                        elem.checked = ((cat_list[cat].length > 0) ? false : true);
 
621
                }
 
622
        }
 
623
 
 
624
DATA
 
625
                }
 
626
 
 
627
                if (defined($profile->{'FILES'})) {
 
628
                        foreach my $file (keys %{$profile->{'FILES'}}) {
 
629
                                if ($profile->{'FILES'}->{$file}->{'DOWNLOAD'}) {
 
630
                                        $res .= "\tts_file_dl['$file'] = ".$profile->{'FILES'}->{$file}->{'DOWNLOAD'}.";\n";
 
631
                                }
 
632
                                if ($profile->{'FILES'}->{$file}->{'INSTALL'}) {
 
633
                                        $res .= "\tts_file_inst['$file'] = ".$profile->{'FILES'}->{$file}->{'INSTALL'}.";\n";
 
634
                                }
 
635
                        }
 
636
                        $res .= "\n";
 
637
                }
 
638
 
 
639
                $res .= $expect_info;
 
640
                $res .= $set_versions;
 
641
                $res .= "\tupdate_elements_state();\n";
 
642
        }
 
643
        else {
 
644
                $res .= "\tcontrol_profile_list();\n";
 
645
        }
 
646
        $res .= "\telem = document.getElementById('std_profile');\n\tif (elem) {\n\t\telem.value = to_set_value['std_profile'];\n\t}\n";
 
647
 
 
648
        return $res;
 
649
}
 
650
 
 
651
################################################################################
 
652
# Initialization code
 
653
 
 
654
sub init() {
 
655
        # Load the Manifest
 
656
        $manifest = load_manifest();
 
657
        if (!is_ok($manifest)) {
 
658
                push @buildlist_errors, error("Failed to load manifest", $Error::Last)->tostring;
 
659
                return;
 
660
        }
 
661
        @all_std_versions = @{$manifest->{'ALL'}->{'STANDARDS'}};
 
662
 
 
663
        # Detect the architecture
 
664
        my $arch = detect_architecture();
 
665
        if (!$arch) {
 
666
                push @buildlist_errors, "Can't determine the machine architecture";
 
667
                return;
 
668
        }
 
669
        @supported_archs = backward_compatible_platforms($arch);
 
670
 
 
671
        # See what packages are installed
 
672
        $Packages::package_manager = guess_package_manager(detect_OS());
 
673
 
 
674
        is_ok packages_info($manifest->{'PACKAGES'})
 
675
                or push @buildlist_errors, $Error::Last->tostring;
 
676
 
 
677
        check_files(values %{$manifest->{'FILES'}});
 
678
 
 
679
        # Build the tests tree
 
680
        build_tests_tree();
 
681
}
 
682
 
 
683
init();
 
684
 
 
685
1;