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#
18
19import logging
20
21from conf import LisaLogging
22LisaLogging.setup()
23import json
24import os
25import devlib
26from env import TestEnv
27from android import Screen, Workload, System
28from trace import Trace
29import trappy
30import pandas as pd
31import sqlite3
32import argparse
33import shutil
34
35# Description: This experiments tests suspend/resume by turning off
36# the screen and cutting off USB
37# REQUIRES DEVICE TO BE CONNECTED THROUGH MONSOON SO THAT PASSTHROUGH
38# CAN BE TURNED OFF. By default energy will be measured in this test.
39
40parser = argparse.ArgumentParser(description='SuspendResume tests')
41
42parser.add_argument('--out_prefix', dest='out_prefix', action='store', default='default',
43                    help='prefix for out directory')
44
45parser.add_argument('--collect', dest='collect', action='store', default='systrace',
46                    help='what to collect (default systrace)')
47
48parser.add_argument('--duration', dest='duration_s', action='store',
49                    default=15, type=int,
50                    help='Duration of test (default 15s)')
51
52parser.add_argument('--serial', dest='serial', action='store',
53                    help='Serial number of device to test')
54
55args = parser.parse_args()
56
57def experiment():
58    # Get workload
59    wload = Workload.getInstance(te, 'SuspendResume')
60
61    outdir=te.res_dir + '_' + args.out_prefix
62    try:
63        shutil.rmtree(outdir)
64    except:
65        print "couldn't remove " + outdir
66        pass
67    os.makedirs(outdir)
68
69    # Run SuspendResume
70    wload.run(outdir, duration_s=args.duration_s, collect=args.collect)
71
72    # Dump platform descriptor
73    te.platform_dump(te.res_dir)
74
75    te._log.info('RESULTS are in out directory: {}'.format(outdir))
76
77# Setup target configuration
78my_conf = {
79
80    # Target platform and board
81    "platform"     : 'android',
82
83    # Useful for reading names of little/big cluster
84    # and energy model info, its device specific and use
85    # only if needed for analysis
86    # "board"        : 'pixel',
87
88    # Device
89    # By default the device connected is detected, but if more than 1
90    # device, override the following to get a specific device.
91    # "device"       : "HT6880200489",
92
93    # Folder where all the results will be collected
94    "results_dir" : "SuspendResume",
95
96    # Define devlib modules to load
97    "modules"     : [
98        'cpufreq',      # enable CPUFreq support
99        'cpuidle',      # enable cpuidle support
100        # 'cgroups'     # Enable for cgroup support
101    ],
102
103    "emeter" : {
104        'instrument': 'monsoon',
105        'conf': { }
106    },
107
108    # Tools required by the experiments
109    "tools"   : [ 'taskset'],
110
111    "skip_nrg_model" : True,
112}
113
114if args.serial:
115    my_conf["device"] = args.serial
116
117# Initialize a test environment using:
118te = TestEnv(my_conf, wipe=False)
119target = te.target
120
121results = experiment()
122