From ba0c5ea90d0e6b2e8b20696e54fea13ead6dda93 Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Fri, 28 Mar 2014 15:59:04 +0000 Subject: Updates to Android.mk generation. Generate SkUserConfig. Include arm64 as another build flavor. Add tests. gyp/common_conditions.gypi: Add conditions for Android framework. These will get written into the generated SkUserConfig. include/core/SkUserConfig.h: Generated version that will ultimately be checked into Android (but not here). platform_tools/android/bin/gyp_to_android.py: Generate SkUserConfig. Add arm64 (note that arm64 is not currently respected by our gyp files, so it results in use _none.cpp for the various opts). Reset the common defines, which are now passed to the generated SkUserConfig. platform_tools/android/gyp_gen/generate_user_config.py: New script to generate SkUserConfig.h. platform_tools/android/gyp_gen/gypd_parser.py: Fix a lint error (unused import). platform_tools/android/gyp_gen/makefile_writer.py: Append any remaining DEFINES to LOCAL_CFLAGS (previously this was done during parsing). Add a warning for arm64 (corresponds to downstream Android.mk). platform_tools/android/gyp_gen/vars_dict_lib.py: Add OrderedSet.reset(). Add DEFINES to VarsDict. platform_tools/android/tests/expectations/: Add and update expectations files. platform_tools/android/tests/generate_user_config_tests.py: New test for generate_user_config.py platform_tools/android/tests/inputs/SkUserConfig.h: Input to the new test, so we don't have to update the expectations each time the real SkUserConfig.h changes. platform_tools/android/tests/makefile_writer_tests.py: Add a way to rebaseline test_write_local_vars, which has changed. Refactor EXPECTATIONS_DIR and compare_files into a separate file for sharing with generate_user_config_tests.py. platform_tools/android/tests/utils.py: Common code for tests. platform_tools/android/tests/var_dict_tests.py: Use a for loop to test the new key (DEFINES) and future proof this test to test any new keys in the future. BUG=skia:1975 R=djsollen@google.com, halcanary@google.com Author: scroggo@google.com Review URL: https://codereview.chromium.org/198063002 git-svn-id: http://skia.googlecode.com/svn/trunk@13975 2bbb7eff-a529-9590-31e7-b0007b416f81 --- .../android/tests/expectations/Android.mk | 13 +++ .../android/tests/expectations/SkUserConfig.h | 43 +++++++ .../tests/expectations/write_local_vars_append_arm | 3 + .../tests/expectations/write_local_vars_append_foo | 3 + .../expectations/write_local_vars_append_no_name | 3 + .../expectations/write_local_vars_no_append_arm | 3 + .../expectations/write_local_vars_no_append_foo | 3 + .../write_local_vars_no_append_no_name | 3 + .../android/tests/generate_user_config_tests.py | 89 +++++++++++++++ platform_tools/android/tests/inputs/SkUserConfig.h | 10 ++ .../android/tests/makefile_writer_tests.py | 125 +++++++++++---------- platform_tools/android/tests/ordered_set_tests.py | 9 ++ platform_tools/android/tests/utils.py | 36 ++++++ platform_tools/android/tests/var_dict_tests.py | 26 +---- 14 files changed, 285 insertions(+), 84 deletions(-) create mode 100644 platform_tools/android/tests/expectations/SkUserConfig.h create mode 100644 platform_tools/android/tests/generate_user_config_tests.py create mode 100644 platform_tools/android/tests/inputs/SkUserConfig.h create mode 100644 platform_tools/android/tests/utils.py (limited to 'platform_tools/android/tests') diff --git a/platform_tools/android/tests/expectations/Android.mk b/platform_tools/android/tests/expectations/Android.mk index 6b5ff8b806..ced1a29d4d 100644 --- a/platform_tools/android/tests/expectations/Android.mk +++ b/platform_tools/android/tests/expectations/Android.mk @@ -49,6 +49,10 @@ ifeq ($(NO_FALLBACK_FONT),true) LOCAL_CFLAGS += -DNO_FALLBACK_FONT endif +ifeq ($(TARGET_ARCH),arm64) + $(warning TODOArm64: Unlike arm32, arm64 has no inline assembly for performance critical code.) +endif + LOCAL_CFLAGS += \ local_cflags @@ -70,6 +74,9 @@ LOCAL_C_INCLUDES := \ LOCAL_EXPORT_C_INCLUDE_DIRS := \ local_export_c_include_dirs +LOCAL_CFLAGS += \ + -Ddefines + ifeq ($(COND), true) LOCAL_CFLAGS_foo += \ local_cflags_foo @@ -92,6 +99,9 @@ LOCAL_C_INCLUDES_foo += \ LOCAL_EXPORT_C_INCLUDE_DIRS_foo += \ local_export_c_include_dirs_foo +LOCAL_CFLAGS_foo += \ + -Ddefines_foo + endif LOCAL_CFLAGS_bar += \ @@ -115,6 +125,9 @@ LOCAL_C_INCLUDES_bar += \ LOCAL_EXPORT_C_INCLUDE_DIRS_bar += \ local_export_c_include_dirs_bar +LOCAL_CFLAGS_bar += \ + -Ddefines_bar + include external/stlport/libstlport.mk LOCAL_MODULE:= libskia include $(BUILD_SHARED_LIBRARY) diff --git a/platform_tools/android/tests/expectations/SkUserConfig.h b/platform_tools/android/tests/expectations/SkUserConfig.h new file mode 100644 index 0000000000..57827ad846 --- /dev/null +++ b/platform_tools/android/tests/expectations/SkUserConfig.h @@ -0,0 +1,43 @@ + +/////////////////////////////////////////////////////////////////////////////// +// +// THIS FILE IS AUTOGENERATED BY GYP_TO_ANDROID.PY. DO NOT EDIT. +// +// This file contains Skia's upstream include/config/SkUserConfig.h as a +// reference, followed by the actual defines set for Android. +// +/////////////////////////////////////////////////////////////////////////////// + +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* + * Unchanging SkUserConfig.h for testing generate_user_config. + */ + +// Android defines: +#ifndef SkUserConfig_Android_DEFINED +#define SkUserConfig_Android_DEFINED +#ifdef ANDROID + #include +#endif + +#if __BYTE_ORDER == __BIG_ENDIAN + #define SK_CPU_BENDIAN + #undef SK_CPU_LENDIAN +#else + #define SK_CPU_LENDIAN + #undef SK_CPU_BENDIAN +#endif + +#define SK_BUILD_FOR_ANDROID +#define SK_BUILD_FOR_ANDROID_FRAMEWORK +#define SK_SCALAR_IS_FLOAT +#define foo +#define bar + +#endif // SkUserConfig_Android_DEFINED diff --git a/platform_tools/android/tests/expectations/write_local_vars_append_arm b/platform_tools/android/tests/expectations/write_local_vars_append_arm index d9f5c888c9..3e5f18094b 100644 --- a/platform_tools/android/tests/expectations/write_local_vars_append_arm +++ b/platform_tools/android/tests/expectations/write_local_vars_append_arm @@ -19,3 +19,6 @@ LOCAL_C_INCLUDES_arm += \ LOCAL_EXPORT_C_INCLUDE_DIRS_arm += \ local_export_c_include_dirs +LOCAL_CFLAGS_arm += \ + -Ddefines + diff --git a/platform_tools/android/tests/expectations/write_local_vars_append_foo b/platform_tools/android/tests/expectations/write_local_vars_append_foo index be9a814e61..66c4f91488 100644 --- a/platform_tools/android/tests/expectations/write_local_vars_append_foo +++ b/platform_tools/android/tests/expectations/write_local_vars_append_foo @@ -19,3 +19,6 @@ LOCAL_C_INCLUDES_foo += \ LOCAL_EXPORT_C_INCLUDE_DIRS_foo += \ local_export_c_include_dirs +LOCAL_CFLAGS_foo += \ + -Ddefines + diff --git a/platform_tools/android/tests/expectations/write_local_vars_append_no_name b/platform_tools/android/tests/expectations/write_local_vars_append_no_name index 302a4fe11c..e0b31c53b7 100644 --- a/platform_tools/android/tests/expectations/write_local_vars_append_no_name +++ b/platform_tools/android/tests/expectations/write_local_vars_append_no_name @@ -19,3 +19,6 @@ LOCAL_C_INCLUDES += \ LOCAL_EXPORT_C_INCLUDE_DIRS += \ local_export_c_include_dirs +LOCAL_CFLAGS += \ + -Ddefines + diff --git a/platform_tools/android/tests/expectations/write_local_vars_no_append_arm b/platform_tools/android/tests/expectations/write_local_vars_no_append_arm index 01aaecb476..c77a9bb96c 100644 --- a/platform_tools/android/tests/expectations/write_local_vars_no_append_arm +++ b/platform_tools/android/tests/expectations/write_local_vars_no_append_arm @@ -19,3 +19,6 @@ LOCAL_C_INCLUDES_arm := \ LOCAL_EXPORT_C_INCLUDE_DIRS_arm := \ local_export_c_include_dirs +LOCAL_CFLAGS_arm += \ + -Ddefines + diff --git a/platform_tools/android/tests/expectations/write_local_vars_no_append_foo b/platform_tools/android/tests/expectations/write_local_vars_no_append_foo index 22c8306bca..d93b242678 100644 --- a/platform_tools/android/tests/expectations/write_local_vars_no_append_foo +++ b/platform_tools/android/tests/expectations/write_local_vars_no_append_foo @@ -19,3 +19,6 @@ LOCAL_C_INCLUDES_foo := \ LOCAL_EXPORT_C_INCLUDE_DIRS_foo := \ local_export_c_include_dirs +LOCAL_CFLAGS_foo += \ + -Ddefines + diff --git a/platform_tools/android/tests/expectations/write_local_vars_no_append_no_name b/platform_tools/android/tests/expectations/write_local_vars_no_append_no_name index 6742050b0b..e7caec4ad2 100644 --- a/platform_tools/android/tests/expectations/write_local_vars_no_append_no_name +++ b/platform_tools/android/tests/expectations/write_local_vars_no_append_no_name @@ -19,3 +19,6 @@ LOCAL_C_INCLUDES := \ LOCAL_EXPORT_C_INCLUDE_DIRS := \ local_export_c_include_dirs +LOCAL_CFLAGS += \ + -Ddefines + diff --git a/platform_tools/android/tests/generate_user_config_tests.py b/platform_tools/android/tests/generate_user_config_tests.py new file mode 100644 index 0000000000..50f80db66c --- /dev/null +++ b/platform_tools/android/tests/generate_user_config_tests.py @@ -0,0 +1,89 @@ +#!/usr/bin/python + +# Copyright 2014 Google Inc. +# +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +""" +Test generate_user_config.py. +""" + +import argparse +import os +import shutil +import sys +import tempfile +import test_variables +import unittest +import utils + +sys.path.append(test_variables.GYP_GEN_DIR) + +from generate_user_config import generate_user_config as gen_config + +# Name of SkUserConfig file. +USER_CONFIG_NAME = 'SkUserConfig.h' +# Path to unchanging Dummy SkUserConfig file. +FULL_DUMMY_PATH = os.path.join(os.path.dirname(__file__), 'inputs', + USER_CONFIG_NAME) +REBASELINE_MSG = ('If you\'ve modified generate_user_config.py, run ' + '"generate_user_config_tests.py --rebaseline" to rebaseline') + +def generate_dummy_user_config(original_sk_user_config, target_dir): + # Add an arbitrary set of defines + defines = [ 'SK_BUILD_FOR_ANDROID', + 'SK_BUILD_FOR_ANDROID_FRAMEWORK', + 'SK_SCALAR_IS_FLOAT', + 'foo', + 'bar' ] + gen_config(original_sk_user_config=original_sk_user_config, + target_dir=target_dir, ordered_set=defines) + + +class GenUserConfigTest(unittest.TestCase): + + def test_missing_sk_user_config(self): + tmp = tempfile.mkdtemp() + original = os.path.join(tmp, 'filename') + assert not os.path.exists(original) + + with self.assertRaises(AssertionError): + ordered_set = [ 'define' ] + gen_config(original_sk_user_config=original, target_dir=tmp, + ordered_set=ordered_set) + shutil.rmtree(tmp) + + def test_gen_config(self): + tmp = tempfile.mkdtemp() + generate_dummy_user_config(FULL_DUMMY_PATH, tmp) + actual_name = os.path.join(tmp, USER_CONFIG_NAME) + utils.compare_to_expectation(actual_name=actual_name, + expectation_name=USER_CONFIG_NAME, + assert_true=self.assertTrue, msg=REBASELINE_MSG) + shutil.rmtree(tmp) + + +def main(): + loader = unittest.TestLoader() + suite = loader.loadTestsFromTestCase(GenUserConfigTest) + results = unittest.TextTestRunner(verbosity=2).run(suite) + print repr(results) + if not results.wasSuccessful(): + raise Exception('failed one or more unittests') + + +def rebaseline(): + generate_dummy_user_config(FULL_DUMMY_PATH, utils.EXPECTATIONS_DIR) + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('-r', '--rebaseline', help='Rebaseline expectations.', + action='store_true') + args = parser.parse_args() + + if args.rebaseline: + rebaseline() + else: + main() + diff --git a/platform_tools/android/tests/inputs/SkUserConfig.h b/platform_tools/android/tests/inputs/SkUserConfig.h new file mode 100644 index 0000000000..a8f97ebe1f --- /dev/null +++ b/platform_tools/android/tests/inputs/SkUserConfig.h @@ -0,0 +1,10 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* + * Unchanging SkUserConfig.h for testing generate_user_config. + */ diff --git a/platform_tools/android/tests/makefile_writer_tests.py b/platform_tools/android/tests/makefile_writer_tests.py index 9a764b5c05..1b42bf37d2 100644 --- a/platform_tools/android/tests/makefile_writer_tests.py +++ b/platform_tools/android/tests/makefile_writer_tests.py @@ -16,14 +16,16 @@ import sys import tempfile import test_variables import unittest +import utils sys.path.append(test_variables.GYP_GEN_DIR) import makefile_writer import vars_dict_lib -EXPECTATIONS_DIR = os.path.join(os.path.dirname(__file__), 'expectations') MAKEFILE_NAME = 'Android.mk' +REBASELINE_MSG = ('If you\'ve modified makefile_writer.py, run ' + '"makefile_writer_tests.py --rebaseline" to rebaseline') def generate_dummy_vars_dict(name): """Create a VarsDict and fill it with dummy entries. @@ -42,6 +44,31 @@ def generate_dummy_vars_dict(name): vars_dict[key].add(entry) return vars_dict +def generate_write_local_vars_params(): + """Generator to compute params for write_local_vars tests. + + Each iteration yields a new tuple: (filename, append, name), specific to a + way to call write_local_vars for the tests. + + Yields: + filename: filename corresponding to the expectation file for this + combination of params to write_local_vars. + append: boolean to pass as append parameter to write_local_vars. + name: string to pass as name parameter to write_local_vars. + """ + for append in [ True, False ]: + for name in [ None, 'arm', 'foo' ]: + filename = 'write_local_vars' + if append: + filename += '_append' + else: + filename += '_no_append' + if name: + filename += '_' + name + else: + filename += '_no_name' + + yield (filename, append, name) def generate_dummy_vars_dict_data(name, condition): """Create a dummy VarsDictData. @@ -94,26 +121,6 @@ class MakefileWriterTest(unittest.TestCase): self.assertEqual(f.tell(), 0) f.close() - def __compare_files(self, actual_name, expectation_name, msg=None): - """Check that two files are identical. - - Assert line by line that the files match. - - Args: - actual_name: Full path to the test file. - expectation_name: Basename of the expectations file within which - to compare. The file is expected to be in - platform_tools/android/tests/expectations. - msg: Message to pass to assertEqual. - Raises: - AssertionError: If the files do not match. - """ - with open(actual_name, 'r') as result: - with open(os.path.join(EXPECTATIONS_DIR, - expectation_name)) as expectation: - for line in result: - self.assertEqual(line, expectation.readline(), msg) - def test_write_group(self): animals = ('dog', 'cat', 'mouse', 'elephant') fd, filename = tempfile.mkstemp() @@ -121,56 +128,44 @@ class MakefileWriterTest(unittest.TestCase): makefile_writer.write_group(f, 'animals', animals, False) os.close(fd) # Now confirm that it matches expectations - self.__compare_files(filename, 'animals.txt') + utils.compare_to_expectation(filename, 'animals.txt', self.assertTrue) with open(filename, 'w') as f: makefile_writer.write_group(f, 'animals_append', animals, True) # Now confirm that it matches expectations - self.__compare_files(filename, 'animals_append.txt') + utils.compare_to_expectation(filename, 'animals_append.txt', + self.assertTrue) os.remove(filename) def test_write_local_vars(self): vars_dict = generate_dummy_vars_dict(None) - - # Call variations of write_local_vars. - for append in [ True, False ]: - for name in [ None, 'arm', 'foo' ]: - # Now write to a temporary file. - fd, outfile = tempfile.mkstemp() - with open(outfile, 'w') as f: - makefile_writer.write_local_vars(f, vars_dict, append, name) - os.close(fd) - - # Compare to the expected file. - filename = 'write_local_vars' - if append: - filename += '_append' - else: - filename += '_no_append' - if name: - filename += '_' + name - else: - filename += '_no_name' - self.__compare_files(outfile, filename) - - # KNOWN_TARGETS is always a part of the input VarsDict, but it should - # not be written to the resulting file. - # Note that this assumes none of our dummy entries is 'KNOWN_TARGETS'. - known_targets_name = 'KNOWN_TARGETS' - self.assertEqual(len(vars_dict[known_targets_name]), 1) - - with open(outfile, 'r') as f: - self.assertNotIn(known_targets_name, f.read()) - os.remove(outfile) + # Compare various ways of calling write_local_vars to expectations. + for (filename, append, name) in generate_write_local_vars_params(): + fd, outfile = tempfile.mkstemp() + with open(outfile, 'w') as f: + makefile_writer.write_local_vars(f, vars_dict, append, name) + os.close(fd) + + # Compare to the expected file. + utils.compare_to_expectation(outfile, filename, self.assertTrue, + REBASELINE_MSG) + + # KNOWN_TARGETS is always a key in the input VarsDict, but it should not + # be written to the resulting file. + # Note that this assumes none of our dummy entries is 'KNOWN_TARGETS'. + known_targets_name = 'KNOWN_TARGETS' + self.assertEqual(len(vars_dict[known_targets_name]), 1) + + with open(outfile, 'r') as f: + self.assertNotIn(known_targets_name, f.read()) + os.remove(outfile) def test_write_android_mk(self): outdir = tempfile.mkdtemp() generate_dummy_makefile(outdir) - self.__compare_files(os.path.join(outdir, MAKEFILE_NAME), MAKEFILE_NAME, - 'If you\'ve modified makefile_writer.py, run ' + - '"makefile_writer_tests.py --rebaseline" ' + - 'to rebaseline') + utils.compare_to_expectation(os.path.join(outdir, MAKEFILE_NAME), + MAKEFILE_NAME, self.assertTrue, REBASELINE_MSG) shutil.rmtree(outdir) @@ -184,15 +179,23 @@ def main(): raise Exception('failed one or more unittests') +def rebaseline(): + generate_dummy_makefile(utils.EXPECTATIONS_DIR) + + vars_dict = generate_dummy_vars_dict(None) + for (filename, append, name) in generate_write_local_vars_params(): + with open(os.path.join(utils.EXPECTATIONS_DIR, filename), 'w') as f: + makefile_writer.write_local_vars(f, vars_dict, append, name) + + if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('-r', '--rebaseline', - help='Rebaseline expectation for Android.mk', + parser.add_argument('-r', '--rebaseline', help='Rebaseline expectations.', action='store_true') args = parser.parse_args() if args.rebaseline: - generate_dummy_makefile(EXPECTATIONS_DIR) + rebaseline() else: main() diff --git a/platform_tools/android/tests/ordered_set_tests.py b/platform_tools/android/tests/ordered_set_tests.py index 248f0f6f6c..01016d9735 100644 --- a/platform_tools/android/tests/ordered_set_tests.py +++ b/platform_tools/android/tests/ordered_set_tests.py @@ -59,6 +59,15 @@ class OrderedSetTest(unittest.TestCase): self.assertEqual(len(self.__set), RANGE-i-1) self.assertFalse(dummy_var in self.__set) + # Test reset(), for a range of ranges. + for subrange in range(RANGE): + for i in range(subrange): + self.__set.add(create_dummy_var(i)) + self.assertEqual(len(self.__set), subrange) + self.__set.reset() + self.assertEqual(len(self.__set), 0) + + def main(): loader = unittest.TestLoader() suite = loader.loadTestsFromTestCase(OrderedSetTest) diff --git a/platform_tools/android/tests/utils.py b/platform_tools/android/tests/utils.py new file mode 100644 index 0000000000..0a969964b5 --- /dev/null +++ b/platform_tools/android/tests/utils.py @@ -0,0 +1,36 @@ +#!/usr/bin/python + +# Copyright 2014 Google Inc. +# +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +""" +Common code for tests. +""" +import filecmp +import os + +EXPECTATIONS_DIR = os.path.join(os.path.dirname(__file__), 'expectations') + +def compare_to_expectation(actual_name, expectation_name, assert_true, + msg=None): + """Check that a generated file matches its expectation in EXPECTATIONS_DIR. + + Assert that the generated file and expectation file are identical. + + Args: + actual_name: Full path to the test file. + expectation_name: Basename of the expectations file within which + to compare. The file is expected to be in + platform_tools/android/tests/expectations. + assert_true: function for asserting a statement is True + + Args: + condition: statement to check for True. + msg: message to print if the files are not equal. + + msg: Message to pass to assert_true. + """ + full_expectations_path = os.path.join(EXPECTATIONS_DIR, expectation_name) + assert_true(filecmp.cmp(actual_name, full_expectations_path), msg) diff --git a/platform_tools/android/tests/var_dict_tests.py b/platform_tools/android/tests/var_dict_tests.py index 8cd9677068..94f0492b6f 100644 --- a/platform_tools/android/tests/var_dict_tests.py +++ b/platform_tools/android/tests/var_dict_tests.py @@ -60,29 +60,9 @@ class VarsDictTest(unittest.TestCase): for i in range(RANGE): v_dict = VarsDict() # Add something common to each field, as well as a unique entry - v_dict.LOCAL_CFLAGS.add('cflag') - v_dict.LOCAL_CFLAGS.add(str(i)) - - v_dict.LOCAL_CPPFLAGS.add('cppflag') - v_dict.LOCAL_CPPFLAGS.add(str(i)) - - v_dict.LOCAL_SRC_FILES.add('src') - v_dict.LOCAL_SRC_FILES.add(str(i)) - - v_dict.LOCAL_SHARED_LIBRARIES.add('shared') - v_dict.LOCAL_SHARED_LIBRARIES.add(str(i)) - - v_dict.LOCAL_STATIC_LIBRARIES.add('static') - v_dict.LOCAL_STATIC_LIBRARIES.add(str(i)) - - v_dict.LOCAL_C_INCLUDES.add('includes') - v_dict.LOCAL_C_INCLUDES.add(str(i)) - - v_dict.LOCAL_EXPORT_C_INCLUDE_DIRS.add('exports') - v_dict.LOCAL_EXPORT_C_INCLUDE_DIRS.add(str(i)) - - v_dict.KNOWN_TARGETS.add('known') - v_dict.KNOWN_TARGETS.add(str(i)) + for key in v_dict.keys(): + v_dict[key].add(key.lower()) + v_dict[key].add(str(i)) self.assert_consistency(v_dict) -- cgit v1.2.3