# Copyright (c) 2012 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/>.
import os
import lava_android_test.config
import lava_android_test.testdef

test_name = 'coremark'

config = lava_android_test.config.get_config()
inst_dir = '%s/%s' % (config.installdir_android, test_name)

options_file = "%s/install_options" % (inst_dir)
coremark = '%s/coremark' % (inst_dir)

curdir = os.path.realpath(os.path.dirname(__file__))
script_host = '%s/%s/download_coremark.sh' % (curdir, test_name)
script_target = '%s/download_coremark.sh' % (inst_dir)

INSTALL_STEPS_ADB_PRE = [
    'push %s %s ' % (script_host, script_target),
    'shell chmod 777 %s' % script_target,
    'shell %s %s %s' % (script_target, options_file, coremark),
]

ADB_SHELL_STEPS = [ '"%s 0x0 0x0 0x66 0 7 1 2000"' % coremark ]
PATTERN = "^CoreMark 1.0\s*:\s+(?P<measurement>\d+\.\d+) / (?P<message>.*)"

inst = lava_android_test.testdef.AndroidTestInstaller(
                                steps_adb_pre=INSTALL_STEPS_ADB_PRE)
run = lava_android_test.testdef.AndroidTestRunner(
                                    adbshell_steps=ADB_SHELL_STEPS)
parser = lava_android_test.testdef.AndroidTestParser(PATTERN,
                                       appendall={'test_case_id':'Iterations/Sec'})
testobj = lava_android_test.testdef.AndroidTest(testname=test_name,
                                    installer=inst,
                                    runner=run,
                                    parser=parser)
