blob: c43364ce226cbb19d9b7e5371f1904230139dbb3 [file] [log] [blame]
Channagoud Kadabi80c82512013-07-01 12:43:37 -07001# Copyright (c) 2013, The Linux Foundation. All rights reserved.
2#
3# Redistribution and use in source and binary forms, with or without
4# modification, are permitted provided that the following conditions are
5# met:
6# * Redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer.
8# * Redistributions in binary form must reproduce the above
9# copyright notice, this list of conditions and the following
10# disclaimer in the documentation and/or other materials provided
11# with the distribution.
12# * Neither the name of The Linux Foundation nor the names of its
13# contributors may be used to endorse or promote products derived
14# from this software without specific prior written permission.
15#
16# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25# * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28
29#!/usr/bin/python
30
31import os
32import sys
33import time
34import re
35import subprocess
36import getopt
37
38#
39# Erase routine, erase a parition & print the time taken for erase
40#
41def fastboot_erase(partition):
42 start_time = time.time()
43 exe = subprocess.Popen(['fastboot', 'erase', partition], stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read()
44 print exe
45 print "Time Taken for erase:", partition, ":", time.time() - start_time, "seconds"
46 print("")
47 return
48
49#
50# Flash routine, flash a parition & print the time taken to flash the image
51#
52def fastboot_flash(image_name, partition):
53 start_time = time.time()
54 exe = subprocess.Popen(['fastboot', 'flash', partition, image_name], stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read()
55 print exe
56 print "Time Taken for flashing:", partition, ":", time.time() - start_time, "seconds"
57 print("")
58 return
59
60#
61# Execute any other fasboot command & print the time taken
62#
63def fastboot_exec(command):
64 start_time = time.time()
65 exe = subprocess.Popen(['fastboot', command], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.read()
66 print exe
67 print "Time Taken for fastboot:", command, time.time() - start_time, "seconds"
68 print("")
69 return
70
71#
72# Aboot test, Test aboot with different use cases
73#
74def test_aboot(iteration, input_path):
75 system=''
76 userdata=''
77 boot=''
78
79 print ("ABOOT TEST START")
80 t0 = time.clock()
81
82 boot = os.path.join(input_path, 'boot.img')
83 system = os.path.join(input_path, 'system.img')
84 userdata = os.path.join(input_path, 'userdata.img')
85
86 print("")
87 getstate = subprocess.Popen(["fastboot", "devices"], stdout=subprocess.PIPE).communicate()[0]
88 if(re.search("fastboot",getstate) == None):
89 print("Device is not in fastboot, please make sure device is in fastboot mode ... [FAIL]")
90 sys.exit(-1)
91 else:
92 print ("fastboot devices ... [OKAY]")
93 print ("Executing other fastboot tests ...")
94 print("")
95
96 fastboot_erase("boot")
97 time.sleep(2)
98
99 fastboot_exec("reboot")
100 time.sleep(2)
101 fastboot_exec("devices")
102 time.sleep(2)
103 getstate = subprocess.Popen(["fastboot", "devices"], stdout=subprocess.PIPE).communicate()[0]
104 if(re.search("fastboot",getstate) == None):
105 print("fastboot reboot ... [FAIL]")
106 sys.exit(-1)
107
108 iteration = int(iteration)
109
110 # Flash images in a loop
111 i = 0
112 while i < iteration:
113 print "Iteration ", i
114 print ("fastboot flash boot boot.img...")
115 fastboot_flash(boot, 'boot')
116 print("")
117 print ("fastboot flash system system.img ...")
118 fastboot_flash(system, 'system')
119 print("")
120 print ("fastboot flash userdata userdata.img ...")
121 fastboot_flash(userdata, 'userdata')
122 print("")
123 i+=1
124
125 fastboot_exec("reboot")
126 print ("fastboot reboot ... [OKAY]")
127 print("")
128 time.sleep(1)
129 print("Waiting for adb to come up ...")
130 print("")
131 i = 0
132 while i < 10:
133 getstate = subprocess.Popen(["adb", "get-state"], stdout=subprocess.PIPE).communicate()[0]
134 if(re.search("device",getstate) == None):
135 i+=1
136 time.sleep(2)
137 else:
138 print("Device Online")
139 print("")
140 break
141
142 os.system("adb reboot-bootloader")
143 time.sleep(4)
144 getstate = subprocess.Popen(["fastboot", "devices"], stdout=subprocess.PIPE).communicate()[0]
145 if(re.search("fastboot",getstate) == None):
146 print ("adb reboot-bootloader ... [FAIL]")
147 sys.exit(-1)
148 else:
149 print ("adb reboot-bootloader ... [PASS]")
150
151 print("")
152 fastboot_exec("devices")
153 print ("fastboot devices ... [OKAY]")
154 print("")
155
156 fastboot_erase("system")
157 fastboot_erase("userdata")
158
159 fastboot_exec("continue")
160 print ("fastboot continue ... [OKAY]")
161 print("")
162
163 print ("ABOOT TEST DONE")
164 return
165
166# Main function to parse i/p args
167def main(argv):
168 input_path = ''
169 iteration = ''
170 if len(sys.argv) < 2:
171 print "aboot_test.py -i <iterations> -p <Binary Image Path>"
172 sys.exit(2)
173 try:
174 opts, args = getopt.getopt(argv, "hi:p:",["iter=","opath="])
175 except getopt.GetoptError:
176 print "aboot_test.py -i <iterations> -p <Binary Image Path>"
177 sys.exit(2)
178 for opt, arg in opts:
179 if opt == '-h':
180 print "aboot_test.py -i <iterations> -o <Binary Image Path>"
181 sys.exit(2)
182 elif opt in ("-i", "--iter"):
183 iteration = arg
184 elif opt in ("-p", "--opath"):
185 input_path = arg
186 test_aboot(iteration, input_path)
187
188if __name__ == "__main__":
189 main(sys.argv[1:])