1#!/usr/bin/env python
2# SPDX-License-Identifier: Apache-2.0
3#
4# Copyright (C) 2017, ARM Limited, Google, and contributors.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18import logging
19
20from conf import LisaLogging
21LisaLogging.setup()
22import json
23import os
24import devlib
25from env import TestEnv
26from android import Screen, Workload, System
27from trace import Trace
28import trappy
29import pandas as pd
30import sqlite3
31import argparse
32import shutil
33
34parser = argparse.ArgumentParser(description='GpsOn')
35
36parser.add_argument('--out_prefix', dest='out_prefix', action='store', default='default',
37                    help='prefix for out directory')
38
39parser.add_argument('--collect', dest='collect', action='store', default='energy',
40                    help='what to collect (default energy)')
41
42parser.add_argument('--duration', dest='duration_s', action='store',
43                    default=30, type=int,
44                    help='Duration of test (default 30s)')
45
46parser.add_argument('--serial', dest='serial', action='store',
47                    help='Serial number of device to test')
48
49args = parser.parse_args()
50
51def experiment():
52    # Get workload
53    wload = Workload.getInstance(te, 'AppStartup')
54
55    outdir=te.res_dir + '_' + args.out_prefix
56    try:
57        shutil.rmtree(outdir)
58    except:
59        print "couldn't remove " + outdir
60        pass
61    os.makedirs(outdir)
62
63    package = 'com.example.android.powerprofile.gpson'
64    permissions = ['android.permission.ACCESS_FINE_LOCATION']
65
66    # Run AppStartup workload with the gps on app
67    wload.run(outdir, package=package, permissions=permissions,
68            duration_s=args.duration_s, collect=args.collect)
69
70    # Dump platform descriptor
71    te.platform_dump(te.res_dir)
72
73    te._log.info('RESULTS are in out directory: {}'.format(outdir))
74
75# Setup target configuration
76my_conf = {
77
78    # Target platform and board
79    "platform"     : 'android',
80
81    # Useful for reading names of little/big cluster
82    # and energy model info, its device specific and use
83    # only if needed for analysis
84    # "board"        : 'pixel',
85
86    # Device
87    # By default the device connected is detected, but if more than 1
88    # device, override the following to get a specific device.
89    # "device"       : "HT6880200489",
90
91    # Folder where all the results will be collected
92    "results_dir" : "GpsOn",
93
94    # Define devlib modules to load
95    "modules"     : [
96        'cpufreq',      # enable CPUFreq support
97    ],
98
99    "emeter" : {
100        'instrument': 'monsoon',
101        'conf': { }
102    },
103
104    # Tools required by the experiments
105    "tools"   : [],
106}
107
108if args.serial:
109    my_conf["device"] = args.serial
110
111# Initialize a test environment using:
112te = TestEnv(my_conf, wipe=False)
113target = te.target
114
115results = experiment()
116