IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1490


Ignore:
Timestamp:
Aug 11, 2004, 1:42:49 PM (22 years ago)
Author:
desonia
Message:

ran perltidy on the scripts to format it to approximately the perlstyle
guidelines.

Location:
trunk/psLib/test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/FullUnitTest

    r1404 r1490  
    1919#  RETURN : integer number of tests which failed
    2020#
    21 #  $Revision: 1.11 $  $Name: not supported by cvs2svn $
    22 #  $Date: 2004-08-06 21:50:13 $
     21#  $Revision: 1.12 $  $Name: not supported by cvs2svn $
     22#  $Date: 2004-08-11 23:42:49 $
    2323#
    2424#  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3535# The ! option allows for --nooption to be set to zero
    3636# (e.g. --noverbose --recursive causes $verbose=0 and $recursive=1)
    37 GetOptions("verbose!"=>\$verbose,
    38            "recursive!"=>\$recursive,
    39            "silent!"=>\$silent,
    40            "clean!"=>\$clean);
     37GetOptions(
     38    "verbose!"   => \$verbose,
     39    "recursive!" => \$recursive,
     40    "silent!"    => \$silent,
     41    "clean!"     => \$clean
     42);
    4143
    4244# Check if both silent and verbose options are set and if so stop the script
    43 die "Can't specify both verbose and silent options." if ($verbose && $silent);
     45die "Can't specify both verbose and silent options." if ( $verbose && $silent );
    4446
    4547# Set up the PSLIB_ROOT environment variable if the user doesn't have
    46 if (! $ENV{'PSLIB_ROOT'})  {
     48if ( !$ENV{'PSLIB_ROOT'} ) {
     49
    4750    # Use the directory directly above where FullUnitTest script resides
    4851    $PSLIB_ROOT = `cd ..;pwd`;
     52
    4953    # Remove newline for the end of path returned
    5054    chomp($PSLIB_ROOT);
     55
    5156    # Set the environment variable
    5257    $ENV{'PSLIB_ROOT'} = $PSLIB_ROOT;
     
    5661# add PSLIB_ROOT/lib to LD_LIBRARY_PATH and DYLD_LIBRARY_PATH environment
    5762# variables
    58 $ENV{'LD_LIBRARY_PATH'} = "$ENV{'PSLIB_ROOT'}/lib:$ENV{'LD_LIBRARY_PATH'}";
     63$ENV{'LD_LIBRARY_PATH'}   = "$ENV{'PSLIB_ROOT'}/lib:$ENV{'LD_LIBRARY_PATH'}";
    5964$ENV{'DYLD_LIBRARY_PATH'} = "$ENV{'PSLIB_ROOT'}/lib:$ENV{'DYLD_LIBRARY_PATH'}";
    6065
    6166# Initialize variables for counting the makes and test failures and the
    6267# total makes and tests performed
    63 $makeFailCount = 0;
    64 $testpointFailCount = 0;
     68$makeFailCount       = 0;
     69$testpointFailCount  = 0;
    6570$testDriverFailCount = 0;
    66 $totalTestpoints = 0;
    67 $totalTestDrivers = 0;
    68 $totalMakes = 0;
     71$totalTestpoints     = 0;
     72$totalTestDrivers    = 0;
     73$totalMakes          = 0;
    6974
    7075# Initialize variable indicating how many arguements were passed
     
    7378# Loop through all the arguements passed to the script
    7479foreach (@ARGV) {
     80
    7581    # Remove newline if there is one
    7682    chomp;
     83
    7784    # Increment number of arguements found
    7885    $args++;
     86
    7987    # Set variable to current working directory
    8088    $cwd = cwd;
     89
    8190    # Change directory to the directory of the arguement
    8291    chdir($_);
     92
    8393    # Check for the recursive option
    8494    if ($recursive) {
     95
    8596        # Invoke subroutine to go to the lowest directory in tree
    8697        # starting at the specified directory
    8798        &worm($_);
    88     } else {
     99    }
     100    else {
     101
    89102        # Invoke subroutines to run the test at the specified directory
    90103        &makeTestDrivers($_);
    91104        &executeTestDrivers($_);
    92105    }
     106
    93107    # Change directory back to the directory where FullUnitTest was invoked
    94108    chdir($cwd);
     
    96110
    97111# Check if there were no arguements specified
    98 if ($args == 0){
     112if ( $args == 0 ) {
     113
    99114    # Display message to user that all directories under the current will be
    100115    # tested
    101116    print("Recursively testing current directory tree.\n") if $verbose;
     117
    102118    # Invoke subroutine to go to recursively test each directory in tree
    103     &worm($ENV{"PWD"});
     119    &worm( $ENV{"PWD"} );
    104120}
    105121
    106122# Check if there were any failures during make or testing
    107 if ($makeFailCount>0 || $testDriverFailCount>0) {
     123if ( $makeFailCount > 0 || $testDriverFailCount > 0 ) {
     124
    108125    # Display summary of failures
    109126    print("\nMake Failures = $makeFailCount out of $totalMakes");
    110127    print("\nTest Driver Failures = $testDriverFailCount out of $totalTestDrivers\n");
    111     print("\nMakes that failed:\n  ".join("\n  ",@makesFailed) . "\n") if $makeFailCount;
    112     print("\nTests that failed:\n  ".join("\n  ",@testsFailed) . "\n") if $testDriverFailCount;
    113 } else {
     128    print( "\nMakes that failed:\n  " . join( "\n  ", @makesFailed ) . "\n" ) if $makeFailCount;
     129    print( "\nTests that failed:\n  " . join( "\n  ", @testsFailed ) . "\n" ) if $testDriverFailCount;
     130}
     131else {
     132
    114133    # Display message of all makes and tests pass to user if silent option
    115134    # not specified
    116     print("\nAll $totalTestDrivers Test Drivers Passed with $totalTestpoints Testpoints.\n") if (! $silent);
     135    print("\nAll $totalTestDrivers Test Drivers Passed with $totalTestpoints Testpoints.\n") if ( !$silent );
    117136}
    118137
     
    120139exit($testDriverFailCount);
    121140
    122 
    123141################################################################################
    124142#
     
    127145#     Description:  This subroutine will perform the necessary unit tests be
    128146#                   calling makeTestDrivers and executeTestDrivers  subroutines
    129 #                   and then check each subdirectory below the base directory 
     147#                   and then check each subdirectory below the base directory
    130148#                   recursively.
    131149#
     
    137155
    138156sub worm {
     157
    139158    # Assign local variable to input parameter
    140     local($base_dir) = @_;
    141     local(@files, $i);
     159    local ($base_dir) = @_;
     160    local ( @files, $i );
    142161
    143162    # Invoke subroutine to make test driver in the base directory
     
    153172    # labelled CVS and recursively invoke subroutine worm
    154173    $i = 0;
    155     while ($files[$i]) {
     174    while ( $files[$i] ) {
     175
    156176        # Check for directory and directory not labelled CVS
    157         if (-d $files[$i] && ($files[$i] ne "CVS") && ($files[$i] ne "temp")
    158                           && ($files[$i] ne "verified")) {
     177        if (   -d $files[$i]
     178            && ( $files[$i] ne "CVS" )
     179            && ( $files[$i] ne "temp" )
     180            && ( $files[$i] ne "verified" ) )
     181        {
     182
    159183            # Change current directory to directory found
    160             chdir($files[$i]);
     184            chdir( $files[$i] );
     185
    161186            # Invoke subroutine worm again
    162             &worm($files[$i]);
     187            &worm( $files[$i] );
     188
    163189            # Change current directory back to parent
    164190            chdir("..");
    165191        }
     192
    166193        # Increment file list index
    167194        $i++;
     
    183210################################################################################
    184211
    185 sub makeTestDrivers{
    186     local($base_dir) = @_;
    187     local($pwd);
     212sub makeTestDrivers {
     213    local ($base_dir) = @_;
     214    local ($pwd);
    188215
    189216    # Set variable pwd to current working directory
     
    192219    # Display message to user in which directory testing is taken place only
    193220    # if the silent command option was not specified
    194     print("---- Entering $pwd ----\n") if ( ! $silent);
     221    print("---- Entering $pwd ----\n") if ( !$silent );
    195222
    196223    # Check for the existence of a file name Makefile in current directory
    197     if (-e "Makefile") {
     224    if ( -e "Makefile" ) {
    198225
    199226        # Increment the total number of makes executed
    200227        $totalMakes++;
    201228
    202         if ($clean) {
     229        if ($clean) {
     230
    203231            # Execute the make clean
    204232            `make clean`;
     
    209237
    210238        # Execute the make and save results
    211         $_ = join("\n|| ",split("\n", "\n" . `make`) );
     239        $_ = join( "\n|| ", split( "\n", "\n" . `make` ) );
    212240
    213241        # Check the output of make for return value != 0 or any of the
    214242        # following words: FAILED, FAULT, ERROR, Not found, SIGNAL
    215         if (($? != 0) || m/FAILED/i || m/FAULT/i || m/\bERROR/i
    216                       || m/Not found/i || m/SIGNAL/i) {
     243        if (   ( $? != 0 )
     244            || m/FAILED/i
     245            || m/FAULT/i
     246            || m/\bERROR/i
     247            || m/Not found/i
     248            || m/SIGNAL/i )
     249        {
     250
    217251            # Display the errored output of make if silent option not enabled
    218             print("$_\n") if ( ! $silent );
     252            print("$_\n") if ( !$silent );
     253
    219254            # Display the make failed in the current directory
    220255            print("\nMake for $pwd Failed\n");
     256
    221257            # Increment the number of makes that have failed
    222258            $makeFailCount++;
     259
    223260            # Push the current working directory onto the list of failed
    224261            # make directories list
    225             push(@makesFailed, $pwd);
    226         } else {
     262            push( @makesFailed, $pwd );
     263        }
     264        else {
     265
    227266            # Display the results of the successful make if verbose option set
    228267            print("$_\n") if $verbose;
     268
    229269            # Display the make was successful if silent option not set
    230             print("\nMake successful.\n") if ( ! $silent);
     270            print("\nMake successful.\n") if ( !$silent );
    231271            if ($clean) {
    232272                `make install`;
     
    248288################################################################################
    249289
    250 sub executeTestDrivers{
    251     local($base_dir) = @_;
    252     local(@files,$j);
    253     local($pwd);
    254     local($exitValue) = 0;
     290sub executeTestDrivers {
     291    local ($base_dir) = @_;
     292    local ( @files, $j );
     293    local ($pwd);
     294    local ($exitValue) = 0;
    255295
    256296    # Set variable to pwd to current test directory
     
    262302    # Loop through all the items in the files array
    263303    $initialTest = 0;
    264     $j = 0;
    265     while ( $files[$j]) {
     304    $j           = 0;
     305    while ( $files[$j] ) {
     306
    266307        # Check that the item is not a directory and is executable and
    267308        # conforms to the test driver naming convention TST
    268         if ( ! (-d $files[$j]) && (-x $files[$j]) &&
    269              ( $files[$j] =~ /^TST/i || $files[$j] =~ /^ATST/i ) ) {
     309        if (   !( -d $files[$j] )
     310            && ( -x $files[$j] )
     311            && ( $files[$j] =~ /^TST/i || $files[$j] =~ /^ATST/i ) )
     312        {
    270313
    271314            # Increment total number of test drivers executed
     
    283326                # Check for the presence of verified directory
    284327                if ( &checkForVerifiedDirectory() ) {
    285            
    286                     # Display message to user that verified directories do not 
     328
     329                    # Display message to user that verified directories do not
    287330                    # exist eventhough TST files have been found
    288 #                    print("Unable to execute test drivers in $base_dir\n");
     331                    #                    print("Unable to execute test drivers in $base_dir\n");
    289332                    print("No verified subdirectory present.\n") if ($verbose);
     333
    290334                    # Increment test fail count
    291  #                   $testDriverFailCount++;
     335                    #                   $testDriverFailCount++;
    292336                    # Save the file failed
    293 #                    push(@testsFailed, $pwd . "/" . $files[$j]);
    294 #                    return;
     337                    #                    push(@testsFailed, $pwd . "/" . $files[$j]);
     338                    #                    return;
    295339                }
    296340            }
    297341
    298342            # Display message to user of which test driver is being executed
    299             print("--- Executing test driver $files[$j]\n") if ( ! $silent );
     343            print("--- Executing test driver $files[$j]\n") if ( !$silent );
     344
    300345            # Execute the test driver
    301346            system("./$files[$j] 1> temp/$files[$j].stdout 2> temp/$files[$j].stderr");
    302347            $retVal = $?;
     348
    303349            # Count testpoints
    304             $testPattern = "\"\\*\\*\\*\\* TESTPOINT \\*\\*\\*\\*\"";
     350            $testPattern = "\"\\*\\*\\*\\* TESTPOINT \\*\\*\\*\\*\"";
    305351            $totalPoints = `grep -c $testPattern temp/$files[$j].stdout`;
    306352            $totalPoints += `grep -c $testPattern temp/$files[$j].stderr`;
    307353            $failPoints = `grep "> TESTPOINT FAILED" temp/$files[$j].stdout | wc -l`;
    308             $failPoints += `grep "> TESTPOINT FAILED" temp/$files[$j].stderr | wc -l`;
     354            $failPoints         += `grep "> TESTPOINT FAILED" temp/$files[$j].stderr | wc -l`;
    309355            $testpointFailCount += $failPoints;
    310             $totalTestpoints += $totalPoints;
     356            $totalTestpoints    += $totalPoints;
     357
    311358            # Check result of test driver
    312             if ( ( ($retVal != 0) && ($files[$j] =~ /^TST/i) ) ||
    313                  ( ($retVal == 0) && ($files[$j] =~ /^ATST/i ) ) ) {
     359            if (   ( ( $retVal != 0 ) && ( $files[$j] =~ /^TST/i ) )
     360                || ( ( $retVal == 0 ) && ( $files[$j] =~ /^ATST/i ) ) )
     361            {
     362
    314363                # Display test driver failed
    315364                $failPoints++;
    316365                print("Test driver: $files[$j] Failed (Return value $retVal).\n");
     366
    317367                # Increment the total number of test failed
    318368                $testDriverFailCount++;
     369
    319370                # Push the current working directory on the list of failed
    320                 push(@testsFailed, $pwd . "/" . $files[$j]);
    321             } else {
     371                push( @testsFailed, $pwd . "/" . $files[$j] );
     372            }
     373            else {
     374
    322375                # Create filter versions of STDOUT and STDERR to replace variable
    323376                # items such as date, time and host
    324                 &filterStdFiles($files[$j]);
     377                &filterStdFiles( $files[$j] );
     378
    325379                # Perform difference on STDOUT file collected
    326380                # with verified files
    327381                $exitValue = &compareStream("verified/$files[$j].stdout");
    328382                if ( $exitValue & 2 ) {
     383
    329384                    # STDOUT verified doesn't exist. Search STDOUT capture
    330385                    # for strings indicating error or failure
    331386                    $exitValue |= &errorStrSearch("$files[$j].stdout");
    332387                }
    333                 if ( ($exitValue & 8) || ($exitValue & 64) ) {
     388                if ( ( $exitValue & 8 ) || ( $exitValue & 64 ) ) {
     389
    334390                    # Increment the total number of test failed
    335391                    $testDriverFailCount++;
     392
    336393                    # Push test on failed list
    337                     print("Test failed ($failPoints out of $totalPoints testpoints failed)\n") if ( ! $silent);
    338                     push(@testsFailed, $pwd . "/" . $files[$j]);
    339                 } else {
     394                    print("Test failed ($failPoints out of $totalPoints testpoints failed)\n")
     395                      if ( !$silent );
     396                    push( @testsFailed, $pwd . "/" . $files[$j] );
     397                }
     398                else {
     399
    340400                    # Perform difference on STDERR file collection with verified
    341401                    $exitValue = &compareStream("verified/$files[$j].stderr");
    342402                    if ( $exitValue & 4 ) {
     403
    343404                        # STDERR verified doesn't exist. Search STDERR capture
    344405                        # for strings indicating error or failure
    345406                        $exitValue |= &errorStrSearch("$files[$j].stderr");
    346407                    }
    347                     if ( ($exitValue & 16) || ($exitValue & 128) ) {
     408                    if ( ( $exitValue & 16 ) || ( $exitValue & 128 ) ) {
     409
    348410                        # Increment the total number of tests failed
    349411                        $testDriverFailCount++;
     412
    350413                        # Push test on failed list
    351                         print("Test failed ($failPoints out of $totalPoints testpoints failed)\n") if ( ! $silent);
    352                         push(@testsFailed, $pwd . "/" . $files[$j]);
    353                     } else {
    354                        print("Test successful ($totalPoints testpoints)\n") if ( ! $silent);
     414                        print("Test failed ($failPoints out of $totalPoints testpoints failed)\n")
     415                          if ( !$silent );
     416                        push( @testsFailed, $pwd . "/" . $files[$j] );
     417                    }
     418                    else {
     419                        print("Test successful ($totalPoints testpoints)\n") if ( !$silent );
    355420                    }
    356421                }
     
    378443
    379444sub errorStrSearch {
    380     local($fileName) = @_;
    381     local($returnVal) = 0;
     445    local ($fileName) = @_;
     446    local ($returnVal) = 0;
    382447
    383448    # Open the captured file
    384     open(CAPT_FILE, "<temp/$fileName");
     449    open( CAPT_FILE, "<temp/$fileName" );
    385450
    386451    # Scan through all the lines of the file searching for error strings
    387     while ( <CAPT_FILE> ) {
    388         if ( m/FAIL/i || m/FAULT/i || m/ERROR/i || m/Not Found/i
    389                       || m/SIGNAL/i || m/NO SUCH FILE/i || m/\|E\|/i
    390                       || m/\|A\|/i ) {
     452    while (<CAPT_FILE>) {
     453        if (   m/FAIL/i
     454            || m/FAULT/i
     455            || m/ERROR/i
     456            || m/Not Found/i
     457            || m/SIGNAL/i
     458            || m/NO SUCH FILE/i
     459            || m/\|E\|/i
     460            || m/\|A\|/i )
     461        {
    391462            print;
    392463            if ( $fileName =~ m/out/ ) {
    393464                print("        Failed - File $fileName contains error strings.\n");
    394465                $returnVal = 64;
    395             } elsif ( $fileName =~ m/err/ ) {
     466            }
     467            elsif ( $fileName =~ m/err/ ) {
    396468                print("        Failed - File $fileName contains error strings.\n");
    397469                $returnVal = 128;
     
    400472        }
    401473    }
     474
    402475    # Close the capture file
    403476    close(CAPT_FILE);
     477
    404478    # Return the return value
    405     return($returnVal);
     479    return ($returnVal);
    406480}
    407481
     
    424498
    425499sub compareStream {
    426     local($streamFile) = @_;
    427     local($returnVal) = 0;
    428     local($tempFile) = "";
     500    local ($streamFile) = @_;
     501    local ($returnVal) = 0;
     502    local ($tempFile)  = "";
    429503
    430504    # Check for existence of verified STD stream files
    431     if ( !( -e $streamFile) ) {
     505    if ( !( -e $streamFile ) ) {
    432506
    433507        # Display message to user that verified STDOUT file doesn't exist
     
    437511        if ( $streamFile =~ /out$/ ) {
    438512            $returnVal |= 2;
    439         } elsif ( $streamFile =~ /err$/ ) {
     513        }
     514        elsif ( $streamFile =~ /err$/ ) {
    440515            $returnVal |= 4;
    441516        }
    442     } else {
     517    }
     518    else {
    443519
    444520        # Verified STD stream file exists
     
    459535            # Check for STDOUT in file name to convey appropirate return value
    460536            if ( $streamFile =~ /out$/ ) {
    461                # Display message of the failure of difference to user
    462                print("        Failed - STDOUT difference\n$diffstdout\n");
    463 
    464                # Exit value to indicate STDOUT did not compare
    465                $returnVal |= 8;
    466             } elsif ( $streamFile =~ /err$/ ) {
    467                # Display message of the failure of difference to user
    468                print("        Failed - STDERR difference\n$diffstdout\n");
    469 
    470                # Exit value to indicate STDERR did not compare
    471                $returnVal |= 16;
     537
     538                # Display message of the failure of difference to user
     539                print("        Failed - STDOUT difference\n$diffstdout\n");
     540
     541                # Exit value to indicate STDOUT did not compare
     542                $returnVal |= 8;
     543            }
     544            elsif ( $streamFile =~ /err$/ ) {
     545
     546                # Display message of the failure of difference to user
     547                print("        Failed - STDERR difference\n$diffstdout\n");
     548
     549                # Exit value to indicate STDERR did not compare
     550                $returnVal |= 16;
    472551            }
    473552        }
     
    475554
    476555    # Return the result of the compare
    477     return($returnVal);
    478 }
    479 
     556    return ($returnVal);
     557}
    480558
    481559################################################################################
     
    493571################################################################################
    494572
    495 sub checkForTempDirectory{
     573sub checkForTempDirectory {
    496574
    497575    # Check if a temp directory already exists in the current work directory
    498     if ( !( -e "temp" )) {
     576    if ( !( -e "temp" ) ) {
     577
    499578        # Create temp directory to store STDOUT, STDERR files during test
    500579        `mkdir temp`;
     580
    501581        # Display message of new directory created
    502         print("Creating temp directory\n") if ( $verbose );
     582        print("Creating temp directory\n") if ($verbose);
    503583    }
    504584}
     
    519599################################################################################
    520600
    521 sub checkForVerifiedDirectory{
     601sub checkForVerifiedDirectory {
    522602    $returnValue = 0;
     603
    523604    # Check if verified subdirectory exists in the current working directory
    524     if ( !( -e "verified")) {
    525        # Set return value to 1
    526        $returnValue = 1;
    527     }
    528     return($returnValue);
     605    if ( !( -e "verified" ) ) {
     606
     607        # Set return value to 1
     608        $returnValue = 1;
     609    }
     610    return ($returnValue);
    529611}
    530612
     
    543625################################################################################
    544626
    545 sub filterStdFiles{
    546 
    547    local($fileName) = @_;
    548 
    549    # Open the STDOUT file for reading
    550    open(OUTFILE, "< temp/$fileName.stdout");
    551    # Open mod file to place filtered STDOUT
    552    open(MODFILE, "> temp/$fileName.stdout.mod");
    553    # Replace the variable data, time and host information with constants
    554    $hostname = `hostname`;
    555    chop $hostname;
    556    while( <OUTFILE> ) {
    557        s/\s+\d+:\d+:\d+\w/<TIME>/g;
    558        s/\d+:\d+:\d+/<DATE>/g;
    559        s/$hostname/<HOST>/g;
    560        s/: Line \d+/: Line <LINENO>/g;
    561        s/\:\d+/\:<LINENO>/g;
    562        # Filter lines with *** malloc.  This is an artifact of Mac testing of
    563        # memory functions
    564        if ( ! m/\*\*\*\smalloc/ ) {
    565           print MODFILE ($_);
    566        }
    567    }
    568    # Close mod file
    569    close(MODFILE);
    570    # Close STDERR file
    571    close(OUTFILE);
    572 
    573    # Open the STDERR file for reading
    574    open(OUTFILE, "< temp/$fileName.stderr");
    575    # Open mod file to place filtered STDERR
    576    open(MODFILE, "> temp/$fileName.stderr.mod");
    577    # Replace the variable date, time and host information with constants
    578    while( <OUTFILE> ) {
    579        s/\s+\d+:\d+:\d+\w/<TIME>/g;
    580        s/\d+:\d+:\d+/<DATE>/g;
    581        s/$hostname/<HOST>/g;
    582        s/: Line \d+/: Line <LINENO>/g;
    583        s/\:\d+/\:<LINENO>/g;
    584        # Filter lines with *** malloc.  This is an artifact of Mac testing of
    585        # memory functions
    586        if ( ! m/\*\*\*\smalloc/ ) {
    587           print MODFILE ($_);
    588        }
    589    }
    590    # Close mod file
    591    close(MODFILE);
    592    # Close STDERR file
    593    close(OUTFILE);
    594 }
    595 
     627sub filterStdFiles {
     628
     629    local ($fileName) = @_;
     630
     631    # Open the STDOUT file for reading
     632    open( OUTFILE, "< temp/$fileName.stdout" );
     633
     634    # Open mod file to place filtered STDOUT
     635    open( MODFILE, "> temp/$fileName.stdout.mod" );
     636
     637    # Replace the variable data, time and host information with constants
     638    $hostname = `hostname`;
     639    chop $hostname;
     640    while (<OUTFILE>) {
     641        s/\s+\d+:\d+:\d+\w/<TIME>/g;
     642        s/\d+:\d+:\d+/<DATE>/g;
     643        s/$hostname/<HOST>/g;
     644        s/: Line \d+/: Line <LINENO>/g;
     645        s/\:\d+/\:<LINENO>/g;
     646
     647        # Filter lines with *** malloc.  This is an artifact of Mac testing of
     648        # memory functions
     649        if ( !m/\*\*\*\smalloc/ ) {
     650            print MODFILE ($_);
     651        }
     652    }
     653
     654    # Close mod file
     655    close(MODFILE);
     656
     657    # Close STDERR file
     658    close(OUTFILE);
     659
     660    # Open the STDERR file for reading
     661    open( OUTFILE, "< temp/$fileName.stderr" );
     662
     663    # Open mod file to place filtered STDERR
     664    open( MODFILE, "> temp/$fileName.stderr.mod" );
     665
     666    # Replace the variable date, time and host information with constants
     667    while (<OUTFILE>) {
     668        s/\s+\d+:\d+:\d+\w/<TIME>/g;
     669        s/\d+:\d+:\d+/<DATE>/g;
     670        s/$hostname/<HOST>/g;
     671        s/: Line \d+/: Line <LINENO>/g;
     672        s/\:\d+/\:<LINENO>/g;
     673
     674        # Filter lines with *** malloc.  This is an artifact of Mac testing of
     675        # memory functions
     676        if ( !m/\*\*\*\smalloc/ ) {
     677            print MODFILE ($_);
     678        }
     679    }
     680
     681    # Close mod file
     682    close(MODFILE);
     683
     684    # Close STDERR file
     685    close(OUTFILE);
     686}
     687
  • trunk/psLib/test/runTest

    r1404 r1490  
    66#  deemed a failure.  STDOUT and STDERR files will be place in a subdirectory
    77#  named temp and the files will be compared with verified STDOUT, STDERR files
    8 #  in a subdirectory named verified.  If there are no STDOUT, STDERR files in 
     8#  in a subdirectory named verified.  If there are no STDOUT, STDERR files in
    99#  the verified directory, the captured STDOUT, STDERR files will be scanned
    1010#  for words which indicate a failure.
    1111#
    12 #  Assumptions:  A verified subdirectory with STDOUT, STDERR files exists for 
     12#  Assumptions:  A verified subdirectory with STDOUT, STDERR files exists for
    1313#                the test driver specified in the arguements if an exact
    1414#                match of the streams STDOUT, STDERR is necessary.
     
    3030#
    3131#  $Revison:  $  $Name: not supported by cvs2svn $
    32 #  $Date: 2004-08-06 21:50:13 $
     32#  $Date: 2004-08-11 23:42:49 $
    3333#
    3434#  Copyright 2004 Maui High Performance Computering Center, University of Hawaii
     
    4040
    4141# Assign variables based on the presence of command line options to the script
    42 GetOptions("reset!"=>\$reset,
    43            "resetStderr!"=>\$resetStderr,
    44            "resetStdout!"=>\$resetStdout,
    45            "help!"=>\$help);
     42GetOptions(
     43    "reset!"       => \$reset,
     44    "resetStderr!" => \$resetStderr,
     45    "resetStdout!" => \$resetStdout,
     46    "help!"        => \$help
     47);
    4648
    4749if ($help) {
     
    5456    $resetStdout = 1;
    5557}
    56    
     58
    5759# Initialize exit value
    5860$exitValue = 0;
    5961
    6062# Set up the PSLIB_ROOT environment variable if the user doesn't have it set
    61 if ( ! $ENV{'PSLIB_ROOT'}) {
     63if ( !$ENV{'PSLIB_ROOT'} ) {
     64
    6265    # Use the directory directly above test
    6366    $PSLIB_ROOT = `cd ..;pwd`;
     67
    6468    # Remove newline for the end of path returned
    6569    chomp($PSLIB_ROOT);
     70
    6671    # Set the environment variable
    6772    $ENV{'PSLIB_ROOT'} = $PSLIB_ROOT;
    68     # Display message that PSLIB_ROOT not found and set to
     73
     74    # Display message that PSLIB_ROOT not found and set to
    6975    print("PSLIB_ROOT not found: set to $PSLIB_ROOT\n");
    7076}
    7177
    7278# Add PSLIB_ROOT/lib to LD_LIBRARY_PATH and DYLD_LIBRARY_PATH environment vars
    73 $ENV{'LD_LIBRARY_PATH'} = "$ENV{'PSLIB_ROOT'}/lib:$ENV{'LD_LIBRARY_PATH'}";
     79$ENV{'LD_LIBRARY_PATH'}   = "$ENV{'PSLIB_ROOT'}/lib:$ENV{'LD_LIBRARY_PATH'}";
    7480$ENV{'DYLD_LIBRARY_PATH'} = "$ENV{'PSLIB_ROOT'}/lib:$ENV{'DYLD_LIBRARY_PATH'}";
    7581
     
    8086
    8187    # Check if a temp directory already exists in the current work directory
    82     if ( !( -e "temp" )) {
    83     # Create temp directory to store STDOUT, STDERR files during test run
    84     `mkdir temp`;
    85     # Display message of new directory created
    86     print("Creating temp directory\n");
    87     }
    88    
     88    if ( !( -e "temp" ) ) {
     89
     90        # Create temp directory to store STDOUT, STDERR files during test run
     91        `mkdir temp`;
     92
     93        # Display message of new directory created
     94        print("Creating temp directory\n");
     95    }
     96
    8997    # Check if a verified directory exists in the current work directory
    90     if ( !( -e "verified" )) {
     98    if ( !( -e "verified" ) ) {
     99
    91100        # Display message that verified subdirectory doesn't exist
    92101        print("        Verified directory doesn't exist.\n");
     102
    93103        # Exit script since the test cannot be run with verified files
    94104        $exitValue = 1;
    95105    }
    96    
     106
    97107    # Check if the test driver file exists and is executable
    98     if ( (-e $testFile) && (-x $testFile) ) {
    99    
     108    if ( ( -e $testFile ) && ( -x $testFile ) ) {
     109
    100110        # Display message the test driver is being executed
    101111        print("--- Executing test driver: $testFile\n");
    102    
     112
    103113        # Invoke the test driver
    104114        system("./$testFile 1> temp/$testFile.stdout 2> temp/$testFile.stderr");
    105        
     115
    106116        # Check the return value of the test driver.  A value other than 0
    107117        # indicates failure of the test driver unless the test driver is name
    108118        # with a leading 'a' which indicates the test driver is expecting an
    109119        # abort condition to terminate the driver.
    110         if ( ( $? != 0  && ( $testFile !~ /^A/i)) ||
    111             ( $? == 0  && ( $testFile =~ /^A/i)) ) {
    112    
     120        if (   ( $? != 0 && ( $testFile !~ /^A/i ) )
     121            || ( $? == 0 && ( $testFile =~ /^A/i ) ) )
     122        {
     123
    113124            # Display failure message with return value to user
    114             if ( $? != 0 && ( $testFile !~ /^A/i) ) {
     125            if ( $? != 0 && ( $testFile !~ /^A/i ) ) {
    115126                print("        Failed - Test Driver expected 0 return value (Return value $?)\n");
    116             } elsif ( $? == 0 && ( $testFile =~ /^A/i) ) {
     127            }
     128            elsif ( $? == 0 && ( $testFile =~ /^A/i ) ) {
    117129                print("        Failed - Test Driver expected abort (Return value $?)\n");
    118130            }
    119131            $exitValue |= 256;
    120         } else {
    121    
     132        }
     133        else {
     134
    122135            # Test driver succeeded.
    123    
     136
    124137            # Create filtered version of stdout and stderr
    125                
    126             # Open the STDOUT file for reading       
    127             open(OUTFILE, "< temp/$testFile.stdout");
     138
     139            # Open the STDOUT file for reading
     140            open( OUTFILE, "< temp/$testFile.stdout" );
     141
    128142            # Open mod file to place filtered STDOUT
    129             open(MODFILE, "> temp/$testFile.stdout.mod");
    130             open(MODFILE2, "> verified/$testFile.stdout") if $resetStdout;
     143            open( MODFILE,  "> temp/$testFile.stdout.mod" );
     144            open( MODFILE2, "> verified/$testFile.stdout" ) if $resetStdout;
     145
    131146            # Replace the variable date, time and host information with constants
    132147            $hostname = `hostname`;
    133148            chop $hostname;
    134             while( <OUTFILE> ) {
     149            while (<OUTFILE>) {
    135150                s/\s+\d+:\d+:\d+\w/<TIME>/g;
    136151                s/\d+:\d+:\d+/<DATE>/g;
     
    138153                s/: Line \d+/: Line <LINENO>/g;
    139154                s/\:\d+/\:<LINENO>/g;
     155
    140156                # Filter lines with malloc.  This is an artifact of memory testing
    141157                # with the Mac testbed
    142                 if ( ! m/\*\*\*\smalloc/ ) {
    143                 print MODFILE ($_);
    144                 print MODFILE2 ($_) if $resetStdout;
     158                if ( !m/\*\*\*\smalloc/ ) {
     159                    print MODFILE ($_);
     160                    print MODFILE2 ($_) if $resetStdout;
    145161                }
    146162            }
     163
    147164            # Close mod file
    148165            close(MODFILE);
    149166            close(MODFILE2) if $resetStdout;
     167
    150168            # Close STDERR file
    151169            close(OUTFILE);
    152    
    153             # Open the STDERR file for reading
    154             open(OUTFILE, "< temp/$testFile.stderr");
     170
     171            # Open the STDERR file for reading
     172            open( OUTFILE, "< temp/$testFile.stderr" );
     173
    155174            # Open mod file to place filtered STDERR
    156             open(MODFILE, "> temp/$testFile.stderr.mod");
    157             open(MODFILE2, "> verified/$testFile.stderr") if $resetStderr;
     175            open( MODFILE,  "> temp/$testFile.stderr.mod" );
     176            open( MODFILE2, "> verified/$testFile.stderr" ) if $resetStderr;
     177
    158178            # Replace the variable date, time and host information with constants
    159             while( <OUTFILE> ) {
     179            while (<OUTFILE>) {
    160180                s/\s+\d+:\d+:\d+\w/<TIME>/g;
    161181                s/\d+:\d+:\d+/<DATE>/g;
     
    163183                s/: Line \d+/: Line <LINENO>/g;
    164184                s/\:\d+/\:<LINENO>/g;
     185
    165186                # Filter lines with malloc.  This is an artifact of memory testing
    166187                # with the Mac testbed
    167                 if ( ! m/\*\*\*\smalloc/ ) {
    168                 print MODFILE ($_);
    169                 print MODFILE2 ($_) if $resetStderr;
     188                if ( !m/\*\*\*\smalloc/ ) {
     189                    print MODFILE ($_);
     190                    print MODFILE2 ($_) if $resetStderr;
    170191                }
    171192            }
     193
    172194            # Close mod file
    173195            close(MODFILE);
    174196            close(MODFILE2) if $resetStderr;
     197
    175198            # Close STDERR file
    176199            close(OUTFILE);
    177    
     200
    178201            # Compare STDOUT capture with verified file
    179202            $exitValue |= &compareStream("verified/$testFile.stdout");
    180    
     203
    181204            # Check exit value to determine if verified file doesn't exist
    182205            if ( $exitValue & 2 ) {
    183    
     206
    184207                # STDOUT verified doesn't exist.  Search STDOUT capture
    185208                # for strings indicating error or failure
    186209                $exitValue |= &errorStrSearch("$testFile.stdout");
    187210            }
    188    
     211
    189212            # Compare STDERR capture with verified file
    190213            $exitValue |= &compareStream("verified/$testFile.stderr");
    191    
     214
    192215            # Check exit value to determine if verified file doesn't exist
    193216            if ( $exitValue & 4 ) {
    194    
     217
    195218                # STDERR verified doesn't exist.  Search STDERR capture
    196219                # for strings indicating error or failure
     
    198221            }
    199222        }
    200     } else {
    201         # Since test driver doesn't exist or is not executable then display
     223    }
     224    else {
     225
     226        # Since test driver doesn't exist or is not executable then display
    202227        # message to user.
    203228        print("        Need to specify an executable test file within directory.\n");
    204        
     229
    205230        # Exit value set to indicate test driver doesn't exist or not executable
    206231        $exitValue |= 32;
     
    211236# Ignore the first three bit flags in exitValue since there are not indicators
    212237# of a failed test
    213 if ( ($exitValue >> 3) != 0 ) {
     238if ( ( $exitValue >> 3 ) != 0 ) {
    214239    print("Test failed - return status = $exitValue\n\n");
    215 } else {
     240}
     241else {
    216242    print("Test successful\n\n");
    217243}
     
    235261
    236262sub errorStrSearch {
    237     local($fileName) = @_;
    238     local($returnVal) = 0;
     263    local ($fileName) = @_;
     264    local ($returnVal) = 0;
    239265
    240266    # Open the captured file
    241     open(CAPT_FILE, "<temp/$fileName");
     267    open( CAPT_FILE, "<temp/$fileName" );
    242268
    243269    # Scan through all the lines of the file searching for error strings
    244     while ( <CAPT_FILE> ) {
    245         if ( m/FAIL/i || m/FAULT/i || m/ERROR/i || m/Not Found/i
    246                       || m/SIGNAL/i || m/NO SUCH FILE/i || m/\|E\|/i
    247                       || m/\|A\|/i ) {
     270    while (<CAPT_FILE>) {
     271        if (   m/FAIL/i
     272            || m/FAULT/i
     273            || m/ERROR/i
     274            || m/Not Found/i
     275            || m/SIGNAL/i
     276            || m/NO SUCH FILE/i
     277            || m/\|E\|/i
     278            || m/\|A\|/i )
     279        {
    248280            if ( $fileName =~ m/out/ ) {
    249281                print("        Failed - File $fileName contains error strings.\n");
    250282                $returnVal = 64;
    251             } elsif ( $fileName =~ m/err/ ) {
     283            }
     284            elsif ( $fileName =~ m/err/ ) {
    252285                print("        Failed - File $fileName contains error strings.\n");
    253286                $returnVal = 128;
     
    256289        }
    257290    }
     291
    258292    # Close the capture file
    259293    close(CAPT_FILE);
     294
    260295    # Return the return value
    261     return($returnVal);
     296    return ($returnVal);
    262297}
    263298
     
    280315
    281316sub compareStream {
    282     local($streamFile) = @_;
    283     local($returnVal) = 0;
    284     local($tempFile) = "";
     317    local ($streamFile) = @_;
     318    local ($returnVal) = 0;
     319    local ($tempFile)  = "";
    285320
    286321    # Check for existence of verified STD stream files
    287     if ( !( -e $streamFile) ) {
    288            
     322    if ( !( -e $streamFile ) ) {
     323
    289324        # Display message to user that verified STDOUT file doesn't exist
    290325        print("        File $streamFile doesn't exist.\n");
    291            
     326
    292327        # Set exit value bit 1 to indicate proper failure
    293328        if ( $streamFile =~ /out$/ ) {
    294329            $returnVal |= 2;
    295         } elsif ( $streamFile =~ /err$/ ) {
     330        }
     331        elsif ( $streamFile =~ /err$/ ) {
    296332            $returnVal |= 4;
    297333        }
    298     } else {
     334    }
     335    else {
    299336
    300337        # Verified STD stream file exists
    301338
    302339        # Create name of the temp file to compare
    303         $tempFile = $streamFile; 
     340        $tempFile = $streamFile;
    304341        $tempFile =~ s/verified/temp/;
    305342        $tempFile = $tempFile . ".mod";
    306    
     343
    307344        # Perform difference on the STD stream files
    308345        $diffstdout = `diff $streamFile $tempFile`;
     
    310347        # Check the return value of the difference
    311348        if ( $? != 0 ) {
    312    
     349
    313350            # Difference of STD stream files failed
    314351
    315352            # Check for STDOUT in file name to convey appropirate return value
    316353            if ( $streamFile =~ /out$/ ) {
    317                # Display message of the failure of difference to user
    318                print("        Failed - STDOUT difference\n$diffstdout\n");
    319  
    320                # Exit value to indicate STDOUT did not compare
    321                $returnVal |= 8;
    322             } elsif ( $streamFile =~ /err$/ ) {
    323                # Display message of the failure of difference to user
    324                print("        Failed - STDERR difference\n$diffstdout\n");
    325 
    326                # Exit value to indicate STDERR did not compare
    327                $returnVal |= 16;
    328             }
    329         }
    330     }
    331    
     354
     355                # Display message of the failure of difference to user
     356                print("        Failed - STDOUT difference\n$diffstdout\n");
     357
     358                # Exit value to indicate STDOUT did not compare
     359                $returnVal |= 8;
     360            }
     361            elsif ( $streamFile =~ /err$/ ) {
     362
     363                # Display message of the failure of difference to user
     364                print("        Failed - STDERR difference\n$diffstdout\n");
     365
     366                # Exit value to indicate STDERR did not compare
     367                $returnVal |= 16;
     368            }
     369        }
     370    }
     371
    332372    # Return the result of the compare
    333     return($returnVal);
    334 }
    335 
     373    return ($returnVal);
     374}
     375
Note: See TracChangeset for help on using the changeset viewer.