run-iexploder-tests 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/usr/bin/perl
  2. # Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions
  6. # are met:
  7. #
  8. # 1. Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # 2. Redistributions in binary form must reproduce the above copyright
  11. # notice, this list of conditions and the following disclaimer in the
  12. # documentation and/or other materials provided with the distribution.
  13. # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  14. # its contributors may be used to endorse or promote products derived
  15. # from this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  18. # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  21. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. # A script to semi-automatically run iExploder tests.
  28. use strict;
  29. use warnings;
  30. use Cwd;
  31. use File::Spec;
  32. use FindBin;
  33. use Getopt::Long;
  34. use IPC::Open2;
  35. use lib $FindBin::Bin;
  36. use webkitperl::httpd;
  37. use webkitdirs;
  38. sub configureAndOpenHTTPDIfNeeded();
  39. sub runSafariWithIExploder();
  40. # Argument handling
  41. my $guardMalloc = '';
  42. my $httpdPort = 8000;
  43. my $downloadTest;
  44. my $iExploderTestDirectory = "/tmp/iExploderTest";
  45. GetOptions(
  46. 'guard-malloc|g' => \$guardMalloc,
  47. 'get=s' => \$downloadTest,
  48. 'port=i' => \$httpdPort
  49. );
  50. setConfiguration();
  51. my $productDir = productDir();
  52. chdirWebKit();
  53. checkFrameworks();
  54. my $isHttpdOpen = 0;
  55. configureAndOpenHTTPDIfNeeded();
  56. if ($downloadTest) {
  57. system "/usr/bin/curl -o ~/Desktop/iexploder$downloadTest.html \"http://127.0.0.1:$httpdPort/iexploder.cgi?lookup=1&test=$downloadTest\"";
  58. print "Saved the test as iexploder$downloadTest.html on the desktop\n";
  59. } else {
  60. runSafariWithIExploder();
  61. print "Last generated tests:\n";
  62. system "grep 'iexploder.cgi' $iExploderTestDirectory/access_log.txt | tail -n -5 | awk -F'[ =&\\?]' '{if (\$8 == \"lookup\") print \$11; else print \$9}'";
  63. }
  64. rmtree $iExploderTestDirectory;
  65. $isHttpdOpen = !closeHTTPD();
  66. sub runSafariWithIExploder()
  67. {
  68. my $redirectTo;
  69. if (@ARGV) {
  70. $redirectTo = "http://127.0.0.1:$httpdPort/iexploder.cgi?lookup=1&test=$ARGV[0]";
  71. } else {
  72. $redirectTo = "http://127.0.0.1:$httpdPort/index.html";
  73. }
  74. open REDIRECT_HTML, ">", "$iExploderTestDirectory/redirect.html" or die;
  75. print REDIRECT_HTML "<html>\n";
  76. print REDIRECT_HTML " <head>\n";
  77. print REDIRECT_HTML " <meta http-equiv=\"refresh\" content=\"1;URL=$redirectTo\" />\n";
  78. print REDIRECT_HTML " <script type=\"text/javascript\">\n";
  79. print REDIRECT_HTML " document.location = \"$redirectTo\";\n";
  80. print REDIRECT_HTML " </script>\n";
  81. print REDIRECT_HTML " </head>\n";
  82. print REDIRECT_HTML " <body>\n";
  83. print REDIRECT_HTML " </body>\n";
  84. print REDIRECT_HTML "</html>\n";
  85. close REDIRECT_HTML;
  86. if (!isAppleWebKit()) {
  87. system "Tools/Scripts/run-launcher", "$iExploderTestDirectory/redirect.html";
  88. } else {
  89. local %ENV;
  90. $ENV{DYLD_INSERT_LIBRARIES} = "/usr/lib/libgmalloc.dylib" if $guardMalloc;
  91. system "Tools/Scripts/run-safari", "-NSOpen", "$iExploderTestDirectory/redirect.html";
  92. }
  93. }
  94. sub configureAndOpenHTTPDIfNeeded()
  95. {
  96. return if $isHttpdOpen;
  97. mkdir $iExploderTestDirectory;
  98. my $webkitDirectory = getcwd();
  99. my $testDirectory = $webkitDirectory . "/LayoutTests";
  100. my $iExploderDirectory = $webkitDirectory . "/Tools/iExploder/iExploder-1.3.2";
  101. my $httpdConfig = getHTTPDConfigPathForTestDirectory($testDirectory);
  102. my $documentRoot = "$iExploderDirectory/htdocs";
  103. my $typesConfig = "$testDirectory/http/conf/mime.types";
  104. my $sslCertificate = "$testDirectory/http/conf/webkit-httpd.pem";
  105. my $listen = "127.0.0.1:$httpdPort";
  106. my @args = (
  107. "-f", "$httpdConfig",
  108. "-C", "DocumentRoot \"$documentRoot\"",
  109. "-C", "Listen $listen",
  110. "-c", "TypesConfig \"$typesConfig\"",
  111. "-c", "CustomLog \"$iExploderTestDirectory/access_log.txt\" common",
  112. "-c", "ErrorLog \"$iExploderTestDirectory/error_log.txt\"",
  113. "-c", "SSLCertificateFile \"$sslCertificate\"",
  114. # Apache wouldn't run CGIs with permissions==700 otherwise
  115. "-c", "User \"#$<\""
  116. );
  117. $isHttpdOpen = openHTTPD(@args);
  118. }