OLD | NEW |
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
| 5 import os, shutil, time |
5 from autotest_lib.client.bin import test, utils | 6 from autotest_lib.client.bin import test, utils |
6 | 7 |
7 def get_pids(program_name): | 8 def get_pids(program_name): |
8 """ | 9 """ |
9 Collect a list of pids for all the instances of a program. | 10 Collect a list of pids for all the instances of a program. |
10 | 11 |
11 @param program_name the name of the program | 12 @param program_name the name of the program |
12 @return list of pids | 13 @return list of pids |
13 """ | 14 """ |
14 pidlist = utils.system_output("pgrep -f \'%s\'" % program_name) | 15 pidlist = utils.system_output("pgrep -f \'%s\'" % program_name) |
(...skipping 30 matching lines...) Expand all Loading... |
45 def get_cpu_usage(duration, time): | 46 def get_cpu_usage(duration, time): |
46 """ | 47 """ |
47 Calculate cpu usage based on duration and time on cpu. | 48 Calculate cpu usage based on duration and time on cpu. |
48 | 49 |
49 @param duration | 50 @param duration |
50 @param time on cpu | 51 @param time on cpu |
51 @return cpu usage | 52 @return cpu usage |
52 """ | 53 """ |
53 return float(time) / float(duration * get_number_of_logical_cpu()) | 54 return float(time) / float(duration * get_number_of_logical_cpu()) |
54 | 55 |
| 56 |
| 57 def setup_playground(src, dst, optionfile): |
| 58 """ |
| 59 Setup playground files. |
| 60 |
| 61 @param src path |
| 62 @param dst path |
| 63 @param optionfile |
| 64 """ |
| 65 shutil.rmtree(dst, ignore_errors=True) |
| 66 shutil.copytree(src, dst) |
| 67 utils.run('chown chronos %s -R' % dst) |
| 68 |
| 69 dst_path= '/home/chronos/.Google/' |
| 70 opt_path= os.path.join(dst_path, 'Google Talk Plugin') |
| 71 dst_opt = os.path.join(opt_path, 'options') |
| 72 utils.run('mkdir -p \'%s\'' % opt_path) |
| 73 utils.run('cp -f %s \'%s\'' % (optionfile, dst_opt)) |
| 74 utils.run('chown chronos \'%s\' -R' % dst_path) |
| 75 utils.run('chmod o+r+w \'%s\'' % dst_opt) |
| 76 |
| 77 |
| 78 def cleanup_playground(playground, testdone=False): |
| 79 """ |
| 80 Cleanup playground files. |
| 81 |
| 82 @param playground path |
| 83 @param testdone |
| 84 """ |
| 85 utils.run('pkill chrome', ignore_status=True) |
| 86 time.sleep(10) |
| 87 utils.run('pkill GoogleTalkPlugin', ignore_status=True) |
| 88 time.sleep(10) |
| 89 utils.run('rm -f /tmp/tmp.log', ignore_status=True) |
| 90 if testdone: |
| 91 shutil.rmtree(playground) |
| 92 |
| 93 # Delete previous browser state if any |
| 94 shutil.rmtree('/home/chronos/.config/chromium', ignore_errors=True) |
| 95 shutil.rmtree('/home/chronos/.config/google-chrome', ignore_errors=True) |
| 96 |
OLD | NEW |