[21711] | 1 | #!/usr/bin/perl -w
|
---|
| 2 |
|
---|
| 3 | #TODO: Individual Testing
|
---|
| 4 |
|
---|
| 5 | ###########################################################################
|
---|
| 6 | #
|
---|
| 7 | # test.pl -- for testing is built collection is consistent with model collection
|
---|
| 8 | # A component of the Greenstone digital library software
|
---|
| 9 | # from the New Zealand Digital Library Project at the
|
---|
| 10 | # University of Waikato, New Zealand.
|
---|
| 11 | #
|
---|
| 12 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 13 | #
|
---|
| 14 | # This program is free software; you can redistribute it and/or modify
|
---|
| 15 | # it under the terms of the GNU General Public License as published by
|
---|
| 16 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 17 | # (at your option) any later version.
|
---|
| 18 | #
|
---|
| 19 | # This program is distributed in the hope that it will be useful,
|
---|
| 20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 22 | # GNU General Public License for more details.
|
---|
| 23 | #
|
---|
| 24 | # You should have received a copy of the GNU General Public License
|
---|
| 25 | # along with this program; if not, write to the Free Software
|
---|
| 26 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 27 | #
|
---|
| 28 | ###########################################################################
|
---|
| 29 |
|
---|
| 30 | package diffcol_mk2;
|
---|
| 31 |
|
---|
| 32 | BEGIN {
|
---|
| 33 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
| 34 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
| 35 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
| 36 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | use parsargv;
|
---|
| 40 | use util;
|
---|
[27536] | 41 | use FileUtils;
|
---|
[21711] | 42 | use logdiff;
|
---|
| 43 | use cfgdiff;
|
---|
| 44 | use gdbdiff;
|
---|
| 45 | use diffutil;
|
---|
| 46 | use Text::Diff;
|
---|
| 47 |
|
---|
| 48 | #--Global Variables Declaration-----------
|
---|
[27536] | 49 | $gv_strModelColRoot = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'},"/model-collect");
|
---|
| 50 | $gv_strTestColRoot = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'},"/collect");
|
---|
[21711] | 51 |
|
---|
| 52 | $gv_blnErrorStop = "false";
|
---|
| 53 | $gv_blnErrorShow = "false";
|
---|
| 54 | $gv_intVerbosity = 0;
|
---|
| 55 | $gv_strMode = "Full";
|
---|
[27537] | 56 | $strOutputFormat = "xml" unless defined $strOutputFormat; # global var with default
|
---|
[21711] | 57 |
|
---|
| 58 | %gv_IndivList = ("archives" => 0,
|
---|
| 59 | "etc" => 0,
|
---|
| 60 | "images" => 0,
|
---|
| 61 | "building" => 0,
|
---|
| 62 | "import" => 0,
|
---|
| 63 | "index" => 0,
|
---|
| 64 | "log" => 0,
|
---|
| 65 | "metadata" => 0,
|
---|
| 66 | "perllib" => 0,
|
---|
| 67 | "temp" => 0);
|
---|
| 68 | #----##
|
---|
| 69 |
|
---|
| 70 | #--System Setup---------------------------
|
---|
| 71 | sub SetMode
|
---|
| 72 | {
|
---|
| 73 | my ($strModeList) = @_;
|
---|
| 74 | $strModeList =~ s/\|/ /g;
|
---|
| 75 | my @Modes = split(" ",$strModeList);
|
---|
| 76 |
|
---|
| 77 | my $blnIndividual = "true";
|
---|
| 78 | my $blnInitial = "false";
|
---|
| 79 | my $blnFull = "false";
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | foreach $strEachMode (@Modes)
|
---|
| 83 | {
|
---|
| 84 | if($strEachMode eq "all")
|
---|
| 85 | {
|
---|
| 86 | $blnFull = "true";
|
---|
| 87 | $blnIndividual = "false";
|
---|
| 88 | }
|
---|
| 89 | elsif($strEachMode eq "init")
|
---|
| 90 | {
|
---|
| 91 | $blnInitial = "true";
|
---|
| 92 | $blnIndividual = "false";
|
---|
| 93 | }
|
---|
| 94 | else
|
---|
| 95 | {
|
---|
| 96 | if(defined $gv_IndivList{$strEachMode})
|
---|
| 97 | {
|
---|
| 98 | $gv_IndivList{$strEachMode} = 1;
|
---|
| 99 | }
|
---|
| 100 | else
|
---|
| 101 | {
|
---|
| 102 | die Help("Error: used undefined mode");
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | if($blnFull eq "true") {return "Full";}
|
---|
| 108 | elsif($blnInitial eq "true") {return "Initial";}
|
---|
| 109 | elsif($blnIndividual eq "true") {return "Individual";}
|
---|
| 110 | else {die "Error occured in function SetMode!!\n";}
|
---|
| 111 | }
|
---|
| 112 | #----##
|
---|
| 113 |
|
---|
| 114 | #--System Process-------------------------
|
---|
| 115 | sub IndivTest
|
---|
| 116 | {
|
---|
| 117 | my ($strModelCol,$strTestCol) = @_;
|
---|
| 118 | my @Errors = ();
|
---|
| 119 | my $intNumberOfErrors = 0;
|
---|
| 120 | foreach $strEachFolder (keys %gv_IndivList)
|
---|
| 121 | {
|
---|
| 122 | if($gv_IndivList{$strEachFolder} == 1)
|
---|
| 123 | {
|
---|
| 124 |
|
---|
| 125 | VobPrint("Start Comparing \"$strEachFolder\"\n",0);
|
---|
[27536] | 126 | my $strModelFolder = &FileUtils::filenameConcatenate($strModelCol,$strEachFolder);
|
---|
| 127 | my $strTestFolder = &FileUtils::filenameConcatenate($strTestCol,$strEachFolder);
|
---|
[21711] | 128 | $intNumberOfErrors = scalar(@Errors);
|
---|
| 129 | push(@Errors,TestEach($strModelFolder,$strTestFolder,0));
|
---|
| 130 | $intNumberOfErrors = scalar(@Errors) - $intNumberOfErrors;
|
---|
| 131 | VobPrint("End Comparing \"$strEachFolder\"\n",0);
|
---|
| 132 | VobPrint("Difference Found: $intNumberOfErrors\n",0);
|
---|
| 133 | VobPrint ("\n",0);
|
---|
| 134 | }
|
---|
| 135 | }
|
---|
| 136 | return @Errors;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | sub InitTest
|
---|
| 140 | {
|
---|
| 141 |
|
---|
| 142 | my ($strModelCol,$strTestCol,$strColName) = @_;
|
---|
| 143 | my $intLevel = 1;
|
---|
| 144 | my @Errors;
|
---|
| 145 |
|
---|
| 146 | # Testing Log files
|
---|
[27536] | 147 | # my $strModelLog = &FileUtils::filenameConcatenate($strModelCol,"log");
|
---|
| 148 | # my $strTestLog = &FileUtils::filenameConcatenate($strTestCol,"log");
|
---|
[21711] | 149 | #
|
---|
| 150 | # if(-e $strModelLog && -e $strTestLog)
|
---|
| 151 | # {
|
---|
| 152 | # my $strLogError = logdiff::test_log($strModelLog,$strTestLog);
|
---|
| 153 | # if($strLogError ne "")
|
---|
| 154 | # {
|
---|
| 155 | # AlignPrint("Log Folder Comparison Result","Failed",$intLevel);
|
---|
| 156 | # VobPrint ("$strLogError\n",$intLevel);
|
---|
| 157 | #
|
---|
| 158 | # $strLogError = "$strLogError";
|
---|
| 159 | # $strLogError = "Difference Found at Log Folder Testing\n".$strLogError."\n";
|
---|
| 160 | # push(@Errors,$strLogError);
|
---|
| 161 | # }
|
---|
| 162 | # else
|
---|
| 163 | # {
|
---|
| 164 | # AlignPrint("Log Folder Comparison Result","Succeed",$intLevel);
|
---|
| 165 | # }
|
---|
| 166 | # }
|
---|
| 167 | # else
|
---|
| 168 | # {
|
---|
| 169 | # my $strErrorColName;
|
---|
| 170 | # my $strLogError;
|
---|
| 171 | #
|
---|
| 172 | # if(!(-e $strModelLog)){ $strErrorColName = $strErrorColName."(Model Collection)";}
|
---|
| 173 | # if(!(-e $strTestLog)){ $strErrorColName = $strErrorColName."(Test Collection)";}
|
---|
| 174 | #
|
---|
| 175 | # AlignPrint("Log Folder Comparison Result","Failed",$intLevel);
|
---|
| 176 | # $strLogError = "Difference Report: No Log Folder found in $strErrorColName";
|
---|
| 177 | # VobPrint ("$strLogError\n",$intLevel);
|
---|
| 178 | # $strLogError = "Difference Found at Log Folder Testing (Log folders are only created using GLI)\n".$strLogError."\n";
|
---|
| 179 | #
|
---|
| 180 | # push(@Errors,$strLogError);
|
---|
| 181 | # }
|
---|
| 182 | # VobPrint ("\n",$intLevel);
|
---|
| 183 |
|
---|
| 184 | # Testing the build.cfg
|
---|
[27536] | 185 | my $strModelBcfg = &FileUtils::filenameConcatenate($strModelCol,"index","build.cfg");
|
---|
| 186 | my $strTestBcfg = &FileUtils::filenameConcatenate($strTestCol,"index","build.cfg");
|
---|
[21711] | 187 |
|
---|
| 188 | if(-e $strModelBcfg && -e $strTestBcfg)
|
---|
| 189 | {
|
---|
| 190 | my $strBcfgError = cfgdiff::test_cfg($strModelBcfg,$strTestBcfg,"build.cfg");
|
---|
| 191 | if($strBcfgError ne "")
|
---|
| 192 | {
|
---|
[27537] | 193 | if( $strOutputFormat eq "xml" ) {
|
---|
[21711] | 194 | print "<build-cfg succeeded=\"no\">\n<message>";
|
---|
| 195 | } else {
|
---|
| 196 | AlignPrint("Config File(build.cfg) Comparison Result","Failed",$intLevel);
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | VobPrint ("$strBcfgError",$intLevel);
|
---|
[27537] | 200 | if( $strOutputFormat eq "xml" ) {
|
---|
[21711] | 201 | print "</message></build-cfg>";
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | $strBcfgError = "$strBcfgError";
|
---|
| 205 | $strBcfgError = "Difference Found at Config File(build.cfg) Comparison\n".$strBcfgError."\n";
|
---|
| 206 | push(@Errors,$strBcfgError);
|
---|
| 207 | }
|
---|
| 208 | else
|
---|
| 209 | {
|
---|
| 210 | if( $strOutputFormat eq "xml" ) {
|
---|
| 211 | print "<build-cfg succeeded=\"yes\"/>";
|
---|
| 212 | } else {
|
---|
| 213 | AlignPrint("Config File(build.cfg) Comparison Result","Succeed",$intLevel);
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 | }
|
---|
| 217 | else
|
---|
| 218 | {
|
---|
| 219 | my $strErrorColName;
|
---|
| 220 | my $strBcfgError;
|
---|
| 221 |
|
---|
| 222 | if(!(-e $strModelBcfg)){ $strErrorColName = $strErrorColName."(Model Collection)";}
|
---|
| 223 | if(!(-e $strTestBcfg)){ $strErrorColName = $strErrorColName."(Test Collection)";}
|
---|
| 224 |
|
---|
| 225 | AlignPrint("Config File(build.cfg) Comparison Result","Failed",$intLevel);
|
---|
| 226 | $strBcfgError = "Difference Report: No Config files found in $strErrorColName";
|
---|
| 227 | VobPrint ("$strBcfgError\n",$intLevel);
|
---|
| 228 | $strBcfgError = "Difference Found at Config File(build.cfg) Comparison\n".$strBcfgError."\n";
|
---|
| 229 |
|
---|
| 230 | push(@Errors,$strBcfgError);
|
---|
| 231 | }
|
---|
| 232 | VobPrint ("\n",$intLevel);
|
---|
| 233 |
|
---|
| 234 | # Testing the collect.cfg
|
---|
| 235 |
|
---|
[27536] | 236 | my $strModelCcfg = &FileUtils::filenameConcatenate($strModelCol,"etc","collect.cfg");
|
---|
| 237 | my $strTestCcfg = &FileUtils::filenameConcatenate($strTestCol,"etc","collect.cfg");
|
---|
[21711] | 238 |
|
---|
| 239 | if(-e $strModelCcfg && -e $strTestCcfg)
|
---|
| 240 | {
|
---|
| 241 | my $strCcfgError = cfgdiff::test_cfg($strModelCcfg,$strTestCcfg,"collect.cfg");
|
---|
| 242 | if($strCcfgError ne "")
|
---|
| 243 | {
|
---|
| 244 | if( $strOutputFormat eq "xml" ) {
|
---|
| 245 | print "<collect-cfg succeeded=\"no\"><message>";
|
---|
| 246 | } else {
|
---|
| 247 | AlignPrint("Config File(collect.cfg) Comparison Result","Failed",$intLevel);
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | VobPrint ("$strCcfgError",$intLevel);
|
---|
| 251 |
|
---|
| 252 | if( $strOutputFormat eq "xml" ) {
|
---|
| 253 | print "</message></collect-cfg>";
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | $strCcfgError = "$strCcfgError";
|
---|
| 257 | $strCcfgError = "Difference Found at Config File(collect.cfg) Comparison\n".$strCcfgError."\n";
|
---|
| 258 | push(@Errors,$strCcfgError);
|
---|
| 259 | }
|
---|
| 260 | else
|
---|
| 261 | {
|
---|
| 262 | if( $strOutputFormat eq "xml" ) {
|
---|
| 263 | print "<collect-cfg succeeded=\"yes\"/>";
|
---|
| 264 | } else {
|
---|
| 265 | AlignPrint("Config File(collect.cfg) Comparison Result","Succeed",$intLevel);
|
---|
| 266 | }
|
---|
| 267 | }
|
---|
| 268 | }
|
---|
| 269 | else
|
---|
| 270 | {
|
---|
| 271 | my $strErrorColName;
|
---|
| 272 | my $strCcfgError;
|
---|
| 273 |
|
---|
| 274 | if(!(-e $strModelCcfg)){ $strErrorColName = $strErrorColName."(Model Collection)";}
|
---|
| 275 | if(!(-e $strTestCcfg)){ $strErrorColName = $strErrorColName."(Test Collection)";}
|
---|
| 276 |
|
---|
| 277 | AlignPrint("Config File(collect.cfg) Comparison Result","Failed",$intLevel);
|
---|
| 278 | $strCcfgError = "Difference Report: No Config files found in $strErrorColName";
|
---|
| 279 | VobPrint ("$strCcfgError\n",$intLevel);
|
---|
| 280 | $strCcfgError = "Difference Found at Config File(collect.cfg) Comparison\n".$strCcfgError."\n";
|
---|
| 281 |
|
---|
| 282 | push(@Errors,$strCcfgError);
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 | VobPrint ("\n",$intLevel);
|
---|
| 286 |
|
---|
| 287 | # Testing database
|
---|
| 288 |
|
---|
[27536] | 289 | my $strModelGdb = &FileUtils::filenameConcatenate($strModelCol,"index","text","$strColName.ldb");
|
---|
| 290 | my $strTestGdb = &FileUtils::filenameConcatenate($strTestCol,"index","text","$strColName.ldb");
|
---|
[21711] | 291 |
|
---|
| 292 | if(-e $strModelGdb && -e $strTestGdb)
|
---|
| 293 | {
|
---|
| 294 | my $strGdbError = gdbdiff::test_gdb($strModelGdb, $strTestGdb);
|
---|
| 295 | if($strGdbError ne "")
|
---|
| 296 | {
|
---|
| 297 | if( $strOutputFormat eq "xml" ) {
|
---|
| 298 | print "<database succeeded=\"no\"><message>";
|
---|
| 299 | } else {
|
---|
| 300 | AlignPrint("Database Comparsion Result","Failed",$intLevel);
|
---|
| 301 | }
|
---|
| 302 | VobPrint ("$strGdbError\n",$intLevel);
|
---|
| 303 |
|
---|
| 304 | if( $strOutputFormat eq "xml" ) {
|
---|
| 305 | print "</message></database>";
|
---|
| 306 | }
|
---|
| 307 |
|
---|
| 308 | $strGdbError = "$strGdbError";
|
---|
| 309 | $strGdbError = "Difference Found at Database Comparsion\n".$strGdbError."\n";
|
---|
| 310 | push(@Errors,$strGdbError);
|
---|
| 311 | }
|
---|
| 312 | else
|
---|
| 313 | {
|
---|
| 314 | if( $strOutputFormat eq "xml" ) {
|
---|
| 315 | print "<database succeeded=\"yes\"/>";
|
---|
| 316 | } else {
|
---|
| 317 | AlignPrint("Database Comparsion Result","Succeed",$intLevel);
|
---|
| 318 | }
|
---|
| 319 | }
|
---|
| 320 | }
|
---|
| 321 | else
|
---|
| 322 | {
|
---|
| 323 | my $strErrorColName;
|
---|
| 324 | my $strGdbError;
|
---|
| 325 |
|
---|
| 326 | if(!(-e $strModelGdb)){ $strErrorColName = $strErrorColName."(Model Collection)";}
|
---|
| 327 | if(!(-e $strTestGdb)){ $strErrorColName = $strErrorColName."(Test Collection)";}
|
---|
| 328 |
|
---|
| 329 | AlignPrint("Database Comparsion Result","Failed",$intLevel);
|
---|
| 330 |
|
---|
| 331 | $strGdbError = "Difference Report: No Database files found in $strErrorColName";
|
---|
| 332 | VobPrint ("$strGdbError\n",$intLevel);
|
---|
| 333 |
|
---|
| 334 | $strGdbError = "Difference Found at Database Comparison\n".$strGdbError."\n";
|
---|
| 335 |
|
---|
| 336 | push(@Errors,$strGdbError);
|
---|
| 337 | }
|
---|
| 338 |
|
---|
| 339 | VobPrint ("\n",$intLevel);
|
---|
| 340 |
|
---|
| 341 | return @Errors;
|
---|
| 342 | }
|
---|
| 343 |
|
---|
| 344 | sub FullTest
|
---|
| 345 | {
|
---|
| 346 | my ($strModelCol,$strTestCol,$strColName) = @_;
|
---|
| 347 | my @Errors = ();
|
---|
| 348 | my $intLevel = 0;
|
---|
| 349 | my $intNumberDiffs = 0;
|
---|
| 350 |
|
---|
| 351 | # <Initial Test>
|
---|
| 352 | if( $strOutputFormat eq "xml" ) {
|
---|
| 353 | #print "<initial-test>";
|
---|
| 354 | } else {
|
---|
| 355 | VobPrint("Initial Testing Start\n",$intLevel);
|
---|
| 356 | }
|
---|
| 357 |
|
---|
| 358 | @Errors = InitTest($strModelCol,$strTestCol,$strColName);
|
---|
| 359 | $intNumberDiffs = scalar(@Errors);
|
---|
| 360 |
|
---|
| 361 | if( $strOutputFormat eq "xml" ) {
|
---|
| 362 | #print "</initial-test>";
|
---|
| 363 | } else {
|
---|
| 364 | VobPrint("Initial Testing End\n",$intLevel);
|
---|
| 365 | VobPrint("Difference Found in Initial Testing: $intNumberDiffs\n",$intLevel);
|
---|
| 366 | VobPrint("\n",$intLevel);
|
---|
| 367 | }
|
---|
| 368 | # </Initial Test>
|
---|
| 369 |
|
---|
| 370 | # <Detailed Test>
|
---|
| 371 | if( $strOutputFormat eq "xml" ) {
|
---|
| 372 | #print "<detailed-test>";
|
---|
| 373 | } else {
|
---|
| 374 | VobPrint("Detail Testing Start\n",$intLevel);
|
---|
| 375 | }
|
---|
| 376 | push(@Errors,TestEach($strModelCol,$strTestCol,$intLevel));
|
---|
| 377 | $intNumberDiffs = scalar(@Errors) - $intNumberDiffs;
|
---|
| 378 |
|
---|
| 379 | if( $strOutputFormat eq "xml" ) {
|
---|
| 380 | #print "</detailed-test>";
|
---|
| 381 | } else {
|
---|
| 382 | VobPrint("Detail Testing End\n",$intLevel);
|
---|
| 383 | VobPrint("Difference Found in Detail Testing: $intNumberDiffs\n",$intLevel);
|
---|
| 384 | }
|
---|
| 385 | # </Detailed Test>
|
---|
| 386 |
|
---|
| 387 | return @Errors;
|
---|
| 388 | }
|
---|
| 389 | #----##
|
---|
| 390 |
|
---|
| 391 |
|
---|
| 392 | #--Other System Utilities
|
---|
| 393 | sub PrintUsage
|
---|
| 394 | {
|
---|
| 395 | my ($strProgName) = @_;
|
---|
| 396 | if ( $strOutputFormat eq "xml" ) {
|
---|
| 397 | print "<error>usage incorrect</error>\n";
|
---|
| 398 | } else {
|
---|
| 399 | print STDERR "Usage: $strProgName test-col [more-col] [-verbosity d] [-mode modes] [-eshow] [-estop]\n";
|
---|
| 400 | }
|
---|
| 401 | Help("Error: used incorrect parameters");
|
---|
| 402 | }
|
---|
| 403 |
|
---|
| 404 | sub Help
|
---|
| 405 | {
|
---|
| 406 | my ($strError) = @_;
|
---|
| 407 | my $aryptHelps =
|
---|
| 408 | [ { 'name' => "verbosity",
|
---|
| 409 | 'type' => "scale",
|
---|
| 410 | 'argu' => "a integer" ,
|
---|
| 411 | 'descrip' => "this parameter setup the verbosity of the testing result"},
|
---|
| 412 | { 'name' => "mode",
|
---|
| 413 | 'type' => "option",
|
---|
| 414 | 'argu' => "mode type \"[all|init|archives|building|etc|images|import|index|perllib|tmp]\" default to \"all\"" ,
|
---|
| 415 | 'descrip' => "setup testing mode: all-full testing, init-initial testing (include configuration file test,database testing and log testing), others-for individual folder testing"},
|
---|
| 416 | { 'name' => "estop",
|
---|
| 417 | 'type' => "flag",
|
---|
| 418 | 'argu' => "NULL" ,
|
---|
| 419 | 'descrip' => "Set then system will stop once it meet an error"},
|
---|
| 420 | { 'name' => "eshow",
|
---|
| 421 | 'type' => "flag",
|
---|
| 422 | 'argu' => "NULL" ,
|
---|
| 423 | 'descrip' => "Set then system will show the error summary"}
|
---|
| 424 | ];
|
---|
| 425 |
|
---|
| 426 |
|
---|
| 427 | if ( $strOutputFormat ne "xml" ) {
|
---|
| 428 | print "$strError\n";
|
---|
| 429 |
|
---|
| 430 | foreach my $hashOneArg (@{$aryptHelps})
|
---|
| 431 | {
|
---|
| 432 | print "\n----------------------------\n";
|
---|
| 433 | print "Parameters: -".$hashOneArg->{"name"}."\n";
|
---|
| 434 | print "Type: ".$hashOneArg->{"type"}."\n";
|
---|
| 435 | print "Supply Argument: ".$hashOneArg->{"argu"}."\n";
|
---|
| 436 | print "Description: ".$hashOneArg->{"descrip"}."\n";
|
---|
| 437 | print "----------------------------\n";
|
---|
| 438 | }
|
---|
| 439 | }
|
---|
| 440 | }
|
---|
| 441 |
|
---|
| 442 | sub OutputStart
|
---|
| 443 | {
|
---|
| 444 | my ($strColName) = @_;
|
---|
| 445 | my $intPadding = 17 - length($strColName);
|
---|
| 446 |
|
---|
| 447 | if ( $strOutputFormat eq "xml" ) {
|
---|
| 448 | print "<diffcol>\n";
|
---|
| 449 | } else {
|
---|
| 450 | print "+---------------------------------------------------------+\n";
|
---|
| 451 | print "| |\n";
|
---|
| 452 | print "| Start Testing Collection: $strColName"," " x $intPadding,"|\n";
|
---|
| 453 | print "| |\n";
|
---|
| 454 | print "+---------------------------------------------------------+\n\n";
|
---|
| 455 | }
|
---|
| 456 | }
|
---|
| 457 |
|
---|
| 458 | sub OutputEnd
|
---|
| 459 | {
|
---|
| 460 | my ($strColName,$aryptErrors) = @_;
|
---|
| 461 | my $intPadding = 12 - length($strColName);
|
---|
| 462 | if ( $strOutputFormat eq "xml" ) {
|
---|
| 463 | print "</diffcol>\n";
|
---|
| 464 | } else {
|
---|
| 465 | print "\n";
|
---|
| 466 | print "+---------------------------------------------------------+\n";
|
---|
| 467 | print "| |\n";
|
---|
| 468 | print "| Result of Collection Testing: $strColName"," " x $intPadding,"|\n";
|
---|
| 469 | print "| |\n";
|
---|
| 470 | print "+---------------------------------------------------------+\n\n";
|
---|
| 471 | }
|
---|
| 472 |
|
---|
| 473 | my $intTotalErrors = scalar(@{$aryptErrors});
|
---|
| 474 | if ( $strOutputFormat ne "xml" ) {
|
---|
| 475 | print "Checking completed, there is $intTotalErrors error(s) found.\n";
|
---|
| 476 | }
|
---|
| 477 |
|
---|
| 478 | if($gv_blnErrorShow ne "off")
|
---|
| 479 | {
|
---|
| 480 | foreach my $strEachError (@{$aryptErrors})
|
---|
| 481 | {
|
---|
| 482 | if ( $strOutputFormat eq "xml" ) {
|
---|
| 483 | print "<error>";
|
---|
| 484 | print $strEachError;
|
---|
| 485 | print "</error>\n";
|
---|
| 486 | } else {
|
---|
| 487 | print "+---------------------------------------------------------+\n";
|
---|
| 488 | print "| Error |\n";
|
---|
| 489 | print "+---------------------------------------------------------+\n\n";
|
---|
| 490 | print "$strEachError\n\n";
|
---|
| 491 | }
|
---|
| 492 | }
|
---|
| 493 | }
|
---|
| 494 | else
|
---|
| 495 | {
|
---|
| 496 | if ( $strOutputFormat ne "xml" ) {
|
---|
| 497 | print "Use -eshow to show the error detail\n\n";
|
---|
| 498 | }
|
---|
| 499 | }
|
---|
| 500 | }
|
---|
| 501 |
|
---|
| 502 | sub AlignPrint
|
---|
| 503 | {
|
---|
| 504 | my ($strMainString,$strStatus,$intLevel) = @_;
|
---|
| 505 | my $intDot = 100 - length($strMainString) - length($strStatus);
|
---|
| 506 | VobPrint ($strMainString."."x$intDot."$strStatus\n",$intLevel);
|
---|
| 507 | }
|
---|
| 508 |
|
---|
| 509 | sub TestEach
|
---|
| 510 | {
|
---|
| 511 | my ($strModel,$strTest,$intLevel) = @_;
|
---|
| 512 | my @Errors = ();
|
---|
| 513 |
|
---|
| 514 | $intLevel++;
|
---|
| 515 | if (-d $strModel && -d $strTest)
|
---|
| 516 | {
|
---|
| 517 | my @aryInModel = &diffutil::files_in_dir($strModel);
|
---|
| 518 | my @aryInTest = &diffutil::files_in_dir($strTest);
|
---|
| 519 | my @aryTwoPointers = FolderTesting(\@aryInModel,\@aryInTest,$strModel,$strTest,$intLevel);
|
---|
| 520 | my @aryCorrectFiles = @{$aryTwoPointers[1]};
|
---|
| 521 | @Errors = @{$aryTwoPointers[0]};
|
---|
| 522 |
|
---|
| 523 | if(scalar(@Errors) == 0)
|
---|
| 524 | {
|
---|
| 525 | foreach my $strEachFile (@aryInModel)
|
---|
| 526 | {
|
---|
[27536] | 527 | my $strNewModel = &FileUtils::filenameConcatenate($strModel,$strEachFile);
|
---|
| 528 | my $strNewTest = &FileUtils::filenameConcatenate($strTest,$strEachFile);
|
---|
[21711] | 529 | if(!($strEachFile eq "log" || $strEachFile =~ m/\.cfg$/g || $strEachFile =~ m/\.(l|b)db$/g))
|
---|
| 530 | {
|
---|
| 531 | push(@Errors,TestEach($strNewModel,$strNewTest,$intLevel));
|
---|
| 532 | }
|
---|
| 533 | else
|
---|
| 534 | {
|
---|
| 535 | if ( $strOutputFormat eq "xml" ) {
|
---|
| 536 | print "<file-comparision location=\"$strEachFile\" blocked=\"yes\" succeeded=\"yes\"/>";
|
---|
| 537 | } else {
|
---|
| 538 | VobPrint ("Blocked File Report: Test \"$strEachFile\" by using -mode \"init\"\n",$intLevel);
|
---|
| 539 | }
|
---|
| 540 | }
|
---|
| 541 | }
|
---|
| 542 | }
|
---|
| 543 | else
|
---|
| 544 | {
|
---|
| 545 | foreach my $strEachFile (@aryCorrectFiles)
|
---|
| 546 | {
|
---|
[27536] | 547 | my $strNewModel = &FileUtils::filenameConcatenate($strModel,$strEachFile);
|
---|
| 548 | my $strNewTest = &FileUtils::filenameConcatenate($strTest,$strEachFile);
|
---|
[21711] | 549 | if(!($strEachFile eq "log" || $strEachFile =~ m/\.cfg$/g || $strEachFile =~ m/\.(l|b)db$/g))
|
---|
| 550 | {
|
---|
| 551 | push(@Errors,TestEach($strNewModel,$strNewTest,$intLevel));
|
---|
| 552 | }
|
---|
| 553 | }
|
---|
| 554 | }
|
---|
| 555 | if($intLevel == $gv_intVerbosity)
|
---|
| 556 | {
|
---|
| 557 | if(scalar(@Errors) == 0){ AlignPrint("Contents Comparsion","Succeed",$intLevel);}
|
---|
| 558 | else { AlignPrint("Contents Comparsion","Failed",$intLevel);}
|
---|
| 559 | }
|
---|
| 560 | }
|
---|
| 561 | else
|
---|
| 562 | {
|
---|
| 563 | my $strResult = diff $strModel, $strTest, { STYLE => "OldStyle" };
|
---|
| 564 | $strResult = &diffutil::GenerateOutput($strResult,"^<Metadata name=\"lastmodified\">.*</Metadata>\$");
|
---|
| 565 | #$strResult = GeneralOutput($strResult);
|
---|
| 566 | if ( $strOutputFormat eq "xml" ) {
|
---|
| 567 | #
|
---|
| 568 | } else {
|
---|
| 569 | VobPrint ("Comparing Files:\n\"$strModel\"\n\"$strTest\"\n",$intLevel);
|
---|
| 570 | }
|
---|
| 571 | if ($strResult eq "")
|
---|
| 572 | {
|
---|
| 573 | if ( $strOutputFormat eq "xml" ) {
|
---|
| 574 | print "<file-comparison location=\"$strModel\" succeeded=\"yes\"/>\n";
|
---|
| 575 | } else {
|
---|
| 576 | AlignPrint("Comparing File","Succeed",$intLevel);
|
---|
| 577 | }
|
---|
| 578 | }
|
---|
| 579 | else
|
---|
| 580 | {
|
---|
| 581 | my $strOutput = "Difference Report:\n$strResult\n";
|
---|
| 582 | if ( $strOutputFormat eq "xml" ) {
|
---|
| 583 | print "<file-comparison location=\"$strModel\" succeeded=\"no\"><message>";
|
---|
| 584 | } else {
|
---|
| 585 | AlignPrint("Comparing File","Failed",$intLevel);
|
---|
| 586 | }
|
---|
| 587 |
|
---|
| 588 | $result=`file -b $strModel`;
|
---|
| 589 | if ( "$result" =~ "data" ) {
|
---|
| 590 | VobPrint( "These binary files differ", $intLevel );
|
---|
| 591 | } else {
|
---|
| 592 | VobPrint ( "$strOutput" , $intLevel);
|
---|
| 593 | }
|
---|
| 594 |
|
---|
| 595 |
|
---|
| 596 | if ( $strOutputFormat eq "xml" ) {
|
---|
| 597 | print "</message></file-comparison>";
|
---|
| 598 | }
|
---|
| 599 |
|
---|
| 600 | if($gv_blnErrorStop ne "off") { exit; }
|
---|
| 601 | push(@Errors,"File content comparison failed($strModel):\n$strOutput");
|
---|
| 602 | }
|
---|
| 603 | }
|
---|
| 604 |
|
---|
| 605 | return @Errors;
|
---|
| 606 | }
|
---|
| 607 |
|
---|
| 608 |
|
---|
| 609 | sub FolderTesting
|
---|
| 610 | {
|
---|
| 611 | my ($aryptModel,$aryptTest,$strModelFolder,$strTestFolder,$intLevel) = @_;
|
---|
| 612 | my %hashCount = ();
|
---|
| 613 | my @Errors = ();
|
---|
| 614 | my @CorrectFiles = ();
|
---|
| 615 | my @TwoPointers = (\@Errors,\@CorrectFiles);
|
---|
| 616 |
|
---|
| 617 | if ( $strOutputFormat eq "xml" ) {
|
---|
| 618 | #print "<folder-comparison location=\"$strModelFolder\">\n";
|
---|
| 619 | } else {
|
---|
| 620 | VobPrint ("Comparing Folder contents at \"$strModelFolder\"\n",$intLevel);
|
---|
| 621 | }
|
---|
| 622 |
|
---|
| 623 | foreach my $strEachItem (@$aryptModel) {$hashCount{$strEachItem} = 'M'}
|
---|
| 624 | foreach my $strEachItem (@$aryptTest)
|
---|
| 625 | {
|
---|
| 626 | if(defined $hashCount{$strEachItem} && $hashCount{$strEachItem} eq 'M') {$hashCount{$strEachItem} = 'B';}
|
---|
| 627 | else {$hashCount{$strEachItem} = 'T';}
|
---|
| 628 | }
|
---|
| 629 |
|
---|
| 630 | if( scalar(@$aryptModel)==scalar(@$aryptTest) && scalar(@$aryptModel)==scalar(keys %hashCount) )
|
---|
| 631 | {
|
---|
| 632 | if ( $strOutputFormat eq "xml" ) {
|
---|
| 633 | print "<folder-comparison location=\"$strModelFolder\" succeeded=\"yes\"/>\n";
|
---|
| 634 | } else {
|
---|
| 635 | AlignPrint("Folder Comparsion","Succeed",$intLevel);
|
---|
| 636 | }
|
---|
| 637 | return @TwoPointers;
|
---|
| 638 | }
|
---|
| 639 | else
|
---|
| 640 | {
|
---|
| 641 | if ( $strOutputFormat eq "xml" ) {
|
---|
| 642 | print "<folder-comparison location=\"$strModelFolder\" succeeded=\"no\"><message>\n";
|
---|
| 643 | } else {
|
---|
| 644 | AlignPrint("Folder Comparsion","Failed",$intLevel);
|
---|
| 645 | }
|
---|
| 646 |
|
---|
| 647 | foreach my $strEachItem (keys %hashCount)
|
---|
| 648 | {
|
---|
| 649 | if($hashCount{$strEachItem} ne 'B')
|
---|
| 650 | {
|
---|
| 651 | my $strOutput = "";
|
---|
| 652 | my $strReport = "";
|
---|
| 653 |
|
---|
| 654 | if($hashCount{$strEachItem} eq 'M')
|
---|
| 655 | {
|
---|
| 656 | $strOutput = "Difference Found at FolderTesting: \"$strEachItem\" is not found in the Test Collcetion";
|
---|
| 657 | $strReport = "Difference Report: difference found at $strTestFolder";
|
---|
| 658 | }
|
---|
| 659 | elsif($hashCount{$strEachItem} eq 'T')
|
---|
| 660 | {
|
---|
| 661 | $strOutput = "Difference Found at FolderTesting: \"$strEachItem\" is not found in the Model Collcetion";
|
---|
| 662 | $strReport = "Difference Report: difference found at $strModelFolder";
|
---|
| 663 | }
|
---|
| 664 | else {die "Error occours in diffcol_mk2::TestingFolder\n"}
|
---|
| 665 |
|
---|
| 666 | VobPrint ("$strOutput\n",$intLevel);
|
---|
| 667 | $strOutput = $strOutput."\n\t".$strReport."\n";
|
---|
| 668 | push(@Errors,$strOutput);
|
---|
| 669 | }
|
---|
| 670 | else {push(@CorrectFiles,$strEachItem);}
|
---|
| 671 | }
|
---|
| 672 | if( $strOutputFormat eq "xml" ) {
|
---|
| 673 | print "</message></folder-comparison>";
|
---|
| 674 | }
|
---|
| 675 |
|
---|
| 676 | return @TwoPointers;
|
---|
| 677 | }
|
---|
| 678 | }
|
---|
| 679 |
|
---|
| 680 | sub VobPrint
|
---|
| 681 | {
|
---|
| 682 | my ($strOutput, $intLevel) = @_;
|
---|
| 683 | my $strTab = "";
|
---|
| 684 | my $intTab = int($intLevel/2);
|
---|
| 685 | if($intLevel <= $gv_intVerbosity)
|
---|
| 686 | {
|
---|
| 687 | if($intLevel >= 1)
|
---|
| 688 | {
|
---|
| 689 | $strTab = "\t"x($intTab+1);
|
---|
| 690 | $strOutput =~ s/\n$//;
|
---|
| 691 | $strOutput =~ s/\n/\n$strTab/g;
|
---|
| 692 | #$strTab =~ s/"\n"/"\n"."\t"x($intTab+1)/g;
|
---|
| 693 | }
|
---|
| 694 |
|
---|
| 695 | if( $strOutputFormat eq "xml" ) {
|
---|
| 696 | $strOutput =~ s/&/&/g;
|
---|
| 697 | $strOutput =~ s/</</g;
|
---|
| 698 | $strOutput =~ s/>/>/g;
|
---|
| 699 | }
|
---|
| 700 |
|
---|
| 701 | if ( length( $strOutput ) > 1000 ) {
|
---|
| 702 | $strOutput = substr( $strOutput, 0, 978) . "... (output truncated)";
|
---|
| 703 | }
|
---|
| 704 |
|
---|
| 705 |
|
---|
| 706 | print $strTab.$strOutput."\n";
|
---|
| 707 | }
|
---|
| 708 | }
|
---|
| 709 | #----##
|
---|
| 710 |
|
---|
| 711 |
|
---|
| 712 | #--Main System----------------------------
|
---|
| 713 | #-----------------------------------------
|
---|
| 714 | # Name: main
|
---|
| 715 | # Perameters: arguments from command line
|
---|
| 716 | # Pre-condition: testing will start by calling this main function.
|
---|
| 717 | # Post-condition: output the test results for one or more collections.
|
---|
| 718 | #-----------------------------------------
|
---|
| 719 | sub main
|
---|
| 720 | {
|
---|
| 721 | my ($intVerbosity,$strErrorStop,$strErrorShow,$strMode);
|
---|
| 722 | my $strProgName = $0;
|
---|
| 723 | my $intArgc = scalar(@ARGV);
|
---|
| 724 |
|
---|
| 725 | #--System Arguments Setup
|
---|
| 726 | if (!parsargv::parse(\@ARGV,
|
---|
| 727 | 'estop//off', \$strErrorStop,
|
---|
| 728 | 'eshow//off', \$strErrorShow,
|
---|
| 729 | 'verbosity/\d+/1', \$intVerbosity,
|
---|
| 730 | 'mode/[\w\-]+/all', \$strMode,
|
---|
| 731 | 'output/[\w\-]+/text', \$strOutputFormat
|
---|
| 732 | )) {
|
---|
| 733 | PrintUsage($strProgName);
|
---|
| 734 | die "\n";
|
---|
| 735 | }
|
---|
| 736 |
|
---|
| 737 | if ($intArgc<1) {
|
---|
| 738 | PrintUsage($strProgName);
|
---|
| 739 | die "\n";
|
---|
| 740 | }
|
---|
| 741 |
|
---|
| 742 | $gv_blnErrorStop = $strErrorStop;
|
---|
| 743 | $gv_blnErrorShow = $strErrorShow;
|
---|
| 744 | $gv_intVerbosity = $intVerbosity;
|
---|
| 745 | $gv_strMode = SetMode($strMode);
|
---|
| 746 |
|
---|
| 747 | #----##
|
---|
| 748 |
|
---|
| 749 | #--Collection(s) Testing
|
---|
| 750 | foreach $strColName (@ARGV)
|
---|
| 751 | {
|
---|
| 752 | my @ErrorsInEachCol;
|
---|
[27536] | 753 | my $strModelCol = &FileUtils::filenameConcatenate($gv_strModelColRoot,$strColName);
|
---|
| 754 | my $strTestCol = &FileUtils::filenameConcatenate($gv_strTestColRoot,$strColName);
|
---|
[21711] | 755 |
|
---|
| 756 | #--Output(Start)
|
---|
| 757 | OutputStart($strColName);
|
---|
| 758 | #----##
|
---|
| 759 |
|
---|
| 760 | if(-e $strModelCol && -e $strTestCol )
|
---|
| 761 | {
|
---|
| 762 |
|
---|
| 763 | #--Individual Testing
|
---|
| 764 | if ($gv_strMode eq "Individual")
|
---|
| 765 | {
|
---|
| 766 | @ErrorsInEachCol = IndivTest($strModelCol,$strTestCol);
|
---|
| 767 | }
|
---|
| 768 | #----##
|
---|
| 769 |
|
---|
| 770 | #--Initial Testing
|
---|
| 771 | elsif ($gv_strMode eq "Initial")
|
---|
| 772 | {
|
---|
| 773 | @ErrorsInEachCol = InitTest($strModelCol,$strTestCol,$strColName);
|
---|
| 774 | }
|
---|
| 775 | #----##
|
---|
| 776 |
|
---|
| 777 | #--Full Testing
|
---|
| 778 | elsif ($gv_strMode eq "Full")
|
---|
| 779 | {
|
---|
| 780 | @ErrorsInEachCol = FullTest($strModelCol,$strTestCol,$strColName);
|
---|
| 781 | }
|
---|
| 782 | #----##
|
---|
| 783 |
|
---|
| 784 | #--Error Checking
|
---|
| 785 | else
|
---|
| 786 | {
|
---|
| 787 | if ( $strOutputFormat eq "xml" ) {
|
---|
| 788 | die "<error>Error occoured in main function</error>\n";
|
---|
| 789 | } else {
|
---|
| 790 | die "Error occoured in main function.\n";
|
---|
| 791 | }
|
---|
| 792 | }
|
---|
| 793 | #----##
|
---|
| 794 |
|
---|
| 795 | }
|
---|
| 796 | else
|
---|
| 797 | {
|
---|
| 798 | if( $strOutputFormat eq "xml" ) {
|
---|
| 799 | die "<error>Cannot find collection: $strColName</error>\n";
|
---|
| 800 | } else {
|
---|
| 801 | die "Error: cannot find collection: $strColName\n";
|
---|
| 802 | }
|
---|
| 803 | }
|
---|
| 804 | #----##
|
---|
| 805 |
|
---|
| 806 | #--Output(Results and Errors)
|
---|
| 807 | OutputEnd($strColName,\@ErrorsInEachCol);
|
---|
| 808 | #----##
|
---|
| 809 |
|
---|
| 810 | }
|
---|
| 811 | }
|
---|
| 812 | #----##
|
---|
| 813 |
|
---|
| 814 | &main();
|
---|