/*
 * 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;

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();
    }

    public void testVisualBench() throws InterruptedException {
        String pkg = getInstrumentation().getTargetContext().getPackageName();
        Intent intent = new Intent(getInstrumentation().getTargetContext(),
                                   VisualBenchActivity.class);
        intent.putExtra("cmdLineFlags", "--outResultsFile /sdcard/skia_results/visualbench.json");
        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);
        }
    }
}

@@ -290,16 +290,169 @@
 til.Log;
+%0Aimport java.io.BufferedReader;%0Aimport java.io.InputStream;%0Aimport java.io.InputStreamReader;%0Aimport java.io.IOException;%0Aimport java.lang.StringBuilder;
 %0A%0Apublic
@@ -833,24 +833,579 @@
 n();%0A    %7D%0A%0A
+    private String getFlags() throws IOException %7B%0A        InputStream s = getInstrumentation().getTargetContext().getResources().getAssets().open(%22nanobench_flags.txt%22);%0A        BufferedReader r = new BufferedReader(new InputStreamReader(s));%0A        StringBuilder flags = new StringBuilder();%0A        String sep = System.getProperty(%22line.separator%22);%0A        String line;%0A        while ((line = r.readLine()) != null) %7B%0A            flags.append(line);%0A            flags.append(sep);%0A        %7D%0A        s.close();%0A        return flags.toString();%0A    %7D%0A%0A
     public v
@@ -1445,32 +1445,45 @@
 rruptedException
+, IOException
  %7B%0A        Strin
@@ -1683,24 +1683,58 @@
 ity.class);%0A
+        String args = getFlags();%0A
         inte
@@ -1765,64 +1765,12 @@
 s%22, 
-%22--outResultsFile /sdcard/skia_results/visualbench.json%22
+args
 );%0A 

Read nanobench_flags.txt