bp2build converter for sh_test followup
Test: m nothing
Bug: 283486885
Change-Id: Ib8229e75dfcd9fd251fb1a83485cf5f88bdc3afb
diff --git a/bp2build/Android.bp b/bp2build/Android.bp
index 4a3786f..c104833 100644
--- a/bp2build/Android.bp
+++ b/bp2build/Android.bp
@@ -83,6 +83,7 @@
"python_library_conversion_test.go",
"python_test_conversion_test.go",
"sh_conversion_test.go",
+ "sh_test_conversion_test.go",
"soong_config_module_type_conversion_test.go",
],
pluginFor: [
diff --git a/bp2build/sh_test_conversion_test.go b/bp2build/sh_test_conversion_test.go
new file mode 100644
index 0000000..e99d566
--- /dev/null
+++ b/bp2build/sh_test_conversion_test.go
@@ -0,0 +1,186 @@
+// Copyright 2023 Google Inc. All rights reserved.
+//
+// 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.
+
+package bp2build
+
+import (
+ "testing"
+
+ "android/soong/android"
+ "android/soong/sh"
+)
+
+func TestShTestSimple(t *testing.T) {
+ RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
+ Description: "sh_test test",
+ ModuleTypeUnderTest: "sh_test",
+ ModuleTypeUnderTestFactory: sh.ShTestFactory,
+ Blueprint: `sh_test{
+ name: "sts-rootcanal-sidebins",
+ src: "empty.sh",
+ test_suites: [
+ "sts",
+ "sts-lite",
+ ],
+ data_bins: [
+ "android.hardware.bluetooth@1.1-service.sim",
+ "android.hardware.bluetooth@1.1-impl-sim"
+ ],
+ data: ["android.hardware.bluetooth@1.1-service.sim.rc"],
+ data_libs: ["libc++","libcrypto"],
+ test_config: "art-gtests-target-install-apex.xml",
+ test_config_template: ":art-run-test-target-template",
+ auto_gen_config: false,
+ test_options:{tags: ["no-remote"],
+ },
+}`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("sh_test", "sts-rootcanal-sidebins", AttrNameToString{
+ "srcs": `["empty.sh"]`,
+ "data": `[
+ "android.hardware.bluetooth@1.1-service.sim.rc",
+ "android.hardware.bluetooth@1.1-service.sim",
+ "android.hardware.bluetooth@1.1-impl-sim",
+ "libc++",
+ "libcrypto",
+ ]`,
+ "test_config": `"art-gtests-target-install-apex.xml"`,
+ "test_config_template": `":art-run-test-target-template"`,
+ "auto_gen_config": "False",
+ "tags": `["no-remote"]`,
+ })},
+ })
+}
+
+func TestShTestHostSimple(t *testing.T) {
+ RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
+ Description: "sh_test_host test",
+ ModuleTypeUnderTest: "sh_test_host",
+ ModuleTypeUnderTestFactory: sh.ShTestHostFactory,
+ Blueprint: `sh_test_host{
+ name: "sts-rootcanal-sidebins",
+ src: "empty.sh",
+ test_suites: [
+ "sts",
+ "sts-lite",
+ ],
+ data_bins: [
+ "android.hardware.bluetooth@1.1-service.sim",
+ "android.hardware.bluetooth@1.1-impl-sim"
+ ],
+ data: ["android.hardware.bluetooth@1.1-service.sim.rc"],
+ data_libs: ["libc++","libcrypto"],
+ test_config: "art-gtests-target-install-apex.xml",
+ test_config_template: ":art-run-test-target-template",
+ auto_gen_config: false,
+ test_options:{tags: ["no-remote"],
+ },
+}`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("sh_test", "sts-rootcanal-sidebins", AttrNameToString{
+ "srcs": `["empty.sh"]`,
+ "data": `[
+ "android.hardware.bluetooth@1.1-service.sim.rc",
+ "android.hardware.bluetooth@1.1-service.sim",
+ "android.hardware.bluetooth@1.1-impl-sim",
+ "libc++",
+ "libcrypto",
+ ]`,
+ "tags": `["no-remote"]`,
+ "test_config": `"art-gtests-target-install-apex.xml"`,
+ "test_config_template": `":art-run-test-target-template"`,
+ "auto_gen_config": "False",
+ "target_compatible_with": `select({
+ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
+ "//conditions:default": [],
+ })`,
+ })},
+ })
+}
+
+func TestShTestSimpleUnset(t *testing.T) {
+ RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
+ Description: "sh_test test",
+ ModuleTypeUnderTest: "sh_test",
+ ModuleTypeUnderTestFactory: sh.ShTestFactory,
+ Blueprint: `sh_test{
+ name: "sts-rootcanal-sidebins",
+ src: "empty.sh",
+ test_suites: [
+ "sts",
+ "sts-lite",
+ ],
+ data_bins: [
+ "android.hardware.bluetooth@1.1-service.sim",
+ "android.hardware.bluetooth@1.1-impl-sim"
+ ],
+ data: ["android.hardware.bluetooth@1.1-service.sim.rc"],
+ data_libs: ["libc++","libcrypto"],
+ test_options:{tags: ["no-remote"],
+ },
+}`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("sh_test", "sts-rootcanal-sidebins", AttrNameToString{
+ "srcs": `["empty.sh"]`,
+ "data": `[
+ "android.hardware.bluetooth@1.1-service.sim.rc",
+ "android.hardware.bluetooth@1.1-service.sim",
+ "android.hardware.bluetooth@1.1-impl-sim",
+ "libc++",
+ "libcrypto",
+ ]`,
+ "tags": `["no-remote"]`,
+ })},
+ })
+}
+
+func TestShTestHostSimpleUnset(t *testing.T) {
+ RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
+ Description: "sh_test_host test",
+ ModuleTypeUnderTest: "sh_test_host",
+ ModuleTypeUnderTestFactory: sh.ShTestHostFactory,
+ Blueprint: `sh_test_host{
+ name: "sts-rootcanal-sidebins",
+ src: "empty.sh",
+ test_suites: [
+ "sts",
+ "sts-lite",
+ ],
+ data_bins: [
+ "android.hardware.bluetooth@1.1-service.sim",
+ "android.hardware.bluetooth@1.1-impl-sim"
+ ],
+ data: ["android.hardware.bluetooth@1.1-service.sim.rc"],
+ data_libs: ["libc++","libcrypto"],
+ test_options:{tags: ["no-remote"],
+ },
+}`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("sh_test", "sts-rootcanal-sidebins", AttrNameToString{
+ "srcs": `["empty.sh"]`,
+ "data": `[
+ "android.hardware.bluetooth@1.1-service.sim.rc",
+ "android.hardware.bluetooth@1.1-service.sim",
+ "android.hardware.bluetooth@1.1-impl-sim",
+ "libc++",
+ "libcrypto",
+ ]`,
+ "tags": `["no-remote"]`,
+ "target_compatible_with": `select({
+ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
+ "//conditions:default": [],
+ })`,
+ })},
+ })
+}
diff --git a/sh/sh_binary.go b/sh/sh_binary.go
index d2eede6..5459904 100644
--- a/sh/sh_binary.go
+++ b/sh/sh_binary.go
@@ -502,7 +502,7 @@
// sh_test defines a shell script based test module.
func ShTestFactory() android.Module {
module := &ShTest{}
- initShBinaryModule(&module.ShBinary, false)
+ initShBinaryModule(&module.ShBinary, true)
module.AddProperties(&module.testProperties)
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst)
@@ -512,7 +512,7 @@
// sh_test_host defines a shell script based test module that runs on a host.
func ShTestHostFactory() android.Module {
module := &ShTest{}
- initShBinaryModule(&module.ShBinary, false)
+ initShBinaryModule(&module.ShBinary, true)
module.AddProperties(&module.testProperties)
// Default sh_test_host to unit_tests = true
if module.testProperties.Test_options.Unit_test == nil {
@@ -548,6 +548,15 @@
// visibility
}
+type bazelShTestAttributes struct {
+ Srcs bazel.LabelListAttribute
+ Data bazel.LabelListAttribute
+ Tags bazel.StringListAttribute
+ Test_config *string
+ Test_config_template *string
+ Auto_gen_config *bool
+}
+
func (m *ShBinary) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
srcs := bazel.MakeLabelListAttribute(
android.BazelLabelForModuleSrc(ctx, []string{*m.properties.Src}))
@@ -576,6 +585,41 @@
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
}
+func (m *ShTest) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ srcs := bazel.MakeLabelListAttribute(
+ android.BazelLabelForModuleSrc(ctx, []string{*m.properties.Src}))
+
+ combinedData := append(m.testProperties.Data, m.testProperties.Data_bins...)
+ combinedData = append(combinedData, m.testProperties.Data_libs...)
+
+ data := bazel.MakeLabelListAttribute(
+ android.BazelLabelForModuleSrc(ctx, combinedData))
+
+ tags := bazel.MakeStringListAttribute(
+ m.testProperties.Test_options.Tags)
+
+ test_config := m.testProperties.Test_config
+
+ test_config_template := m.testProperties.Test_config_template
+
+ auto_gen_config := m.testProperties.Auto_gen_config
+
+ attrs := &bazelShTestAttributes{
+ Srcs: srcs,
+ Data: data,
+ Tags: tags,
+ Test_config: test_config,
+ Test_config_template: test_config_template,
+ Auto_gen_config: auto_gen_config,
+ }
+
+ props := bazel.BazelTargetModuleProperties{
+ Rule_class: "sh_test",
+ Bzl_load_location: "//build/bazel/rules:sh_test.bzl",
+ }
+ ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
+}
+
var Bool = proptools.Bool
var _ snapshot.RelativeInstallPath = (*ShBinary)(nil)