aboutsummaryrefslogtreecommitdiff
path: root/lava_android_test/test_definitions/0xbench.py
blob: 8327629870270a1dd23e5a077fb6a3cf09b3a6ac (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
# Copyright (c) 2011 Linaro

# Author: Linaro Validation Team <linaro-dev@lists.linaro.org>
#
# This file is part of LAVA Android Test.
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""
0xbench integrates several popular benchmarks into a single Android
app that can be run to get benchmark reports for a given device.
Here by default we will run the math/2d/3d test on the target device.

**URL:** http://code.google.com/p/0xbench/

**Default options:** "--ez math true --ez 2d true --ez 3d true --ez vm true"
"""

import os
import json

import lava_android_test.testdef

curdir = os.path.realpath(os.path.dirname(__file__))

# "-timeout timeout" must be specified with at least one test
# can not only specified the "-timeout timeout" as option
DEFAULT_OPTIONS = '--ez math true --ez 2d true --ez 3d true --ez vm true'
INSTALL_STEPS_HOST_POST = [
        ("python %s/android-0xbenchmark/android_0xbenchmark_modify_path.py"
         " $(SERIAL)") % curdir]

RUN_STEPS_HOST_PRE = [
        ("python %s/android-0xbenchmark/android_0xbenchmark_kill.py"
         " $(SERIAL)") % curdir]
RUN_STEPS_ADB_SHELL = ['logcat -c',
        ("am start -n org.zeroxlab.zeroxbenchmark/"
         "org.zeroxlab.zeroxbenchmark.Benchmark --ez autorun true $(OPTIONS)")]
RUN_STEPS_HOST_POST = [
        'python %s/android-0xbenchmark/android_0xbenchmark_wait.py '
        '$(SERIAL) $(OPTIONS)' % curdir]


class ZeroXBenchmarkTestParser(lava_android_test.testdef.AndroidTestParser):

    def parse(self, result_filename=None, output_filename='0xBenchmark.bundle',
               test_name=''):
        """Parse test output to gather results
        Use the pattern specified when the class was instantiated to look
        through the results line-by-line and find lines that match it.
        Results are then stored in self.results.  If a fixupdict was supplied
        it is used to convert test result strings to a standard format.
        """
        with open(output_filename) as stream:
            test_results_data = stream.read()
            test_results_json = json.loads(test_results_data)
            self.results['test_results'] = test_results_json[
                                                'test_runs'][0]['test_results']
        if self.fixupdict:
            self.fixresults(self.fixupdict)
        if self.appendall:
            self.appendtoall(self.appendall)
        self.fixmeasurements()
        self.fixids()

save_dir = '/data/data/org.zeroxlab.zeroxbenchmark/files'
inst = lava_android_test.testdef.AndroidTestInstaller(
                                    steps_host_post=INSTALL_STEPS_HOST_POST)
run = lava_android_test.testdef.AndroidTestRunner(
                                    steps_host_pre=RUN_STEPS_HOST_PRE,
                                    adbshell_steps=RUN_STEPS_ADB_SHELL,
                                    steps_host_post=RUN_STEPS_HOST_POST)
parser = ZeroXBenchmarkTestParser()
testobj = lava_android_test.testdef.AndroidTest(testname="0xbench",
            installer=inst, runner=run, parser=parser,
            org_ouput_file=os.path.join(save_dir, '0xBenchmark.bundle'),
            default_options=DEFAULT_OPTIONS)