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

Commit d3c50019 authored by gopinath's avatar gopinath
Browse files

Add Simulate maitanance mode in app startup test cases.

Note : Dismissing initial dialogs on the apps (maps, youtube
and camera) craetes the profile.

Bug : b/28941042

Change-Id: Ifbc2853059ca59026d0a833e6dc7e7f96bda9117
parent 6c250a72
Loading
Loading
Loading
Loading
+46 −13
Original line number Diff line number Diff line
@@ -15,43 +15,43 @@
 */
package com.android.tests.applaunch;

import java.io.OutputStreamWriter;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.ActivityManager;
import android.app.ActivityManager.ProcessErrorStateInfo;
import android.app.IActivityManager;
import android.app.UiAutomation;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.UserHandle;
import android.app.UiAutomation;
import android.app.IActivityManager;
import android.support.test.rule.logging.AtraceLogger;
import android.test.InstrumentationTestCase;
import android.test.InstrumentationTestRunner;
import android.util.Log;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import android.os.ParcelFileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;

/**
 * This test is intended to measure the time it takes for the apps to start.
 * Names of the applications are passed in command line, and the
@@ -73,6 +73,7 @@ public class AppLaunch extends InstrumentationTestCase {
    private static final String KEY_LAUNCH_ITERATIONS = "launch_iterations";
    private static final String KEY_LAUNCH_ORDER = "launch_order";
    private static final String KEY_DROP_CACHE = "drop_cache";
    private static final String KEY_SIMULATE_MAINTANANCE = "simulate_maintanance";
    private static final String KEY_SIMPLEPPERF_CMD = "simpleperf_cmd";
    private static final String KEY_TRACE_ITERATIONS = "trace_iterations";
    private static final String KEY_LAUNCH_DIRECTORY = "launch_directory";
@@ -97,6 +98,7 @@ public class AppLaunch extends InstrumentationTestCase {
    private static final String DROP_CACHE_SCRIPT = "/data/local/tmp/dropCache.sh";
    private static final String APP_LAUNCH_CMD = "am start -W -n";
    private static final String SUCCESS_MESSAGE = "Status: ok";
    private static final String PROFILE_COMPILE_SUCCESS = "Success";
    private static final String THIS_TIME = "ThisTime:";
    private static final String LAUNCH_ITERATION = "LAUNCH_ITERATION - %d";
    private static final String TRACE_ITERATION = "TRACE_ITERATION - %d";
@@ -104,6 +106,8 @@ public class AppLaunch extends InstrumentationTestCase {
    private static final String TRACE_ITERATION_PREFIX = "TRACE_ITERATION";
    private static final String LAUNCH_ORDER_CYCLIC = "cyclic";
    private static final String LAUNCH_ORDER_SEQUENTIAL = "sequential";
    private static final String SPEED_PROFILE_CMD = "cmd package compile -f -m speed-profile %s";



    private Map<String, Intent> mNameToIntent;
@@ -124,6 +128,7 @@ public class AppLaunch extends InstrumentationTestCase {
    private File mFile = null;
    private FileOutputStream mOutputStream = null;
    private BufferedWriter mBufferedWriter = null;
    private boolean mSimulateMaintanance = false;


    @Override
@@ -149,6 +154,8 @@ public class AppLaunch extends InstrumentationTestCase {
        mDropCache = Boolean.parseBoolean(args.getString(KEY_DROP_CACHE));
        mSimplePerfCmd = args.getString(KEY_SIMPLEPPERF_CMD);
        mLaunchOrder = args.getString(KEY_LAUNCH_ORDER, LAUNCH_ORDER_CYCLIC);
        mSimulateMaintanance =  Boolean.parseBoolean(args.getString(KEY_SIMULATE_MAINTANANCE));

        createMappings();
        parseArgs(args);
        checkAccountSignIn();
@@ -229,6 +236,12 @@ public class AppLaunch extends InstrumentationTestCase {
                    sleep(INITIAL_LAUNCH_IDLE_TIMEOUT);
                    closeApp(launch.getApp(), true);
                    dropCache();
                    if (mSimulateMaintanance) {
                        String appPkgName = mNameToIntent.get(launch.getApp())
                                .getComponent().getPackageName();
                        assertTrue(String.format("Not able to speed profile the app : %s",
                                appPkgName), profileCompileApp(appPkgName));
                    }
                    sleep(BETWEEN_LAUNCH_SLEEP_TIMEOUT);
                }

@@ -304,6 +317,26 @@ public class AppLaunch extends InstrumentationTestCase {
        instrumentation.sendStatus(0, mResult);
    }

    /**
     * Compile the app package using speed compile command and return true or false
     * based on status of the compilation command.
     */
    private boolean profileCompileApp(String appPkgName) throws IOException {
        Log.i(TAG, "Starting to speed profile " + appPkgName);
        try (ParcelFileDescriptor result = getInstrumentation().getUiAutomation().
                executeShellCommand(String.format(SPEED_PROFILE_CMD, appPkgName));
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(
                        new FileInputStream(result.getFileDescriptor())))) {
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                if (line.contains(PROFILE_COMPILE_SUCCESS)) {
                    return true;
                }
            }
            return false;
        }
    }

    /**
     * If launch order is "cyclic" then apps will be launched one after the
     * other for each iteration count.