Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eefca737 authored by Ronald Braunstein's avatar Ronald Braunstein Committed by Gerrit Code Review
Browse files

Merge "Test_Module_Config soong implementation" into main

parents d3a0ea94 fce43165
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1316,6 +1316,12 @@ func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	a.extraTestConfigs = android.PathsForModuleSrc(ctx, a.testProperties.Test_options.Extra_test_configs)
	a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
	android.SetProvider(ctx, testing.TestModuleProviderKey, testing.TestModuleProviderData{})
	android.SetProvider(ctx, tradefed.BaseTestProviderKey, tradefed.BaseTestProviderData{
		InstalledFiles:          a.data,
		OutputFile:              a.OutputFile(),
		TestConfig:              a.testConfig,
		HostRequiredModuleNames: a.HostRequiredModuleNames(),
	})
}

func (a *AndroidTest) FixTestConfig(ctx android.ModuleContext, testConfig android.Path) android.Path {
+54 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
from __future__ import print_function

import argparse
import json
import sys
from xml.dom import minidom

@@ -31,6 +32,8 @@ from manifest import write_xml
KNOWN_PREPARERS = ['com.android.tradefed.targetprep.TestAppInstallSetup',
                   'com.android.tradefed.targetprep.suite.SuiteApkInstaller']

KNOWN_TEST_RUNNERS = ['com.android.tradefed.testtype.AndroidJUnitTest']

MAINLINE_CONTROLLER = 'com.android.tradefed.testtype.suite.module.MainlineTestModuleController'

def parse_args():
@@ -43,8 +46,12 @@ def parse_args():
                      help=('overwrite package fields in the test config'))
  parser.add_argument('--test-file-name', default='', dest='test_file_name',
                      help=('overwrite test file name in the test config'))
  parser.add_argument('--orig-test-file-name', default='', dest='orig_test_file_name',
                      help=('Use with test-file-name to only override a single apk'))
  parser.add_argument('--mainline-package-name', default='', dest='mainline_package_name',
                      help=('overwrite mainline module package name in the test config'))
  parser.add_argument('--test-runner-options', default='', dest='test_runner_options',
                      help=('Add test runner options in the test config'))
  parser.add_argument('input', help='input test config file')
  parser.add_argument('output', help='output test config file')
  return parser.parse_args()
@@ -76,6 +83,18 @@ def overwrite_test_file_name(test_config_doc, test_file_name):
        if option.getAttribute('name') == "test-file-name":
          option.setAttribute('value', test_file_name)

def overwrite_single_test_file_name(test_config_doc, orig_test_file_name, new_test_file_name):

  test_config = parse_test_config(test_config_doc)
  tests = get_children_with_tag(test_config, 'target_preparer')

  for test in tests:
    if test.getAttribute('class') in KNOWN_PREPARERS:
      options = get_children_with_tag(test, 'option')
      for option in options:
        if option.getAttribute('name') == "test-file-name" and option.getAttribute('value') == orig_test_file_name:
          option.setAttribute('value', new_test_file_name)

def overwrite_mainline_module_package_name(test_config_doc, mainline_package_name):

  test_config = parse_test_config(test_config_doc)
@@ -86,6 +105,31 @@ def overwrite_mainline_module_package_name(test_config_doc, mainline_package_nam
        if option.getAttribute('name') == "mainline-module-package-name":
          option.setAttribute('value', mainline_package_name)

def add_test_runner_options_toplevel(test_config_doc, test_runner_options):

  test_config = parse_test_config(test_config_doc)

  test_config.appendChild(test_config_doc.createComment("Options from Android.bp"))
  test_config.appendChild(test_config_doc.createTextNode("\n"))
  for new_option in json.loads(test_runner_options):
    option = test_config_doc.createElement("option")
    # name and value are mandatory,
    name = new_option.get('Name')
    if not name:
      raise RuntimeError('"name" must set in test_runner_option"')
    value = new_option.get('Value')
    if not value:
      raise RuntimeError('"value" must set in test_runner_option"')
    option.setAttribute('name', name) # 'include-filter')
    option.setAttribute('value', value) # 'android.test.example.devcodelab.DevCodelabTest#testHelloFail')
    key = new_option.get('Key')
    if key:
      option.setAttribute('key', key) # 'include-filter')
    # add tab and newline for readability
    test_config.appendChild(test_config_doc.createTextNode("    "))
    test_config.appendChild(option)
    test_config.appendChild(test_config_doc.createTextNode("\n"))

def main():
  """Program entry point."""
  try:
@@ -100,11 +144,20 @@ def main():
      overwrite_package_name(doc, manifest_doc, args.package_name)

    if args.test_file_name:
      if args.orig_test_file_name:
        overwrite_single_test_file_name(doc, args.orig_test_file_name, args.test_file_name)
      else:
        # You probably never want to override the test_file_name if there
        # are several in the xml, but this is currently only used on generated
        # AndroidTest.xml where there is only a single test-file-name (no data)
        overwrite_test_file_name(doc, args.test_file_name)

    if args.mainline_package_name:
      overwrite_mainline_module_package_name(doc, args.mainline_package_name)

    if args.test_runner_options:
      add_test_runner_options_toplevel(doc, args.test_runner_options)

    with open(args.output, 'w') as f:
      write_xml(f, doc)

+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ bootstrap_go_package {
        "autogen.go",
        "config.go",
        "makevars.go",
        "providers.go",
    ],
    pluginFor: ["soong_build"],
}

tradefed/providers.go

0 → 100644
+21 −0
Original line number Diff line number Diff line
package tradefed

import (
	"android/soong/android"

	"github.com/google/blueprint"
)

// Output files we need from a base test that we derive from.
type BaseTestProviderData struct {
	// data files and apps for android_test
	InstalledFiles android.Paths
	// apk for android_test
	OutputFile android.Path
	// Either handwritten or generated TF xml.
	TestConfig android.Path
	// Other modules we require to be installed to run tests. We expect base to build them.
	HostRequiredModuleNames []string
}

var BaseTestProviderKey = blueprint.NewProvider[BaseTestProviderData]()
+21 −0
Original line number Diff line number Diff line
package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

bootstrap_go_package {
    name: "soong-tradefed-modules",
    pkgPath: "android/soong/tradefed_modules",
    deps: [
        "blueprint",
        "soong-android",
        "soong-java",
        "soong-tradefed",
    ],
    srcs: [
        "test_module_config.go",
    ],
    testSrcs: [
        "test_module_config_test.go",
    ],
    pluginFor: ["soong_build"],
}
Loading