run-mangleme-tests 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 mangleme 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 webkitdirs;
  37. sub openHTTPDIfNeeded();
  38. sub closeHTTPD();
  39. sub runSafariWithMangleme();
  40. # Argument handling
  41. my $guardMalloc = '';
  42. my $httpdPort = 8000;
  43. my $downloadTest;
  44. GetOptions(
  45. 'guard-malloc|g' => \$guardMalloc,
  46. 'get=s' => \$downloadTest,
  47. 'port=i' => \$httpdPort
  48. );
  49. setConfiguration();
  50. my $productDir = productDir();
  51. chdirWebKit();
  52. checkFrameworks();
  53. mkdir "WebKitBuild/mangleme";
  54. (system "/usr/bin/make", "-C", "Tools/mangleme") == 0 or die;
  55. my $httpdOpen = 0;
  56. openHTTPDIfNeeded();
  57. if ($downloadTest) {
  58. system "/usr/bin/curl -o ~/Desktop/mangleme$downloadTest.html http://127.0.0.1:$httpdPort/remangle.cgi?$downloadTest";
  59. print "Saved the test as mangleme$downloadTest.html on the desktop\n";
  60. } else {
  61. runSafariWithMangleme();
  62. print "Last generated tests:\n";
  63. system "grep 'Mangle attempt' /tmp/WebKit/error_log.txt | tail -n -5 | awk ' {print \$4}'";
  64. }
  65. closeHTTPD();
  66. sub runSafariWithMangleme()
  67. {
  68. my $redirectTo;
  69. if (@ARGV) {
  70. $redirectTo = "http://127.0.0.1:$httpdPort/remangle.cgi?$ARGV[0]";
  71. } else {
  72. $redirectTo = "http://127.0.0.1:$httpdPort/mangle.cgi";
  73. }
  74. open REDIRECT_HTML, ">", "/tmp/WebKit/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. local %ENV;
  87. $ENV{DYLD_INSERT_LIBRARIES} = "/usr/lib/libgmalloc.dylib" if $guardMalloc;
  88. system "Tools/Scripts/run-safari", "-NSOpen", "/tmp/WebKit/redirect.html";
  89. }
  90. sub openHTTPDIfNeeded()
  91. {
  92. return if $httpdOpen;
  93. mkdir "/tmp/WebKit";
  94. if (-f "/tmp/WebKit/httpd.pid") {
  95. my $oldPid = `cat /tmp/WebKit/httpd.pid`;
  96. chomp $oldPid;
  97. if (0 != kill 0, $oldPid) {
  98. print "\nhttpd is already running: pid $oldPid, killing...\n";
  99. kill 15, $oldPid;
  100. my $retryCount = 20;
  101. while ((0 != kill 0, $oldPid) && $retryCount) {
  102. sleep 1;
  103. --$retryCount;
  104. }
  105. die "Timed out waiting for httpd to quit" unless $retryCount;
  106. }
  107. }
  108. my $testDirectory = getcwd() . "/LayoutTests";
  109. my $manglemeDirectory = getcwd() . "/WebKitBuild/mangleme";
  110. my $httpdPath = "/usr/sbin/httpd";
  111. my $httpdConfig = "$testDirectory/http/conf/httpd.conf";
  112. $httpdConfig = "$testDirectory/http/conf/apache2-httpd.conf" if `$httpdPath -v` =~ m|Apache/2|;
  113. my $documentRoot = "$manglemeDirectory";
  114. my $typesConfig = "$testDirectory/http/conf/mime.types";
  115. my $sslCertificate = "$testDirectory/http/conf/webkit-httpd.pem";
  116. my $listen = "127.0.0.1:$httpdPort";
  117. open2(\*HTTPDIN, \*HTTPDOUT, $httpdPath,
  118. "-f", "$httpdConfig",
  119. "-C", "DocumentRoot \"$documentRoot\"",
  120. "-C", "Listen $listen",
  121. "-c", "TypesConfig \"$typesConfig\"",
  122. "-c", "CustomLog \"/tmp/WebKit/access_log.txt\" common",
  123. "-c", "ErrorLog \"/tmp/WebKit/error_log.txt\"",
  124. "-c", "SSLCertificateFile \"$sslCertificate\"",
  125. # Apache wouldn't run CGIs with permissions==700 otherwise
  126. "-c", "User \"#$<\"");
  127. my $retryCount = 20;
  128. while (system("/usr/bin/curl -q --silent --stderr - --output " . File::Spec->devnull() . " $listen") && $retryCount) {
  129. sleep 1;
  130. --$retryCount;
  131. }
  132. die "Timed out waiting for httpd to start" unless $retryCount;
  133. $httpdOpen = 1;
  134. }
  135. sub closeHTTPD()
  136. {
  137. return if !$httpdOpen;
  138. close HTTPDIN;
  139. close HTTPDOUT;
  140. kill 15, `cat /tmp/WebKit/httpd.pid` if -f "/tmp/WebKit/httpd.pid";
  141. $httpdOpen = 0;
  142. }