aboutsummaryrefslogtreecommitdiffhomepage
path: root/platform_tools/android/apps/visualbench/src/main/java/com/skia/VisualBenchTestActivity.java
blob: 48507bea68df80faa4f1ea6ad9c297bc962b83c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

package com.skia;

import android.app.Instrumentation;
import android.content.Intent;
import android.test.ActivityUnitTestCase;
import android.util.Log;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.lang.StringBuilder;

public class VisualBenchTestActivity extends ActivityUnitTestCase<VisualBenchActivity> {
    private VisualBenchActivity mActivity;
    private Instrumentation mInstrumentation;

    public VisualBenchTestActivity() {
        super(VisualBenchActivity.class);
    }

    protected void setUp() throws Exception {
        super.setUp();
        mInstrumentation = getInstrumentation();
    }

    private String getFlags() throws IOException {
        InputStream s = getInstrumentation().getTargetContext().getResources().getAssets().open("nanobench_flags.txt");
        BufferedReader r = new BufferedReader(new InputStreamReader(s));
        StringBuilder flags = new StringBuilder();
        String sep = System.getProperty("line.separator");
        String line;
        while ((line = r.readLine()) != null) {
            flags.append(line);
            flags.append(sep);
        }
        s.close();
        return flags.toString();
    }

    public void testVisualBench() throws InterruptedException, IOException {
        String pkg = getInstrumentation().getTargetContext().getPackageName();
        Intent intent = new Intent(getInstrumentation().getTargetContext(),
                                   VisualBenchActivity.class);
        String args = getFlags();
        intent.putExtra("cmdLineFlags", args);
        mActivity = launchActivityWithIntent(pkg, VisualBenchActivity.class, intent);

        assertNotNull("mActivity is null", mActivity);
        Thread.sleep(5000);
        while (!mActivity.isDestroyed()) {
            Log.d("skiatest", "Waiting for subprocess to finish.");
            Thread.sleep(1000);
        }
    }
}