1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.tradefed.testtype.binary;
17 
18 import com.android.tradefed.config.Option;
19 import com.android.tradefed.config.OptionClass;
20 import com.android.tradefed.device.DeviceNotAvailableException;
21 import com.android.tradefed.device.ITestDevice;
22 import com.android.tradefed.result.ITestInvocationListener;
23 import com.android.tradefed.result.TestDescription;
24 import com.android.tradefed.testtype.IDeviceTest;
25 import com.android.tradefed.util.CommandResult;
26 import com.android.tradefed.util.CommandStatus;
27 import java.io.IOException;
28 import java.util.concurrent.TimeUnit;
29 
30 /**
31  * Test runner for executable running on the target and parsing tesult of kernel test.
32  */
33 @OptionClass(alias = "kernel-target-test")
34 public class KernelTargetTest extends ExecutableTargetTest {
35     @Option(name = "ignore-binary-check", description = "Ignore the binary check in findBinary().")
36     private boolean mIgnoreBinaryCheck = false;
37 
38     @Override
findBinary(String binary)39     public String findBinary(String binary) throws DeviceNotAvailableException {
40         if (mIgnoreBinaryCheck)
41             return binary;
42         return super.findBinary(binary);
43     }
44 
45     /**
46      * Check the result of the test command.
47      *
48      * @param result test result of the command {@link CommandResult}
49      * @param listener the {@link ITestInvocationListener}
50      * @param description The test in progress.
51      */
checkCommandResult( CommandResult result, ITestInvocationListener listener, TestDescription description)52     protected void checkCommandResult(
53             CommandResult result, ITestInvocationListener listener, TestDescription description) {
54         int exitCodeTCONF = 32;
55         if (result.getExitCode() == exitCodeTCONF) {
56             listener.testIgnored(description);
57         } else {
58             super.checkCommandResult(result, listener, description);
59         }
60     }
61 }
62