diff options
author | Brett Chabot <brettchabot@android.com> | 2011-06-17 17:07:12 -0700 |
---|---|---|
committer | Brett Chabot <brettchabot@android.com> | 2011-07-10 13:26:41 -0700 |
commit | bb5918ed814ed8dded262d4558588a7183ca71ce (patch) | |
tree | 48adabe79f50f2dca57fb2ccbe0ce05af71b269d /testrunner/tests | |
parent | 6b47b8888cfa5c9e24b52b8077b611c7fd8d9a34 (diff) | |
download | android_development-bb5918ed814ed8dded262d4558588a7183ca71ce.tar.gz android_development-bb5918ed814ed8dded262d4558588a7183ca71ce.tar.bz2 android_development-bb5918ed814ed8dded262d4558588a7183ca71ce.zip |
Add gtest target support for runtest --path.
This is a rough initial version. It makes several assumptions:
- assumes each test source file is built into module with name equal
to basename of source file
- assumes tests get installed into /data/nativetest
However, given those assumptions, both:
$ runtest --path <path to directory containing gtest source> and
$ runtest --path <path to single source file>
should work.
Coming soon: gtest host support
Bugs 4563370, 4584339
Change-Id: Ia42aeed7f9ee6402b0ceb7b5ccaaa66ac636fe49
Diffstat (limited to 'testrunner/tests')
-rw-r--r-- | testrunner/tests/Android_gtestlib.mk | 56 | ||||
-rw-r--r-- | testrunner/tests/Android_java.mk | 26 | ||||
-rw-r--r-- | testrunner/tests/Android_native.mk | 21 | ||||
-rwxr-xr-x | testrunner/tests/android_mk_tests.py | 90 |
4 files changed, 193 insertions, 0 deletions
diff --git a/testrunner/tests/Android_gtestlib.mk b/testrunner/tests/Android_gtestlib.mk new file mode 100644 index 000000000..0d3ec8faf --- /dev/null +++ b/testrunner/tests/Android_gtestlib.mk @@ -0,0 +1,56 @@ +# Copyright (C) 2011 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Build the unit tests. +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +ifneq ($(TARGET_SIMULATOR),true) + +# Build the unit tests. +test_src_files := $(call find-subdir-files, *.cpp) + +shared_libraries := \ + libz \ + liblog \ + libcutils \ + libutils \ + libstlport + +static_libraries := \ + libgtest \ + libgtest_main + +c_includes := \ + external/zlib \ + external/icu4c/common \ + bionic \ + bionic/libstdc++/include \ + external/gtest/include \ + external/stlport/stlport + +module_tags := eng tests + +$(foreach file,$(test_src_files), \ + $(eval include $(CLEAR_VARS)) \ + $(eval LOCAL_SHARED_LIBRARIES := $(shared_libraries)) \ + $(eval LOCAL_STATIC_LIBRARIES := $(static_libraries)) \ + $(eval LOCAL_C_INCLUDES := $(c_includes)) \ + $(eval LOCAL_SRC_FILES := $(file)) \ + $(eval LOCAL_MODULE := $(notdir $(file:%.cpp=%))) \ + $(eval LOCAL_MODULE_TAGS := $(module_tags)) \ + $(eval include $(BUILD_EXECUTABLE)) \ +) + +endif diff --git a/testrunner/tests/Android_java.mk b/testrunner/tests/Android_java.mk new file mode 100644 index 000000000..ff9138a53 --- /dev/null +++ b/testrunner/tests/Android_java.mk @@ -0,0 +1,26 @@ +# Copyright (C) 2011 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) +# We only want this apk build for tests. +LOCAL_MODULE_TAGS := tests +LOCAL_JAVA_LIBRARIES := foo android.test.runner +# Include all test java files. +LOCAL_SRC_FILES := $(call all-java-files-under, src) +LOCAL_PACKAGE_NAME := ApiDemosTests +LOCAL_INSTRUMENTATION_FOR := ApiDemos +LOCAL_SDK_VERSION := current + +include $(BUILD_PACKAGE) diff --git a/testrunner/tests/Android_native.mk b/testrunner/tests/Android_native.mk new file mode 100644 index 000000000..6273ccbd8 --- /dev/null +++ b/testrunner/tests/Android_native.mk @@ -0,0 +1,21 @@ +# Copyright (C) 2011 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +include $(CLEAR_VARS) +test_module := foo +LOCAL_MODULE := $(test_module) +recursive_var := $(recursive_var) +LOCAL_MODULE_TAGS := tags +LOCAL_SRC_FILES := src +include $(BUILD_NATIVE_TEST) diff --git a/testrunner/tests/android_mk_tests.py b/testrunner/tests/android_mk_tests.py new file mode 100755 index 000000000..ff1f2896c --- /dev/null +++ b/testrunner/tests/android_mk_tests.py @@ -0,0 +1,90 @@ +#!/usr/bin/python +# +# +# Copyright 2011, The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import unittest +sys.path.append('../..') + +from testrunner import android_mk + + +class AndroidMKTest(unittest.TestCase): + """Unit tests for AndroidMK.""" + + def testHasGTest(self): + """Test for AndroidMK.HasGTest.""" + mk_parser = android_mk.CreateAndroidMK(path='.', + filename='Android_native.mk') + self.assertTrue(mk_parser.HasGTest()) + + def testHasGTest_lib(self): + """Test for AndroidMK.HasGTest.""" + mk_parser = android_mk.CreateAndroidMK(path='.', + filename='Android_gtestlib.mk') + self.assertTrue(mk_parser.HasGTest()) + + def testHasGTest_false(self): + """Negative test for AndroidMK.HasGTest.""" + mk_parser = android_mk.CreateAndroidMK(path='.', filename='Android_java.mk') + self.assertFalse(mk_parser.HasGTest()) + + def testHasJavaLibrary(self): + """Test for AndroidMK.HasJavaLibrary.""" + mk_parser = android_mk.CreateAndroidMK(path='.', + filename='Android_java.mk') + self.assertTrue(mk_parser.HasJavaLibrary('android.test.runner')) + + def testHasJavaLibrary_missing(self): + """Negative test for AndroidMK.HasJavaLibrary. + + Test behavior when LOCAL_JAVA_LIBARIES rule is not present in makefile. + """ + mk_parser = android_mk.CreateAndroidMK(path='.', + filename='Android_native.mk') + self.assertFalse(mk_parser.HasJavaLibrary('android.test.runner')) + + def testHasJavaLibrary_false(self): + """Negative test for AndroidMK.HasJavaLibrary. + + Test behavior when LOCAL_JAVA_LIBARIES rule is present, but does not list + given library. + """ + mk_parser = android_mk.CreateAndroidMK(path='.', filename='Android_java.mk') + self.assertFalse(mk_parser.HasJavaLibrary('doesntexist')) + + def testGetExpandedVariable(self): + """Test for AndroidMK.GetExpandedVariable. + """ + mk_parser = android_mk.CreateAndroidMK(path='.', + filename='Android_native.mk') + self.assertEquals('foo', mk_parser.GetExpandedVariable('LOCAL_MODULE')) + + def testGetExpandedVariable_loop(self): + """Test for AndroidMK.GetExpandedVariable where variable expansion loops + """ + mk_parser = android_mk.CreateAndroidMK(path='.', + filename='Android_native.mk') + try: + mk_parser.GetExpandedVariable('recursive_var') + self.assertTrue(False) + except RuntimeError: + # expected + pass + + +if __name__ == '__main__': + unittest.main() |