2 * Copyright (C) 2010-2011 0xlab - http://0xlab.org/
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * Authored by Julian Chu <walkingice@0xlab.org> and
17 * Joseph Chang (bizkit) <bizkit@0xlab.org>
20 package org.zeroxlab.benchmark;
22 import android.util.Log;
24 import android.app.Activity;
25 import android.app.ActivityManager;
26 import android.app.ProgressDialog;
27 import android.app.TabActivity;
28 import android.content.Context;
29 import android.content.Intent;
30 import android.content.res.Configuration;
31 import android.os.Build;
32 import android.os.Bundle;
33 import android.os.Environment;
34 import android.os.Handler;
35 import android.os.Message;
36 import android.os.PowerManager;
37 import android.os.PowerManager.WakeLock;
38 import android.os.SystemClock;
39 import android.view.Gravity;
40 import android.view.KeyEvent;
41 import android.view.Menu;
42 import android.view.MenuItem;
43 import android.view.MotionEvent;
44 import android.view.View;
45 import android.view.ViewGroup;
46 import android.webkit.WebView;
47 import android.webkit.WebViewClient;
48 import android.widget.Button;
49 import android.widget.CheckBox;
50 import android.widget.ImageView;
51 import android.widget.LinearLayout;
52 import android.widget.ScrollView;
53 import android.widget.TabHost;
54 import android.widget.TabHost.TabContentFactory;
55 import android.widget.TextView;
57 import java.io.BufferedReader;
59 import java.io.FileOutputStream;
60 import java.io.FileReader;
61 import java.io.IOException;
62 import java.lang.StringBuffer;
63 import java.text.SimpleDateFormat;
64 import java.util.Arrays;
65 import java.util.Date;
66 import java.util.HashSet;
67 import java.util.HashMap;
68 import java.util.LinkedList;
69 import java.util.regex.Pattern;
70 import java.util.regex.Matcher;
71 import java.util.UUID;
73 import org.json.JSONObject;
74 import org.json.JSONArray;
75 import org.json.JSONException;
76 import org.opensolaris.hub.libmicro.NativeCaseMicro;
77 import org.zeroxlab.byteunix.NativeCaseUbench;;
78 import org.zeroxlab.utils.BenchUtil;
80 /* Construct a basic UI */
81 public class Benchmark extends TabActivity implements View.OnClickListener {
83 public final static String TAG = "Benchmark";
84 public final static String PACKAGE = "org.zeroxlab.benchmark";
86 private final static String mOutputFile = "0xBenchmark";
88 private final static int GROUP_DEFAULT = 0;
89 private final static int SETTINGS_ID = Menu.FIRST;
91 private static String mXMLResult;
92 private static String mJSONResult;
93 private final static String mOutputXMLFile = "0xBenchmark.xml";
94 private final static String mOutputJSONFile = "0xBenchmark.bundle";
98 private CheckBox mCheckList[];
99 private TextView mDesc[];
100 private TextView mBannerInfo;
102 private ScrollView mScrollView;
103 private LinearLayout mLinearLayout;
104 private LinearLayout mMainView;
105 private TabHost mTabHost;
107 LinkedList<Case> mCases;
108 boolean mTouchable = true;
109 private int orientation = Configuration.ORIENTATION_UNDEFINED;
111 private WakeLock mWakeLock;
113 private final String MAIN = "Main";
114 private final String D2 = "2D";
115 private final String D3 = "3D";
116 private final String MATH = "Math";
117 private final String VM = "VM";
118 private final String NATIVE = "Native";
119 private final String MISC = "Misc";
121 private CheckBox d2CheckBox;
122 private CheckBox d3CheckBox;
123 private CheckBox mathCheckBox;
124 private CheckBox vmCheckBox;
125 private CheckBox nativeCheckBox;
126 private CheckBox miscCheckBox;
128 private HashMap< String, HashSet<Case> > mCategory = new HashMap< String, HashSet<Case> >();
130 private final String trackerUrl = "http://0xbenchmark.appspot.com/static/MobileTracker.html";
132 boolean mAutoRun = false;
133 boolean mCheckMath = false;
134 boolean mCheck2D = false;
135 boolean mCheck3D = false;
136 boolean mCheckVM = false;
137 boolean mCheckNative = false;
138 boolean mCheckMisc = false;
139 boolean mAutoUpload = false;
142 protected void onDestroy() {
148 protected void onCreate(Bundle savedInstanceState) {
149 super.onCreate(savedInstanceState);
150 orientation = getResources().getConfiguration().orientation;
151 PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
152 mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, TAG);
155 setContentView(R.layout.main);
156 mCases = new LinkedList<Case>();
157 Case arith = new CaseArithmetic();
158 Case javascript = new CaseJavascript();
159 Case scimark2 = new CaseScimark2();
160 Case canvas = new CaseCanvas();
161 Case glcube = new CaseGLCube();
162 Case circle = new CaseDrawCircle();
163 Case nehe08 = new CaseNeheLesson08();
164 Case nehe16 = new CaseNeheLesson16();
165 Case teapot = new CaseTeapot();
166 Case gc = new CaseGC();
167 Case libMicro = new NativeCaseMicro();
168 Case libUbench = new NativeCaseUbench();
170 Case dc2 = new CaseDrawCircle2();
171 Case dr = new CaseDrawRect();
172 Case da = new CaseDrawArc();
173 Case di = new CaseDrawImage();
174 Case dt = new CaseDrawText();
176 mCategory.put(D2, new HashSet<Case>());
177 mCategory.put(D3, new HashSet<Case>());
178 mCategory.put(MATH, new HashSet<Case>());
179 mCategory.put(VM, new HashSet<Case>());
180 mCategory.put(NATIVE, new HashSet<Case>());
181 mCategory.put(MISC, new HashSet<Case>());
185 mCases.add(scimark2);
186 mCases.add(javascript);
187 mCategory.get(MATH).add(arith);
188 mCategory.get(MATH).add(scimark2);
189 mCategory.get(MISC).add(javascript);
200 mCategory.get(D2).add(canvas);
201 mCategory.get(D2).add(circle);
202 mCategory.get(D2).add(dc2);
203 mCategory.get(D2).add(dr);
204 mCategory.get(D2).add(da);
205 mCategory.get(D2).add(di);
206 mCategory.get(D2).add(dt);
214 mCategory.get(D3).add(glcube);
215 mCategory.get(D3).add(nehe08);
216 mCategory.get(D3).add(nehe16);
217 mCategory.get(D3).add(teapot);
221 mCategory.get(VM).add(gc);
224 mCases.add(libMicro);
225 mCases.add(libUbench);
227 mCategory.get(NATIVE).add(libMicro);
228 mCategory.get(NATIVE).add(libUbench);
232 Intent intent = getIntent();
233 Bundle bundle = intent.getExtras();
234 if (bundle != null) {
235 mAutoRun = bundle.getBoolean("autorun");
236 mCheckMath = bundle.getBoolean("math");
237 mCheck2D = bundle.getBoolean("2d");
238 mCheck3D = bundle.getBoolean("3d");
239 mCheckVM = bundle.getBoolean("vm");
240 mCheckNative = bundle.getBoolean("native");
241 mAutoUpload = bundle.getBoolean("autoupload");
244 if (mCheckMath && !mathCheckBox.isChecked()) {
245 mathCheckBox.performClick();
248 if (mCheck2D && !d2CheckBox.isChecked()) {
249 d2CheckBox.performClick();
252 if (mCheck3D && !d3CheckBox.isChecked()) {
253 d3CheckBox.performClick();
256 if (mCheckVM && !vmCheckBox.isChecked()) {
257 vmCheckBox.performClick();
260 if (mCheckNative && !nativeCheckBox.isChecked()) {
261 nativeCheckBox.performClick();
264 if (mCheckMisc && !miscCheckBox.isChecked()) {
265 miscCheckBox.performClick();
268 if (intent.getBooleanExtra("AUTO", false)) {
269 ImageView head = (ImageView)findViewById(R.id.banner_img);
270 head.setImageResource(R.drawable.icon_auto);
281 public boolean onCreateOptionsMenu(Menu menu) {
282 super.onCreateOptionsMenu(menu);
283 MenuItem item1 = menu.add(GROUP_DEFAULT, SETTINGS_ID, Menu.NONE, R.string.menu_settings);
288 public boolean onOptionsItemSelected(MenuItem menu) {
289 if (menu.getGroupId() == GROUP_DEFAULT && menu.getItemId() == SETTINGS_ID) {
290 org.zeroxlab.utils.Util.launchActivity(this, "org.zeroxlab.benchmark.ActivitySettings");
296 public boolean dispatchTouchEvent(MotionEvent event) {
298 return super.dispatchTouchEvent(event);
305 public boolean dispatchKeyEvent(KeyEvent event) {
307 return super.dispatchKeyEvent(event);
314 public boolean dispatchTrackballEvent(MotionEvent event) {
316 return super.dispatchTrackballEvent(event);
322 private void _checkTagCase(String [] Tags) {
324 for (int i = 0; i < mCheckList.length; i++) {
325 String [] caseTags = mCases.get(i).mTags;
326 for (String t: caseTags) {
327 int search = Arrays.binarySearch(Tags, t);
329 mCheckList[i].setChecked(true);
334 private void _checkCatCase(String [] Cats) {
336 for (int i = 0; i < mCheckList.length; i++) {
337 int search = Arrays.binarySearch(Cats, mCases.get(i).mType);
339 mCheckList[i].setChecked(true);
343 private void _checkAllCase(boolean check) {
344 for (int i = 0; i < mCheckList.length; i++)
345 mCheckList[i].setChecked(check);
348 private void initAuto() {
349 Intent intent = getIntent();
350 String TAG = intent.getStringExtra("TAG");
351 String CAT = intent.getStringExtra("CAT");
354 _checkAllCase(false);
356 _checkTagCase( TAG.split(",") );
358 _checkCatCase( CAT.split(",") );
359 if (TAG == null && CAT == null)
361 final Handler h = new Handler() {
362 public void handleMessage(Message msg) {
363 if (msg.what == 0x1234)
368 final ProgressDialog dialog = new ProgressDialog(this).show(this, "Starting Benchmark", "Please wait...", true, false);
371 SystemClock.sleep(1000);
373 Message m = new Message();
381 private void initViews() {
383 mRun = (Button)findViewById(R.id.btn_run);
384 mRun.setOnClickListener(this);
386 mShow = (Button)findViewById(R.id.btn_show);
387 mShow.setOnClickListener(this);
388 mShow.setClickable(false);
390 mLinearLayout = (LinearLayout)findViewById(R.id.list_container);
391 mMainView = (LinearLayout)findViewById(R.id.main_view);
393 mBannerInfo = (TextView)findViewById(R.id.banner_info);
394 mBannerInfo.setText("Hello!\nSelect cases to Run.\nUploaded results:\nhttp://0xbenchmark.appspot.com");
397 mTabHost = getTabHost();
399 int length = mCases.size();
400 mCheckList = new CheckBox[length];
401 mDesc = new TextView[length];
402 for (int i = 0; i < length; i++) {
403 mCheckList[i] = new CheckBox(this);
404 mCheckList[i].setText(mCases.get(i).getTitle());
405 mDesc[i] = new TextView(this);
406 mDesc[i].setText(mCases.get(i).getDescription());
407 mDesc[i].setTextSize(mDesc[i].getTextSize() - 2);
408 mDesc[i].setPadding(42, 0, 10, 10);
411 TabContentFactory mTCF = new TabContentFactory() {
412 public View createTabContent(String tag) {
413 ViewGroup.LayoutParams fillParent = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
414 ViewGroup.LayoutParams fillWrap = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
415 LinearLayout.LayoutParams wrapContent = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
416 wrapContent.gravity = Gravity.CENTER;
417 LinearLayout.LayoutParams weightedFillWrap = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
418 weightedFillWrap.weight = 1;
420 if (tag.equals(MAIN)) {
421 LinearLayout mMainView = new LinearLayout(Benchmark.this);
422 mMainView.setOrientation(1);
423 ScrollView mListScroll = new ScrollView(Benchmark.this);
425 LinearLayout mMainViewContainer = new LinearLayout(Benchmark.this);
426 mMainViewContainer.setOrientation(1);
427 ImageView mIconView = new ImageView(Benchmark.this);
428 mIconView.setImageResource(R.drawable.icon);
430 TextView mBannerInfo = new TextView(Benchmark.this);
431 mBannerInfo.setText("0xbench\nSelect benchmarks in the tabs,\nor batch select:");
433 d2CheckBox = new CheckBox(Benchmark.this);
434 d2CheckBox.setText(D2);
435 d2CheckBox.setOnClickListener(Benchmark.this);
437 d3CheckBox = new CheckBox(Benchmark.this);
438 d3CheckBox.setText(D3);
439 d3CheckBox.setOnClickListener(Benchmark.this);
441 mathCheckBox = new CheckBox(Benchmark.this);
442 mathCheckBox.setText(MATH);
443 mathCheckBox.setOnClickListener(Benchmark.this);
445 vmCheckBox = new CheckBox(Benchmark.this);
446 vmCheckBox.setText(VM);
447 vmCheckBox.setOnClickListener(Benchmark.this);
449 nativeCheckBox = new CheckBox(Benchmark.this);
450 nativeCheckBox.setText(NATIVE);
451 nativeCheckBox.setOnClickListener(Benchmark.this);
453 miscCheckBox = new CheckBox(Benchmark.this);
454 miscCheckBox.setText(MISC);
455 miscCheckBox.setOnClickListener(Benchmark.this);
457 TextView mWebInfo = new TextView(Benchmark.this);
458 mWebInfo.setText("Uploaded results:\nhttp://0xbenchmark.appspot.com");
460 LinearLayout mButtonContainer = new LinearLayout(Benchmark.this);
461 mRun = new Button(Benchmark.this);
462 mShow = new Button(Benchmark.this);
464 mShow.setText("Show");
465 mRun.setOnClickListener(Benchmark.this);
466 mShow.setOnClickListener(Benchmark.this);
467 mButtonContainer.addView(mRun, weightedFillWrap);
468 mButtonContainer.addView(mShow, weightedFillWrap);
469 WebView mTracker = new WebView(Benchmark.this);
470 mTracker.clearCache(true);
471 mTracker.setWebViewClient(new WebViewClient () {
472 public void onPageFinished(WebView view, String url) {
473 Log.i(TAG, "Tracker: " + view.getTitle() + " -> " + url);
475 public void onReceivedError(WebView view, int errorCode,
476 String description, String failingUrl) {
477 Log.e(TAG, "Track err: " + description);
480 mTracker.loadUrl(trackerUrl);
481 mMainViewContainer.addView(mIconView,wrapContent);
482 mMainViewContainer.addView(mBannerInfo);
483 mMainViewContainer.addView(mathCheckBox);
484 mMainViewContainer.addView(d2CheckBox);
485 mMainViewContainer.addView(d3CheckBox);
486 mMainViewContainer.addView(vmCheckBox);
487 mMainViewContainer.addView(nativeCheckBox);
488 mMainViewContainer.addView(miscCheckBox);
489 mMainViewContainer.addView(mWebInfo);
490 mMainViewContainer.addView(mButtonContainer, fillWrap);
491 mMainViewContainer.addView(mTracker, 0,0);
492 mListScroll.addView(mMainViewContainer, fillParent);
493 mMainView.addView(mListScroll, fillWrap);
499 LinearLayout mMainView = new LinearLayout(Benchmark.this);
500 mMainView.setOrientation(1);
501 ScrollView mListScroll = new ScrollView(Benchmark.this);
502 LinearLayout mListContainer = new LinearLayout(Benchmark.this);
503 mListContainer.setOrientation(1);
504 mListScroll.addView(mListContainer, fillParent);
505 mMainView.addView(mListScroll, fillWrap);
508 int length = mCases.size();
509 Log.i(TAG, "L: " + length);
510 Log.i(TAG, "TCF: " + tag);
511 for (int i = 0; i < length; i++) {
512 if (!mCategory.get(tag).contains(mCases.get(i)))
514 Log.i(TAG, "Add: " + i);
515 mListContainer.addView(mCheckList[i], fillWrap);
516 mListContainer.addView(mDesc[i], fillWrap);
518 int color = 0xFF333333; //ARGB
519 mCheckList[i].setBackgroundColor(color);
520 mDesc[i].setBackgroundColor(color);
528 mTabHost.addTab(mTabHost.newTabSpec(MAIN).setIndicator(MAIN, getResources().getDrawable(R.drawable.ic_eye)).setContent(mTCF));
529 mTabHost.addTab(mTabHost.newTabSpec(D2).setIndicator(D2, getResources().getDrawable(R.drawable.ic_2d)).setContent(mTCF));
530 mTabHost.addTab(mTabHost.newTabSpec(D3).setIndicator(D3, getResources().getDrawable(R.drawable.ic_3d)).setContent(mTCF));
531 mTabHost.addTab(mTabHost.newTabSpec(MATH).setIndicator(MATH, getResources().getDrawable(R.drawable.ic_pi)).setContent(mTCF));
532 mTabHost.addTab(mTabHost.newTabSpec(VM).setIndicator(VM, getResources().getDrawable(R.drawable.ic_vm)).setContent(mTCF));
533 mTabHost.addTab(mTabHost.newTabSpec(NATIVE).setIndicator(NATIVE, getResources().getDrawable(R.drawable.ic_c)).setContent(mTCF));
534 mTabHost.addTab(mTabHost.newTabSpec(MISC).setIndicator(MISC, getResources().getDrawable(R.drawable.ic_misc)).setContent(mTCF));
537 public void onClick(View v) {
539 int numberOfCaseChecked = 0;
540 for (int i = 0; i < mCheckList.length; i++) {
541 if (mCheckList[i].isChecked()) {
542 mCases.get(i).reset();
543 numberOfCaseChecked++;
545 mCases.get(i).clear();
548 if (numberOfCaseChecked > 0)
550 } else if (v == mShow) {
551 String result = getResult();
552 Log.i(TAG,"\n\n"+result+"\n\n");
553 writeResult(mOutputFile, result);
554 Intent intent = new Intent();
555 intent.putExtra(Report.REPORT, result);
556 intent.putExtra(Report.XML, mXMLResult);
558 intent.putExtra(Report.AUTOUPLOAD, true);
561 intent.setClassName(Report.packageName(), Report.fullClassName());
562 startActivity(intent);
563 } else if (v == d2CheckBox || v == d3CheckBox || v == mathCheckBox ||
564 v == vmCheckBox || v == nativeCheckBox || v == miscCheckBox) {
565 int length = mCases.size();
566 String tag = ((CheckBox)v).getText().toString();
567 for (int i = 0; i < length; i++) {
568 if (!mCategory.get(tag).contains(mCases.get(i)))
570 mCheckList[i].setChecked(((CheckBox)v).isChecked());
575 public void runCase(LinkedList<Case> list) {
577 boolean finish = true;
578 for (int i = 0; i < list.size(); i++) {
579 pointer = list.get(i);
580 if (!pointer.isFinish()) {
587 // mBannerInfo.setText("Benchmarking complete.\nClick Show to upload.\nUploaded results:\nhttp://0xbenchmark.appspot.com");
588 String result = getResult();
589 writeResult(mOutputFile, result);
591 final ProgressDialog dialogGetXml = new ProgressDialog(this).show(this, "Generating XML Report", "Please wait...", true, false);
594 mJSONResult = getJSONResult();
595 mXMLResult = getXMLResult();
596 Log.d(TAG, "XML: " + mXMLResult);
597 writeResult(mOutputXMLFile, mXMLResult);
598 Log.d(TAG, "JSON: " + mJSONResult);
599 writeResult(mOutputJSONFile, mJSONResult);
600 mShow.setClickable(true);
603 dialogGetXml.dismiss();
607 Intent intent = pointer.generateIntent();
608 if (intent != null) {
609 startActivityForResult(intent, 0);
614 public String getXMLResult() {
615 if (mCases.size() == 0)
618 Date date = new Date();
619 //2010-05-28T17:40:25CST
620 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
623 xml += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
625 xml += " executedTimestamp=\"" + sdf.format(date) + "\"";
626 xml += " manufacturer=\"" + Build.MANUFACTURER.replace(' ', '_') + "\"";
627 xml += " model=\"" + Build.MODEL.replace(' ', '_') + ":" + Build.DISPLAY + "\"";
628 xml += " buildTimestamp=\"" + sdf.format(new Date(Build.TIME)) + "\"";
629 xml += " orientation=\"" + Integer.toString(orientation) + "\"";
631 try { // read kernel version
632 BufferedReader procVersion = new BufferedReader( new FileReader("/proc/version") );
633 StringBuffer sbuff = new StringBuffer();
635 while ((tmp = procVersion.readLine()) != null)
638 tmp = sbuff.toString().replace("[\n\r]+", " ").replace(" +", ".");
639 xml += " version=\"" + tmp + "\"";
640 } catch (IOException e){
641 Log.e(TAG, "opening /proc/version failed: " + e.toString());
644 try { // read and parse cpu info
645 BufferedReader procVersion = new BufferedReader(new FileReader("/proc/cpuinfo") );
646 StringBuffer sbuff = new StringBuffer();
648 while ((tmp = procVersion.readLine()) != null)
649 sbuff.append(tmp + "\n");
652 tmp = sbuff.toString();
654 sbuff = new StringBuffer();
656 Pattern p1 = Pattern.compile("(Processor\\s*:\\s*(.*)\\s*[\n\r]+)");
657 Matcher m1 = p1.matcher(tmp);
658 if (m1.find()) sbuff.append(m1.group(2));
660 Pattern p2 = Pattern.compile("(Hardware\\s*:\\s*(.*)\\s*[\n\r]+)");
661 Matcher m2 = p2.matcher(tmp);
662 if (m2.find()) sbuff.append(":"+m2.group(2));
664 Pattern p3 = Pattern.compile("(Revision\\s*:\\s*(.*)\\s*[\n\r]+)");
665 Matcher m3 = p3.matcher(tmp);
666 if (m3.find()) sbuff.append(":"+m3.group(2));
668 Log.e(TAG, sbuff.toString());
669 xml += " cpu=\"" + sbuff.toString() + "\"";
670 } catch (IOException e) {
671 Log.e(TAG, "opening /proc/version failed: " + e.toString());
677 for (int i = 0; i < mCases.size(); i++) {
678 mycase = mCases.get(i);
679 xml += mycase.getXMLBenchmark();
687 * Add Linaro Dashboard Bundle's JSON format support
688 * https://launchpad.net/linaro-python-dashboard-bundle/trunk
690 public String getJSONResult() {
691 Date date = new Date();
692 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
694 JSONObject result = new JSONObject();
696 JSONArray testRunsArray = new JSONArray();
697 JSONObject testRunsObject = new JSONObject();
698 testRunsObject.put("analyzer_assigned_date", sdf.format(date));
699 testRunsObject.put("time_check_performed", false);
700 // TODO: should be UUID version 1
701 testRunsObject.put("analyzer_assigned_uuid", UUID.randomUUID().toString());
702 testRunsObject.put("test_id", "0xbench");
704 JSONArray testResultsList = new JSONArray();
706 for (int i = 0; i < mCases.size(); i++) {
707 myCase = mCases.get(i);
708 JSONArray caseResultList = myCase.getJSONBenchmark();
709 for (int j = 0; j < caseResultList.length(); j++) {
710 testResultsList.put(caseResultList.get(j));
713 testRunsObject.put("test_results", testResultsList);
715 testRunsArray.put(testRunsObject);
716 result.put("test_runs", testRunsArray);
717 result.put("format", "Dashboard Bundle Format 1.2");
719 catch (JSONException jsonE) {
720 jsonE.printStackTrace();
722 return result.toString();
725 public String getResult() {
728 for (int i = 0; i < mCases.size(); i++) {
729 mycase = mCases.get(i);
730 if ( !mycase.couldFetchReport() ) continue;
731 result += "============================================================\n";
732 result += mycase.getTitle() + "\n";
733 result += "------------------------------------------------------------\n";
734 result += mycase.getResultOutput().trim() + "\n";
736 result += "============================================================\n";
741 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
743 Log.i(TAG, "oooops....Intent is null");
748 for (int i = 0; i < mCases.size(); i++) {
749 mycase = mCases.get(i);
750 if (mycase.realize(data)) {
751 mycase.parseIntent(data);
758 private boolean writeResult(String filename, String output) {
759 File writeDir = new File(BenchUtil.getResultDir(this));
760 if (!writeDir.exists()) {
764 File file = new File(writeDir, filename);
766 Log.w(TAG, "File exists, delete " + writeDir.getPath() + filename);
771 file.createNewFile();
772 FileOutputStream fos = new FileOutputStream(file);
773 fos.write(output.getBytes());
775 } catch (Exception e) {
776 Log.i(TAG, "Write Failed.");