Home | History | Annotate | Download | only in invoker
      1 /*
      2  * Copyright (C) 2017 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.invoker;
     17 
     18 import com.android.tradefed.build.BuildRetrievalError;
     19 import com.android.tradefed.config.IConfiguration;
     20 import com.android.tradefed.device.DeviceNotAvailableException;
     21 import com.android.tradefed.invoker.shard.IShardHelper;
     22 import com.android.tradefed.result.ITestInvocationListener;
     23 import com.android.tradefed.targetprep.BuildError;
     24 import com.android.tradefed.targetprep.TargetSetupError;
     25 
     26 public interface IInvocationExecution {
     27 
     28     /**
     29      * Execute the build_provider step of the invocation.
     30      *
     31      * @param context the {@link IInvocationContext} of the invocation.
     32      * @param config the {@link IConfiguration} of this test run.
     33      * @param rescheduler the {@link IRescheduler}, for rescheduling portions of the invocation for
     34      *     execution on another resource(s)
     35      * @param listener the {@link ITestInvocation} to report build download failures.
     36      * @return True if we successfully downloaded the build, false otherwise.
     37      * @throws BuildRetrievalError
     38      * @throws DeviceNotAvailableException
     39      */
     40     public default boolean fetchBuild(
     41             IInvocationContext context,
     42             IConfiguration config,
     43             IRescheduler rescheduler,
     44             ITestInvocationListener listener)
     45             throws BuildRetrievalError, DeviceNotAvailableException {
     46         return false;
     47     }
     48 
     49     /**
     50      * Execute the build_provider clean up step. Associated with the build fetching.
     51      *
     52      * @param context the {@link IInvocationContext} of the invocation.
     53      * @param config the {@link IConfiguration} of this test run.
     54      */
     55     public default void cleanUpBuilds(IInvocationContext context, IConfiguration config) {}
     56 
     57     /**
     58      * Execute the target_preparer and multi_target_preparer setUp step. Does all the devices setup
     59      * required for the test to run.
     60      *
     61      * @param context the {@link IInvocationContext} of the invocation.
     62      * @param config the {@link IConfiguration} of this test run.
     63      * @param listener the {@link ITestInvocation} to report setup failures.
     64      * @throws TargetSetupError
     65      * @throws BuildError
     66      * @throws DeviceNotAvailableException
     67      */
     68     public default void doSetup(
     69             IInvocationContext context,
     70             IConfiguration config,
     71             final ITestInvocationListener listener)
     72             throws TargetSetupError, BuildError, DeviceNotAvailableException {}
     73 
     74     /**
     75      * Execute the target_preparer and multi_target_preparer teardown step. Does the devices tear
     76      * down associated with the setup.
     77      *
     78      * @param context the {@link IInvocationContext} of the invocation.
     79      * @param config the {@link IConfiguration} of this test run.
     80      * @param exception the original exception thrown by the test running.
     81      * @throws Throwable
     82      */
     83     public default void doTeardown(
     84             IInvocationContext context, IConfiguration config, Throwable exception)
     85             throws Throwable {}
     86 
     87     /**
     88      * Execute the target_preparer and multi_target_preparer cleanUp step. Does the devices clean
     89      * up.
     90      *
     91      * @param context the {@link IInvocationContext} of the invocation.
     92      * @param config the {@link IConfiguration} of this test run.
     93      * @param exception the original exception thrown by the test running.
     94      */
     95     public default void doCleanUp(
     96             IInvocationContext context, IConfiguration config, Throwable exception) {}
     97 
     98     /**
     99      * Attempt to shard the configuration into sub-configurations, to be re-scheduled to run on
    100      * multiple resources in parallel.
    101      *
    102      * <p>If a shard count is greater than 1, it will simply create configs for each shard by
    103      * setting shard indices and reschedule them. If a shard count is not set,it would fallback to
    104      * {@link IShardHelper#shardConfig}.
    105      *
    106      * @param config the current {@link IConfiguration}.
    107      * @param context the {@link IInvocationContext} holding the info of the tests.
    108      * @param rescheduler the {@link IRescheduler}
    109      * @return true if test was sharded. Otherwise return <code>false</code>
    110      */
    111     public default boolean shardConfig(
    112             IConfiguration config, IInvocationContext context, IRescheduler rescheduler) {
    113         return false;
    114     }
    115 
    116     /**
    117      * Runs the test.
    118      *
    119      * @param context the {@link IInvocationContext} to run tests on
    120      * @param config the {@link IConfiguration} to run
    121      * @param listener the {@link ITestInvocationListener} of test results
    122      * @throws DeviceNotAvailableException
    123      */
    124     public default void runTests(
    125             IInvocationContext context, IConfiguration config, ITestInvocationListener listener)
    126             throws DeviceNotAvailableException {}
    127 
    128     /**
    129      * Report a failure for the invocation.
    130      *
    131      * @param exception The exception that should be reported.
    132      * @param listener The invocation listener.
    133      * @param config The configuration currently running.
    134      * @param context The {@link IInvocationContext} of the invocation.
    135      * @return True if the configuration should be rescheduled, False otherwise.
    136      */
    137     public boolean resetBuildAndReschedule(
    138             Throwable exception,
    139             ITestInvocationListener listener,
    140             IConfiguration config,
    141             IInvocationContext context);
    142 }
    143