common/tools/ats/ats_specialise_test_drop.pl
author Mike Kinghan <mikek@symbian.org>
Wed, 03 Jun 2009 11:21:24 +0100
changeset 134 039d0b7e56f3
child 279 6aa713519d4e
permissions -rw-r--r--
Comments and code tidying for ats3_testdrop.pl Adding new ATS support script ats_specialise_test_drop.pl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
134
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     1
#!/usr/bin/perl
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     2
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     3
# Copyright (c) 2009 Symbian Foundation Ltd
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     4
# This component and the accompanying materials are made available
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     6
# which accompanies this distribution, and is available
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     8
#
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     9
# Initial Contributors:
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    10
# Symbian Foundation Ltd - initial contribution.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    11
#   Mike Kinghan, mikek@symbian.org
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    12
#
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    13
# Contributors:
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    14
#
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    15
# Description:
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    16
#   This is a tool for setting the name of an ATS test drop, and/or the build id
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    17
#   of the build being tested, and/or the name of the device on which
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    18
#   it is to be run, by modifying the XML test drop specificcation.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    19
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    20
use strict;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    21
use Getopt::Long;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    22
use XML::Simple;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    23
use File::Copy;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    24
use Data::Dumper;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    25
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    26
my $test_drop_name;	# Test drop name to be embedded in output XML
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    27
my $build_id;    # Build ID to be embedded in output XML 
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    28
my $device_name; # Device name to be embedded in output XML
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    29
my $srcfile;	# Input test drop file, either .xml or .zip
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    30
my $destfile;	# Leafname for output file. Extension will be .xml or .zip as input.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    31
				# If unspecified then the input file is updated. 
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    32
my $help;		# Do help?
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    33
my $srctype;	# Type of inpout file, .xml or .zip
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    34
my $dev_null = $^O =~ /^MSWin/ ? "nul" : "/dev/null";	# OS-dependent nul device.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    35
my $zipper;		# Zip command, depending on whether zip or 7z is available.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    36
my $unzipper;	# Unzip command, depending on whether [unzip or 7z is available.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    37
my $xml_in;		# Name of the input xml file. Always 'test.xml' if extracted from zipped test drop.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    38
my $temp_dest_name; # Leafname of temporary output file, if $destfile undefined.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    39
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    40
sub usage($);
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    41
sub help();
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    42
sub usage_error();
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    43
sub silent_command($);
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    44
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    45
my %optmap = (  'test-drop-name' => \$test_drop_name,
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    46
			    'device-name' => \$device_name,
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    47
			    'build-id' => \$build_id,
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    48
			    'src' => \$srcfile,
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    49
			    'dest' => \$destfile,
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    50
                'help' => \$help);
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    51
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    52
GetOptions(\%optmap,
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    53
          'test-drop-name=s',
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    54
          'device-name=s',
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    55
          'build-id=s',
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    56
          'src=s',
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    57
          'dest=s',
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    58
          'help!') 
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    59
          or usage_error();
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    60
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    61
if ($help) {
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    62
	help();
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    63
}
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    64
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    65
# --src is mandatory.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    66
usage_error(), unless (defined($srcfile));
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    67
if ($srcfile =~ /(\.xml$)/i) {
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    68
    $srctype = lc($1);
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    69
}
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    70
elsif ($srcfile =~ /(\.zip$)/i) {
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    71
    $srctype = lc($1);
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    72
}
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    73
else {
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    74
	# src file must have extension .xml or .zip
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    75
    usage_error();
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    76
}
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    77
die("File \"$srcfile\" does not exist"), unless -f $srcfile;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    78
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    79
if (!$destfile) { # dest file unspecified. We will update the src file.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    80
	$temp_dest_name = "ats_specialise_test_drop.out";
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    81
	$destfile = $temp_dest_name;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    82
}
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    83
else {
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    84
    # If dest file has same extension as src then strip off, cos we'll append it anyway.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    85
    $destfile =~ s/$srctype$//;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    86
}
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    87
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    88
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    89
if ($srctype =~ /^\.zip$/) { # Test drop is zip. Must contain test.xml.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    90
    $xml_in = "test.xml"; # This is our input XML.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    91
    if ( -f $xml_in) {
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    92
		# Pre-emptively delete anystale xml file.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    93
        unlink($xml_in) or die("Cannot delete stale $xml_in: $!\n");
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    94
    }
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    95
    if (!silent_command("zip -v")) { # See if we've got zip
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    96
        $zipper = "zip -m $destfile.zip test.xml";
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    97
        $unzipper = "unzip -o $srcfile $xml_in -d .";
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    98
    }
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    99
    elsif (!silent_command("7z -version")) { # Else see if we've got 7zip
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   100
        $zipper = "7z u $destfile.zip test.xml";
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   101
        $unzipper = "7z e $srcfile $xml_in";
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   102
    }
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   103
    else { # Got no archiver.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   104
        die ("Need programs zip/unzip or 7z. Not found\n");
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   105
    }
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   106
    # Extract test.xml from zip.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   107
    system("$unzipper > $dev_null") and die("Could not unzip \"$srcfile\"\n");
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   108
    die("Did not find $xml_in within \"$srcfile\"\n"), unless( -f "$xml_in");
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   109
    
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   110
}
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   111
else {
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   112
    $xml_in = $srcfile;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   113
}
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   114
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   115
# Parse the input XML into hashref.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   116
my $test_drop = XMLin("./$xml_in", keeproot => 1,
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   117
    forcearray => [ 'name', 'id','owner','priority','buildid','target','device', 'property', 'command', 'param'],#
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   118
        keyattr => [] );
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   119
    
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   120
        
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   121
# Insert the specified test drop name, if any.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   122
$test_drop->{'test'}->{'name'}->[0] = $test_drop_name, if $test_drop_name;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   123
# Insert the specified build id, if any.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   124
$test_drop->{'test'}->{'buildid'}->[0] = $build_id, if $build_id;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   125
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   126
if ($device_name) { # Also insert sepcified device name.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   127
	
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   128
	my $device_properties = $test_drop->{'test'}->{'target'}->[0]->{'device'}->[0]->{'property'};
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   129
	my $num_properties = @{$device_properties};
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   130
	$device_properties->[$num_properties]= { 'name' => "NAME", 'value' => "$device_name" };
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   131
	$test_drop->{'test'}->{'target'}->[0]->{'device'}->[0]->{'property'} = $device_properties;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   132
    #print Dumper($device_properties);
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   133
    #exit(0);		
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   134
}
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   135
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   136
if ($srctype =~ /^\.xml$/i ) { # Input file was XML
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   137
    # Write new XML to dest file.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   138
    open OUT,">$destfile.xml" or die("Cannot open file \"$destfile.xml\" for writing. $!\n");
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   139
    print OUT XMLout($test_drop, keeproot => 1);
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   140
    close OUT;    
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   141
}
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   142
else { #Input file was a zip.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   143
    # Write new XML to test.xml
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   144
    open OUT,">test.xml" or die("Cannot open file \"test.xml\" for writing. $!\n");
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   145
    print OUT XMLout($test_drop, keeproot => 1);
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   146
    close OUT;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   147
    if ( -f "$destfile.zip") {
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   148
        unlink("$destfile.zip") or die("Could not delete \"$destfile.zip\": $!\n");
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   149
    } 
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   150
    copy("$srcfile","$destfile.zip") or die("Could not copy \"$srcfile\" -> \"$destfile.zip\": $!\n");
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   151
    system("$zipper > $dev_null") and die("Could not zip \"test.xml\" into \"$destfile\"\n");    
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   152
}
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   153
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   154
if ($temp_dest_name) { # We are to update the src file. dest file is a temporary.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   155
   # Delete src file 
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   156
   unlink($srcfile) or die("Cannot delete file \"$srcfile\" to replace: $!\n");
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   157
   # Replace with temporary.
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   158
   move("$destfile$srctype","$srcfile") or die("Could not move \"$destfile$srctype\" -> \"$srcfile\": $!\n");
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   159
}
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   160
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   161
print "OK\n";
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   162
exit 0;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   163
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   164
sub usage($)
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   165
{
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   166
    my $error = shift;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   167
    my $fh = $error == 0 ? *STDOUT : *STDERR;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   168
    print $fh "ats_specialise_test_drop.pl\n" .
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   169
            "Specify the name, build id and target device in an ATS XML test drop\n" .
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   170
            "synopsis:\n" .
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   171
            "  ats_specialise_test_drop.pl --help\n" .
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   172
            "  ats_specialise_test_drop.pl [--test-drop-name=TESTNAME] [--build-id=BUILDID] [--device-name=DEVICENAME] [--dest=FILE] --src=FILE \n" .
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   173
            "options:\n" .
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   174
            "  --help                        Display this help and exit\n" .
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   175
            "  --test-drop-name=TESTNAME     TESTNAME is the desired name of the test drop. If not specified then the test drop name is not modified.\n" .
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   176
            "  --build-id=BUILDID            BUILDID is id of the build being tested. If not specified then the build id is not modified.\n" .            
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   177
            "  --device-name=DEVICENAME      DEVICENAME  is the name of the device on which the test should be run. " .
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   178
            "If not specified then the test device name is not modified.\n" .
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   179
            "  --src=INFILE                  INFILE is the file containing the test drop XML to be modified, or else a zip file " .
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   180
            "                                containing the test drop XML in the file 'test.xml'. INFILE must have extension .xml or.zip\n" .
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   181
            "  --dest=OUTFILE                The modified output will be written to the file OUTFILE.EXT " .
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   182
            "where EXT is same extention, .xml or .zip, found on INFILE. " .
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   183
            "If OUTFILE is not specified then INFILE is modified\n";              
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   184
    exit $error;            
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   185
}
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   186
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   187
sub help()
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   188
{
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   189
    usage(0);
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   190
}
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   191
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   192
sub usage_error()
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   193
{
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   194
    usage(1);
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   195
}             
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   196
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   197
sub silent_command($)
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   198
{
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   199
    my $cmd = shift;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   200
    system("$cmd 1> $dev_null 2>&1");
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   201
    return $? >> 8;
039d0b7e56f3 Comments and code tidying for ats3_testdrop.pl
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   202
}