summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.com>2017-07-12 23:05:47 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-07-27 22:36:52 +0100
commitb8c208e8e83742805be6a3841fa8c1d465c8770d (patch)
tree19914f105749c696a1b79b28502e504cf8188d33 /scripts
parentd4c3ace09790a18e240c4aea655e41ecee786e1b (diff)
downloadpoky-b8c208e8e83742805be6a3841fa8c1d465c8770d.tar.gz
runqemu: add --debug and --quiet
And move some debug info into logger.debug(), this can make it easy to read key messages like errors or warnings. I checked meta/lib/oeqa/ they don't depend on these messages. And I have run "oe-selftest -a", it doesn't break anything. [YOCTO #10474] (From OE-Core rev: e696425e7627edada128b40304fddc84d8d56ba7) Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/runqemu50
1 files changed, 31 insertions, 19 deletions
diff --git a/scripts/runqemu b/scripts/runqemu
index d44afc7e7a..7188bd7883 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -48,7 +48,7 @@ def create_logger():
48 48
49 # create console handler and set level to debug 49 # create console handler and set level to debug
50 ch = logging.StreamHandler() 50 ch = logging.StreamHandler()
51 ch.setLevel(logging.INFO) 51 ch.setLevel(logging.DEBUG)
52 52
53 # create formatter 53 # create formatter
54 formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s') 54 formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
@@ -85,6 +85,8 @@ of the following environment variables (in any order):
85 qemuparams=<xyz> - specify custom parameters to QEMU 85 qemuparams=<xyz> - specify custom parameters to QEMU
86 bootparams=<xyz> - specify custom kernel parameters during boot 86 bootparams=<xyz> - specify custom kernel parameters during boot
87 help, -h, --help: print this text 87 help, -h, --help: print this text
88 -d, --debug: Enable debug output
89 -q, --quite: Hide most output except error messages
88 90
89Examples: 91Examples:
90 runqemu 92 runqemu
@@ -112,7 +114,7 @@ def check_tun():
112 114
113def check_libgl(qemu_bin): 115def check_libgl(qemu_bin):
114 cmd = 'ldd %s' % qemu_bin 116 cmd = 'ldd %s' % qemu_bin
115 logger.info('Running %s...' % cmd) 117 logger.debug('Running %s...' % cmd)
116 need_gl = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8') 118 need_gl = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
117 if re.search('libGLU', need_gl): 119 if re.search('libGLU', need_gl):
118 # We can't run without a libGL.so 120 # We can't run without a libGL.so
@@ -229,12 +231,12 @@ class BaseConfig(object):
229 self.mac_slirp = "52:54:00:12:35:" 231 self.mac_slirp = "52:54:00:12:35:"
230 232
231 def acquire_lock(self): 233 def acquire_lock(self):
232 logger.info("Acquiring lockfile %s..." % self.lock) 234 logger.debug("Acquiring lockfile %s..." % self.lock)
233 try: 235 try:
234 self.lock_descriptor = open(self.lock, 'w') 236 self.lock_descriptor = open(self.lock, 'w')
235 fcntl.flock(self.lock_descriptor, fcntl.LOCK_EX|fcntl.LOCK_NB) 237 fcntl.flock(self.lock_descriptor, fcntl.LOCK_EX|fcntl.LOCK_NB)
236 except Exception as e: 238 except Exception as e:
237 logger.info("Acquiring lockfile %s failed: %s" % (self.lock, e)) 239 logger.error("Acquiring lockfile %s failed: %s" % (self.lock, e))
238 if self.lock_descriptor: 240 if self.lock_descriptor:
239 self.lock_descriptor.close() 241 self.lock_descriptor.close()
240 return False 242 return False
@@ -259,10 +261,10 @@ class BaseConfig(object):
259 def is_deploy_dir_image(self, p): 261 def is_deploy_dir_image(self, p):
260 if os.path.isdir(p): 262 if os.path.isdir(p):
261 if not re.search('.qemuboot.conf$', '\n'.join(os.listdir(p)), re.M): 263 if not re.search('.qemuboot.conf$', '\n'.join(os.listdir(p)), re.M):
262 logger.info("Can't find required *.qemuboot.conf in %s" % p) 264 logger.debug("Can't find required *.qemuboot.conf in %s" % p)
263 return False 265 return False
264 if not any(map(lambda name: '-image-' in name, os.listdir(p))): 266 if not any(map(lambda name: '-image-' in name, os.listdir(p))):
265 logger.info("Can't find *-image-* in %s" % p) 267 logger.debug("Can't find *-image-* in %s" % p)
266 return False 268 return False
267 return True 269 return True
268 else: 270 else:
@@ -281,9 +283,9 @@ class BaseConfig(object):
281 283
282 def set_machine_deploy_dir(self, machine, deploy_dir_image): 284 def set_machine_deploy_dir(self, machine, deploy_dir_image):
283 """Set MACHINE and DEPLOY_DIR_IMAGE""" 285 """Set MACHINE and DEPLOY_DIR_IMAGE"""
284 logger.info('MACHINE: %s' % machine) 286 logger.debug('MACHINE: %s' % machine)
285 self.set("MACHINE", machine) 287 self.set("MACHINE", machine)
286 logger.info('DEPLOY_DIR_IMAGE: %s' % deploy_dir_image) 288 logger.debug('DEPLOY_DIR_IMAGE: %s' % deploy_dir_image)
287 self.set("DEPLOY_DIR_IMAGE", deploy_dir_image) 289 self.set("DEPLOY_DIR_IMAGE", deploy_dir_image)
288 290
289 def check_arg_nfs(self, p): 291 def check_arg_nfs(self, p):
@@ -337,10 +339,10 @@ class BaseConfig(object):
337 339
338 elif os.path.isdir(p) or re.search(':', p) and re.search('/', p): 340 elif os.path.isdir(p) or re.search(':', p) and re.search('/', p):
339 if self.is_deploy_dir_image(p): 341 if self.is_deploy_dir_image(p):
340 logger.info('DEPLOY_DIR_IMAGE: %s' % p) 342 logger.debug('DEPLOY_DIR_IMAGE: %s' % p)
341 self.set("DEPLOY_DIR_IMAGE", p) 343 self.set("DEPLOY_DIR_IMAGE", p)
342 else: 344 else:
343 logger.info("Assuming %s is an nfs rootfs" % p) 345 logger.debug("Assuming %s is an nfs rootfs" % p)
344 self.check_arg_nfs(p) 346 self.check_arg_nfs(p)
345 elif os.path.basename(p).startswith('ovmf'): 347 elif os.path.basename(p).startswith('ovmf'):
346 self.ovmf_bios.append(p) 348 self.ovmf_bios.append(p)
@@ -356,7 +358,7 @@ class BaseConfig(object):
356 elif re.search('/', arg): 358 elif re.search('/', arg):
357 raise RunQemuError("Unknown arg: %s" % arg) 359 raise RunQemuError("Unknown arg: %s" % arg)
358 360
359 logger.info('Assuming MACHINE = %s' % arg) 361 logger.debug('Assuming MACHINE = %s' % arg)
360 362
361 # if we're running under testimage, or similarly as a child 363 # if we're running under testimage, or similarly as a child
362 # of an existing bitbake invocation, we can't invoke bitbake 364 # of an existing bitbake invocation, we can't invoke bitbake
@@ -393,6 +395,16 @@ class BaseConfig(object):
393 self.set("MACHINE", arg) 395 self.set("MACHINE", arg)
394 396
395 def check_args(self): 397 def check_args(self):
398 for debug in ("-d", "--debug"):
399 if debug in sys.argv:
400 logger.setLevel(logging.DEBUG)
401 sys.argv.remove(debug)
402
403 for quiet in ("-q", "--quiet"):
404 if quiet in sys.argv:
405 logger.setLevel(logging.ERROR)
406 sys.argv.remove(quiet)
407
396 unknown_arg = "" 408 unknown_arg = ""
397 for arg in sys.argv[1:]: 409 for arg in sys.argv[1:]:
398 if arg in self.fstypes + self.vmtypes: 410 if arg in self.fstypes + self.vmtypes:
@@ -608,7 +620,7 @@ class BaseConfig(object):
608 break 620 break
609 621
610 if biosdir: 622 if biosdir:
611 logger.info("Assuming biosdir is: %s" % biosdir) 623 logger.debug("Assuming biosdir is: %s" % biosdir)
612 self.qemu_opt_script += ' -L %s' % biosdir 624 self.qemu_opt_script += ' -L %s' % biosdir
613 else: 625 else:
614 logger.error("Custom BIOS directory not found. Tried: %s, %s, and %s" % (self.custombiosdir, biosdir_native, biosdir_host)) 626 logger.error("Custom BIOS directory not found. Tried: %s, %s, and %s" % (self.custombiosdir, biosdir_native, biosdir_host))
@@ -663,7 +675,7 @@ class BaseConfig(object):
663 if self.get('DEPLOY_DIR_IMAGE'): 675 if self.get('DEPLOY_DIR_IMAGE'):
664 deploy_dir_image = self.get('DEPLOY_DIR_IMAGE') 676 deploy_dir_image = self.get('DEPLOY_DIR_IMAGE')
665 else: 677 else:
666 logger.info("Can't find qemuboot conf file, DEPLOY_DIR_IMAGE is NULL!") 678 logger.warn("Can't find qemuboot conf file, DEPLOY_DIR_IMAGE is NULL!")
667 return 679 return
668 680
669 if self.rootfs and not os.path.exists(self.rootfs): 681 if self.rootfs and not os.path.exists(self.rootfs):
@@ -675,7 +687,7 @@ class BaseConfig(object):
675 self.rootfs, machine) 687 self.rootfs, machine)
676 else: 688 else:
677 cmd = 'ls -t %s/*.qemuboot.conf' % deploy_dir_image 689 cmd = 'ls -t %s/*.qemuboot.conf' % deploy_dir_image
678 logger.info('Running %s...' % cmd) 690 logger.debug('Running %s...' % cmd)
679 try: 691 try:
680 qbs = subprocess.check_output(cmd, shell=True).decode('utf-8') 692 qbs = subprocess.check_output(cmd, shell=True).decode('utf-8')
681 except subprocess.CalledProcessError as err: 693 except subprocess.CalledProcessError as err:
@@ -700,7 +712,7 @@ class BaseConfig(object):
700 if not os.path.exists(self.qemuboot): 712 if not os.path.exists(self.qemuboot):
701 raise RunQemuError("Failed to find %s (wrong image name or BSP does not support running under qemu?)." % self.qemuboot) 713 raise RunQemuError("Failed to find %s (wrong image name or BSP does not support running under qemu?)." % self.qemuboot)
702 714
703 logger.info('CONFFILE: %s' % self.qemuboot) 715 logger.debug('CONFFILE: %s' % self.qemuboot)
704 716
705 cf = configparser.ConfigParser() 717 cf = configparser.ConfigParser()
706 cf.read(self.qemuboot) 718 cf.read(self.qemuboot)
@@ -899,7 +911,7 @@ class BaseConfig(object):
899 pass 911 pass
900 912
901 cmd = '%s link' % ip 913 cmd = '%s link' % ip
902 logger.info('Running %s...' % cmd) 914 logger.debug('Running %s...' % cmd)
903 ip_link = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8') 915 ip_link = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
904 # Matches line like: 6: tap0: <foo> 916 # Matches line like: 6: tap0: <foo>
905 possibles = re.findall('^[1-9]+: +(tap[0-9]+): <.*', ip_link, re.M) 917 possibles = re.findall('^[1-9]+: +(tap[0-9]+): <.*', ip_link, re.M)
@@ -931,7 +943,7 @@ class BaseConfig(object):
931 self.lock = lockfile + '.lock' 943 self.lock = lockfile + '.lock'
932 self.acquire_lock() 944 self.acquire_lock()
933 self.cleantap = True 945 self.cleantap = True
934 logger.info('Created tap: %s' % tap) 946 logger.debug('Created tap: %s' % tap)
935 947
936 if not tap: 948 if not tap:
937 logger.error("Failed to setup tap device. Run runqemu-gen-tapdevs to manually create.") 949 logger.error("Failed to setup tap device. Run runqemu-gen-tapdevs to manually create.")
@@ -1150,7 +1162,7 @@ class BaseConfig(object):
1150 def cleanup(self): 1162 def cleanup(self):
1151 if self.cleantap: 1163 if self.cleantap:
1152 cmd = 'sudo %s %s %s' % (self.qemuifdown, self.tap, self.bindir_native) 1164 cmd = 'sudo %s %s %s' % (self.qemuifdown, self.tap, self.bindir_native)
1153 logger.info('Running %s' % cmd) 1165 logger.debug('Running %s' % cmd)
1154 subprocess.check_call(cmd, shell=True) 1166 subprocess.check_call(cmd, shell=True)
1155 if self.lock_descriptor: 1167 if self.lock_descriptor:
1156 logger.info("Releasing lockfile for tap device '%s'" % self.tap) 1168 logger.info("Releasing lockfile for tap device '%s'" % self.tap)
@@ -1159,7 +1171,7 @@ class BaseConfig(object):
1159 if self.nfs_running: 1171 if self.nfs_running:
1160 logger.info("Shutting down the userspace NFS server...") 1172 logger.info("Shutting down the userspace NFS server...")
1161 cmd = "runqemu-export-rootfs stop %s" % self.rootfs 1173 cmd = "runqemu-export-rootfs stop %s" % self.rootfs
1162 logger.info('Running %s' % cmd) 1174 logger.debug('Running %s' % cmd)
1163 subprocess.check_call(cmd, shell=True) 1175 subprocess.check_call(cmd, shell=True)
1164 1176
1165 if self.saved_stty: 1177 if self.saved_stty: