From d79572f73e650d644099fbc60bbff156db0281d5 Mon Sep 17 00:00:00 2001 From: Dan Shi Date: Fri, 13 Nov 2020 14:33:46 -0800 Subject: [PATCH] Add unit_test test option in test configs This change allows a test (native, java, rust or python) to be included in host-unit-tests suite when test option `unit_test` is set to true. Bug: 172006742 Test: m host-unit-tests Change-Id: I69d3eb5b51198c549e2e6914ceac3a4fc33c3cf2 --- androidmk/androidmk/android.go | 2 ++ cc/androidmk.go | 3 +++ cc/test.go | 3 +++ java/androidmk.go | 3 +++ java/java.go | 3 +++ python/androidmk.go | 4 ++++ python/test.go | 9 +++++++++ rust/androidmk.go | 3 +++ rust/test.go | 9 +++++++++ 9 files changed, 39 insertions(+) diff --git a/androidmk/androidmk/android.go b/androidmk/androidmk/android.go index 739a9658f..4540a1f3d 100644 --- a/androidmk/androidmk/android.go +++ b/androidmk/androidmk/android.go @@ -214,6 +214,8 @@ func init() { "LOCAL_PRIVATE_PLATFORM_APIS": "platform_apis", "LOCAL_JETIFIER_ENABLED": "jetifier", + + "LOCAL_IS_UNIT_TEST": "unit_test", }) } diff --git a/cc/androidmk.go b/cc/androidmk.go index 38269cb8f..8c1aead62 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -370,6 +370,9 @@ func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android. entries.SetBool("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", true) } entries.AddStrings("LOCAL_TEST_MAINLINE_MODULES", test.Properties.Test_mainline_modules...) + if Bool(test.Properties.Test_options.Unit_test) { + entries.SetBool("LOCAL_IS_UNIT_TEST", true) + } }) androidMkWriteTestData(test.data, ctx, entries) diff --git a/cc/test.go b/cc/test.go index 619dc4d00..37726914b 100644 --- a/cc/test.go +++ b/cc/test.go @@ -46,6 +46,9 @@ type TestOptions struct { // a list of extra test configuration files that should be installed with the module. Extra_test_configs []string `android:"path,arch_variant"` + + // If the test is a hostside(no device required) unittest that shall be run during presubmit check. + Unit_test *bool } type TestBinaryProperties struct { diff --git a/java/androidmk.go b/java/androidmk.go index c6062457f..d428abdb1 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -160,6 +160,9 @@ func (j *Test) AndroidMkEntries() []android.AndroidMkEntries { entries.SetString("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", "true") } entries.AddStrings("LOCAL_TEST_MAINLINE_MODULES", j.testProperties.Test_mainline_modules...) + if Bool(j.testProperties.Test_options.Unit_test) { + entries.SetBool("LOCAL_IS_UNIT_TEST", true) + } }) return entriesList diff --git a/java/java.go b/java/java.go index d6dc148a6..bae8dcf4f 100644 --- a/java/java.go +++ b/java/java.go @@ -2226,6 +2226,9 @@ func LibraryHostFactory() android.Module { type TestOptions struct { // a list of extra test configuration files that should be installed with the module. Extra_test_configs []string `android:"path,arch_variant"` + + // If the test is a hostside(no device required) unittest that shall be run during presubmit check. + Unit_test *bool } type testProperties struct { diff --git a/python/androidmk.go b/python/androidmk.go index 8ad5889b5..040b6bef8 100644 --- a/python/androidmk.go +++ b/python/androidmk.go @@ -80,6 +80,10 @@ func (p *testDecorator) AndroidMk(base *Module, ret *android.AndroidMkData) { fmt.Fprintln(w, "LOCAL_TEST_DATA :=", strings.Join(android.AndroidMkDataPaths(p.data), " ")) } + + if Bool(p.testProperties.Test_options.Unit_test) { + fmt.Fprintln(w, "LOCAL_IS_UNIT_TEST := true") + } }) base.subAndroidMk(ret, p.binaryDecorator.pythonInstaller) } diff --git a/python/test.go b/python/test.go index 434e71abf..f9baa465c 100644 --- a/python/test.go +++ b/python/test.go @@ -26,6 +26,12 @@ func init() { android.RegisterModuleType("python_test", PythonTestFactory) } +// Test option struct. +type TestOptions struct { + // If the test is a hostside(no device required) unittest that shall be run during presubmit check. + Unit_test *bool +} + type TestProperties struct { // the name of the test configuration (for example "AndroidTest.xml") that should be // installed with the module. @@ -38,6 +44,9 @@ type TestProperties struct { // list of files or filegroup modules that provide data that should be installed alongside // the test Data []string `android:"path,arch_variant"` + + // Test options. + Test_options TestOptions } type testDecorator struct { diff --git a/rust/androidmk.go b/rust/androidmk.go index 29e4bd75b..f98360a32 100644 --- a/rust/androidmk.go +++ b/rust/androidmk.go @@ -116,6 +116,9 @@ func (test *testDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidM if !BoolDefault(test.Properties.Auto_gen_config, true) { fmt.Fprintln(w, "LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG := true") } + if Bool(test.Properties.Test_options.Unit_test) { + fmt.Fprintln(w, "LOCAL_IS_UNIT_TEST := true") + } }) // TODO(chh): add test data with androidMkWriteTestData(test.data, ctx, ret) } diff --git a/rust/test.go b/rust/test.go index bc7f53c7c..408e03a6d 100644 --- a/rust/test.go +++ b/rust/test.go @@ -19,6 +19,12 @@ import ( "android/soong/tradefed" ) +// Test option struct. +type TestOptions struct { + // If the test is a hostside(no device required) unittest that shall be run during presubmit check. + Unit_test *bool +} + type TestProperties struct { // Disables the creation of a test-specific directory when used with // relative_install_path. Useful if several tests need to be in the same @@ -44,6 +50,9 @@ type TestProperties struct { // if set, build with the standard Rust test harness. Defaults to true. Test_harness *bool + + // Test options. + Test_options TestOptions } // A test module is a binary module with extra --test compiler flag