Implement LOCAL_TEST_DATA to ship data with tests
This can be used to ship source data as test artifacts next to native
tests. It works for both local builds and the test bundles using
package_modules.mk.
You just specify a file list relative to the local directory, and those
files will be copied next to the executable under
/data/nativetest*/<module>/...:
LOCAL_MODULE := mytest
LOCAL_TEST_DATA := data/file1 file2
/data/nativetest/mytest/mytest
/data/nativetest/mytest/data/file1
/data/nativetest/mytest/file2
If the data is in another directory, you may also specify a different
prefix for the source files:
LOCAL_TEST_DATA := external/skia:resources/f.xml
/data/nativetest/skia_test/resources/f.xml
And there's a new convenience macro to find a list of files in this
format:
LOCAL_TEST_DATA := $(call find-test-data-in-subdirs,external/skia,"*.xml",resources)
I'll expand this to native benchmarks and fuzz tests in a later change,
since they don't have their own module classes yet.
Bug: 30564705
Test: m -j minikin_tests; ls $OUT/data/nativetest*/minikin_tests
Test: m -j continuous_native_tests dist; zipinfo -1 out/dist/*continuous_native_tests*.zip
Change-Id: Ic76a7b62e7f567f259c4ab1510ee97d26600ba9a
diff --git a/core/definitions.mk b/core/definitions.mk
index 698f52c..969260b 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -469,6 +469,20 @@
endef
###########################################################
+## Find test data in a form required by LOCAL_TEST_DATA
+## $(1): the base dir, relative to the root of the source tree.
+## $(3): the file name pattern to be passed to find as "-name"
+## $(2): a list of subdirs of the base dir
+###########################################################
+
+define find-test-data-in-subdirs
+$(foreach f,$(sort $(patsubst ./%,%, \
+ $(shell cd $(1) ; \
+ find -L $(3) -type f -and -name $(2) -and -not -name ".*") \
+)),$(1):$(f))
+endef
+
+###########################################################
## Function we can evaluate to introduce a dynamic dependency
###########################################################