aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryelinhsieh <yelinhsieh@google.com>2019-08-12 16:11:41 +0800
committeryangbill <yangbill@google.com>2020-03-13 13:08:50 +0800
commit481adc125400e1e46242489496052483b8da942f (patch)
tree75dd9442e1e05d40a4607191f4ae4c703ef3357b
parent1dc3ceb8f46a68e0253ae2796daf22f467c94f62 (diff)
downloadtradefederation-481adc125400e1e46242489496052483b8da942f.tar.gz
[ATest] Create ATest's own logsaver to save logs in specific path
1. Create an exposed method generateLogReportDir() for subclass customize generating logic. 2. Create ATestFileSystemLogSaver extends FileSystemLogSaver, and use the generating logic that ATest needs. Bug:124819561 Bug:151241514 Test: source && lunch tools/tradefederation/core/tests/run_tradefed_tests.sh --class com.android.tradefed.result.ATestFileSystemLogSaverTest tools/tradefederation/core/tests/run_tradefed_tests.sh --class com.android.tradefed.result.FileSystemLogSaverTest Change-Id: I8a931feb6e7806b4531b0a496444f505a34624f7 Merged-In: I3bd6edf743db67031436510af5775165421cac5b Merged-In: I8feb5415027348acdb2c4baf980aaa8a73a17826 Merged-In: I7d9a365472dc082e75cb4e89babc5bd40567517b
-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());
+ }
+}