activityfw/activityserviceplugin/tsrc/ctc.pl
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     1 #!/usr/bin/perl
       
     2 #
       
     3 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 # All rights reserved.
       
     5 # This component and the accompanying materials are made available
       
     6 # under the terms of "Eclipse Public License v1.0"
       
     7 # which accompanies this distribution, and is available
       
     8 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 #
       
    10 # Initial Contributors:
       
    11 # Nokia Corporation - initial contribution.
       
    12 #
       
    13 # Contributors:
       
    14 #
       
    15 # Description:
       
    16 #
       
    17  
       
    18 #USAGE:
       
    19 #    Usage: 101ctc.pl [-make=command]
       
    20 #    -make=instrument || run || ctcpost
       
    21 
       
    22 # import module
       
    23 use Getopt::Long;
       
    24 use Cwd;
       
    25 use Win32::Job;
       
    26 
       
    27 # read options
       
    28 my $make = "all";
       
    29 my $success = GetOptions ("make=s"   => \$make);
       
    30 
       
    31 if($make) {
       
    32 	chdir("..");
       
    33     
       
    34     my @testdirs = ( "tsrc\\unittest_activityclient" , 
       
    35                      "tsrc\\unittest_activitydatastorage" , 
       
    36                      "tsrc\\unittest_activitymanager" , 
       
    37                      "tsrc\\unittest_activityserviceplugin" );
       
    38 
       
    39     if (($make eq "instrument") || ($make eq "all")) {
       
    40 		`for /R . %i IN (mon.*) DO del %i`;
       
    41         system("del profile.txt");
       
    42 		`for /D %f IN (CTC*) DO rmdir /S /Q %f`;
       
    43 
       
    44         system("call qmake -spec symbian-sbsv2");
       
    45         system("call sbs reallyclean -c winscw_udeb");
       
    46         system("call sbs -j 4 -c winscw_udeb");
       
    47 		
       
    48         my $cwd = cwd();
       
    49         foreach my $testdir (@testdirs) {
       
    50             chdir($testdir);
       
    51 			system("call qmake -config coverage");
       
    52 			system("call bldmake bldfiles");
       
    53 			system("call abld makefile winscw");
       
    54 			system("call abld reallyclean winscw");
       
    55 			system("ctcwrap -i fd -C EXCLUDE+moc_*.cpp,*/tsrc/* -C SOURCE_IDENTIFICATION=absolute abld build winscw udeb");        
       
    56             chdir($cwd);            
       
    57         }
       
    58     }
       
    59     if (($make eq "run") || ($make eq "all")) {
       
    60         foreach my $testdir (@testdirs) {
       
    61             my $test = (split m/\\/ , $testdir)[-1];
       
    62 			print ("Running $test\n");
       
    63             if ( run_for("\\epoc32\\release\\winscw\\udeb\\$test.exe", "$test.exe >C:\\testresult_$test.txt", 300) ) {
       
    64                 warn("$test execution timed out.");
       
    65             }
       
    66         }        
       
    67     }
       
    68     if (($make eq "ctcpost") || ($make eq "all")) {
       
    69         my $coverageData = "";
       
    70 
       
    71         foreach my $testdir (@testdirs) {
       
    72             if (-e "$testdir\\MON.dat" && -e "$testdir\\MON.sym") {
       
    73                 $coverageData .= "$testdir\\MON.dat ";
       
    74             }
       
    75         }
       
    76         if ( $coverageData ne "" ) {
       
    77             system("call ctcpost -ff $coverageData -p profile.txt");
       
    78             system("call ctc2html -nsb -i profile.txt -o CTCFUNCTION");
       
    79             system("call del profile.txt");
       
    80             system("call ctcpost -T 70 -fd $coverageData -p profile.txt");
       
    81             system("call ctc2html -t 70 -nsb -i profile.txt -o CTCDECISION");
       
    82         } else {
       
    83             warn("No coverage data generated.");
       
    84         }
       
    85     }
       
    86 }
       
    87 
       
    88 print "END.\n";
       
    89 
       
    90 sub run_for {
       
    91     my ($cmd, $args, $timeout) = @_;
       
    92     my $job = Win32::Job->new() or die "Error creating job: $^E";
       
    93     my $pid = $job->spawn($cmd, $args, { stdin => 'NUL', stdout => 'NUL', stderr => 'NUL' } ) or die "Error starting job $cmd: $^E";
       
    94     $job->run($timeout);
       
    95     my $stat = $job->status();
       
    96     exists($stat->{$pid}) or die "No status for $pid ($cmd)";
       
    97     return $stat->{$pid}->{exitcode};
       
    98 }