common/tools/test/pckg_status/scripts/check_all_pckg_test_status.pl
changeset 840 3b9cc38657db
equal deleted inserted replaced
839:57b0cd458573 840:3b9cc38657db
       
     1 # Copyright (c) 2009 Symbian Foundation Ltd
       
     2 # This component and the accompanying materials are made available
       
     3 # under the terms of the License "Eclipse Public License v1.0"
       
     4 # which accompanies this distribution, and is available
       
     5 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     6 #
       
     7 #
       
     8 # Script name: check_all_pckg_test_status.pl
       
     9 #
       
    10 # Initial Contributors:
       
    11 # Symbian Foundation Ltd - initial contribution.
       
    12 #
       
    13 # Contributors:
       
    14 # Arnaud Lenoir <arnaudl@symbian.org>
       
    15 #
       
    16 # Created 30/11/2009
       
    17 #
       
    18 # Description:
       
    19 # Task 286 - Package test status prep - Compile a global view for all packages that we want to analyse
       
    20 #
       
    21 # Parameters passed:
       
    22 #	Param1: Path to the file containing the directories to check for test status
       
    23 #	Param2: Path to the directory containing the source code to analyse (generate a file)
       
    24 #	Param3: Path to the directory where DB will be published
       
    25 
       
    26 # Modules necessary to run this script
       
    27 use Getopt::Long;
       
    28 use strict;
       
    29 use Text::CSV;
       
    30 
       
    31 # Parameters passed to this script
       
    32 my $help;
       
    33 my $source_path_to_analyse;
       
    34 my $dirs_file_path_to_analyse;
       
    35 my $source_csv_path_to_analyse;
       
    36 my $publication_directory_path;
       
    37 my $pattern_file_path;
       
    38 
       
    39 # Variables
       
    40 my @tab_package_extraction;
       
    41 my @tab_package_extraction_S2;
       
    42 my @tab_package_extraction_S3;
       
    43 
       
    44 my $system_cmd;
       
    45 
       
    46 # Constantes declaration
       
    47 my $default_publication_directory_path = "\.\\results";
       
    48 my $default_pattern_file_path = ".\\pckg_test_status_patterns.csv";
       
    49 my $pckg_dir_paths_file_name = "pckg_test_status_paths.txt";
       
    50 my $pckg_dir_paths_file_name_S2 = "pckg_test_status_paths_S2.txt";
       
    51 my $pckg_dir_paths_file_name_S3 = "pckg_test_status_paths_S3.txt";
       
    52 my $all_pckgs_from_source_csv= "all_pckgs_from_source_csv.txt";
       
    53 my $pckg_definition_pattern = "package_definition*.xml";
       
    54 my $pckg_definition_pattern_S2 = "package_definition.xml";
       
    55 my $pckg_definition_pattern_S3 = "package_definition_*.xml";
       
    56 my $pckg_definition_extraction_pattern = "(^[\\w\\W]+)\\package_definition";
       
    57 my $csv_status_file_name = "packages_tests_supported_status.csv";
       
    58 
       
    59 my $nb_arg_passed = scalar(@ARGV);
       
    60 if(!$nb_arg_passed)
       
    61 {
       
    62 	print "No arguments/parameters passed then print help!\n";
       
    63 	helpme();
       
    64 }
       
    65 
       
    66 my %optmap = (  'source_path_to_analyse' => \$source_path_to_analyse,
       
    67 			    'dirs_file_path_to_analyse' => \$dirs_file_path_to_analyse,
       
    68 			    'publication_directory_path' => \$publication_directory_path,
       
    69 				'source_csv_path_to_analyse' => \$source_csv_path_to_analyse,
       
    70 			    'pattern_file_path' => \$pattern_file_path,
       
    71                 'help' => \$help);
       
    72 
       
    73 GetOptions(\%optmap,
       
    74 		  'source_path_to_analyse=s',
       
    75 		  'dirs_file_path_to_analyse=s',
       
    76 		  'publication_directory_path=s',
       
    77 		  'source_csv_path_to_analyse=s',
       
    78 		  'pattern_file_path=s',
       
    79           'help');
       
    80 
       
    81 print "The value for help is: <$help>\n";
       
    82 print "source_path_to_analyse: <$source_path_to_analyse>\n";
       
    83 print "dirs_file_path_to_analyse: <$dirs_file_path_to_analyse>\n";
       
    84 print "publication_directory_path: <$publication_directory_path>\n";
       
    85 print "source_csv_path_to_analyse: <$source_csv_path_to_analyse>\n";
       
    86 print "pattern_file_path: <$pattern_file_path>\n";
       
    87 
       
    88 if ($help)
       
    89 {
       
    90 	print "We want to print the help\n";
       
    91 	helpme();
       
    92 }
       
    93 else
       
    94 {
       
    95 	print "\nIt's from here that the real work starts!\n";
       
    96 }
       
    97 
       
    98 # Check if we need default values for some of the parameters
       
    99 # Publication directory
       
   100 if (!defined($publication_directory_path))
       
   101 {
       
   102 	print "No publication_directory_path passed as argument, therefore use default path\n";
       
   103 	$publication_directory_path = $default_publication_directory_path;
       
   104 	print "publication_directory_path = <$publication_directory_path>\n";
       
   105 }
       
   106 # Check if we have a directory use for publishing. If not create it
       
   107 print "Check if $publication_directory_path exist or not!\n";
       
   108 if (!(-d $publication_directory_path))
       
   109 {
       
   110 	print "The directory $publication_directory_path, doesn't exist, therefore we create it\n";
       
   111 	$system_cmd = "mkdir $publication_directory_path";	
       
   112 	print "Exec: $system_cmd\n";
       
   113 	system($system_cmd);
       
   114 }
       
   115 
       
   116 # We are going to packages type of tests supported in a csv file and before to do that we are going to make sure that if a file exist, then we rename it.
       
   117 # File will be renamed before .csv with date & time in the format:
       
   118 # year-month-day@hour-minute
       
   119 # Eg: packages_tests_supported_status-2009-12-11@10-57.csv
       
   120 
       
   121 my $csv_status_file_path = "$publication_directory_path\\$csv_status_file_name";
       
   122 print "The full path for the csv packages tests status file is: $csv_status_file_path\n";
       
   123 
       
   124 if(-f $csv_status_file_path)
       
   125 {
       
   126 	print "the file exists, we need to rename it to allow a new file to be created with new data\n";
       
   127 	my $date;
       
   128 	my $time;
       
   129 	
       
   130 	open (GETTIME,"time /t |");
       
   131 	$time = <GETTIME>;
       
   132 	chomp($time);
       
   133 	
       
   134 	open (GETDATE,"date /t |");
       
   135 	$date = <GETDATE>;
       
   136 	chomp($date);
       
   137 	
       
   138 	print "date is <$date>\n";
       
   139 	print "time is <$time>\n";
       
   140 	
       
   141 	$time =~ s/:/-/g;
       
   142 	
       
   143 	$date =~ m~([0-9]+)\/([0-9]+)\/([0-9]+)~;
       
   144 	print "$3-$2-$1\n";
       
   145 	$date = "$3-$2-$1";
       
   146 	
       
   147 	print "date is <$date>\n";
       
   148 	print "time is <$time>\n";
       
   149 
       
   150 	my $csv_status_file_path_renamed = $csv_status_file_name;
       
   151 	print "Current file name: $csv_status_file_path_renamed\n";	
       
   152 	$csv_status_file_path_renamed =~ s/\.csv/\-$date\@$time.csv/;
       
   153 	print "Renamed file name: $csv_status_file_path_renamed\n";
       
   154 
       
   155 	# Rename file to be saved and to use new one to work with.
       
   156 	$system_cmd = "rename $csv_status_file_path $csv_status_file_path_renamed";	
       
   157 	print "Exec: $system_cmd\n";
       
   158 	system($system_cmd);
       
   159 }
       
   160 else
       
   161 {
       
   162 	print "The file doesn't exist, we are starting from scratch! Nothing else to do!\n";
       
   163 }
       
   164 
       
   165 # Define Pacakge list & path by searching for "package_definition*.xml" file.
       
   166 # The directory having that file is considerated as the short package name.
       
   167 # Store list in a file? DB? or table?
       
   168 
       
   169 if (defined($source_csv_path_to_analyse))
       
   170 {
       
   171 	print "We have been given the path to a source.csv file to extract all the packages to be used\n";
       
   172 	if(!(-f $source_csv_path_to_analyse))
       
   173 	{
       
   174 		print "The file $source_csv_path_to_analyse doesn't exist! Please provide a new path!";
       
   175 		exit(0);
       
   176 	}
       
   177 	open (CSVFILE, "$source_csv_path_to_analyse");
       
   178 	
       
   179 	my @local_tab = <CSVFILE>;
       
   180 	
       
   181 	# Need to discard the first line of the file
       
   182 	print "local_tab[0]=<$local_tab[0]>\n";
       
   183 	$local_tab[0] = undef;
       
   184 	print "local_tab[0]=<$local_tab[0]> has been removed as garbage for us\n";
       
   185 	
       
   186 	my $nb_packgs_in_csv = 0;
       
   187 
       
   188 	# Extract package names
       
   189 	foreach my $line (@local_tab)
       
   190 	{
       
   191 		#Typical line: <E:\hgcache\mercurial_master_prod/sfl/MCL/sf/app/contentcontrol/,/sf/app/contentcontrol,changeset,8cb47bc684d4,layers.sysdef.xml>
       
   192 		#print "Line from file is: $line\n";
       
   193 		#if($line =~ m;,(/sf/[\w\/_]+),;) # Use for the second column of the csv file
       
   194 		if($line =~ m;([\w\W]+)\/,\/sf;) # Use for the first column of the csv file
       
   195 		{
       
   196 			#print "We have detected $1\n";
       
   197 			my $transform = $1;
       
   198 			$transform =~ s/\//\\/ig;
       
   199 			#print "transformed to: $transform\n";
       
   200 			$tab_package_extraction[$nb_packgs_in_csv++] = $transform;
       
   201 		}
       
   202 	}
       
   203 	print "# of packages is: <$nb_packgs_in_csv>\n";
       
   204 	
       
   205 	close (CSVFILE);
       
   206 	
       
   207 	# Save data in a file to be reused later on.
       
   208 	my $file2use = "$publication_directory_path\\$all_pckgs_from_source_csv";
       
   209 	print "File to open=$file2use\n";
       
   210 	
       
   211 	open(SAVINGDATAFILE,">$file2use");
       
   212 	foreach my $val2save (@tab_package_extraction)
       
   213 	{
       
   214 		print SAVINGDATAFILE "$val2save\n";
       
   215 	}
       
   216 	close(SAVINGDATAFILE);
       
   217 }
       
   218 elsif (defined($dirs_file_path_to_analyse))
       
   219 {
       
   220 	print "Use the file <$dirs_file_path_to_analyse> that contains the directories to scan\n";
       
   221 	
       
   222 	open(FILEWITHPCKGPATHS,"$dirs_file_path_to_analyse");
       
   223 	my $count_line = 0;
       
   224 	
       
   225 	while(<FILEWITHPCKGPATHS>)
       
   226 	{
       
   227 		#print "$_";
       
   228 		$tab_package_extraction[$count_line] = $_;
       
   229 		#print "tab_package_extraction[$count_line]=$tab_package_extraction[$count_line]\n";
       
   230 		$count_line++;
       
   231 	}
       
   232 	my $total_pckg_found = scalar(@tab_package_extraction);
       
   233 	print "nb of packages found in $dirs_file_path_to_analyse is: <$total_pckg_found>\n";
       
   234 	close(FILEWITHPCKGPATHS);
       
   235 }
       
   236 elsif (defined($source_path_to_analyse))
       
   237 {
       
   238 	print "Use the directory \\sf that contains the code to scan\n";
       
   239 	generate_file_with_path_2_pckgs($source_path_to_analyse);
       
   240 }
       
   241 else
       
   242 {
       
   243 	print "No parameters <source_path_to_analyse> or <dirs_file_path_to_analyse> or <source_csv_path_to_analyse> passed, therefore can't work\n";
       
   244 	helpme();
       
   245 }
       
   246 
       
   247 # Patterns file used
       
   248 if (!defined($pattern_file_path))
       
   249 {
       
   250 	print "No specific patterns file has been passed as parameters, therefore we use default patterns file\n";
       
   251 	$pattern_file_path = $default_pattern_file_path;
       
   252 	print "pattern_file_path = <$pattern_file_path>\n";
       
   253 }
       
   254 # End check if default values are necessary
       
   255 
       
   256 print "\n\n";
       
   257 
       
   258 # Call script to extract test data from each packge.
       
   259 # foreach package in the list, call check_pckg_test_status.pl script with right parameters
       
   260 # check_pckg_test_status.pl will automatically fill the DB with the right info	
       
   261 
       
   262 # May need to remove trailing \n using chomp($path2passed);
       
   263 foreach my $path2passed (@tab_package_extraction)
       
   264 {
       
   265 	#print "Remove trailing \\n for each line\n";
       
   266 	chomp($path2passed);
       
   267 	#print "The path we pass is: <$path2passed>\n";
       
   268 	
       
   269 	$system_cmd = "check_pckg_test_status.pl --package_path=$path2passed --pattern_file_path=$pattern_file_path --publication_directory_path=$publication_directory_path";	
       
   270 	print "Exec: $system_cmd\n";
       
   271 	system($system_cmd);
       
   272 }
       
   273 
       
   274 # Create / update the global DB files.
       
   275 # Can be adding all the smaller files generated to a bigger unigue file
       
   276 # Use XSLT using all the xml files generated?
       
   277 
       
   278 # End of the script
       
   279 exit(0);
       
   280 
       
   281 
       
   282 # Functions section
       
   283 
       
   284 # If no parameters entered or help selected, display help
       
   285 sub helpme
       
   286 {
       
   287 	print "\nfct: helpme\n";
       
   288 	print "check_all_pckg_test_status.pl\n";
       
   289 	print "Usage:\n";
       
   290 	print "check_all_pckg_test_status.pl --help\n";
       
   291 	print "check_all_pckg_test_status.pl --dirs_file_path_to_analyse=I:\\Task-286\\Scripts\\pckg_test_status_paths.txt --publication_directory_path=.\\result\n";
       
   292 	print "check_all_pckg_test_status.pl --source_path_to_analyse=I:\\sf --publication_directory_path=.\\result --pattern_file_path=I:\\Task-286\\Scripts\\pckg_test_status_patterns.csv\n";
       
   293 	print "check_all_pckg_test_status.pl --source_csv_path_to_analyse=I:\\sf --publication_directory_path=.\\result --pattern_file_path=I:\\Task-286\\Scripts\\pckg_test_status_patterns.csv\n";
       
   294 	print "Options:\n";
       
   295 	print "--help:\t\t\t\t display this help and exit\n";
       
   296 	print "--dirs_file_path_to_analyse:\t path to a file that contains the path to the directories containing package_definition.xml\n";
       
   297 	print "--source_path_to_analyse:\t path of the root of the source code \\sf\n";
       
   298 	print "--publication_directory_path:\t is the path to the directory where the results will be published (optional)\n";
       
   299 	print "--source_csv_path_to_analyse:\t is path to sources.csv file in case packages haven't got a package_definition.xml (optional)\n";
       
   300 	print "\t\t\t\t default value is $default_publication_directory_path\n";
       
   301 	print "--pattern_file_path:\t is the path to file that contain the patterns to be search for (optional)\n";
       
   302 	print "\t\t\t\t default value is $default_pattern_file_path\n";
       
   303 
       
   304 	exit(0);
       
   305 }
       
   306 # End section related to help
       
   307 
       
   308 
       
   309 # This function is called with the path to the directory \\sf and then we scan for all the directories / packages that contains package_definition*.xml
       
   310 # Result should be a file with something like this: "I:\sf\os\kernelhwsrv"
       
   311 # Parameter passed is the path to the directory \\sf
       
   312 sub generate_file_with_path_2_pckgs
       
   313 {
       
   314 	my ($path_2_dir_sf_2_analyse) = @_;
       
   315 	my @tab_package_definition_list;
       
   316 	
       
   317 	print "The path to the \\sf directory we want to analyse is: <$path_2_dir_sf_2_analyse>\n";
       
   318 	
       
   319 	print "The pattern used to find out the root directory for a pacakge is: <$pckg_definition_pattern>\n";
       
   320 	
       
   321 	# Ananlyse directories for package_definition*.xml
       
   322 	# Find a way to parse all the directories and get results as fast as possible
       
   323 	# something like <dir I:\sf\package_definition*.xml /s/b>
       
   324 
       
   325 	print "\n";
       
   326 	
       
   327 	open(FINDPCKDEFPATHS,"dir $path_2_dir_sf_2_analyse\\$pckg_definition_pattern /s/b |");
       
   328 	my $local_ctr = 0;
       
   329 	
       
   330 	while(<FINDPCKDEFPATHS>)
       
   331 	{
       
   332 		print "$_";
       
   333 		$tab_package_definition_list[$local_ctr] = $_;
       
   334 		#print "tab_package_definition_list[$local_ctr]=$tab_package_definition_list[$local_ctr]\n";
       
   335 		$local_ctr++;
       
   336 	}
       
   337 	my $total_pckg_def_files_found = scalar(@tab_package_definition_list);
       
   338 	print "nb of $pckg_definition_pattern found in $path_2_dir_sf_2_analyse are: <$total_pckg_def_files_found>\n";
       
   339 	
       
   340 	close(FINDPCKDEFPATHS);
       
   341 	
       
   342 	print "\n";
       
   343 	
       
   344 	my $local_ctr1=0;
       
   345 	my $local_ctr2=0;
       
   346 	my $local_ctr3=0;
       
   347 		
       
   348 	# What to extract
       
   349 	#I:\sf\adaptation\qemu\package_definition.xml
       
   350 	#I:\sf\adaptation\qemu\package_definition_2.0.1.xml
       
   351 	# Anything before the last \\, whcih should not be included!
       
   352 	foreach my $val (@tab_package_definition_list)
       
   353 	{		
       
   354 		if ($val =~ m#(^[\w\W]+)\\package_definition#i)
       
   355 		#if ($val =~ m,$pckg_definition_extraction_pattern,i)
       
   356 		{
       
   357 			#print "Value to analyse is: $val\n";
       
   358 			#print "Managed to extract: $1\n";
       
   359 			$tab_package_extraction[$local_ctr1] = $1;
       
   360 			#print "tab_package_extraction[$local_ctr1]=$tab_package_extraction[$local_ctr1]\n";
       
   361 			$local_ctr1++;
       
   362 		}
       
   363 		
       
   364 		#print "\n";
       
   365 		
       
   366 		# Create tables for S^2 & S^3 package_definition.xml file
       
   367 		# Store them in a table and save it in 2 different files
       
   368 
       
   369 		#S^2
       
   370 		if ($val =~ m#(^[\w\W]+)\\package_definition.xml#i)
       
   371 		{
       
   372 			#print "Value to analyse is: $val\n";
       
   373 			#print "Managed to extract: $1\n";
       
   374 			$tab_package_extraction_S2[$local_ctr2] = $1;
       
   375 			#print "tab_package_extraction_S2[$local_ctr2]=$tab_package_extraction_S2[$local_ctr2]\n";
       
   376 			$local_ctr2++;
       
   377 		}
       
   378 
       
   379 		#S^3
       
   380 		if ($val =~ m#(^[\w\W]+)\\package_definition_#i)
       
   381 		{
       
   382 			#print "Value to analyse is: $val\n";
       
   383 			#print "Managed to extract: $1\n";
       
   384 			$tab_package_extraction_S3[$local_ctr3] = $1;
       
   385 			#print "tab_package_extraction_S3[$local_ctr3]=$tab_package_extraction_S3[$local_ctr3]\n";
       
   386 			$local_ctr3++;
       
   387 		}
       
   388 	}
       
   389 
       
   390 	# Eliminate duplicates packages paths!
       
   391 	my %seen;
       
   392 	for ( my $i = 0; $i <= $#tab_package_extraction ; )
       
   393 	{
       
   394     splice @tab_package_extraction, --$i, 1
       
   395         if $seen{$tab_package_extraction[$i++]}++;
       
   396 	}
       
   397 	#print "Sorted out table:\n @tab_package_extraction\n";
       
   398 
       
   399 	# Save data in a file that will be reused later on
       
   400 	# Create a new file everytime. Save old one if exist with date and time?
       
   401 	print "Path to the file where data will be saved is called: <$publication_directory_path>\n";
       
   402 	print "File name where data will be saved is called: <$pckg_dir_paths_file_name>\n";
       
   403 	
       
   404 	my $data_2_save_file_path = "$publication_directory_path\\$pckg_dir_paths_file_name";
       
   405 	my $path2save;
       
   406 	
       
   407 	print "The path to the file to write to is: <$data_2_save_file_path>\n";
       
   408 	
       
   409 	# Save generic table in a file
       
   410 	# Open the file
       
   411 	open(FILE2SAVEDATA, ">$data_2_save_file_path");
       
   412 	
       
   413 	foreach $path2save (@tab_package_extraction)
       
   414 	{
       
   415 		print FILE2SAVEDATA "$path2save\n";
       
   416 	}
       
   417 	
       
   418 	# Close the file
       
   419 	close(FILE2SAVEDATA);
       
   420 
       
   421 	# Save generic table for S^2 in a file
       
   422 	$data_2_save_file_path = "$publication_directory_path\\$pckg_dir_paths_file_name_S2";
       
   423 	print "The path to the file to write to is: <$data_2_save_file_path>\n";
       
   424 	# Open the file
       
   425 	open(FILE2SAVEDATA, ">$data_2_save_file_path");
       
   426 	
       
   427 	foreach $path2save (@tab_package_extraction_S2)
       
   428 	{
       
   429 		print FILE2SAVEDATA "$path2save\n";
       
   430 	}
       
   431 
       
   432 	# Save generic table for S^3 in a file
       
   433 	$data_2_save_file_path = "$publication_directory_path\\$pckg_dir_paths_file_name_S3";
       
   434 	print "The path to the file to write to is: <$data_2_save_file_path>\n";
       
   435 	# Open the file
       
   436 	open(FILE2SAVEDATA, ">$data_2_save_file_path");
       
   437 	
       
   438 	foreach $path2save (@tab_package_extraction_S3)
       
   439 	{
       
   440 		print FILE2SAVEDATA "$path2save\n";
       
   441 	}
       
   442 	
       
   443 	# Close the file
       
   444 	close(FILE2SAVEDATA);
       
   445 }