1 /*
2  * Copyright 2019 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 
17 package androidx.benchmark.junit4
18 
19 import android.app.Application
20 import android.os.Bundle
21 import androidx.benchmark.argumentSource
22 import androidx.test.platform.app.InstrumentationRegistry
23 
24 /**
25  * Hack to enable overriding benchmark arguments (since we can't easily do this in CI, per apk)
26  *
27  * The *correct* way to do this would be to put the following in benchmark/build.gradle:
28  * ```
29  * android {
30  *     defaultConfig {
31  *         testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] =
32  *             "CODE-COVERAGE,DEBUGGABLE,EMULATOR,LOW-BATTERY,UNLOCKED"
33  *     }
34  * }
35  * ```
36  */
37 class ArgumentInjectingApplication : Application() {
onCreatenull38     override fun onCreate() {
39         super.onCreate()
40 
41         argumentSource =
42             Bundle().apply {
43                 // allow cli args to pass through
44                 putAll(InstrumentationRegistry.getArguments())
45 
46                 // Since these benchmark correctness tests run as part of the regular
47                 // (non-performance-test) suite, they will have debuggable=true, won't be
48                 // clock-locked,
49                 // can run with low-battery or on an emulator, and code coverage enabled.
50                 putString(
51                     "androidx.benchmark.suppressErrors",
52                     "CODE-COVERAGE,DEBUGGABLE,EMULATOR,LOW-BATTERY,UNLOCKED,ENG-BUILD"
53                 )
54             }
55     }
56 }
57