diff options
author | Oliver Nguyen <olivernguyen@google.com> | 2019-06-20 12:57:36 -0700 |
---|---|---|
committer | Oliver Nguyen <olivernguyen@google.com> | 2019-07-02 10:48:35 -0700 |
commit | 859849ecac7309790263c7a906925a0e84fd278e (patch) | |
tree | 8abed487ad8c5e3eb14db5c16fc31c76ceea33db | |
parent | 99f08f687ca1a2c9bf7498256f90c79fc753807f (diff) | |
download | tradefederation-859849ecac7309790263c7a906925a0e84fd278e.tar.gz |
Handle no native coverage files in NativeCodeCoverageListener.
Test: Unit tests.
Bug: 64915804
Change-Id: Ife78d15cb82600bf51ee14933758886a4b8051a8
(cherry picked from commit 562792280b9d4d917771a620232e0b78bc05631c)
-rw-r--r-- | src/com/android/tradefed/testtype/NativeCodeCoverageListener.java | 4 | ||||
-rw-r--r-- | tests/src/com/android/tradefed/testtype/NativeCodeCoverageListenerTest.java | 23 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/com/android/tradefed/testtype/NativeCodeCoverageListener.java b/src/com/android/tradefed/testtype/NativeCodeCoverageListener.java index b1b6c8d10..976c71e54 100644 --- a/src/com/android/tradefed/testtype/NativeCodeCoverageListener.java +++ b/src/com/android/tradefed/testtype/NativeCodeCoverageListener.java @@ -28,6 +28,8 @@ import com.android.tradefed.result.ResultForwarder; import com.android.tradefed.util.FileUtil; import com.android.tradefed.util.ZipUtil; +import com.google.common.base.Splitter; + import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -73,7 +75,7 @@ public final class NativeCodeCoverageListener extends ResultForwarder { String findResult = mDevice.executeShellCommand(COVERAGE_FILE_LIST_COMMAND); Path devicePathRoot = Paths.get(NATIVE_COVERAGE_DEVICE_PATH); - for (String deviceFile : findResult.split("\n")) { + for (String deviceFile : Splitter.on("\n").omitEmptyStrings().split(findResult)) { // Compute the relative path for the device file. Path relativePath = devicePathRoot.relativize(Paths.get(deviceFile)); Path localFullPath = localDir.toPath().resolve(relativePath); diff --git a/tests/src/com/android/tradefed/testtype/NativeCodeCoverageListenerTest.java b/tests/src/com/android/tradefed/testtype/NativeCodeCoverageListenerTest.java index dd65aca90..11b225022 100644 --- a/tests/src/com/android/tradefed/testtype/NativeCodeCoverageListenerTest.java +++ b/tests/src/com/android/tradefed/testtype/NativeCodeCoverageListenerTest.java @@ -59,6 +59,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringJoiner; +import java.util.zip.ZipFile; /** Unit tests for {@link NativeCodeCoverageListener}. */ @RunWith(JUnit4.class) @@ -135,6 +136,28 @@ public class NativeCodeCoverageListenerTest { } @Test + public void testNoCoverageFiles_logsEmptyZip() throws DeviceNotAvailableException, IOException { + doReturn(true).when(mMockDevice).enableAdbRoot(); + doReturn("").when(mMockDevice).executeShellCommand(anyString()); + + // Simulate a test run. + mCodeCoverageListener.testRunStarted(RUN_NAME, TEST_COUNT); + Map<String, String> metric = new HashMap<>(); + mCodeCoverageListener.testRunEnded(ELAPSED_TIME, TfMetricProtoUtil.upgradeConvert(metric)); + + // Verify testLog(..) was called with an empty zip. + List<ByteString> logs = mFakeListener.getLogs(); + assertThat(logs).hasSize(1); + File outputZip = folder.newFile("empty_coverage.zip"); + try (OutputStream out = new FileOutputStream(outputZip)) { + logs.get(0).writeTo(out); + } + + ZipFile loggedZip = new ZipFile(outputZip); + assertThat(loggedZip.size()).isEqualTo(0); + } + + @Test public void testFailure_unableToPullFile() throws DeviceNotAvailableException { // Setup mocks. doReturn("/data/misc/trace/some/path/to/coverage.gcda\n") |