diff options
author | Guang Zhu <guangzhu@google.com> | 2024-03-15 20:55:31 +0000 |
---|---|---|
committer | Guang Zhu <guangzhu@google.com> | 2024-03-15 14:10:43 -0700 |
commit | ecc1a6a937371a4add43e8327fa6e5f6c5874660 (patch) | |
tree | df05899f9578ad34530ddfc789963f80afad2d86 | |
parent | 09b8bb9d3938685dfb2596d1bdeda1afdadd8452 (diff) | |
download | contrib-ecc1a6a937371a4add43e8327fa6e5f6c5874660.tar.gz |
clean up obsolete parsers from monkey
- removed monkey log parsers since it was for inspect bug which
has been deprecated
- arguably some metadata parsed out and reported could still
be meaningful for monkey runs but they can be implemented
via a much simpler parser
- the current parser has a lot of complexity due to handling
multiline traces like ANR, Java crash but that's been
replaced by centralized infra based log parsers already
- remove ANR report generator since it's been deprecated
Bug: 329542554
Test: http://go/abtd-run/L99500030002548885
Change-Id: Ied294dd0df3a5c31b6e624632a2cd77984df9857
-rw-r--r-- | src/com/android/monkey/MonkeyBase.java | 129 |
1 files changed, 6 insertions, 123 deletions
diff --git a/src/com/android/monkey/MonkeyBase.java b/src/com/android/monkey/MonkeyBase.java index 552c3b6..25cd98c 100644 --- a/src/com/android/monkey/MonkeyBase.java +++ b/src/com/android/monkey/MonkeyBase.java @@ -18,13 +18,10 @@ package com.android.monkey; import com.android.ddmlib.CollectingOutputReceiver; import com.android.ddmlib.IShellOutputReceiver; -import com.android.loganalysis.item.AnrItem; import com.android.loganalysis.item.BugreportItem; import com.android.loganalysis.item.MiscKernelLogItem; -import com.android.loganalysis.item.MonkeyLogItem; import com.android.loganalysis.parser.BugreportParser; import com.android.loganalysis.parser.KernelLogParser; -import com.android.loganalysis.parser.MonkeyLogParser; import com.android.tradefed.config.Option; import com.android.tradefed.config.Option.Importance; import com.android.tradefed.device.DeviceNotAvailableException; @@ -56,7 +53,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -259,38 +255,8 @@ public class MonkeyBase implements IDeviceTest, IRemoteTest { description = "Enable a continuous circular buffer to collect atrace information") private boolean mAtraceEnabled = false; - // options for generating ANR report via post processing script - @Option(name = "generate-anr-report", description = "Generate ANR report via post-processing") - private boolean mGenerateAnrReport = false; - - @Option( - name = "anr-report-script", - description = "Path to the script for monkey ANR " + "report generation.") - private String mAnrReportScriptPath = null; - - @Option( - name = "anr-report-storage-backend-base-path", - description = "Base path to the storage " + "backend used for saving the reports") - private String mAnrReportBasePath = null; - - @Option( - name = "anr-report-storage-backend-url-prefix", - description = - "URL prefix for the " - + "storage backend that would enable web acess to the stored reports.") - private String mAnrReportUrlPrefix = null; - - @Option( - name = "anr-report-storage-path", - description = - "Sub path under the base storage " - + "location for generated monkey ANR reports.") - private String mAnrReportPath = null; - private ITestDevice mTestDevice = null; - private MonkeyLogItem mMonkeyLog = null; private BugreportItem mBugreport = null; - private AnrReportGenerator mAnrGen = null; /** {@inheritDoc} */ @Override @@ -327,7 +293,7 @@ public class MonkeyBase implements IDeviceTest, IRemoteTest { return LAUNCH_APP_CMD + extras; } - /** Run the monkey one time and return a {@link MonkeyLogItem} for the run. */ + /** Run the monkey one time. */ protected void runMonkey(ITestInvocationListener listener) throws DeviceNotAvailableException { ITestDevice device = getDevice(); if (mRebootDevice) { @@ -383,18 +349,6 @@ public class MonkeyBase implements IDeviceTest, IRemoteTest { CircularAtraceUtil.startTrace(getDevice(), null, 10); } - if (mGenerateAnrReport) { - mAnrGen = - new AnrReportGenerator( - mAnrReportScriptPath, - mAnrReportBasePath, - mAnrReportUrlPrefix, - mAnrReportPath, - mTestDevice.getBuildId(), - mTestDevice.getBuildFlavor(), - mTestDevice.getSerialNumber()); - } - try { onMonkeyStart(); commandHelper.runCommand(mTestDevice, command, getMonkeyTimeoutMs()); @@ -433,25 +387,14 @@ public class MonkeyBase implements IDeviceTest, IRemoteTest { uptimeAfter, duration / 1000 / 60, duration / 1000 % 60)); - mMonkeyLog = createMonkeyLog(listener, MONKEY_LOG_NAME, outputBuilder.toString()); + listener.testLog( + MONKEY_LOG_NAME, + LogDataType.MONKEY_LOG, + new ByteArrayInputStreamSource(outputBuilder.toString().getBytes())); - boolean isAnr = mMonkeyLog.getCrash() instanceof AnrItem; - if (mAtraceEnabled && isAnr) { - // This was identified as an ANR; post atrace data + if (mAtraceEnabled) { listener.testLog("circular-atrace", LogDataType.TEXT, atraceStream); } - if (mAnrGen != null) { - if (isAnr) { - if (!mAnrGen.genereateAnrReport(listener)) { - CLog.w("Failed to post-process ANR."); - } else { - CLog.i("Successfully post-processed ANR."); - } - mAnrGen.cleanTempFiles(); - } else { - CLog.d("ANR post-processing enabled but no ANR detected."); - } - } StreamUtil.cancel(atraceStream); } } @@ -478,8 +421,6 @@ public class MonkeyBase implements IDeviceTest, IRemoteTest { } } } - - checkResults(); } /** A hook to allow subclasses to perform actions just before the monkey starts. */ @@ -522,10 +463,6 @@ public class MonkeyBase implements IDeviceTest, IRemoteTest { CLog.e("Bugreport has no main file"); return null; } - if (mAnrGen != null) { - is = new FileInputStreamSource(main); - mAnrGen.setBugReportInfo(is); - } return new BugreportParser().parse(new BufferedReader(new FileReader(main))); } catch (IOException e) { CLog.e("Could not process bugreport"); @@ -551,23 +488,6 @@ public class MonkeyBase implements IDeviceTest, IRemoteTest { } } - /** Create the monkey log, parse it, and send it to a listener. */ - protected MonkeyLogItem createMonkeyLog( - ITestInvocationListener listener, String monkeyLogName, String log) { - try (InputStreamSource source = new ByteArrayInputStreamSource(log.getBytes())) { - if (mAnrGen != null) { - mAnrGen.setMonkeyLogInfo(source); - } - listener.testLog(monkeyLogName, LogDataType.MONKEY_LOG, source); - return new MonkeyLogParser() - .parse(new BufferedReader(new InputStreamReader(source.createInputStream()))); - } catch (IOException e) { - CLog.e("Could not process monkey log."); - CLog.e(e); - return null; - } - } - /** * A helper method to build a monkey command given the specified arguments. * @@ -711,43 +631,6 @@ public class MonkeyBase implements IDeviceTest, IRemoteTest { return mTestDevice; } - /** Check the results and return if valid or throw an assertion error if not valid. */ - private void checkResults() { - Assert.assertNotNull("Monkey log is null", mMonkeyLog); - Assert.assertNotNull("Bugreport is null", mBugreport); - Assert.assertNotNull("Bugreport is empty", mBugreport.getTime()); - - // If there are no activities, retrying the test won't matter. - if (mMonkeyLog.getNoActivities()) { - return; - } - - Assert.assertNotNull("Start uptime is missing", mMonkeyLog.getStartUptimeDuration()); - Assert.assertNotNull("Stop uptime is missing", mMonkeyLog.getStopUptimeDuration()); - Assert.assertNotNull("Total duration is missing", mMonkeyLog.getTotalDuration()); - - long startUptime = mMonkeyLog.getStartUptimeDuration(); - long stopUptime = mMonkeyLog.getStopUptimeDuration(); - long totalDuration = mMonkeyLog.getTotalDuration(); - - Assert.assertTrue( - "Uptime failure", stopUptime - startUptime > totalDuration - UPTIME_BUFFER); - - // False count - Assert.assertFalse( - "False count", - mMonkeyLog.getIsFinished() - && mMonkeyLog.getTargetCount() - mMonkeyLog.getIntermediateCount() > 100); - - // Monkey finished or crashed, so don't fail - if (mMonkeyLog.getIsFinished() || mMonkeyLog.getFinalCount() != null) { - return; - } - - // Missing count - Assert.fail("Missing count"); - } - /** Get the monkey timeout in milliseconds */ protected long getMonkeyTimeoutMs() { return (mPerEventTimeout + mThrottle) * mTargetCount; |