Skip to content

Internal change #3530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

load("@rules_java//java:defs.bzl", "java_library")

package(default_applicable_licenses = ["//:license"])

java_library(
name = "android_decorator_validator_util",
srcs = [
Expand All @@ -29,3 +31,20 @@ java_library(
"@maven//:com_google_guava_guava",
],
)

java_library(
name = "mobly_decorator_adapter_job_validator_util",
srcs = ["MoblyDecoratorAdapterJobValidatorUtil.java"],
visibility = [
],
deps = [
"//src/java/com/google/devtools/mobileharness/api/model/error",
"//src/java/com/google/wireless/qa/mobileharness/shared/api/job:job_type_util",
"//src/java/com/google/wireless/qa/mobileharness/shared/model/job",
"//src/java/com/google/wireless/qa/mobileharness/shared/proto:job_java_proto",
"//src/java/com/google/wireless/qa/mobileharness/shared/proto/spec:base_spec_java_proto",
"//src/java/com/google/wireless/qa/mobileharness/shared/proto/spec:mobly_decorator_adapter_spec_java_proto",
"//src/java/com/google/wireless/qa/mobileharness/shared/proto/spec:testbed_decorator_adapter_spec_java_proto",
"@maven//:com_google_guava_guava",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright 2022 Google LLC
*
* 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
*
* https://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 com.google.wireless.qa.mobileharness.shared.api.validator.util;

import com.google.common.base.Joiner;
import com.google.devtools.mobileharness.api.model.error.ExtErrorId;
import com.google.devtools.mobileharness.api.model.error.MobileHarnessException;
import com.google.wireless.qa.mobileharness.shared.api.job.JobTypeUtil;
import com.google.wireless.qa.mobileharness.shared.model.job.JobInfo;
import com.google.wireless.qa.mobileharness.shared.proto.Job.JobType;
import com.google.wireless.qa.mobileharness.shared.proto.Job.TestStatus;
import com.google.wireless.qa.mobileharness.shared.proto.spec.Google3File;
import com.google.wireless.qa.mobileharness.shared.proto.spec.decorator.DeviceSelector;
import com.google.wireless.qa.mobileharness.shared.proto.spec.decorator.DeviceToJobSpec;
import com.google.wireless.qa.mobileharness.shared.proto.spec.decorator.MoblyDecoratorAdapterSpec;
import com.google.wireless.qa.mobileharness.shared.proto.spec.decorator.SubDeviceJobSpec;
import com.google.wireless.qa.mobileharness.shared.proto.spec.decorator.SubDeviceJobSpec.FileSpec;
import com.google.wireless.qa.mobileharness.shared.proto.spec.decorator.SubDeviceJobSpec.ParamSpec;

/** Utils for validators of decorators that extend from {@code MoblyDecoratorAdapter}. */
public final class MoblyDecoratorAdapterJobValidatorUtil {
private MoblyDecoratorAdapterJobValidatorUtil() {}

/** Validates {@code spec}. Throws exceptions if it contains any errors. */
public static void validateSpec(MoblyDecoratorAdapterSpec spec) throws MobileHarnessException {
if (spec.getDeviceToJobSpecCount() == 0) {
throw new MobileHarnessException(
ExtErrorId.MOBLY_DECORATOR_ADAPTER_DECORATOR_SPEC_ERROR,
"Spec has no devices to decorate");
}
for (DeviceToJobSpec deviceSpec : spec.getDeviceToJobSpecList()) {
if (!deviceSpec.hasDeviceSelector()) {
throw new MobileHarnessException(
ExtErrorId.MOBLY_DECORATOR_ADAPTER_DECORATOR_SPEC_ERROR,
"Spec is missing device selector");
}
DeviceSelector selector = deviceSpec.getDeviceSelector();
if (!selector.hasDeviceLabel()
&& selector.getDimensionsCount() == 0
&& !selector.hasSubDeviceId()) {
throw new MobileHarnessException(
ExtErrorId.MOBLY_DECORATOR_ADAPTER_DECORATOR_SPEC_ERROR, "Device selector is empty");
}
}
}

/**
* Creates a {@link JobInfo} from a SubDeviceJobSpec.
*
* @param rootJobInfo The {@link JobInfo} from the root job
* @param deviceSpec The spec containing the params, files and decorators for this subdevice
* @return a {@link JobInfo} with the same settings as the root ID, but with a custom type string,
* param, and file list.
* @throws MobileHarnessException if resolving files or parsing the job spec fails.
*/
public static JobInfo makeSubDeviceJobInfo(JobInfo rootJobInfo, SubDeviceJobSpec deviceSpec)
throws MobileHarnessException {
String jobTypeStr =
"_nodevice_+_nodriver_+" + Joiner.on('+').join(deviceSpec.getDecoratorList());
JobType jobType = JobTypeUtil.parseString(jobTypeStr);
JobInfo subJobInfo =
JobInfo.newBuilder()
.setLocator(rootJobInfo.locator())
.setJobUser(rootJobInfo.jobUser())
.setType(jobType)
.setSetting(rootJobInfo.setting())
.build();
for (ParamSpec param : deviceSpec.getParamsList()) {
subJobInfo.params().add(param.getName(), param.getValue());
}
// Add files from job's root info to sub job info.
subJobInfo.files().addAll(rootJobInfo.files().getAll());
// Add files from scoped job spec to sub job info.
for (FileSpec fileSpec : deviceSpec.getFilesList()) {
for (String filePath : fileSpec.getFilesList()) {
subJobInfo.files().add(fileSpec.getTag(), filePath);
}
for (Google3File file : fileSpec.getG3FilesList()) {
for (String output : file.getOutputList()) {
subJobInfo.files().add(fileSpec.getTag(), output);
}
}
}
// This subJobInfo is only used to pass Job parameters to sub tests. Job status does not mean
// anything to test runner. Set the status to "RUNNING" to avoid {@link MobileHarnessException}
// with {@link ErrorCode.JOB_NOT_STARTED} at {@link JobInfo#getExpireTime}, error message:
// "Failed to calculate the job expire time because job is not started. Please set the
// job status from NEW to any other status."
// This will be set to DONE once all tests are completed.
subJobInfo.status().set(TestStatus.RUNNING);
return subJobInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package(
default_visibility = ["//visibility:public"],
)

PYTHON_API_VERSION = 2

# If you are adding a new spec, please add it as a dependency here. If your spec is
# not in the deps list here, it may not be included in the lab server build and will
# fail to be populated.
Expand Down Expand Up @@ -287,6 +285,20 @@ cc_proto_library(
deps = [":install_apk_step_spec_proto"],
)

proto_library(
name = "mobly_decorator_adapter_spec_proto",
srcs = ["decorator/mobly_decorator_adapter_spec.proto"],
deps = [
":base_spec_proto",
":testbed_decorator_adapter_spec_proto",
],
)

java_proto_library(
name = "mobly_decorator_adapter_spec_java_proto",
deps = [":mobly_decorator_adapter_spec_proto"],
)

proto_library(
name = "no_op_decorator_spec_proto",
srcs = ["decorator/no_op_decorator_spec.proto"],
Expand Down Expand Up @@ -325,6 +337,20 @@ java_proto_library(
deps = [":no_op_driver_spec_proto"],
)

proto_library(
name = "testbed_decorator_adapter_spec_proto",
srcs = ["decorator/testbed_decorator_adapter_spec.proto"],
deps = [
":base_spec_proto",
"//src/java/com/google/wireless/qa/mobileharness/shared/proto:common_proto",
],
)

java_proto_library(
name = "testbed_decorator_adapter_spec_java_proto",
deps = [":testbed_decorator_adapter_spec_proto"],
)

proto_library(
name = "xts_tradefed_test_spec_proto",
srcs = ["driver/xts_tradefed_test_spec.proto"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2022 Google LLC
*
* 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
*
* https://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.
*/

syntax = "proto2";

package mobileharness.shared.spec;

import "src/java/com/google/wireless/qa/mobileharness/shared/proto/spec/base_spec.proto";
import "src/java/com/google/wireless/qa/mobileharness/shared/proto/spec/decorator/testbed_decorator_adapter_spec.proto";

option java_package = "com.google.wireless.qa.mobileharness.shared.proto.spec.decorator";
option java_multiple_files = true;

// Specs for MoblyDecoratorAdapter.
message MoblyDecoratorAdapterSpec {
extend DecoratorSpec {
optional MoblyDecoratorAdapterSpec ext = 144150782;
}
repeated DeviceToJobSpec device_to_job_spec = 1 [(field_detail) = {
help: "The decorator stack and parameters to run on each subdevice."
}];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2022 Google LLC
*
* 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
*
* https://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.
*/

syntax = "proto2";

package mobileharness.shared.spec;

import "src/java/com/google/wireless/qa/mobileharness/shared/proto/common.proto";
import "src/java/com/google/wireless/qa/mobileharness/shared/proto/spec/base_spec.proto";

option java_package = "com.google.wireless.qa.mobileharness.shared.proto.spec.decorator";
option java_multiple_files = true;

message SubDeviceJobSpec {
message FileSpec {
optional string tag = 1;
repeated string files = 2 [(file_detail) = {
help: "arbitrary extra files to supply to the subdecorator stack."
}];
repeated Google3File g3_files = 3;
}

message ParamSpec {
optional string name = 1;
optional string value = 2;
}

repeated string decorator = 1;
repeated FileSpec files = 2;
repeated ParamSpec params = 3;
}

message DeviceSelector {
// For backwards compadability with the Mobly definition.
optional string device_label = 1;
// The structure of this should match that of the linked proto.
// LINT.IfChange
// Device type name.
optional string type_name = 2;
// A subdevice dimensions specification. Uses old format for compadability.
repeated StrPair dimensions = 3;
// LINT.ThenChange(
// //depot/google3/java/com/google/wireless/qa/mobileharness/shared/proto/job_config.proto
// )

// Match a sub device by its id.
optional string sub_device_id = 4;
}

message DeviceToJobSpec {
optional DeviceSelector device_selector = 1;
optional SubDeviceJobSpec job_spec = 2;
}

// Specs for TestbedDecoratorAdapter.
message TestbedDecoratorAdapterSpec {
extend DecoratorSpec {
optional TestbedDecoratorAdapterSpec ext = 144657321;
}
repeated DeviceToJobSpec device_to_job_spec = 1 [(field_detail) = {
help: "The decorator stack and parameters to run on each subdevice."
}];
}