aboutsummaryrefslogtreecommitdiff
path: root/src/org/linaro/benchmarks/BenchmarksTestCase.java
blob: 07205a3acceaf8030ba50dacf44dff528c25fd06 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
/*
 * Author: Linaro Android Team <linaro-dev@lists.linaro.org>
 *
 * These files are Copyright (C) 2012 Linaro Limited and they
 * are licensed under the Apache License, Version 2.0.
 * You may obtain a copy of this license at
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package org.linaro.benchmarks;

import java.io.File;

import android.app.Activity;
import android.graphics.Point;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;

import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
import com.android.uiautomator.core.UiObjectNotFoundException;

public class BenchmarksTestCase extends UiAutomatorTestCase {

    String TAG = "BenchmarksTestCase";

    String png_dir = "/data/local/tmp/";

    public boolean takeScreenshot(String name){
        try{
            //only avaliable for 4.2
            return getUiDevice().takeScreenshot(
                    new File(png_dir + name + ".png"));
        }catch(NoSuchMethodError e){
            return true;
        }
    }

    public void sleep(int second){
        super.sleep(second * 1000);
    }

    public void waitText(String text) throws UiObjectNotFoundException{
        waitText(text, 600);
    }

    public void waitText(String text, int second)
                                throws UiObjectNotFoundException{
        UiSelector selector = new UiSelector();
        UiObject text_obj = new UiObject(selector.text(text)
                                       .className("android.widget.TextView"));
        waitObject(text_obj, second);
    }

    public void waitObject(UiObject obj) throws UiObjectNotFoundException{
        waitObject(obj, 600);
    }

    public void waitObject(UiObject obj, int second)
                                throws UiObjectNotFoundException{
        if (! obj.waitForExists(second * 1000)){
            throw new UiObjectNotFoundException("UiObject is not found: "
                    + obj.getSelector().toString());
        }
    }

    public boolean waitUntilNoObject(UiObject obj, int second){
        return obj.waitUntilGone(second * 1000);
    }

    public void testOrientationNatural() throws Exception{
        Bundle status = new Bundle();
        status.putString("product", getUiDevice().getProductName());
        Point p = getUiDevice().getDisplaySizeDp();
        status.putInt("dp-width", p.x);
        status.putInt("dp-height", p.y);
        //Application specific
        getUiDevice().setOrientationNatural();
        getUiDevice().freezeRotation();

        getUiDevice().unfreezeRotation();
        getAutomationSupport().sendStatus(Activity.RESULT_OK, status);
    }

    public void testGeekbench() throws Exception{
        Bundle status = new Bundle();
        status.putString("product", getUiDevice().getProductName());
        Point p = getUiDevice().getDisplaySizeDp();
        status.putInt("dp-width", p.x);
        status.putInt("dp-height", p.y);
        //application related
        UiSelector selector = new UiSelector();
        UiObject btn_run = new UiObject(selector.text("Run Benchmarks")
                                       .className("android.widget.Button"));
        btn_run.click();
        try{
            UiObject res_webview = new UiObject(selector.className(
                                                "android.webkit.WebView"));
            waitObject(res_webview);
            takeScreenshot("geekbench-0");
            sleep(2);
            getUiDevice().pressKeyCode(KeyEvent.KEYCODE_PAGE_DOWN);
            takeScreenshot("geekbench-1");
            sleep(2);
            getUiDevice().pressKeyCode(KeyEvent.KEYCODE_PAGE_DOWN);
            takeScreenshot("geekbench-2");
            sleep(2);
            getUiDevice().pressKeyCode(KeyEvent.KEYCODE_PAGE_DOWN);
            takeScreenshot("geekbench-3");
            sleep(2);
            getUiDevice().pressKeyCode(KeyEvent.KEYCODE_PAGE_DOWN);
            takeScreenshot("geekbench-4");

        }catch(UiObjectNotFoundException e){
            takeScreenshot("geekbench-error");
        }
        getAutomationSupport().sendStatus(Activity.RESULT_OK, status);
    }

    public void testLinpack() throws Exception{
        Bundle status = new Bundle();
        status.putString("product", getUiDevice().getProductName());
        Point p = getUiDevice().getDisplaySizeDp();
        status.putInt("dp-width", p.x);
        status.putInt("dp-height", p.y);
        UiSelector selector = new UiSelector();
        UiObject btn_st = new UiObject(selector.text("Run Single Thread"));
        btn_st.click();
        sleep(10);
        takeScreenshot("linpack-st");
        UiObject btn_mt = new UiObject(selector.text("Run Multi-Thread"));
        btn_mt.click();
        sleep(10);
        takeScreenshot("linpack-mt");
        getAutomationSupport().sendStatus(Activity.RESULT_OK, status);
    }

    public void testAntutu() throws Exception{
        Bundle status = new Bundle();
        status.putString("product", getUiDevice().getProductName());
        Point p = getUiDevice().getDisplaySizeDp();
        status.putInt("dp-width", p.x);
        status.putInt("dp-height", p.y);
        UiSelector selector = new UiSelector();
        //
        //click the Test test
        UiObject text_scores = new UiObject(selector.text("Scores")
                                       .className("android.widget.TextView"));
        text_scores.click();
        sleep(2);

        //click the Test test
        UiObject text_detail = new UiObject(selector.text("Detailed Scores")
                                       .className("android.widget.TextView"));
        text_detail.click();
        sleep(2);

        //click the Test test
        UiObject text_test = new UiObject(selector.text("Test")
                                       .className("android.widget.TextView"));
        text_test.click();
        sleep(2);

        Log.v(TAG, "Start the test");
        //begin the test
        UiObject btn_test = new UiObject(selector.text("Start Test")
                                       .className("android.widget.Button"));
        btn_test.click();
        try{
            UiObject submit = new UiObject(selector
                    .text("Submit Scores")
                    .className("android.widget.TextView"));
            UiObject detail = new UiObject(selector
                    .text("Detailed Scores")
                    .className("android.widget.TextView"));
            for(int i = 0; i < 60; i++){
                if (detail.exists() || submit.exists()){
                    break;
                }
                sleep(10);
            }
        }finally{
            takeScreenshot("antutu");
        }
        getAutomationSupport().sendStatus(Activity.RESULT_OK, status);
    }

    public void testCaffeine() throws Exception{
        Bundle status = new Bundle();
        status.putString("product", getUiDevice().getProductName());
        Point p = getUiDevice().getDisplaySizeDp();
        status.putInt("dp-width", p.x);
        status.putInt("dp-height", p.y);
        //Application specific
        UiSelector selector = new UiSelector();
        UiObject btn_run = new UiObject(selector.text("Run benchmark")
                                       .className("android.widget.Button"));
        btn_run.click();

        try{
            waitText("CaffeineMark results");
            takeScreenshot("caffeine-0");
            UiObject btn_details = new UiObject(selector.text("Details")
                                       .className("android.widget.Button"));
            btn_details.click();
            sleep(2);
            takeScreenshot("caffeine-1");
        }catch(UiObjectNotFoundException e){
            takeScreenshot("caffeine-error");
        }

        getAutomationSupport().sendStatus(Activity.RESULT_OK, status);
    }

    public void testAndEBench() throws Exception{
        Bundle status = new Bundle();
        status.putString("product", getUiDevice().getProductName());
        Point p = getUiDevice().getDisplaySizeDp();
        status.putInt("dp-width", p.x);
        status.putInt("dp-height", p.y);
        //Application specific
        getUiDevice().setOrientationNatural();
        UiSelector selector = new UiSelector();
        UiObject btn_start = new UiObject(selector
                                    .className("android.widget.ImageButton")
                                    .packageName("com.eembc.coremark"));
        btn_start.click();

        try{
            UiObject running_text = new UiObject(selector
                                    .textContains("Running...")
                                    .className("android.widget.TextView")
                                    .packageName("com.eembc.coremark"));
            waitUntilNoObject(running_text, 600);

            UiObject result_text = new UiObject(selector
                                    .textContains("Results in Iterations/sec:")
                                    .className("android.widget.TextView")
                                    .packageName("com.eembc.coremark"));
            waitObject(result_text);
            sleep(2);
            takeScreenshot("AndEBench-0");
        }catch(UiObjectNotFoundException e){
            takeScreenshot("AndEBench-error");
        }

        getAutomationSupport().sendStatus(Activity.RESULT_OK, status);
    }

    public void testNBench() throws Exception{
        Bundle status = new Bundle();
        status.putString("product", getUiDevice().getProductName());
        Point p = getUiDevice().getDisplaySizeDp();
        status.putInt("dp-width", p.x);
        status.putInt("dp-height", p.y);
        //Application specific
        getUiDevice().setOrientationNatural();
        UiSelector selector = new UiSelector();
        UiObject btn_start = new UiObject(selector.text("Start the benchmark")
                                    .className("android.widget.Button")
                                    .packageName("com.drolez.nbench"));
        btn_start.click();

        try{

            UiObject running_text = new UiObject(selector
                                    .textContains("Benchmark running.")
                                    .className("android.widget.TextView")
                                    .packageName("com.drolez.nbench"));
            waitUntilNoObject(running_text, 600);

            UiObject result_text = new UiObject(selector
                                    .textContains("Last run:")
                                    .className("android.widget.TextView")
                                    .packageName("com.drolez.nbench"));
            waitObject(result_text);
            sleep(2);
            takeScreenshot("NBench-0");
        }catch(UiObjectNotFoundException e){
            takeScreenshot("NBench-error");
        }

        getAutomationSupport().sendStatus(Activity.RESULT_OK, status);
    }

    public void testQuadrant() throws Exception{
        Bundle status = new Bundle();
        status.putString("product", getUiDevice().getProductName());
        Point p = getUiDevice().getDisplaySizeDp();
        status.putInt("dp-width", p.x);
        status.putInt("dp-height", p.y);
        //Application specific
        getUiDevice().setOrientationNatural();
        UiSelector selector = new UiSelector();
        try{
            waitText("Information");
            UiObject btn_ok = new UiObject(selector.text("OK")
                     .className("android.widget.Button")
                     .packageName("com.aurorasoftworks.quadrant.ui.standard"));
            if (btn_ok.exists()){
                btn_ok.click();
            }
        }catch(UiObjectNotFoundException e){
            //do nothing
        }


        UiObject text_run = new UiObject(selector.text("Run full benchmark")
                     .className("android.widget.TextView")
                     .packageName("com.aurorasoftworks.quadrant.ui.standard"));
        text_run.click();
        waitText("Benchmark result");
        UiObject btn_yes = new UiObject(selector.text("Yes")
                     .className("android.widget.Button")
                     .packageName("com.aurorasoftworks.quadrant.ui.standard"));
        if (btn_yes.exists()){
            btn_yes.click();
        }
        UiObject text_sending = new UiObject(selector
                                       .text("Sending benchmark results...")
                                       .className("android.widget.TextView"));
        try{
            waitObject(text_sending);
        }catch(UiObjectNotFoundException e){
            takeScreenshot("quadrant-no-sending");
        }

        waitUntilNoObject(text_sending, 600);
        sleep(3);
        takeScreenshot("quadrant");

        getAutomationSupport().sendStatus(Activity.RESULT_OK, status);
    }

    public void testVellamo() throws Exception{
        Bundle status = new Bundle();
        status.putString("product", getUiDevice().getProductName());
        Point p = getUiDevice().getDisplaySizeDp();
        status.putInt("dp-width", p.x);
        status.putInt("dp-height", p.y);
        //Application specific
        getUiDevice().setOrientationNatural();
        UiSelector selector = new UiSelector();
        try{
            waitText("Vellamo EULA");
            UiObject btn_accept = new UiObject(selector.text("Accept")
                     .className("android.widget.Button")
                     .packageName("com.quicinc.vellamo"));
            if (btn_accept.exists()){
                btn_accept.click();
            }
        }catch(UiObjectNotFoundException e){
            //do nothing
        }

        UiObject btn_no = new UiObject(selector.text("No")
                     .className("android.widget.Button")
                     .packageName("com.quicinc.vellamo"));
        try{
            waitText(
               "Would you like to edit the list of websites Vellamo accesses?");
            if (btn_no.exists()){
                btn_no.click();
            }
        }catch(UiObjectNotFoundException e){
            //do nothing
        }

        UiObject text_start = new UiObject(selector.text("Start")
                     .className("android.widget.TextView")
                     .packageName("com.quicinc.vellamo"));
        text_start.click();

        waitText("Enable Tutorial?");
        btn_no.click();
        try{
            waitText("Vellamo Score");
            btn_no.click();
            sleep(3);
            getUiDevice().pressKeyCode(KeyEvent.KEYCODE_BACK);
            takeScreenshot("vellamo-0");
            sleep(2);
            getUiDevice().pressKeyCode(KeyEvent.KEYCODE_PAGE_DOWN);
            takeScreenshot("vellamo-1");
            sleep(2);
            getUiDevice().pressKeyCode(KeyEvent.KEYCODE_PAGE_DOWN);
            takeScreenshot("vellamo-2");
            sleep(2);
        }catch(UiObjectNotFoundException e){
            takeScreenshot("vellamo-error");
            throw e;
        }

        getAutomationSupport().sendStatus(Activity.RESULT_OK, status);
    }

    public void testGLBenchmark() throws Exception{
        Bundle status = new Bundle();
        status.putString("product", getUiDevice().getProductName());
        Point p = getUiDevice().getDisplaySizeDp();
        status.putInt("dp-width", p.x);
        status.putInt("dp-height", p.y);
        //Application specific
        getUiDevice().setOrientationNatural();
        UiSelector selector = new UiSelector();

        UiObject download_fail = new UiObject(selector.text("Retry Download")
                     .className("android.widget.Button"));
        if (download_fail.exists()){
            takeScreenshot("glbenchmark-retry");
            throw new Exception(
                    "Download failed because the resources could not be found");
        }
        UiObject text_perf_test = new UiObject(selector
                               .text("Performance Tests")
                               .className("android.widget.TextView"));
        text_perf_test.click();
        sleep(3);

        UiObject btn_all = new UiObject(selector.text("All")
                     .className("android.widget.Button"));
        btn_all.click();
        sleep(1);
        //uncheck the crash item
        UiObject crash_item = new UiObject(selector
                               .text("C24Z24MS4")
                               .className("android.widget.TextView"));
        crash_item.click();

        UiObject btn_start= new UiObject(selector.text("Start")
                     .className("android.widget.Button"));
        btn_start.click();
        try{
            UiObject error = new UiObject(selector
                    .text("Error during network communication!")
                    .className("android.widget.TextView"));
            UiObject processing = new UiObject(selector
                    .text("Processing results...")
                    .className("android.widget.TextView"));
            UiObject results = new UiObject(selector
                    .text("Results")
                    .className("android.widget.TextView"));
            for(int i = 0; i < 360; i++){
                if (results.exists()){
                    break;
                }
                if (processing.exists()){
                    continue;
                }

                if (error.exists()){
                    UiObject btn_retry= new UiObject(selector.text("Retry")
                     .className("android.widget.Button"));
                    btn_retry.click();
                }
                sleep(10);
            }
            waitText("Results");
            sleep(2);
            takeScreenshot("glbenchmark-0");
            getUiDevice().pressKeyCode(KeyEvent.KEYCODE_DPAD_DOWN);
            getUiDevice().pressKeyCode(KeyEvent.KEYCODE_DPAD_DOWN);
            takeScreenshot("glbenchmark-1");
            sleep(1);
            getUiDevice().pressKeyCode(KeyEvent.KEYCODE_DPAD_DOWN);
            getUiDevice().pressKeyCode(KeyEvent.KEYCODE_DPAD_DOWN);
            sleep(1);
            takeScreenshot("glbenchmark-2");
            getUiDevice().pressKeyCode(KeyEvent.KEYCODE_DPAD_DOWN);
            getUiDevice().pressKeyCode(KeyEvent.KEYCODE_DPAD_DOWN);
            sleep(1);
            takeScreenshot("glbenchmark-3");
            getUiDevice().pressKeyCode(KeyEvent.KEYCODE_DPAD_DOWN);
            getUiDevice().pressKeyCode(KeyEvent.KEYCODE_DPAD_DOWN);
            sleep(1);
            takeScreenshot("glbenchmark-4");
        }catch(UiObjectNotFoundException e){
            takeScreenshot("glbenchmark-error");
            throw e;
        }

        getAutomationSupport().sendStatus(Activity.RESULT_OK, status);
    }
}