~n3npq/lsb/distribution-checker

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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
# Distribution Checker
# Manifest Generation Module (Manifest_gen.pm)
#
# Copyright (C) 2007-2009 The Linux Foundation. All rights reserved.
#
# This program has been developed by ISP RAS for LF.
# The ptyshell tool is originally written by Jiri Dluhos <jdluhos@suse.cz>
# Copyright (C) 2005-2007 SuSE Linux Products GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

package Manifest_gen;
use strict;

use Common;
use Manifest;

# Export symbols
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(
	&manifest_check
	&print_manifest
);

#----------------------------------------------------------------------

sub manifest_check {
	my ($manifest, %options) = @_;
	
	my @errors = ();
	
	# Check MANIFEST section
	if ( !$manifest->{MANIFEST}{VERSION} ) {
		return error "No VERSION in the MANIFEST section";
	}
	if ( $manifest->{MANIFEST}{VERSION} ne MANIFEST_FORMAT_VER ) {
		return error "Unsupported manifest version '".$manifest->{MANIFEST}{VERSION}."'"
				." The only supported version is ".MANIFEST_FORMAT_VER;
	}
	
	if ( !$manifest->{MANIFEST}{URL} ) {
		push @errors, "The MANIFEST section should specify the URL.";
	}
	
	# Check DESCRIPTION
	foreach my $standard ( keys %{$manifest->{TREE}} ) {
	foreach my $testsuite ( keys %{$manifest->{TREE}{$standard}} ) {
		# ->{DESCRIPTIONS}{$testsuite}[]->{STANDARD|DISPLAYNAME|DESCRIPTION} = ".."
		my @descr = grep {version_filter($_->{STANDARD}, $standard)} @{$manifest->{'DESCRIPTIONS'}{$testsuite}};
		if ( !@descr ) {
			push @errors, error "No DESCRIPTION for '$testsuite': '$standard'";
		}
		elsif ( @descr > 1 ) {
			if ( $options{'strict'} ) {
				push @errors, error "Multiple DESCRIPTIONS for '$testsuite': '$standard' (".join(", ", map {$_->{STANDARD}} @descr).")";
			}
		}
		else {
			my ($descr) = @descr;
			( $descr->{DISPLAYNAME} )
				or push @errors, error "No DISPLAYNAME for '$testsuite': '$standard'";
			( $descr->{DESCRIPTION} )
				or push @errors, error "No DESCRIPTION for '$testsuite': '$standard'";
		}
	}}
	# ->{DESCRIPTIONS}{$testsuite}[]->{STANDARD|DISPLAYNAME|DESCRIPTION} = ".."
	foreach my $testsuite ( keys %{$manifest->{DESCRIPTIONS}} ) {
		( in_array($testsuite, @{$manifest->{ALL}{TESTSUITES}}) )
			or push @errors, error "Unknown '$testsuite' at DESCRIPTIONS.";
	}
	
	# Check PROFILES
	# ->{STD_PROFILES}{$standard}{DISPLAY_NAME}{$profile_id} = "Display name (html)";
	#                            {DEFAULT} = $profile_id;
	#                            {TESTS}{$testsuite}{$profile_id} = 1;
	foreach my $standard ( keys %{$manifest->{STD_PROFILES}} ) {
		my $default_profile = $manifest->{STD_PROFILES}{$standard}{DEFAULT};
		( defined $default_profile
			&& $manifest->{STD_PROFILES}{$standard}{DISPLAY_NAME}{$default_profile} )
				or push @errors, error "No default PROFILE for '$standard'.";
		if ( $manifest->{STD_PROFILES}{$standard}{TESTS} ) {
			foreach my $testsuite ( keys %{$manifest->{STD_PROFILES}{$standard}{TESTS}} ) {
				if ( $options{'strict'} ) {
					( defined $manifest->{TREE}{$standard}{$testsuite} )
						or push @errors, error "PROFILES for '$testsuite' '$standard' isn't specified in TREE.";
				}
				foreach my $profile_name ( keys %{$manifest->{STD_PROFILES}{$standard}{TESTS}{$testsuite}} ) {
					( defined $manifest->{STD_PROFILES}{$standard}{DISPLAY_NAME}{$profile_name} )
						or push @errors, error "Profile '$profile_name' specified for '$testsuite' is not allowed for '$standard'. See the beginning of the PROFILES section."
								." Allowed profiles for '$standard' are: ".join(";", map "'$_'", keys %{$manifest->{STD_PROFILES}{$standard}{DISPLAY_NAME}});
				}
			}
		}
	}
	
	# CHECK [COMPOSITION]
	#  ->{COMPOSITION}{$standard}{$testsuite}{$arch}{$status}{$test_ver}[]->{PACKAGE|PACKAGE_VER|LOCATION} = ".."
	my $composition = $manifest->{COMPOSITION};
	foreach my $standard  ( keys %{$composition} ) {
	foreach my $testsuite ( keys %{$composition->{$standard}} ) {
		( defined $manifest->{TREE}{$standard}{$testsuite} )
			or push @errors, error "Test '$testsuite' '$standard' isn't specified in TREE.";
	foreach my $arch      ( keys %{$composition->{$standard}{$testsuite}} ) {
		my $status_list = $composition->{$standard}{$testsuite}{$arch};
	foreach my $status    ( keys %$status_list ) {
	foreach my $test_ver  ( keys %{$status_list->{$status}} ) {
		next if $test_ver eq '*'; # Unavailable test
		
		my $reqs = $status_list->{$status}{$test_ver};
		foreach my $req ( @$reqs ) {
			( $req->{LOCATION} ) or next;
			
			my $found = 0;
			foreach my $package_manager ( "rpm", "dpkg" ) {
				my $found_files = Manifest::select_file($manifest, $arch, $package_manager, $req);
				if ( is_err($found_files) || !$found_files || !@$found_files ) {
					# It's no good if there is no rpm package.
					if ( $package_manager eq 'rpm' && $options{'strict'} ) {
						push @errors, error "check: Can't find RPM package '$req->{PACKAGE}'"
							.($req->{PACKAGE_VER} ? " v. '$req->{PACKAGE_VER}'" : "")
							.", '$standard', arch: '$arch', required by '$testsuite'"
							.($req->{LOCATION} ? " in '$req->{LOCATION}'" : "")
							, $Error::Last;
					}
					next;
				}
				if ( @$found_files > 1 && $options{'strict'} ) {
					push @errors, error  "Ambigous file choise: ".$found_files->[0]->{SRC}
						.": ".join ", ", map {$_->{FILENAME}} @$found_files;
				}
				
				$found = 1;
			} # end of  foreach my $package_manager ( "rpm", "dpkg" )
			if ( !$found ) { 
				push @errors, error "check: Can't find file '$req->{PACKAGE}'"
						.($req->{PACKAGE_VER} ? " v. '$req->{PACKAGE_VER}'" : "")
						.", '$standard', arch: '$arch', required by '$testsuite'"
						.($req->{LOCATION} ? " in '$req->{LOCATION}'": ""), $Error::Last;
			}
		} # end of  foreach my $req ( @$reqs )
	}}}}} # end of  foreach {$testsuite}{$standard}{$status}{$arch}{$test_ver}
	
	# CHECK [MODULES]
	{
		my $versions = {};
		foreach my $standard  ( keys %$composition ) {
		foreach my $testsuite ( keys %{$composition->{$standard}} ) {
		foreach my $arch      ( keys %{$composition->{$standard}{$testsuite}} ) {
			foreach my $status    ( keys %{$composition->{$standard}{$testsuite}{$arch}} ) {
				foreach my $test_ver  ( keys %{$composition->{$standard}{$testsuite}{$arch}{$status}} ) {
					$versions->{$testsuite}{$standard}{$test_ver} = 1;
				}
			}
		}}}
		foreach my $testsuite ( keys %$versions ) {
			if ( !defined $manifest->{MODULES}{$testsuite} ) {
				push @errors, error "No MODULES for '$testsuite'";
				next;
			}
			foreach my $standard  ( keys %{$versions->{$testsuite}} ) {
			foreach my $test_ver  ( keys %{$versions->{$testsuite}{$standard}} ) {
				my @modules = grep {
						   version_filter($_->{TEST_VER}, $test_ver)
						&& version_filter($_->{STANDARD}, $standard)
					} @{$manifest->{MODULES}{$testsuite}};
				if ( !@modules ) {
					push @errors, error "No MODULES for '$testsuite' ver $test_ver, '$standard'";
					next;
				}
				@modules = grep $_->{MAIN}, @modules;
				if ( scalar @modules != 1 ) {
					push @errors, error "Should be one main MODULE for '$testsuite' ver $test_ver, '$standard'";
					next;
				}
			}}
		}
	}
	
	# Check OPTIONS
	# ->{OPTIONS}{$testsuite}[]->{ID|Q|GLOBAL=>1|TEST_VER|STANDARD|PRE|TYPE|VARIANTS->[]|DEFAULT|VALUE};
	if ( defined $manifest->{OPTIONS} ) {
		my $used_options = {};
		foreach my $testsuite ( keys %{$manifest->{OPTIONS}} ) {
			foreach my $opt ( @{$manifest->{OPTIONS}{$testsuite}} ) {
				( defined $opt->{ID} )
					or push @errors, error "Option without ID: '$testsuite'."; # Should not happen
				my $id = $opt->{ID};
				( defined $opt->{STANDARD} && $opt->{STANDARD} =~ /\S/ )
					or push @errors, error "Standard isn't specified for OPTION: '$testsuite' '$id'.";
				if ( $opt->{GLOBAL} && !$opt->{DEFAULT} ) {
					push @errors, error "Global option without default value: ID '$id' for '$testsuite'.";
				}
				if ( $opt->{GLOBAL} && $opt->{TYPE} !~ /^(enum|bool)$/ ) {
					push @errors, error "Global option of unsupported type (only 'enum' and 'bool' types are allowed by now): ID '$id' for '$testsuite'.";
				}
				if ( !$opt->{GLOBAL} && !$opt->{Q} ) {
					push @errors, error "Option without the Q value (short text description): ID '$id' for '$testsuite'.";
				}
				my $key = $id."|";
				$key .= "VER ".$opt->{TEST_VER} if $opt->{TEST_VER};
				$key .= "|".($opt->{STANDARD} or "");
				$used_options->{$testsuite}{$key} = 0;
			}
		}
		if ( $options{'strict'} ) {
			my $versions = {};
			foreach my $standard  ( keys %$composition ) {
			foreach my $testsuite ( keys %{$composition->{$standard}} ) {
			foreach my $arch      ( keys %{$composition->{$standard}{$testsuite}} ) {
				next if !$manifest->{OPTIONS}{$testsuite};
				
				foreach my $status    ( keys %{$composition->{$standard}{$testsuite}{$arch}} ) {
					foreach my $test_ver  ( keys %{$composition->{$standard}{$testsuite}{$arch}{$status}} ) {
						next if $test_ver eq '*';
						$versions->{$testsuite}{$standard}{$test_ver} = 1;
					}
				}
			}}}
			foreach my $testsuite ( keys %$versions ) {
			foreach my $standard  ( keys %{$versions->{$testsuite}} ) {
			foreach my $test_ver  ( keys %{$versions->{$testsuite}{$standard}} ) {
				my $test_opts = {};
				for my $opt ( grep { version_filter($_->{TEST_VER}, $test_ver) }
							  grep { version_filter($_->{STANDARD}, $standard) }
							  @{$manifest->{OPTIONS}{$testsuite}} )
				{
					my $id = $opt->{ID};
					if ( $test_opts->{$id} ) {
						my $v1 = ($opt->{TEST_VER} ? "VER ".$opt->{TEST_VER} : "")."|".($opt->{STANDARD} or "");
						my $v2 = $test_opts->{$id};
						push @errors, error "Double option for '$testsuite': '$v1' == '$v2' for VER '$test_ver' '$standard', ID '$id'.";
					}
					$test_opts->{$id} = ($opt->{TEST_VER} ? "VER ".$opt->{TEST_VER} : "")."|".($opt->{STANDARD} or "");
					my $key = $id."|";
					$key .= "VER ".$opt->{TEST_VER} if $opt->{TEST_VER};
					$key .= "|".($opt->{STANDARD} or "");
					$used_options->{$testsuite}{$key} = 1;
				}
			}}}
			foreach my $testsuite ( keys %{$manifest->{OPTIONS}} ) {
				my @unused = grep {$used_options->{$testsuite}{$_}==0} keys %{$used_options->{$testsuite}};
				if ( @unused ) {
					push @errors, error "Unused options for '$testsuite': ".join(", ", @unused);
				}
			}
		}
	} # end of  if ( defined $manifest->{OPTIONS} ) 
	
	# Check MANUAL
	# ->{MANUAL}{$testsuite}[]->{STEP|STANDARD}
	if ( defined $manifest->{MANUAL} ) {
		my $used_manual = {};
		foreach my $testsuite ( keys %{$manifest->{MANUAL}} ) {
			foreach my $step ( @{$manifest->{MANUAL}{$testsuite}} ) {
				( defined $step->{STEP} )
					or push @errors, error "Manual step without ID: '$testsuite'."; # Should not happen
				my $text = $step->{STEP};
				my $text_short = substr($text, 0, 80); # for error messages
				( defined $step->{STANDARD} && $step->{STANDARD} =~ /\S/ )
					or push @errors, error "Standard isn't specified for MANUAL test step: '$testsuite' '$text_short'.";
				my $key = $text."|".($step->{STANDARD} or "");
				$used_manual->{$testsuite}{$key} = 0;
			}
		}
		if ( $options{'strict'} ) {
			foreach my $standard ( keys %$composition ) {
			foreach my $testsuite ( keys %{$composition->{$standard}} ) {
				next if !$manifest->{MANUAL}{$testsuite};
				my $test_steps = {};
				for my $step ( grep { version_filter($_->{STANDARD}, $standard) }
							  @{$manifest->{MANUAL}{$testsuite}} )
				{
					my $text = $step->{STEP};
					my $text_short = substr($text, 0, 80); # for error messages
					if ( $test_steps->{$text} ) {
						my $v1 = $step->{STANDARD} || "";
						my $v2 = $test_steps->{$text};
						push @errors, error "Double manual step for '$testsuite': '$v1' == '$v2' for '$standard', STEP '$text_short'.";
					}
					$test_steps->{$text} = $step->{STANDARD} || "";
					my $key = $text."|".($step->{STANDARD} or "");
					$used_manual->{$testsuite}{$key} = 1;
				}
			}}
			foreach my $testsuite ( keys %{$manifest->{MANUAL}} ) {
				my @unused = grep {$used_manual->{$testsuite}{$_}==0} keys %{$used_manual->{$testsuite}};
				for my $s ( @unused ) {
					my $standard = "";
					if ( $s =~ s/\|([^\|]*)$// ) { $standard = $1; }
					push @errors, error "Unused manual step for '$testsuite': $standard, '$s'";
				}
			}
		}
	} # end of  if ( defined $manifest->{MANUAL} ) 
	
	if ( @errors ) { return join_errors(@errors); }
	
	return 1;
}
#----------------------------------------------------------------------

sub print_manifest {
	my ($manifest) = @_;
	
	#my $manifest_url = "http://...";
	#my $hash = ???;
	
	my $res = "";
	
	# [MANIFEST]
	$res .= "[MANIFEST]"."\n";
	$res .= "VERSION = ".MANIFEST_FORMAT_VER."\n";
	$res .= "URL = ".$manifest->{MANIFEST}{URL}."\n" if $manifest->{MANIFEST}{URL};
	$manifest->{MANIFEST}{TIMESTAMP} ||= time();
	$res .= "TIMESTAMP = ".$manifest->{MANIFEST}{TIMESTAMP}."\n";
	#$res .= "HASH = ".$hash."\n";
	$res .= "\n"; # -----
	
	# [TREE]
	$res .= "[TREE]"."\n";
	# $manifest->{TREE}{$standard}{$testsuite} = "<..>/<..>"
	{
		my @lines = ();
		foreach my $standard ( keys %{$manifest->{TREE}} ) {
		foreach my $testsuite ( keys %{$manifest->{TREE}{$standard}} ) {
			my $path = $manifest->{TREE}{$standard}{$testsuite};
			# <LSB 3.0>/<Certification Tests>/<Automated Application Battery Tests>/expect
			push @lines, "<".$standard.">/".$path."/".$testsuite;
		}}
		$res .= $_."\n" foreach ( sort @lines );
	}
	$res .= "\n"; # -----

	# [DESCRIPTIONS]
	$res .= "[DESCRIPTIONS]"."\n";
	$res .= "## Format:\n";
	$res .= "# TESTSUITE testname [Standard (<=|<|=|>=|>) ver]"."\n"; 
	$res .= "#     DISPLAYNAME = ..."."\n"; 
	$res .= "#     DESCRIPTION = description ..."."\n"; 
	$res .= "# ...can be multiline..."."\n"; 
	$res .= "# [TESTSUITE END]"."\n"; 
	# $manifest->{DESCRIPTIONS}{$testsuite}->{STANDARD|DISPLAYNAME|DESCRIPTION} = ".."
	foreach my $testsuite ( sort keys %{$manifest->{DESCRIPTIONS}} ) {
		my $descriptions;
		foreach ( @{$manifest->{DESCRIPTIONS}{$testsuite}} ) {
			my $standard_spec = ( $_->{STANDARD} or "" );
			$descriptions->{$standard_spec} = $_;
		}
		
		foreach my $standard_spec ( sort keys %$descriptions ) {
			my $obj = $descriptions->{$standard_spec};
			$res .= "TESTSUITE $testsuite"."\t".$standard_spec."\n";
			$res .= "\tDISPLAYNAME = ".$obj->{DISPLAYNAME}."\n";
			$res .= "\tDESCRIPTION = ".$obj->{DESCRIPTION}."\n";
			$res .= "TESTSUITE END"."\n";
		}
	}
	$res .= "\n"; # -----

	# [OPTIONS]
	$res .= "[OPTIONS]"."\n";
	$res .= "## Format:\n";
	$res .= "# TESTSUITE testsuite [VER >=version] [LSB <=version | Moblin ver]"."\n";
	$res .= "# (ID|GLOBAL): option ID"."\n";
	$res .= "# Q: option title"."\n";
	$res .= "# PRE: perl regular expression (for dialogue with the testsuite)"."\n";
	$res .= "# TYPE: enum (val1, val2) OR bool (val_true, val_false) OR string"."\n";
	$res .= "#       If TYPE is omitted, then TYPE is string by default."."\n";
	$res .= "#       Note, bool type requires two values to be specified."."\n";
	$res .= "# DEFAULT: default value"."\n";
	$res .= "# [TESTSUITE END]"."\n";
	foreach my $testsuite ( sort keys %{$manifest->{OPTIONS}} ) {
		my $options;
		foreach ( @{$manifest->{OPTIONS}{$testsuite}} ) {
			my $test_ver_spec = ( $_->{TEST_VER} ? "VER ".$_->{TEST_VER} : "" );
			my $standard_spec = ( $_->{STANDARD} or "" );
			push @{$options->{$test_ver_spec}{$standard_spec}}, $_;
		}
		
		foreach my $test_ver_spec ( sort keys %$options ) {
		foreach my $standard_spec ( sort keys %{$options->{$test_ver_spec}} ) {
			$res .= "TESTSUITE\t".$testsuite."\t".$test_ver_spec."\t".$standard_spec."\n";
			$res .= "\n";
			
			foreach my $opt ( @{$options->{$test_ver_spec}{$standard_spec}} ) {
				if ( defined $opt->{GLOBAL} && $opt->{GLOBAL} ) {
					$res .= "GLOBAL: ".$opt->{ID}."\n";
				} else {
					$res .= "ID: ".$opt->{ID}."\n";
				}
				$res .= "Q: ".$opt->{Q}."\n" if defined $opt->{Q};
				$res .= "PRE: ".$opt->{PRE}."\n" if defined $opt->{PRE};
				if ( defined $opt->{TYPE} ) {
					$res .= "TYPE: ".$opt->{TYPE};
					if ( defined $opt->{VARIANTS} ) {
					# Print joined option=displayname pairs in parentheses
						my @tmp;
						foreach ( @{$opt->{VARIANTS}} ) {
							my $tmp = $_;
							if ( defined $opt->{DISPLAY} && defined $opt->{DISPLAY}{$_}
								&& $opt->{DISPLAY}{$_} ne $_ ) 
							{
								$tmp .= "=".$opt->{DISPLAY}{$_};
							}
							push @tmp, $tmp;
						}
						$res .= " {".join("|", @tmp)."}";
					}
					$res .= "\n";
				}
				$res .= "DEFAULT: ".$opt->{DEFAULT}."\n" if defined $opt->{DEFAULT};
				$res .= "\n";
			}
			
			$res .= "TESTSUITE END"."\n";
			$res .= "\n"; # -----
		}}
	}

	# [MANUAL]
	$res .= "[MANUAL]"."\n";
	$res .= "## Format:\n";
	$res .= "# TESTSUITE testsuite [LSB >=version | Moblin 2.0]"."\n";
	$res .= "# STEP instructions for tester (in html)"."\n";
	$res .= "# [TESTSUITE END]"."\n";
	foreach my $testsuite ( sort keys %{$manifest->{MANUAL}} ) {
		my $manual;
		foreach ( @{$manifest->{MANUAL}{$testsuite}} ) {
			my $standard_spec = ( $_->{STANDARD} or "" );
			push @{$manual->{$standard_spec}}, $_;
		}
		
		foreach my $standard_spec ( sort keys %$manual ) {
			$res .= "TESTSUITE\t".$testsuite."\t".$standard_spec."\n";
			$res .= "\n";
			
			foreach my $step ( @{$manual->{$standard_spec}} ) {
				$res .= "STEP";
				$res .= " OPTIONAL" if $step->{OPTIONAL};
				$res .=" ".$step->{STEP};
				$res .= "\n\n";
			}
			
			$res .= "TESTSUITE END"."\n";
			$res .= "\n"; # -----
		}
	}

	# [PROFILES]
	$res .= "[PROFILES]"."\n";
	$res .= "## Standard profiles\n";
	$res .= "# Format: PROFILE Standard ver [DEFAULT] <profile_name> = <profile display name (html)>"."\n";
	# ->{STD_PROFILES}{$standard}{DISPLAY_NAME}{$profile_id} = "Display name (html)";
	#                            {DEFAULT} = $profile_id;
	#                            {TESTS}{$testsuite}{$profile_id} = 1;
	foreach my $standard   ( sort keys %{$manifest->{STD_PROFILES}} ) {
	foreach my $profile_name ( sort keys %{$manifest->{STD_PROFILES}{$standard}{DISPLAY_NAME}} ) {
		my $display_name = $manifest->{STD_PROFILES}{$standard}{DISPLAY_NAME}{$profile_name};
		(defined $display_name) or return error "Display name isn't defined for profile '$profile_name' for '$standard'.";
		my $default = ( $profile_name eq $manifest->{STD_PROFILES}{$standard}{DEFAULT} );
		$res .= "PROFILE ".$standard." ".($default ? "DEFAULT " : "").$profile_name." = ".$display_name;
		$res .= "\n";
	}}
	$res .= "\n"; # -----
	
	$res .= "## Test suite to profile references\n";
	$res .= "# Format: testsuite [Standard ver]: <profiles>"."\n";
	foreach my $standard ( sort keys %{$manifest->{STD_PROFILES}} ) {
	foreach my $testsuite ( sort keys %{$manifest->{STD_PROFILES}{$standard}{TESTS}} ) {
		$res .= $testsuite."\t".$standard.": ";
		$res .= join "|", sort keys %{$manifest->{STD_PROFILES}{$standard}{TESTS}{$testsuite}};
		$res .= "\n";
	}}
	$res .= "\n"; # -----
	
	# [MODULES]
	# ->{MODULES}{$testsuite}[]->{MAIN|FILE|FROM}
	$res .= "[MODULES]"."\n";
	$res .= "# TESTSUITE xts5 [VER >=3.0] LSB|MOBLIN"."\n";
	$res .= "#  module Xts5_test.pm	[from /var/opt/lsb/.../Xts5_test.pm]"."\n";
	$res .= "#  requires X11_common.pm	from http://.../X11_common.pm"."\n";
	$res .= "\n";
	foreach my $testsuite ( sort keys %{$manifest->{MODULES}} ) {
		my $modules;
		foreach ( @{$manifest->{MODULES}{$testsuite}} ) {
			my $test_ver_spec = ( $_->{TEST_VER} ? "VER ".$_->{TEST_VER} : "" );
			my $standard_spec = ( $_->{STANDARD} or "" );
			push @{$modules->{$test_ver_spec}{$standard_spec}}, $_;
		}
		
		foreach my $test_ver_spec ( sort keys %$modules ) {
		foreach my $standard_spec ( sort keys %{$modules->{$test_ver_spec}} ) {
			$res .= "TESTSUITE\t".$testsuite."\t".$test_ver_spec."\t".$standard_spec."\n";
			
			foreach my $obj ( @{$modules->{$test_ver_spec}{$standard_spec}} ) {
				$res .= " ".($obj->{MAIN}?'module':'requires')." ".$obj->{FILE};
				$res .= " from ".$obj->{FROM} if defined $obj->{FROM};
				$res .= "\n";
			}
		}}
		$res .= "\n";
	}
	
	# [COMPOSITION]
	$res .= "[COMPOSITION]"."\n";
	$res .= "## Format:\n";
	$res .= "# TESTSUITE  test\tversion\tStandard ver [arch] status"."\n";
	$res .= "#  package-name\tpackage-ver\t[location] (comma-separated and/or on a new line)"."\n";
	$res .= "\n";
	#  ->{COMPOSITION}{$standard}{$testsuite}{$arch}{$status}{$test_ver}[]->{PACKAGE|PACKAGE_VER|LOCATION} = ".."
	foreach my $standard ( sort keys %{$manifest->{COMPOSITION}} ) {
	foreach my $testsuite   ( sort keys %{$manifest->{COMPOSITION}{$standard}} ) {
		my $arch_ref = $manifest->{COMPOSITION}{$standard}{$testsuite};
		
		# Pack architectures together
		my $aggreg_hash = {};

		foreach my $arch ( sort keys %$arch_ref ) {
		foreach my $status ( keys %{$arch_ref->{$arch}} ) {
		foreach my $test_ver ( keys %{$arch_ref->{$arch}{$status}} ) {
			my $reqs = $arch_ref->{$arch}{$status}{$test_ver} or next;
			my $key = "";
			foreach my $package ( @$reqs ) {
				$key .= $package->{PACKAGE};
				$key .= "-".$package->{PACKAGE_VER} if defined $package->{PACKAGE_VER};
				$key .= "@".$package->{LOCATION} if defined $package->{LOCATION};
				$key .= "\t";
			}
			
			foreach my $arch_d ( @all_archs ) { # expand arch *
				next if $arch ne '*' && $arch_d ne $arch;
				
				$aggreg_hash->{$key}{$test_ver}{$status}{$arch_d} = 1;
			}
		}}}
		
		foreach my $key ( sort keys %$aggreg_hash ) {
		foreach my $test_ver ( sort keys %{$aggreg_hash->{$key}} ) {
		foreach my $status ( sort keys %{$aggreg_hash->{$key}{$test_ver}} ) {
			my @archs = keys %{$aggreg_hash->{$key}{$test_ver}{$status}};
			
			my $arch_str = "";
			if ( scalar @archs == scalar @all_archs ) {
				$arch_str = "";
			} else {
				$arch_str = (join ",", @archs)."\t";
			}
		
			$res .= "TESTSUITE ".$testsuite."\t".$test_ver."\t\t".$standard;
			$res .= "\t".$arch_str;
			$res .= $status."\n";
			
			my $any_arch = $archs[0]; # Should have equal reqs
			my $reqs = $arch_ref->{$any_arch}{$status}{$test_ver};
		
			foreach my $req ( @$reqs ) {
				$res .= "\t".$req->{PACKAGE};
				$res .= "\t".(defined $req->{PACKAGE_VER} ? $req->{PACKAGE_VER} : "");
				$res .= "\t".($req->{LOCATION} or "");
				$res .= "\n";
			}
			$res .= "\n";
		}}}
	}}
	$res .= "\n"; # -----

	# [PACKAGES]
	$res .= "[PACKAGES]"."\n";
	if ( defined $manifest->{CONFLICTS} ) {
		my $conflicts = { %{$manifest->{CONFLICTS}} };
		
		while ( %$conflicts ) {
			my $seed = (sort keys %$conflicts)[0];
			
			my @cluster = ($seed);
			
			INNER:
			while ( 1 ) {
				foreach ( @cluster ) {
					if ( defined $conflicts->{$_} ) {
						push @cluster, grep {!in_array($_, @cluster) } keys %{$conflicts->{$_}};
						delete $conflicts->{$_};
						next INNER;
					}
				}
				last;
			}
			
			$res .= "CONFLICTS ".join(", ", @cluster)."\n";
		}
	}
	$res .= "\n"; # -----

	# [SERVERS]
	$res .= "[SERVERS]"."\n";
	$res .= "## Format:\n";
	$res .= "# DIR dir_in_cache"."\n";
	$res .= "#   url_corresponding_to_cache_dir"."\n";
	foreach my $dir ( keys %{$manifest->{SERVERS}} ) {
		$res .= "DIR $dir"."\n";
		foreach my $link ( keys %{$manifest->{SERVERS}{$dir}} ) {
			$res .= "\t".$link."\n";
		}
		$res .= "\n";
	}
	$res .= "\n"; # -----
		
	# [FILES]
	$res .= "[FILES]"."\n";

	foreach my $name ( sort keys %{$manifest->{LOCATIONS}} ) {
		$res .= "ALIAS ".$name." = ".$manifest->{LOCATIONS}{$name}."\n";
	}
	$res .= "\n";
	
	$res .= "## Format:\n";
	$res .= "# filename | location | size [timestamp]"
		." [ arch [ package kind | package name | package version ]]"."\n";
	foreach my $key ( sort keys %{$manifest->{FILES}} ) {
		my $file = $manifest->{FILES}{$key};
		
		# Print file line
		$res .= $file->{FILENAME};
		$res .= "\t".$file->{LOCATION};
		$res .= "\t"."rm" if $file->{REMOVED};
		$res .= "\t".$file->{SIZE};
		$res .= "\t"."t".$file->{TIMESTAMP} if defined $file->{TIMESTAMP};
		$res .= "\t".$file->{ARCH};
		
		$res .= "\t".$file->{KIND};
		$res .= "\t".$file->{PACKAGE};
		if ( $file->{KIND} ne 'file' ) {
			$res .= "\t".$file->{VERSION} if $file->{VERSION};
		}
		$res .= "\n";
	}
	$res .= "\n"; # -----
	
	return $res;
}
#----------------------------------------------------------------------

1;