sl@0: # Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: # All rights reserved. sl@0: # This component and the accompanying materials are made available sl@0: # under the terms of "Eclipse Public License v1.0" sl@0: # which accompanies this distribution, and is available sl@0: # at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: # sl@0: # Initial Contributors: sl@0: # Nokia Corporation - initial contribution. sl@0: # sl@0: # Contributors: sl@0: # sl@0: # Description: sl@0: # sl@0: sl@0: #!/usr/bin/perl sl@0: sl@0: ################################################################################ sl@0: ######### This file is meant to be used only once to create an initial sl@0: ######### test list and the belonging batch and command files. sl@0: ################################################################################ sl@0: sl@0: ######### The input is the old mmbuild batch files under TestTools\Scripts sl@0: ################################################################################ sl@0: use strict; sl@0: sl@0: # open file which contains all batch files that contains copy and delete commands. sl@0: open FILES, "test_data.txt" or die "couldn't open file: $!"; sl@0: sl@0: my $input_file; sl@0: my $output_copy_file; sl@0: my $output_del_file; sl@0: sl@0: while () sl@0: { sl@0: chomp; sl@0: sl@0: $output_copy_file = $_; sl@0: $input_file = $output_copy_file; sl@0: $output_copy_file =~ s/.bat//g; sl@0: $output_copy_file =~ s/\.\.\/run//g; sl@0: $output_copy_file .= "_copy_data.txt"; sl@0: sl@0: open OUT, ">$output_copy_file" or die "couldn't open $output_copy_file: $!"; sl@0: sl@0: open IN, "$input_file" or die "couldn't open $input_file: $!"; sl@0: sl@0: # write all copy commands to OUT file. sl@0: while () sl@0: { sl@0: chomp; sl@0: my $line = $_; sl@0: if ($line =~ /^md/i || $line =~ /^copy/i) sl@0: { sl@0: print OUT $line . "\n"; sl@0: } sl@0: } sl@0: close OUT; sl@0: close IN; sl@0: sl@0: # create the DABS pretest command file. Can only be one row. sl@0: #commented out for the moment as a DABS hack exists. sl@0: #my $output_cmd_file = $output_copy_file; sl@0: #$output_cmd_file =~ s/bat$/txt/; sl@0: #open DABS_cmd_file, ">$output_cmd_file" or die "couldn't open $output_cmd_file: $!"; sl@0: sl@0: #print DABS_cmd_file "call e:\\$output_copy_file\n"; sl@0: sl@0: #close DABS_cmd_file; sl@0: sl@0: $output_del_file = $output_copy_file; sl@0: $output_del_file =~ s/copy/del/g; sl@0: sl@0: open OUT, ">$output_del_file" or die "couldn't open $output_del_file: $!"; sl@0: sl@0: open IN, "$input_file" or die "couldn't open $input_file: $!"; sl@0: sl@0: # write all del commands to OUT file sl@0: while () sl@0: { sl@0: chomp; sl@0: my $line = $_; sl@0: if ($line =~ /^del.*c:/i) sl@0: { sl@0: print OUT $line . "\n"; sl@0: } sl@0: } sl@0: sl@0: close OUT; sl@0: close IN; sl@0: sl@0: # create the DABS posttest command file. Can only be one row. sl@0: #commented out for the moment as a DABS hack exists. sl@0: #$output_cmd_file = $output_del_file; sl@0: #$output_cmd_file =~ s/bat$/txt/; sl@0: #open DABS_cmd_file, ">$output_cmd_file" or die "couldn't open $output_cmd_file: $!"; sl@0: sl@0: #print DABS_cmd_file "call e:\\$output_del_file\n"; sl@0: sl@0: #close DABS_cmd_file; sl@0: sl@0: sl@0: } sl@0: sl@0: close FILES; sl@0: sl@0: open DABS_TESTS, "new_tests_92.txt" or die "couldn't open file: $!"; sl@0: sl@0: open FILES, "test_data.txt" or die "couldn't open file: $!"; sl@0: sl@0: open OUT_SCRIPT, ">real_tests_92.txt" or die "couldn't open file: $!"; sl@0: sl@0: my @test_rows; sl@0: sl@0: # find where in the test list the pretest and posttest commands should be, sl@0: # and insert them in the list. sl@0: # This while loop actually creates load of duplicates of tests that don't sl@0: # need a pre or post test command. sl@0: # Those duplicates are removed futher down. sl@0: while () sl@0: { sl@0: my ( $program, $log, $commdb, $script, $timeout, $release, $preCommand, $postCommand ); sl@0: sl@0: chomp; sl@0: sl@0: ($program, $log, $commdb, $script, $timeout, $release, $preCommand, $postCommand) = split(/,/); sl@0: sl@0: # Strip any trailing spaces sl@0: $program =~ s!\ $!! if( defined($program)); sl@0: $log =~ s!\ $!! if( defined($log)); sl@0: $commdb =~ s!\ $!! if( defined($commdb)); sl@0: $script =~ s!\ $!! if( defined($script)); sl@0: $timeout =~ s!\ $!! if( defined($timeout)); sl@0: $release =~ s!\ $!! if( defined($release)); sl@0: $preCommand =~ s!\ $!! if( defined($preCommand)); sl@0: $postCommand =~ s!\ $!! if( defined($postCommand)); sl@0: sl@0: # Strip any leading spaces sl@0: $program =~ s!^\ !! if( defined($program)); sl@0: $log =~ s!^\ !! if( defined($log)); sl@0: $commdb =~ s!^\ !! if( defined($commdb)); sl@0: $script =~ s!^\ !! if( defined($script)); sl@0: $timeout =~ s!^\ !! if( defined($timeout)); sl@0: $release =~ s!^\ !! if( defined($release)); sl@0: $preCommand =~ s!^\ !! if( defined($preCommand)); sl@0: $postCommand =~ s!^\ !! if( defined($postCommand)); sl@0: sl@0: # Set defaults for undefined values sl@0: $program = "" unless ($program); sl@0: $log = "" unless ($log); sl@0: $commdb = "" unless ($commdb); sl@0: $script = "" unless ($script); sl@0: $timeout = $::TestTimeout unless ($timeout); sl@0: $preCommand = "" unless ($preCommand); sl@0: $postCommand = "" unless ($postCommand); sl@0: sl@0: my $found_script = 0; sl@0: open FILES, "test_data.txt" or die "couldn't open file: $!"; sl@0: sl@0: while () sl@0: { sl@0: chomp; sl@0: my $input_file = $_; sl@0: sl@0: open IN, "$input_file" or die "couldn't open $input_file: $!"; sl@0: sl@0: while () sl@0: { sl@0: chomp; sl@0: my $line = $_; sl@0: if ($line =~ /$script/i) sl@0: { sl@0: $preCommand = $input_file; sl@0: $preCommand =~ s/.bat//g; sl@0: $preCommand =~ s/\.\.\/run//g; sl@0: $preCommand .= "_copy_data.txt"; sl@0: $postCommand = $preCommand; sl@0: $postCommand =~ s/copy/del/g; sl@0: sl@0: push @test_rows, "$program, $log, $commdb, $script, $timeout, $release, $preCommand, $postCommand\n"; sl@0: $found_script = 1; sl@0: } sl@0: } sl@0: close IN; sl@0: } sl@0: close FILES; sl@0: sl@0: if (!$found_script) sl@0: { sl@0: push @test_rows, "$program, $log, $commdb, $script, $timeout, $release, ,\n"; sl@0: } sl@0: } sl@0: sl@0: sl@0: # Some perl magic to remove duplicate lines. sl@0: # Input: @list sl@0: # Output: @uniqed sl@0: my %u = (); sl@0: sl@0: my @uniqed = grep {defined} map { sl@0: if (exists $u{$_}) { undef; } else { $u{$_} = undef; $_; } sl@0: } @test_rows; sl@0: sl@0: undef %u; sl@0: sl@0: my $row; sl@0: sl@0: # The tests have been uniqed, so write them out to the new test list. sl@0: foreach $row (@uniqed) sl@0: { sl@0: print OUT_SCRIPT "$row"; sl@0: } sl@0: sl@0: close OUT_SCRIPT; sl@0: sl@0: open DABS_TESTS, "real_tests_92.txt" or die "couldn't open file: $!"; sl@0: sl@0: # Fix the del files so they remove the log file of the test script. sl@0: while () sl@0: { sl@0: my ( $program, $log, $commdb, $script, $timeout, $release, $preCommand, $postCommand ); sl@0: sl@0: chomp; sl@0: sl@0: ($program, $log, $commdb, $script, $timeout, $release, $preCommand, $postCommand) = split(/,/); sl@0: sl@0: next if ($postCommand eq ""); sl@0: sl@0: # Strip any trailing spaces sl@0: $log =~ s!\ $!! if( defined($log)); sl@0: $postCommand =~ s!\ $!! if( defined($postCommand)); sl@0: sl@0: # Strip any leading spaces sl@0: $log =~ s!^\ !! if( defined($log)); sl@0: $postCommand =~ s!^\ !! if( defined($postCommand)); sl@0: sl@0: # $postCommand =~ s/\.txt/\.bat/i; sl@0: sl@0: open DEL, ">>$postCommand" || die "couldn't open $postCommand for append: $!"; sl@0: print DEL "del c:\\$log\n"; sl@0: close DEL; sl@0: }