Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d828089 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "tests: Save contents of dumpsys iorapd to launch_logs directory." into...

Merge "tests: Save contents of dumpsys iorapd to launch_logs directory." into rvc-dev am: c51f4912 am: a061c9ae am: da033add

Change-Id: I15edae70f4d7c90992db1bf1baec2f05ab5ccc89
parents 51c9c0f6 da033add
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
@@ -509,16 +509,68 @@ public class AppLaunch extends InstrumentationTestCase {
        for (int i = 0; i < IORAP_COMPILE_CMD_TIMEOUT; ++i) {
            IorapCompilationStatus status = waitForIorapCompiled(appPkgName);
            if (status == IorapCompilationStatus.COMPLETE) {
                Log.v(TAG, "compileAppForIorap: success");
                logDumpsysIorapd(appPkgName);
                return true;
            } else if (status == IorapCompilationStatus.INSUFFICIENT_TRACES) {
                Log.e(TAG, "compileAppForIorap: failed due to insufficient traces");
                logDumpsysIorapd(appPkgName);
                return false;
            } // else INCOMPLETE. keep asking iorapd if it's done yet.
            sleep(1000);
        }

        Log.e(TAG, "compileAppForIorap: failed due to timeout");
        logDumpsysIorapd(appPkgName);
        return false;
    }

    /** Save the contents of $(adb shell dumpsys iorapd) to the launch_logs directory. */
    private void logDumpsysIorapd(String packageName) throws IOException {
        InstrumentationTestRunner instrumentation =
                (InstrumentationTestRunner)getInstrumentation();
        Bundle args = instrumentation.getArguments();

        String launchDirectory = args.getString(KEY_LAUNCH_DIRECTORY);

        // Root directory for applaunch file to log the app launch output
        // Will be useful in case of simpleperf command is used
        File launchRootDir = null;
        if (null != launchDirectory && !launchDirectory.isEmpty()) {
            launchRootDir = new File(launchDirectory);
            if (!launchRootDir.exists() && !launchRootDir.mkdirs()) {
                throw new IOException("Unable to create the destination directory "
                    + launchRootDir + ". Try disabling selinux.");
            }
        } else {
            Log.w(TAG, "logDumpsysIorapd: Missing launch-directory arg");
            return;
        }

        File launchSubDir = new File(launchRootDir, LAUNCH_SUB_DIRECTORY);

        if (!launchSubDir.exists() && !launchSubDir.mkdirs()) {
            throw new IOException("Unable to create the lauch file sub directory "
                + launchSubDir + ". Try disabling selinux.");
        }
        String path = "iorapd_dumpsys_" + packageName + "_" + System.nanoTime() + ".txt";
        File file = new File(launchSubDir, path);
        try (FileOutputStream outputStream = new FileOutputStream(file);
                BufferedWriter writer = new BufferedWriter(
                        new OutputStreamWriter(outputStream));
                ParcelFileDescriptor result = getInstrumentation().getUiAutomation().
                        executeShellCommand(IORAP_DUMPSYS_CMD);
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(
                        new FileInputStream(result.getFileDescriptor())))) {
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                writer.write(line + "\n");
            }
        }

        Log.v(TAG, "logDumpsysIorapd: Saved to file: " + path);
    }

    enum IorapCompilationStatus {
        INCOMPLETE,
        COMPLETE,