Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: client/tests/kvm/scripts/ksm_overcommit_guest.py

Issue 6246035: Merge remote branch 'cros/upstream' into master (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/autotest.git@master
Patch Set: patch Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 """ 3 """
4 Auxiliary script used to allocate memory on guests. 4 Auxiliary script used to allocate memory on guests.
5 5
6 @copyright: 2008-2009 Red Hat Inc. 6 @copyright: 2008-2009 Red Hat Inc.
7 @author: Jiri Zupka (jzupka@redhat.com) 7 @author: Jiri Zupka (jzupka@redhat.com)
8 """ 8 """
9 9
10 10
11 import os, array, sys, struct, random, copy, inspect, tempfile, datetime, math 11 import os, array, sys, random, copy, tempfile, datetime, math
12 12
13 PAGE_SIZE = 4096 # machine page size 13 PAGE_SIZE = 4096 # machine page size
14 14
15 TMPFS_OVERHEAD = 0.0022 # overhead on 1MB of write data 15 TMPFS_OVERHEAD = 0.0022 # overhead on 1MB of write data
16 16
17 17
18 class MemFill(object): 18 class MemFill(object):
19 """ 19 """
20 Fills guest memory according to certain patterns. 20 Fills guest memory according to certain patterns.
21 """ 21 """
22 def __init__(self, mem, static_value, random_key): 22 def __init__(self, mem, static_value, random_key):
23 """ 23 """
24 Constructor of MemFill class. 24 Constructor of MemFill class.
25 25
26 @param mem: Amount of test memory in MB. 26 @param mem: Amount of test memory in MB.
27 @param random_key: Seed of random series used for fill up memory. 27 @param random_key: Seed of random series used for fill up memory.
28 @param static_value: Value used to fill all memory. 28 @param static_value: Value used to fill all memory.
29 """ 29 """
30 if (static_value < 0 or static_value > 255): 30 if (static_value < 0 or static_value > 255):
31 print ("FAIL: Initialization static value" 31 print ("FAIL: Initialization static value"
32 "can be only in range (0..255)") 32 "can be only in range (0..255)")
33 return 33 return
34 34
35 self.tmpdp = tempfile.mkdtemp() 35 self.tmpdp = tempfile.mkdtemp()
36 ret_code = os.system("mount -o size=%dM tmpfs %s -t tmpfs" % 36 ret_code = os.system("mount -o size=%dM tmpfs %s -t tmpfs" %
37 ((mem+math.ceil(mem*TMPFS_OVERHEAD)), 37 ((mem+math.ceil(mem*TMPFS_OVERHEAD)),
38 self.tmpdp)) 38 self.tmpdp))
39 if ret_code != 0: 39 if ret_code != 0:
40 if os.getuid() != 0: 40 if os.getuid() != 0:
41 print ("FAIL: Unable to mount tmpfs " 41 print ("FAIL: Unable to mount tmpfs "
42 "(likely cause: you are not root)") 42 "(likely cause: you are not root)")
43 else: 43 else:
44 print "FAIL: Unable to mount tmpfs" 44 print "FAIL: Unable to mount tmpfs"
45 else: 45 else:
46 self.f = tempfile.TemporaryFile(prefix='mem', dir=self.tmpdp) 46 self.f = tempfile.TemporaryFile(prefix='mem', dir=self.tmpdp)
47 self.allocate_by = 'L' 47 self.allocate_by = 'L'
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 """ 228 """
229 print "PASS: Start" 229 print "PASS: Start"
230 end = False 230 end = False
231 while not end: 231 while not end:
232 str = raw_input() 232 str = raw_input()
233 exec str 233 exec str
234 234
235 235
236 if __name__ == "__main__": 236 if __name__ == "__main__":
237 main() 237 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698