aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2020-03-16 23:22:15 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2020-03-16 23:22:15 +0000
commit4896a9f3e0aae7e443eeb104bbaceee318b76cd5 (patch)
tree75dd9442e1e05d40a4607191f4ae4c703ef3357b
parente25637d09866368af9285bd32b10cd8401f43239 (diff)
parent481adc125400e1e46242489496052483b8da942f (diff)
downloadtradefederation-android10-d4-s1-release.tar.gz
Snap for 6300905 from 481adc125400e1e46242489496052483b8da942f to qt-d4-releaseandroid-10.0.0_r45android-10.0.0_r44android-10.0.0_r43android-10.0.0_r42android10-d4-s1-releaseandroid10-d4-release
Change-Id: I9a2b74a35fe7947f8222e34974f629d087b91ac8
-rw-r--r--src/com/android/tradefed/result/ATestFileSystemLogSaver.java42
-rw-r--r--src/com/android/tradefed/result/FileSystemLogSaver.java15
-rw-r--r--tests/src/com/android/tradefed/UnitTests.java2
-rw-r--r--tests/src/com/android/tradefed/result/ATestFileSystemLogSaverTest.java67
4 files changed, 124 insertions, 2 deletions
diff --git a/src/com/android/tradefed/result/ATestFileSystemLogSaver.java b/src/com/android/tradefed/result/ATestFileSystemLogSaver.java
new file mode 100644
index 000000000..eec9a0e5b
--- /dev/null
+++ b/src/com/android/tradefed/result/ATestFileSystemLogSaver.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2019 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.tradefed.result;
+
+import com.android.tradefed.build.IBuildInfo;
+import com.android.tradefed.config.Option;
+import com.android.tradefed.config.OptionClass;
+import com.android.tradefed.util.FileUtil;
+
+import java.io.File;
+import java.io.IOException;
+
+/** This LogSaver class is used by ATest to save logs in a specific path. */
+@OptionClass(alias = "atest-file-system-log-saver")
+public class ATestFileSystemLogSaver extends FileSystemLogSaver {
+
+ @Option(name = "atest-log-file-path", description = "root file system path to store log files.")
+ private File mAtestRootReportDir = new File(System.getProperty("java.io.tmpdir"));
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return The directory created in the path that option atest-log-file-path specify.
+ */
+ @Override
+ protected File generateLogReportDir(IBuildInfo buildInfo, File reportDir) throws IOException {
+ return FileUtil.createTempDir("invocation_", mAtestRootReportDir);
+ }
+}
diff --git a/src/com/android/tradefed/result/FileSystemLogSaver.java b/src/com/android/tradefed/result/FileSystemLogSaver.java
index 35b83e62c..f8ba5f002 100644
--- a/src/com/android/tradefed/result/FileSystemLogSaver.java
+++ b/src/com/android/tradefed/result/FileSystemLogSaver.java
@@ -195,8 +195,7 @@ public class FileSystemLogSaver implements ILogSaver {
File logReportDir;
// now create unique directory within the buildDir
try {
- File buildDir = createBuildDir(buildInfo, reportDir);
- logReportDir = FileUtil.createTempDir("inv_", buildDir);
+ logReportDir = generateLogReportDir(buildInfo, reportDir);
} catch (IOException e) {
CLog.e("Unable to create unique directory in %s. Attempting to use tmp dir instead",
reportDir.getAbsolutePath());
@@ -218,6 +217,18 @@ public class FileSystemLogSaver implements ILogSaver {
}
/**
+ * An exposed method that allow subclass to customize generating path logic.
+ *
+ * @param buildInfo the {@link IBuildInfo}
+ * @param reportDir the {@link File} for the report directory.
+ * @return The directory created.
+ */
+ protected File generateLogReportDir(IBuildInfo buildInfo, File reportDir) throws IOException {
+ File buildDir = createBuildDir(buildInfo, reportDir);
+ return FileUtil.createTempDir("inv_", buildDir);
+ }
+
+ /**
* A helper method to get or create a build directory based on the build info of the invocation.
* <p>
* Create a unique file system directory with the structure
diff --git a/tests/src/com/android/tradefed/UnitTests.java b/tests/src/com/android/tradefed/UnitTests.java
index 31e4be469..8e6606e74 100644
--- a/tests/src/com/android/tradefed/UnitTests.java
+++ b/tests/src/com/android/tradefed/UnitTests.java
@@ -136,6 +136,7 @@ import com.android.tradefed.log.TerribleFailureEmailHandlerTest;
import com.android.tradefed.postprocessor.AggregatePostProcessorTest;
import com.android.tradefed.postprocessor.AveragePostProcessorTest;
import com.android.tradefed.postprocessor.BasePostProcessorTest;
+import com.android.tradefed.result.ATestFileSystemLogSaverTest;
import com.android.tradefed.result.BugreportCollectorTest;
import com.android.tradefed.result.CollectingTestListenerTest;
import com.android.tradefed.result.ConsoleResultReporterTest;
@@ -536,6 +537,7 @@ import org.junit.runners.Suite.SuiteClasses;
BasePostProcessorTest.class,
// result
+ ATestFileSystemLogSaverTest.class,
BugreportCollectorTest.class,
CollectingTestListenerTest.class,
ConsoleResultReporterTest.class,
diff --git a/tests/src/com/android/tradefed/result/ATestFileSystemLogSaverTest.java b/tests/src/com/android/tradefed/result/ATestFileSystemLogSaverTest.java
new file mode 100644
index 000000000..63de554f0
--- /dev/null
+++ b/tests/src/com/android/tradefed/result/ATestFileSystemLogSaverTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2019 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.tradefed.result;
+
+import static org.junit.Assert.*;
+
+import com.android.tradefed.build.IBuildInfo;
+import com.android.tradefed.config.ConfigurationException;
+import com.android.tradefed.config.OptionSetter;
+import com.android.tradefed.invoker.InvocationContext;
+import com.android.tradefed.util.FileUtil;
+
+import java.io.File;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+import org.mockito.Mockito;
+
+/** Unit tests for {@link ATestFileSystemLogSaver}. */
+@RunWith(JUnit4.class)
+public class ATestFileSystemLogSaverTest {
+
+ private File mReportDir;
+ private IBuildInfo mMockBuild;
+ private InvocationContext mContext;
+
+ @Before
+ public void setUp() throws Exception {
+ mReportDir = FileUtil.createTempDir("tmpdir");
+ mMockBuild = Mockito.mock(IBuildInfo.class);
+ mContext = new InvocationContext();
+ mContext.addDeviceBuildInfo("fakeDevice", mMockBuild);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ FileUtil.recursiveDelete(mReportDir);
+ }
+
+ /** Test if generated dir in specific path. */
+ @Test
+ public void testGenerateLogReportDir() throws ConfigurationException {
+ ATestFileSystemLogSaver saver = new ATestFileSystemLogSaver();
+ OptionSetter setter = new OptionSetter(saver);
+ setter.setOptionValue("atest-log-file-path", mReportDir.getAbsolutePath());
+ saver.invocationStarted(mContext);
+ File generatedDir = new File(saver.getLogReportDir().getPath());
+ File expectedParentFolder = generatedDir.getParentFile();
+ assertEquals(expectedParentFolder.getAbsolutePath(), mReportDir.getAbsolutePath());
+ }
+}