os/mm/mmtestenv/mmtesttools/Scripts/DABS/DABS_test_data.pl
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 # Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 # All rights reserved.
     3 # This component and the accompanying materials are made available
     4 # under the terms of "Eclipse Public License v1.0"
     5 # which accompanies this distribution, and is available
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 #
     8 # Initial Contributors:
     9 # Nokia Corporation - initial contribution.
    10 #
    11 # Contributors:
    12 #
    13 # Description:
    14 #
    15 
    16 #!/usr/bin/perl
    17 
    18 ################################################################################
    19 ######### This file is meant to be used only once to create an initial
    20 ######### test list and the belonging batch and command files.
    21 ################################################################################
    22 
    23 ######### The input is the old mmbuild batch files under TestTools\Scripts
    24 ################################################################################
    25 use strict;
    26 
    27 # open file which contains all batch files that contains copy and delete commands.
    28 open FILES, "test_data.txt" or die "couldn't open file: $!";
    29 
    30 my $input_file;
    31 my $output_copy_file;
    32 my $output_del_file;
    33 
    34 while (<FILES>)
    35 {
    36     chomp;
    37     
    38     $output_copy_file = $_;
    39     $input_file = $output_copy_file;
    40     $output_copy_file =~ s/.bat//g;
    41     $output_copy_file =~ s/\.\.\/run//g;
    42     $output_copy_file .= "_copy_data.txt";
    43 
    44     open OUT, ">$output_copy_file" or die "couldn't open $output_copy_file: $!";
    45 
    46     open IN, "$input_file" or die "couldn't open $input_file: $!";
    47 
    48     # write all copy commands to OUT file.
    49     while (<IN>)
    50     {
    51 	chomp;
    52 	my $line = $_;
    53 	if ($line =~ /^md/i || $line =~ /^copy/i)
    54 	{
    55 	    print OUT $line . "\n";
    56 	}
    57     }
    58     close OUT;
    59     close IN;
    60 
    61     # create the DABS pretest command file. Can only be one row.
    62     #commented out for the moment as a DABS hack exists.
    63     #my $output_cmd_file = $output_copy_file;
    64     #$output_cmd_file =~ s/bat$/txt/;
    65     #open DABS_cmd_file, ">$output_cmd_file" or die "couldn't open $output_cmd_file: $!";
    66 
    67     #print DABS_cmd_file "call e:\\$output_copy_file\n";
    68 
    69     #close DABS_cmd_file;
    70     
    71     $output_del_file = $output_copy_file;
    72     $output_del_file =~ s/copy/del/g;
    73 
    74     open OUT, ">$output_del_file" or die "couldn't open $output_del_file: $!";
    75 
    76     open IN, "$input_file" or die "couldn't open $input_file: $!";
    77 
    78     # write all del commands to OUT file
    79     while (<IN>)
    80     {
    81 	chomp;
    82 	my $line = $_;
    83 	if ($line =~ /^del.*c:/i)
    84 	{
    85 	    print OUT $line . "\n";
    86 	}
    87     }
    88     
    89     close OUT;
    90     close IN;
    91 
    92     # create the DABS posttest command file. Can only be one row.
    93     #commented out for the moment as a DABS hack exists.
    94     #$output_cmd_file = $output_del_file;
    95     #$output_cmd_file =~ s/bat$/txt/;
    96     #open DABS_cmd_file, ">$output_cmd_file" or die "couldn't open $output_cmd_file: $!";
    97 
    98     #print DABS_cmd_file "call e:\\$output_del_file\n";
    99 
   100     #close DABS_cmd_file;
   101     
   102     
   103 }
   104 
   105 close FILES;
   106 
   107 open DABS_TESTS, "new_tests_92.txt" or die "couldn't open file: $!";
   108 
   109 open FILES, "test_data.txt" or die "couldn't open file: $!";
   110 
   111 open OUT_SCRIPT, ">real_tests_92.txt" or die "couldn't open file: $!";
   112 
   113 my @test_rows;
   114 
   115 # find where in the test list the pretest and posttest commands should be,
   116 # and insert them in the list.
   117 # This while loop actually creates load of duplicates of tests that don't
   118 # need a pre or post test command.
   119 # Those duplicates are removed futher down.
   120 while (<DABS_TESTS>)
   121 {
   122     my ( $program, $log, $commdb, $script, $timeout, $release, $preCommand, $postCommand );
   123 
   124     chomp;
   125 
   126     ($program, $log, $commdb, $script, $timeout, $release, $preCommand, $postCommand) = split(/,/);
   127 
   128     # Strip any trailing spaces
   129     $program =~ s!\ $!! if( defined($program));
   130     $log =~ s!\ $!! if( defined($log));
   131     $commdb =~ s!\ $!! if( defined($commdb));
   132     $script =~ s!\ $!! if( defined($script));
   133     $timeout =~ s!\ $!! if( defined($timeout));
   134     $release =~ s!\ $!! if( defined($release));
   135     $preCommand =~ s!\ $!! if( defined($preCommand));
   136     $postCommand =~ s!\ $!! if( defined($postCommand));
   137     
   138     # Strip any leading spaces
   139     $program =~ s!^\ !! if( defined($program));
   140     $log =~ s!^\ !! if( defined($log));
   141     $commdb =~ s!^\ !! if( defined($commdb));
   142     $script =~ s!^\ !! if( defined($script));
   143     $timeout =~ s!^\ !! if( defined($timeout));
   144     $release =~ s!^\ !! if( defined($release));
   145     $preCommand =~ s!^\ !! if( defined($preCommand));
   146     $postCommand =~ s!^\ !! if( defined($postCommand));
   147     
   148     # Set defaults for undefined values
   149     $program = "" unless ($program);
   150     $log = "" unless ($log);
   151     $commdb = "" unless ($commdb);
   152     $script = "" unless ($script);
   153     $timeout = $::TestTimeout unless ($timeout);
   154     $preCommand = "" unless ($preCommand);
   155     $postCommand = "" unless ($postCommand);
   156     
   157     my 	$found_script = 0;
   158     open FILES, "test_data.txt" or die "couldn't open file: $!";
   159     
   160     while (<FILES>)
   161     {
   162 	chomp;
   163 	my $input_file = $_;
   164 
   165 	open IN, "$input_file" or die "couldn't open $input_file: $!";
   166 
   167 	while (<IN>)
   168 	{
   169 	    chomp;
   170 	    my $line = $_;
   171 	    if ($line =~ /$script/i)
   172 	    {
   173 		$preCommand = $input_file;
   174 		$preCommand =~ s/.bat//g;
   175 		$preCommand =~ s/\.\.\/run//g;
   176 		$preCommand .= "_copy_data.txt";
   177 		$postCommand = $preCommand;
   178 		$postCommand =~ s/copy/del/g;
   179 		
   180 		push @test_rows, "$program, $log, $commdb, $script, $timeout, $release, $preCommand, $postCommand\n";
   181 		$found_script = 1;
   182 	    }
   183 	}
   184     	close IN;
   185     }
   186     close FILES;
   187 
   188     if (!$found_script)
   189     {
   190 	push @test_rows, "$program, $log, $commdb, $script, $timeout, $release, ,\n";
   191     }
   192 }
   193 
   194 
   195 # Some perl magic to remove duplicate lines.
   196 # Input: @list
   197 # Output: @uniqed
   198 my %u = ();
   199 
   200 my @uniqed = grep {defined} map {
   201     if (exists $u{$_}) { undef; } else { $u{$_} = undef; $_; }
   202 } @test_rows;
   203 
   204 undef %u;
   205 
   206 my $row;
   207 
   208 # The tests have been uniqed, so write them out to the new test list.
   209 foreach $row (@uniqed)
   210 {
   211     print OUT_SCRIPT "$row";
   212 }
   213 
   214 close OUT_SCRIPT;
   215 
   216 open DABS_TESTS, "real_tests_92.txt" or die "couldn't open file: $!";
   217 
   218 # Fix the del files so they remove the log file of the test script.
   219 while (<DABS_TESTS>)
   220 {
   221     my ( $program, $log, $commdb, $script, $timeout, $release, $preCommand, $postCommand );
   222 
   223     chomp;
   224 
   225     ($program, $log, $commdb, $script, $timeout, $release, $preCommand, $postCommand) = split(/,/);
   226 
   227     next if ($postCommand eq "");
   228 
   229     # Strip any trailing spaces
   230     $log =~ s!\ $!! if( defined($log));
   231     $postCommand =~ s!\ $!! if( defined($postCommand));
   232     
   233     # Strip any leading spaces
   234     $log =~ s!^\ !! if( defined($log));
   235     $postCommand =~ s!^\ !! if( defined($postCommand));
   236     
   237     # $postCommand =~ s/\.txt/\.bat/i;
   238 
   239     open DEL, ">>$postCommand" || die "couldn't open $postCommand for append: $!";
   240     print DEL "del c:\\$log\n";
   241     close DEL;
   242 }