Changeset 86511 in webkit


Ignore:
Timestamp:
May 15, 2011 3:41:22 PM (13 years ago)
Author:
weinig@apple.com
Message:

2011-05-15 Sam Weinig <sam@webkit.org>

Reviewed by David Levin.

Make API tester more gtest friendly
https://bugs.webkit.org/show_bug.cgi?id=60859

  • Scripts/run-api-tests: Numerous changes:
  • Remove logic to run tests one at a time.
  • Remove logic to build up a list of tests, instead just pass --gtest_list_tests to the test runner and allow gtest to print it for us.
  • Forward stdout from the test tool to stdout, even in non-verbose runs.
  • Run test tool from the current working directory instead of the root webkit directory.
  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Move plist to be with other bundle sources.
  • TestWebKitAPI/TestsController.cpp: (TestWebKitAPI::TestsController::TestsController): (TestWebKitAPI::TestsController::run):
  • TestWebKitAPI/TestsController.h:
  • TestWebKitAPI/mac/main.mm: Simplify TestController down to a single run function. We should consider removing the class entirely at some point.
Location:
trunk/Tools
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r86505 r86511  
     12011-05-15  Sam Weinig  <sam@webkit.org>
     2
     3        Reviewed by David Levin.
     4
     5        Make API tester more gtest friendly
     6        https://bugs.webkit.org/show_bug.cgi?id=60859
     7
     8        * Scripts/run-api-tests:
     9        Numerous changes:
     10        - Remove logic to run tests one at a time.
     11        - Remove logic to build up a list of tests, instead just pass --gtest_list_tests to
     12          the test runner and allow gtest to print it for us.
     13        - Forward stdout from the test tool to stdout, even in non-verbose runs.
     14        - Run test tool from the current working directory instead of the root webkit
     15          directory.
     16
     17        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     18        Move plist to be with other bundle sources.
     19
     20        * TestWebKitAPI/TestsController.cpp:
     21        (TestWebKitAPI::TestsController::TestsController):
     22        (TestWebKitAPI::TestsController::run):
     23        * TestWebKitAPI/TestsController.h:
     24        * TestWebKitAPI/mac/main.mm:
     25        Simplify TestController down to a single run function. We should consider removing the class
     26        entirely at some point.
     27
    1282011-05-15  Sheriff Bot  <webkit.review.bot@gmail.com>
    229
  • trunk/Tools/Scripts/run-api-tests

    r86287 r86511  
    3737use lib $FindBin::Bin;
    3838use webkitdirs;
    39 use Term::ANSIColor qw(:constants);
    4039
    41 sub dumpAllTests();
    42 sub runAllTests();
    43 sub runAllTestsInSuite($);
    44 sub runTest($$);
    45 sub populateTests();
     40sub runTestTool(@);
    4641sub buildTestTool();
    4742
     
    7267buildTestTool();
    7368setPathForRunningWebKitApp(\%ENV);
    74 my %testsToRun = populateTests();
    7569
    7670if ($dump) {
    77     dumpAllTests();
    78     exit 0;
     71    my @dumpArguments = ("--gtest_list_tests");
     72    runTestTool(@dumpArguments);
     73    exit(0);
    7974}
    8075
    81 runAllTests();
     76runTestTool();
    8277
    83 sub dumpAllTests()
     78sub runTestTool(@)
    8479{
    85     print "Dumping test cases\n";
    86     print "------------------\n";
    87     for my $suite (keys %testsToRun) {
    88         print $suite . ":\n";
    89         print map { "    " . $_ . "\n" } @{ $testsToRun{$suite} };
    90     }
    91     print "------------------\n";
    92 }
    93 
    94 sub runAllTests()
    95 {
    96     my $anyFailures = 0;
    97     for my $suite (keys %testsToRun) {
    98         my $failed = runAllTestsInSuite($suite);
    99         if ($failed) {
    100             $anyFailures = 1;
    101         }
    102     }
    103     return $anyFailures;
    104 }
    105 
    106 sub runAllTestsInSuite($)
    107 {
    108     my ($suite) = @_;
    109     print "Suite: $suite\n";
    110 
    111     my $anyFailures = 0;
    112     for my $test (@{$testsToRun{$suite}}) {
    113         my $failed = runTest($suite, $test);
    114         if ($failed) {
    115             $anyFailures = 1;
    116         }
    117     }
    118    
    119     return $anyFailures;
    120 }
    121 
    122 sub runTest($$)
    123 {
    124     my ($suite, $testName) = @_;
    125     my $test = $suite . "." . $testName;
    126 
    127     print "    Test: $testName -> ";
     80    my (@arguments) = @_;
    12881
    12982    my $result = 0;
     
    13689        local *DEVNULL;
    13790        my ($childIn, $childOut, $childErr);
     91
     92        $childOut = ">&STDOUT";
    13893        unless ($verbose) {
    13994            open(DEVNULL, ">", File::Spec->devnull()) or die "Failed to open /dev/null";
    140             $childOut = ">&DEVNULL";
    14195            $childErr = ">&DEVNULL";
    14296        } else {
    143             $childOut = ">&STDOUT";
    14497            $childErr = ">&STDERR";
    14598        }
     
    147100        my $pid;
    148101        if (architecture()) {
    149             $pid = open3($childIn, $childOut, $childErr, "arch", "-" . architecture(), $apiTesterPath, $test, @ARGV) or die "Failed to run test: $test.";
     102            $pid = open3($childIn, $childOut, $childErr, "arch", "-" . architecture(), $apiTesterPath, @arguments, @ARGV) or die "Failed to run test tool.";
    150103        } else {
    151             $pid = open3($childIn, $childOut, $childErr, $apiTesterPath, $test, @ARGV) or die "Failed to run test: $test.";
     104            $pid = open3($childIn, $childOut, $childErr, $apiTesterPath, @arguments, @ARGV) or die "Failed to run test tool.";
    152105        }
    153106
     
    155108        close($childOut);
    156109        close($childErr);
    157         close(DEVNULL) unless ($verbose);
     110        close(DEVNULL);
    158111
    159112        waitpid($pid, 0);
     
    167120        }
    168121        my $apiTesterPath = File::Spec->catfile(productDir(), "TestWebKitAPI$apiTesterNameSuffix.exe");
    169         $result = system $apiTesterPath, $test, @ARGV;
     122        $result = system $apiTesterPath, @ARGV;
    170123    } else {
    171124        die "run-api-tests is not supported on this platform.\n"
    172125    }
    173126   
    174     if ($result == 0) {
    175         print BOLD GREEN, "Passed", RESET, "\n";
    176     } else {
    177         print BOLD RED, "Failed", RESET, "\n";
    178     }
    179 }
    180 
    181 sub populateTests()
    182 {
    183     my @tests;
    184 
    185     if (isAppleMacWebKit()) {
    186         my $productDir = productDir();
    187         $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
    188         $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
    189         my $apiTesterPath = "$productDir/TestWebKitAPI";
    190 
    191         local *DEVNULL;
    192         my ($childIn, $childOut, $childErr);
    193         unless ($verbose) {
    194             open(DEVNULL, ">", File::Spec->devnull()) or die "Failed to open /dev/null";
    195             $childErr = ">&DEVNULL";
    196         } else {
    197             $childErr = ">&STDERR";
    198         }
    199 
    200         my $pid;
    201         if (architecture()) {
    202             $pid = open3($childIn, $childOut, $childErr, "arch", "-" . architecture(), $apiTesterPath, "--dump-tests") or die "Failed to build list of tests!";
    203         } else {
    204             $pid = open3($childIn, $childOut, $childErr, $apiTesterPath, "--dump-tests") or die "Failed to build list of tests!";
    205         }
    206 
    207         close($childIn);
    208         @tests = <$childOut>;
    209         close($childOut);
    210         close($childErr);
    211         close(DEVNULL) unless ($verbose);
    212 
    213         waitpid($pid, 0);
    214         my $result = $?;
    215 
    216         if ($result) {
    217             print STDERR "Failed to build list of tests!\n";
    218             exit exitStatus($result);
    219         }
    220     } elsif (isAppleWinWebKit()) {
    221         my $apiTesterNameSuffix;
    222         if (configurationForVisualStudio() ne "Debug_All") {
    223             $apiTesterNameSuffix = "";
    224         } else {
    225             $apiTesterNameSuffix = "_debug";
    226         }
    227         my $apiTesterPath = File::Spec->catfile(productDir(), "TestWebKitAPI$apiTesterNameSuffix.exe");
    228         open(TESTS, "-|", $apiTesterPath, "--dump-tests") or die $!;
    229         @tests = <TESTS>;
    230         close(TESTS) or die $!;
    231     } else {
    232         die "run-api-tests is not supported on this platform.\n"
    233     }
    234 
    235     my %keyedTests = ();
    236     for my $test (@tests) {
    237         $test =~ s/[\r\n]*$//;
    238         my ($suite, $testName) = split(/\./, $test);
    239         push @{$keyedTests{$suite}}, $testName;
    240     }
    241    
    242     return %keyedTests;
     127    return $result;
    243128}
    244129
    245130sub buildTestTool()
    246131{
     132    my $originalCwd = getcwd();
     133
    247134    chdirWebKit();
    248135
     
    277164        exit exitStatus($buildResult);
    278165    }
     166
     167    chdir $originalCwd;
    279168}
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r86354 r86511  
    207207                                08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */,
    208208                                1AB674ADFE9D54B511CA2CBB /* Products */,
    209                                 BC575981126E74AF006F0F12 /* InjectedBundle-Info.plist */,
    210209                        );
    211210                        name = TestWebKitAPI;
     
    254253                        isa = PBXGroup;
    255254                        children = (
     255                                BC575981126E74AF006F0F12 /* InjectedBundle-Info.plist */,
    256256                                BC575946126E7351006F0F12 /* InjectedBundleMain.cpp */,
    257257                                BC575A9E126E75FB006F0F12 /* InjectedBundleTest.h */,
  • trunk/Tools/TestWebKitAPI/TestsController.cpp

    r86287 r86511  
    2626#include "TestsController.h"
    2727
    28 #include "Test.h"
    29 #include <assert.h>
    3028#include <gtest/gtest.h>
    31 #include <cstdio>
    3229
    3330namespace TestWebKitAPI {
     
    4138TestsController::TestsController()
    4239{
    43     int argc = 0;
    44     ::testing::InitGoogleTest(&argc, (char**)0);
    4540}
    4641
    47 void TestsController::dumpTestNames()
     42bool TestsController::run(int argc, char** argv)
    4843{
    49     ::testing::UnitTest* unit_test = ::testing::UnitTest::GetInstance();
    50 
    51     for (int i = 0; i < unit_test->total_test_case_count(); i++) {
    52         const ::testing::TestCase* test_case = unit_test->GetTestCase(i);
    53         for (int j = 0; j < test_case->total_test_count(); j++) {
    54           const ::testing::TestInfo* test_info = test_case->GetTestInfo(j);
    55           printf("%s.%s\n", test_case->name(), test_info->name());
    56         }
    57     }
    58 }
    59 
    60 bool TestsController::runTestNamed(const std::string& identifier)
    61 {
    62     ::testing::GTEST_FLAG(filter) = identifier;
    63     return !RUN_ALL_TESTS();
    64 }
    65 
    66 bool TestsController::runAllTests()
    67 {
     44    ::testing::InitGoogleTest(&argc, argv);
    6845    return !RUN_ALL_TESTS();
    6946}
  • trunk/Tools/TestWebKitAPI/TestsController.h

    r86287 r86511  
    2727#define TestsController_h
    2828
    29 #include <map>
    30 #include <string>
    31 
    3229namespace TestWebKitAPI {
    33 
    34 class Test;
    3530
    3631class TestsController {
     
    3833    static TestsController& shared();
    3934
    40     void dumpTestNames();
    41     bool runTestNamed(const std::string&);
    42     bool runAllTests();
     35    bool run(int argc, char** argv);
    4336
    4437private:
  • trunk/Tools/TestWebKitAPI/mac/main.mm

    r86130 r86511  
    2626#import "TestsController.h"
    2727
    28 int main(int argc, const char* argv[])
     28int main(int argc, char** argv)
    2929{
    3030    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     
    3232    [NSApplication sharedApplication];
    3333
    34     bool passed = true;
    35 
    36     std::string argument(argv[1]);
    37     if (argument == "--dump-tests")
    38         TestWebKitAPI::TestsController::shared().dumpTestNames();
    39     else   
    40         passed = TestWebKitAPI::TestsController::shared().runTestNamed(argument);
     34    bool passed = TestWebKitAPI::TestsController::shared().run(argc, argv);
    4135
    4236    [pool drain];
Note: See TracChangeset for help on using the changeset viewer.