From d9b2ef1b267206c2ef353aa352bdffdedefdd532 Mon Sep 17 00:00:00 2001 From: mukesh agrawal Date: Fri, 14 Apr 2017 14:24:40 -0700 Subject: tests: don't crash on Log.wtf() in eng builds We'd like to be able to run the unit tests on eng builds, and get meaningful results. Unfortunately, at the moment, any test that excerises a call to Log.wtf() will cause the tests to abort (not fail -- abort). The abort happens because Log.wtf() aborts on eng builds (by design). While that likely makes sense for normal code, it gets in the way of testing. Resolve this, by installing a custom TerribleFailureHandler before running our tests. Note that this does mean that our code behaves differently under eng-test than eng-normal. I think we're okay with that, since the eng-test behavior now more closely reflects the user-normal and userdebug-normal behavior. Bug: 36981745 Test: tests/wifitests/runtests.sh (on aosp_bullhead-eng) Change-Id: Ieb3a3a98eacdf7131efd1efc6a966f68724e701b --- tests/wifitests/AndroidManifest.xml | 2 +- tests/wifitests/runtests.sh | 2 +- .../com/android/server/wifi/CustomTestRunner.java | 33 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tests/wifitests/src/com/android/server/wifi/CustomTestRunner.java diff --git a/tests/wifitests/AndroidManifest.xml b/tests/wifitests/AndroidManifest.xml index 63b9542d9..dcb61c740 100644 --- a/tests/wifitests/AndroidManifest.xml +++ b/tests/wifitests/AndroidManifest.xml @@ -30,7 +30,7 @@ - diff --git a/tests/wifitests/runtests.sh b/tests/wifitests/runtests.sh index 529a535e6..7a34bf7dc 100755 --- a/tests/wifitests/runtests.sh +++ b/tests/wifitests/runtests.sh @@ -42,4 +42,4 @@ adb install -r -g "$OUT/data/app/FrameworksWifiTests/FrameworksWifiTests.apk" adb shell am instrument -w "$@" \ -e notAnnotation com.android.server.wifi.DisabledForUpdateToAnyMatcher \ - 'com.android.server.wifi.test/android.support.test.runner.AndroidJUnitRunner' + 'com.android.server.wifi.test/com.android.server.wifi.CustomTestRunner' diff --git a/tests/wifitests/src/com/android/server/wifi/CustomTestRunner.java b/tests/wifitests/src/com/android/server/wifi/CustomTestRunner.java new file mode 100644 index 000000000..d51f16e36 --- /dev/null +++ b/tests/wifitests/src/com/android/server/wifi/CustomTestRunner.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * 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 + * + * http://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.android.server.wifi; + +import android.os.Bundle; +import android.support.test.runner.AndroidJUnitRunner; +import android.util.Log; + +import static org.mockito.Mockito.mock; + +public class CustomTestRunner extends AndroidJUnitRunner { + @Override + public void onCreate(Bundle arguments) { + // Override the default TerribleFailureHandler, as that handler might terminate + // the process (if we're on an eng build). + Log.setWtfHandler(mock(Log.TerribleFailureHandler.class)); + super.onCreate(arguments); + } +} -- cgit v1.2.3