summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordmichael@google.com <dmichael@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-19 22:55:00 +0000
committerdmichael@google.com <dmichael@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-19 22:55:00 +0000
commit227b06711ccc640bb61568ee81a452744ece6f94 (patch)
tree2692ecc706ecf2b28f8d03c576aa4be147dce50c
parenta983c1c744fcc936c84128355e5e51cb111ca41c (diff)
downloadchromium_src-227b06711ccc640bb61568ee81a452744ece6f94.zip
chromium_src-227b06711ccc640bb61568ee81a452744ece6f94.tar.gz
chromium_src-227b06711ccc640bb61568ee81a452744ece6f94.tar.bz2
- Add a script which:
--- Checks that all source files are in ppapi.gyp and vice-versa --- Generates test_c_includes.c and test_cc_includes.cc - Removes tests/test_image_data, which appears to be obsolete I want to make the script a gyp action, but it didn't work on Windows last I tried. If desired, I can fix that in this CL, or I can make it automated later. BUG=63527,59791,53451 TEST=None; improves build-time checking Review URL: http://codereview.chromium.org/5190004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66833 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ppapi/generate_ppapi_include_tests.py164
-rw-r--r--ppapi/ppapi.gyp15
-rw-r--r--ppapi/tests/test_c_includes.c5
-rw-r--r--ppapi/tests/test_cc_includes.cc5
-rw-r--r--ppapi/tests/test_image_data/test_image_data.cc151
-rw-r--r--ppapi/tests/test_image_data/test_image_data.html11
6 files changed, 185 insertions, 166 deletions
diff --git a/ppapi/generate_ppapi_include_tests.py b/ppapi/generate_ppapi_include_tests.py
new file mode 100644
index 0000000..0668a68
--- /dev/null
+++ b/ppapi/generate_ppapi_include_tests.py
@@ -0,0 +1,164 @@
+#!/usr/bin/python
+
+# Copyright (c) 2010 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# This script should be run manually on occasion to make sure the gyp file and
+# the includes tests are up to date.
+# It does the following:
+# - Verifies that all source code is in ppapi.gyp
+# - Verifies that all sources in ppapi.gyp really do exist
+# - Generates tests/test_c_includes.c
+# - Generates tests/test_cc_includes.cc
+# These tests are checked in to SVN.
+# TODO(dmichael): Make this script execute as a gyp action, move the include
+# tests to some 'generated' area, and remove them from version
+# control.
+
+import re
+import os
+import sys
+import posixpath
+
+# A simple regular expression that should match source files for C++ and C.
+SOURCE_FILE_RE = re.compile('.+\.(cc|c|h)$')
+
+# IGNORE_RE is a regular expression that matches directories which contain
+# source that we don't (currently) expect to be in ppapi.gyp. This script will
+# not check whether source files under these directories are in the gyp file.
+# TODO(dmichael): Put examples back in the build.
+# TODO(brettw): Put proxy in the build when it's ready.
+IGNORE_RE = re.compile('^(examples|GLES2|proxy).*')
+
+GYP_TARGETS_KEY = 'targets'
+GYP_SOURCES_KEY = 'sources'
+GYP_TARGET_NAME_KEY = 'target_name'
+
+
+# Return a set containing all source files found given an object read from a gyp
+# file.
+def GetAllGypSources(gyp_file_data):
+ sources = set([])
+ for target in gyp_file_data[GYP_TARGETS_KEY]:
+ # Get a list of sources in the target that are not ignored, and 'normalize'
+ # them. The main reason for this is to turn the forward slashes in the gyp
+ # file in to backslashes when the script is run on Windows.
+ source_list = [posixpath.normpath(src) for src in target[GYP_SOURCES_KEY]
+ if not IGNORE_RE.match(src)]
+ sources |= set(source_list)
+ return sources
+
+
+# Search the directory named start_root and all its subdirectories for source
+# files.
+# Return a set containing the string names of all the source files found,
+# relative to start_root.
+def GetFileSources(start_root):
+ file_set = set([])
+ for root, dirs, files in os.walk(start_root):
+ relative_root = os.path.relpath(root, start_root)
+ if not IGNORE_RE.match(relative_root):
+ for source in files:
+ if SOURCE_FILE_RE.match(source):
+ file_set |= set([os.path.join(relative_root, source)])
+ return file_set
+
+
+# Make sure all source files are in the given gyp object (evaluated from a gyp
+# file), and that all source files listed in the gyp object exist in the
+# directory.
+def VerifyGypFile(gyp_file_data):
+ gyp_sources = GetAllGypSources(gyp_file_data)
+ file_sources = GetFileSources('.')
+ in_gyp_not_file = gyp_sources - file_sources
+ in_file_not_gyp = file_sources - gyp_sources
+ if len(in_gyp_not_file):
+ print 'Found source file(s) in ppapi.gyp but not in the directory:', \
+ in_gyp_not_file
+ if len(in_file_not_gyp):
+ print 'Found source file(s) in the directory but not in ppapi.gyp:', \
+ in_file_not_gyp
+ error_count = len(in_gyp_not_file) + len(in_file_not_gyp)
+ if error_count:
+ sys.exit(error_count)
+
+
+def WriteLines(filename, lines):
+ outfile = open(filename, 'w')
+ for line in lines:
+ outfile.write(line)
+ outfile.write('\n')
+
+
+COPYRIGHT_STRING_C = \
+"""
+/* Copyright (c) 2010 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * This test simply includes all the C headers to ensure they compile with a C
+ * compiler. If it compiles, it passes.
+ */
+"""
+
+COPYRIGHT_STRING_CC = \
+"""
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// This test simply includes all the C++ headers to ensure they compile with a
+// C++ compiler. If it compiles, it passes.
+//
+"""
+
+
+# Get the source file names out of the given gyp file data object (as evaluated
+# from a gyp file) for the given target name. Return the string names in
+# sorted order.
+def GetSourcesForTarget(target_name, gyp_file_data):
+ for target in gyp_file_data[GYP_TARGETS_KEY]:
+ if target[GYP_TARGET_NAME_KEY] == target_name:
+ sources = target[GYP_SOURCES_KEY]
+ sources.sort()
+ return sources
+ print 'Warning: no target named ', target, ' found.'
+ return []
+
+
+# Generate test_c_includes.c, which is a test to ensure that all the headers in
+# ppapi/c can be compiled with a C compiler.
+def GenerateCIncludeTest(gyp_file_data):
+ c_sources = GetSourcesForTarget('ppapi_c', gyp_file_data)
+ lines = [COPYRIGHT_STRING_C]
+ for source in c_sources:
+ lines.append('#include "ppapi/' + source + '"\n')
+ WriteLines('tests/test_c_includes.c', lines)
+
+
+# Generate test_cc_includes.cc, which is a test to ensure that all the headers
+# in ppapi/cpp can be compiled with a C++ compiler.
+def GenerateCCIncludeTest(gyp_file_data):
+ cc_sources = GetSourcesForTarget('ppapi_cpp_objects', gyp_file_data)
+ header_re = re.compile('.+\.h$')
+ lines = [COPYRIGHT_STRING_CC]
+ for source in cc_sources:
+ if header_re.match(source):
+ lines.append('#include "ppapi/' + source + '"\n')
+ WriteLines('tests/test_cc_includes.cc', lines)
+
+
+def main():
+ ppapi_gyp_file_name = 'ppapi.gyp'
+ gyp_file_contents = open(ppapi_gyp_file_name).read()
+ gyp_file_data = eval(gyp_file_contents)
+ VerifyGypFile(gyp_file_data)
+ GenerateCIncludeTest(gyp_file_data)
+ GenerateCCIncludeTest(gyp_file_data)
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())
+
diff --git a/ppapi/ppapi.gyp b/ppapi/ppapi.gyp
index ea81f98..b9fb347 100644
--- a/ppapi/ppapi.gyp
+++ b/ppapi/ppapi.gyp
@@ -478,6 +478,21 @@
'product_extension': 'plugin',
}],
],
+# TODO(dmichael): Figure out what is wrong with the script on Windows and add
+# it as an automated action.
+# 'actions': [
+# {
+# 'action_name': 'generate_ppapi_include_tests',
+# 'inputs': [],
+# 'outputs': [
+# 'tests/test_c_includes.c',
+# 'tests/test_cc_includes.cc',
+# ],
+# 'action': [
+# '<!@(python generate_ppapi_include_tests.py)',
+# ],
+# },
+# ],
},
{
'target_name': 'ppapi_proxy',
diff --git a/ppapi/tests/test_c_includes.c b/ppapi/tests/test_c_includes.c
index 05e8899..c54b427 100644
--- a/ppapi/tests/test_c_includes.c
+++ b/ppapi/tests/test_c_includes.c
@@ -1,9 +1,10 @@
+
/* Copyright (c) 2010 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
- * This test simply includes all the C headers to ensure they compile with a
- * C compiler. If it compiles, it passes.
+ * This test simply includes all the C headers to ensure they compile with a C
+ * compiler. If it compiles, it passes.
*/
#include "ppapi/c/dev/deprecated_bool.h"
#include "ppapi/c/dev/pp_cursor_type_dev.h"
diff --git a/ppapi/tests/test_cc_includes.cc b/ppapi/tests/test_cc_includes.cc
index b22ec00..1e76230 100644
--- a/ppapi/tests/test_cc_includes.cc
+++ b/ppapi/tests/test_cc_includes.cc
@@ -1,9 +1,10 @@
+
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
-// This test simply includes all the C++ headers to ensure they compile with
-// a C++ compiler. If it compiles, it passes.
+// This test simply includes all the C++ headers to ensure they compile with a
+// C++ compiler. If it compiles, it passes.
//
#include "ppapi/cpp/common.h"
#include "ppapi/cpp/completion_callback.h"
diff --git a/ppapi/tests/test_image_data/test_image_data.cc b/ppapi/tests/test_image_data/test_image_data.cc
deleted file mode 100644
index 0f04472..0000000
--- a/ppapi/tests/test_image_data/test_image_data.cc
+++ /dev/null
@@ -1,151 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ppapi/tests/test_instance.h"
-
-#include "ppapi/cpp/device_context_2d.h"
-#include "ppapi/cpp/image_data.h"
-#include "ppapi/cpp/instance.h"
-#include "ppapi/cpp/module.h"
-
-class Instance : public TestInstance {
- public:
- Instance(PP_Instance instance) : TestInstance(instance) {}
-
- virtual bool Init(size_t argc, const char* argn[], const char* argv[]) {
- image_data_interface_ = reinterpret_cast<PPB_ImageData const*>(
- pp::Module::Get()->GetBrowserInterface(PPB_IMAGEDATA_INTERFACE));
- return !!image_data_interface_;
- }
-
- virtual std::string GetTestCaseName() const {
- return std::string("ImageData");
- }
-
- virtual void RunTest() {
- LogTest("InvalidFormat", TestInvalidFormat());
- LogTest("InvalidSize", TestInvalidSize());
- LogTest("HugeSize", TestHugeSize());
- LogTest("InitToZero", TestInitToZero());
- LogTest("IsImageData", TestIsImageData());
- }
-
- private:
- std::string TestInvalidFormat() {
- pp::ImageData a(static_cast<PP_ImageDataFormat>(1337), 16, 16, true);
- if (!a.is_null())
- return "Crazy image data format accepted";
-
- pp::ImageData b(static_cast<PP_ImageDataFormat>(-1), 16, 16, true);
- if (!b.is_null())
- return "Negative image data format accepted";
-
- return "";
- }
-
- std::string TestInvalidSize() {
- pp::ImageData zero_size(PP_IMAGEDATAFORMAT_BGRA_PREMUL, 0, 0, true);
- if (!zero_size.is_null())
- return "Zero width and height accepted";
-
- pp::ImageData zero_height(PP_IMAGEDATAFORMAT_BGRA_PREMUL, 16, 0, true);
- if (!zero_height.is_null())
- return "Zero height accepted";
-
- pp::ImageData zero_width(PP_IMAGEDATAFORMAT_BGRA_PREMUL, 0, 16, true);
- if (!zero_width.is_null())
- return "Zero width accepted";
-
- pp::ImageData negative_height(PP_IMAGEDATAFORMAT_BGRA_PREMUL, 16, -2, true);
- if (!negative_height.is_null())
- return "Negative height accepted";
-
- pp::ImageData negative_width(PP_IMAGEDATAFORMAT_BGRA_PREMUL, -2, 16, true);
- if (!negative_width.is_null())
- return "Negative width accepted";
-
- return "";
- }
-
- std::string TestHugeSize() {
- pp::ImageData huge_size(PP_IMAGEDATAFORMAT_BGRA_PREMUL,
- 100000000, 100000000, true);
- if (!huge_size.is_null())
- return "31-bit overflow size accepted";
- return "";
- }
-
- std::string TestInitToZero() {
- const int w = 5;
- const int h = 6;
- pp::ImageData img(PP_IMAGEDATAFORMAT_BGRA_PREMUL, w, h, true);
- if (img.is_null())
- return "Could not create bitmap";
-
- // Basic validity checking of the bitmap. This also tests "describe" since
- // that's where the image data object got its imfo from.
- if (img.width() != w || img.height() != h)
- return "Wrong size";
- if (img.format() != PP_IMAGEDATAFORMAT_BGRA_PREMUL)
- return "Wrong format";
- if (img.stride() < w * 4)
- return "Stride too small";
-
- // Now check that everything is 0.
- for (int y = 0; y < h; y++) {
- uint32_t* row = img.GetAddr32(0, y);
- for (int x = 0; x < w; x++) {
- if (row[x] != 0)
- return "Image data isn't entirely zero";
- }
- }
-
- return "";
- }
-
- std::string TestIsImageData() {
- // Test that a NULL resource isn't an image data.
- pp::Resource null_resource;
- if (image_data_interface_->IsImageData(null_resource.pp_resource()))
- return "Null resource was reported as a valid image";
-
- // Make another resource type and test it.
- const int w = 16, h = 16;
- pp::DeviceContext2D device(w, h, true);
- if (device.is_null())
- return "Couldn't create device context";
- if (image_data_interface_->IsImageData(device.pp_resource()))
- return "Device context was reported as an image";
-
- // Make a valid image resource.
- pp::ImageData img(PP_IMAGEDATAFORMAT_BGRA_PREMUL, w, h, true);
- if (img.is_null())
- return "Couldn't create image data";
- if (!image_data_interface_->IsImageData(img.pp_resource()))
- return "Image data should be identified as an image";
-
- return "";
- }
-
- // Used by the tests that access the C API directly.
- const PPB_ImageData* image_data_interface_;
-};
-
-class Module : public pp::Module {
- public:
- Module() : pp::Module() {}
- virtual ~Module() {}
-
- virtual pp::Instance* CreateInstance(PP_Instance instance) {
- return new Instance(instance);
- }
-};
-
-namespace pp {
-
-Module* CreateModule() {
- return new ::Module();
-}
-
-} // namespace pp
diff --git a/ppapi/tests/test_image_data/test_image_data.html b/ppapi/tests/test_image_data/test_image_data.html
deleted file mode 100644
index 0dc06e5..0000000
--- a/ppapi/tests/test_image_data/test_image_data.html
+++ /dev/null
@@ -1,11 +0,0 @@
-<html><head>
-<title>Test PPAPI ImageData</title>
-<link rel="stylesheet" href="../test_page.css">
-</head><body>
-<h1>Test PPAPI ImageData</h1>
-
-<object id="plugin" type="application/x-ppapi-test-image-data" width="16" height="16"></object>
-
-<div id="console" /><span class="load_msg">loading...</span></div>
-
-</body></html>