os/mm/mmtestenv/mmtesttools/Scripts/DABS/DABS_test_data.pl
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmtestenv/mmtesttools/Scripts/DABS/DABS_test_data.pl	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,242 @@
     1.4 +# Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +# All rights reserved.
     1.6 +# This component and the accompanying materials are made available
     1.7 +# under the terms of "Eclipse Public License v1.0"
     1.8 +# which accompanies this distribution, and is available
     1.9 +# at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +#
    1.11 +# Initial Contributors:
    1.12 +# Nokia Corporation - initial contribution.
    1.13 +#
    1.14 +# Contributors:
    1.15 +#
    1.16 +# Description:
    1.17 +#
    1.18 +
    1.19 +#!/usr/bin/perl
    1.20 +
    1.21 +################################################################################
    1.22 +######### This file is meant to be used only once to create an initial
    1.23 +######### test list and the belonging batch and command files.
    1.24 +################################################################################
    1.25 +
    1.26 +######### The input is the old mmbuild batch files under TestTools\Scripts
    1.27 +################################################################################
    1.28 +use strict;
    1.29 +
    1.30 +# open file which contains all batch files that contains copy and delete commands.
    1.31 +open FILES, "test_data.txt" or die "couldn't open file: $!";
    1.32 +
    1.33 +my $input_file;
    1.34 +my $output_copy_file;
    1.35 +my $output_del_file;
    1.36 +
    1.37 +while (<FILES>)
    1.38 +{
    1.39 +    chomp;
    1.40 +    
    1.41 +    $output_copy_file = $_;
    1.42 +    $input_file = $output_copy_file;
    1.43 +    $output_copy_file =~ s/.bat//g;
    1.44 +    $output_copy_file =~ s/\.\.\/run//g;
    1.45 +    $output_copy_file .= "_copy_data.txt";
    1.46 +
    1.47 +    open OUT, ">$output_copy_file" or die "couldn't open $output_copy_file: $!";
    1.48 +
    1.49 +    open IN, "$input_file" or die "couldn't open $input_file: $!";
    1.50 +
    1.51 +    # write all copy commands to OUT file.
    1.52 +    while (<IN>)
    1.53 +    {
    1.54 +	chomp;
    1.55 +	my $line = $_;
    1.56 +	if ($line =~ /^md/i || $line =~ /^copy/i)
    1.57 +	{
    1.58 +	    print OUT $line . "\n";
    1.59 +	}
    1.60 +    }
    1.61 +    close OUT;
    1.62 +    close IN;
    1.63 +
    1.64 +    # create the DABS pretest command file. Can only be one row.
    1.65 +    #commented out for the moment as a DABS hack exists.
    1.66 +    #my $output_cmd_file = $output_copy_file;
    1.67 +    #$output_cmd_file =~ s/bat$/txt/;
    1.68 +    #open DABS_cmd_file, ">$output_cmd_file" or die "couldn't open $output_cmd_file: $!";
    1.69 +
    1.70 +    #print DABS_cmd_file "call e:\\$output_copy_file\n";
    1.71 +
    1.72 +    #close DABS_cmd_file;
    1.73 +    
    1.74 +    $output_del_file = $output_copy_file;
    1.75 +    $output_del_file =~ s/copy/del/g;
    1.76 +
    1.77 +    open OUT, ">$output_del_file" or die "couldn't open $output_del_file: $!";
    1.78 +
    1.79 +    open IN, "$input_file" or die "couldn't open $input_file: $!";
    1.80 +
    1.81 +    # write all del commands to OUT file
    1.82 +    while (<IN>)
    1.83 +    {
    1.84 +	chomp;
    1.85 +	my $line = $_;
    1.86 +	if ($line =~ /^del.*c:/i)
    1.87 +	{
    1.88 +	    print OUT $line . "\n";
    1.89 +	}
    1.90 +    }
    1.91 +    
    1.92 +    close OUT;
    1.93 +    close IN;
    1.94 +
    1.95 +    # create the DABS posttest command file. Can only be one row.
    1.96 +    #commented out for the moment as a DABS hack exists.
    1.97 +    #$output_cmd_file = $output_del_file;
    1.98 +    #$output_cmd_file =~ s/bat$/txt/;
    1.99 +    #open DABS_cmd_file, ">$output_cmd_file" or die "couldn't open $output_cmd_file: $!";
   1.100 +
   1.101 +    #print DABS_cmd_file "call e:\\$output_del_file\n";
   1.102 +
   1.103 +    #close DABS_cmd_file;
   1.104 +    
   1.105 +    
   1.106 +}
   1.107 +
   1.108 +close FILES;
   1.109 +
   1.110 +open DABS_TESTS, "new_tests_92.txt" or die "couldn't open file: $!";
   1.111 +
   1.112 +open FILES, "test_data.txt" or die "couldn't open file: $!";
   1.113 +
   1.114 +open OUT_SCRIPT, ">real_tests_92.txt" or die "couldn't open file: $!";
   1.115 +
   1.116 +my @test_rows;
   1.117 +
   1.118 +# find where in the test list the pretest and posttest commands should be,
   1.119 +# and insert them in the list.
   1.120 +# This while loop actually creates load of duplicates of tests that don't
   1.121 +# need a pre or post test command.
   1.122 +# Those duplicates are removed futher down.
   1.123 +while (<DABS_TESTS>)
   1.124 +{
   1.125 +    my ( $program, $log, $commdb, $script, $timeout, $release, $preCommand, $postCommand );
   1.126 +
   1.127 +    chomp;
   1.128 +
   1.129 +    ($program, $log, $commdb, $script, $timeout, $release, $preCommand, $postCommand) = split(/,/);
   1.130 +
   1.131 +    # Strip any trailing spaces
   1.132 +    $program =~ s!\ $!! if( defined($program));
   1.133 +    $log =~ s!\ $!! if( defined($log));
   1.134 +    $commdb =~ s!\ $!! if( defined($commdb));
   1.135 +    $script =~ s!\ $!! if( defined($script));
   1.136 +    $timeout =~ s!\ $!! if( defined($timeout));
   1.137 +    $release =~ s!\ $!! if( defined($release));
   1.138 +    $preCommand =~ s!\ $!! if( defined($preCommand));
   1.139 +    $postCommand =~ s!\ $!! if( defined($postCommand));
   1.140 +    
   1.141 +    # Strip any leading spaces
   1.142 +    $program =~ s!^\ !! if( defined($program));
   1.143 +    $log =~ s!^\ !! if( defined($log));
   1.144 +    $commdb =~ s!^\ !! if( defined($commdb));
   1.145 +    $script =~ s!^\ !! if( defined($script));
   1.146 +    $timeout =~ s!^\ !! if( defined($timeout));
   1.147 +    $release =~ s!^\ !! if( defined($release));
   1.148 +    $preCommand =~ s!^\ !! if( defined($preCommand));
   1.149 +    $postCommand =~ s!^\ !! if( defined($postCommand));
   1.150 +    
   1.151 +    # Set defaults for undefined values
   1.152 +    $program = "" unless ($program);
   1.153 +    $log = "" unless ($log);
   1.154 +    $commdb = "" unless ($commdb);
   1.155 +    $script = "" unless ($script);
   1.156 +    $timeout = $::TestTimeout unless ($timeout);
   1.157 +    $preCommand = "" unless ($preCommand);
   1.158 +    $postCommand = "" unless ($postCommand);
   1.159 +    
   1.160 +    my 	$found_script = 0;
   1.161 +    open FILES, "test_data.txt" or die "couldn't open file: $!";
   1.162 +    
   1.163 +    while (<FILES>)
   1.164 +    {
   1.165 +	chomp;
   1.166 +	my $input_file = $_;
   1.167 +
   1.168 +	open IN, "$input_file" or die "couldn't open $input_file: $!";
   1.169 +
   1.170 +	while (<IN>)
   1.171 +	{
   1.172 +	    chomp;
   1.173 +	    my $line = $_;
   1.174 +	    if ($line =~ /$script/i)
   1.175 +	    {
   1.176 +		$preCommand = $input_file;
   1.177 +		$preCommand =~ s/.bat//g;
   1.178 +		$preCommand =~ s/\.\.\/run//g;
   1.179 +		$preCommand .= "_copy_data.txt";
   1.180 +		$postCommand = $preCommand;
   1.181 +		$postCommand =~ s/copy/del/g;
   1.182 +		
   1.183 +		push @test_rows, "$program, $log, $commdb, $script, $timeout, $release, $preCommand, $postCommand\n";
   1.184 +		$found_script = 1;
   1.185 +	    }
   1.186 +	}
   1.187 +    	close IN;
   1.188 +    }
   1.189 +    close FILES;
   1.190 +
   1.191 +    if (!$found_script)
   1.192 +    {
   1.193 +	push @test_rows, "$program, $log, $commdb, $script, $timeout, $release, ,\n";
   1.194 +    }
   1.195 +}
   1.196 +
   1.197 +
   1.198 +# Some perl magic to remove duplicate lines.
   1.199 +# Input: @list
   1.200 +# Output: @uniqed
   1.201 +my %u = ();
   1.202 +
   1.203 +my @uniqed = grep {defined} map {
   1.204 +    if (exists $u{$_}) { undef; } else { $u{$_} = undef; $_; }
   1.205 +} @test_rows;
   1.206 +
   1.207 +undef %u;
   1.208 +
   1.209 +my $row;
   1.210 +
   1.211 +# The tests have been uniqed, so write them out to the new test list.
   1.212 +foreach $row (@uniqed)
   1.213 +{
   1.214 +    print OUT_SCRIPT "$row";
   1.215 +}
   1.216 +
   1.217 +close OUT_SCRIPT;
   1.218 +
   1.219 +open DABS_TESTS, "real_tests_92.txt" or die "couldn't open file: $!";
   1.220 +
   1.221 +# Fix the del files so they remove the log file of the test script.
   1.222 +while (<DABS_TESTS>)
   1.223 +{
   1.224 +    my ( $program, $log, $commdb, $script, $timeout, $release, $preCommand, $postCommand );
   1.225 +
   1.226 +    chomp;
   1.227 +
   1.228 +    ($program, $log, $commdb, $script, $timeout, $release, $preCommand, $postCommand) = split(/,/);
   1.229 +
   1.230 +    next if ($postCommand eq "");
   1.231 +
   1.232 +    # Strip any trailing spaces
   1.233 +    $log =~ s!\ $!! if( defined($log));
   1.234 +    $postCommand =~ s!\ $!! if( defined($postCommand));
   1.235 +    
   1.236 +    # Strip any leading spaces
   1.237 +    $log =~ s!^\ !! if( defined($log));
   1.238 +    $postCommand =~ s!^\ !! if( defined($postCommand));
   1.239 +    
   1.240 +    # $postCommand =~ s/\.txt/\.bat/i;
   1.241 +
   1.242 +    open DEL, ">>$postCommand" || die "couldn't open $postCommand for append: $!";
   1.243 +    print DEL "del c:\\$log\n";
   1.244 +    close DEL;
   1.245 +}