import-w3c-performance-wg-tests 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env python
  2. # Copyright (C) 2012 Google Inc. All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are
  6. # met:
  7. #
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above
  11. # copyright notice, this list of conditions and the following disclaimer
  12. # in the documentation and/or other materials provided with the
  13. # distribution.
  14. # * Neither the name of Google Inc. nor the names of its
  15. # contributors may be used to endorse or promote products derived from
  16. # this software without specific prior written permission.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. # This script imports the W3C Web Performance WG's test suite into WebKit.
  30. #
  31. # You must have checked out the 'webperf' repository from https://dvcs.w3.org/hg/
  32. #
  33. # This script will populate the LayoutTests directory with the new tests. If the
  34. # tests already exist, the script will refuse to run. Please clear out the
  35. # w3c/webperf directory first.
  36. #
  37. # The main step in importing the tests is updating all of the URLs to match our
  38. # directory layout.
  39. import os
  40. import sys
  41. if len(sys.argv) != 3:
  42. print 'USAGE: %s path_to_webperf_checkout_root path_to_webkit_checkout_root' % sys.argv[0]
  43. sys.exit(1)
  44. source_directory = os.path.join(sys.argv[1], 'tests')
  45. destination_directory = os.path.join(sys.argv[2], 'LayoutTests', 'http', 'tests', 'w3c', 'webperf')
  46. if os.path.exists(destination_directory):
  47. print 'Refusing to overwrite existing directory: %s' % destination_directory
  48. sys.exit(1)
  49. os.makedirs(destination_directory)
  50. directories_to_copy = ['approved', 'resources']
  51. directories_to_ignore = ['html5'] # These are just duplicates of the sibling directory 'html'.
  52. replacements = [
  53. ('www.w3c-test.org', 'localhost:8000'), # This is the alternate host for cross-server requests.
  54. ('w3c-test.org', '127.0.0.1:8000'), # This is the primary test server.
  55. ('webperf/tests', 'w3c/webperf'), # We prepend /w3c to all of our paths.
  56. ('/resources/testharness', '/w3c/resources/testharness'),
  57. ('+ "(" + reloadTime[time] + ")"', ''), # Remove dynamic values from the output. We'll still see PASS.
  58. ('+ "(" + startingTime[time] + ")"', ''),
  59. ('\r\n', '\n'), # Convert to *NIX format.
  60. ]
  61. for directory_to_copy in directories_to_copy:
  62. os.makedirs(os.path.join(destination_directory, directory_to_copy))
  63. os.chdir(source_directory)
  64. for root, dirs, files in os.walk(directory_to_copy):
  65. for dirname in directories_to_ignore:
  66. if dirname in dirs:
  67. dirs.remove(dirname)
  68. for dirname in dirs:
  69. os.makedirs(os.path.join(destination_directory, root, dirname))
  70. for filename in files:
  71. with open(os.path.join(source_directory, root, filename), 'r') as in_file:
  72. with open(os.path.join(destination_directory, root, filename), 'w') as out_file:
  73. for line in in_file:
  74. for to_find, replace_with in replacements:
  75. line = line.replace(to_find, replace_with)
  76. assert 'w3c-test.org' not in line, 'Imported test must not depend on live site. Bad line: "%s"' % line
  77. out_file.write(line)