summaryrefslogtreecommitdiffstats
path: root/scripts/qemuimage-testlib-pythonhelper
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2013-03-19 11:44:27 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-03-19 11:48:21 +0000
commitb9e052ed6b604f0049bcfa968a57f15d6e3d6395 (patch)
tree0a71f2b9e65d8427cb61bca8b6786446e229a90b /scripts/qemuimage-testlib-pythonhelper
parent7032d559c04bae09e6b7c39ddeb1bf35acc0584c (diff)
downloadopenembedded-core-b9e052ed6b604f0049bcfa968a57f15d6e3d6395.tar.gz
qemu-testlib: Add python helper and simplify shell
The current code has a race since it greps for *any* qemu process running, even if it isn't the one we started. This leads to some sanity tests potentially failing on machines where multiple sets of sanity tests are running. To resovle this and some other ugly code issues, add a python script to accurately walk the process tree and find the qemu process. We can then replace all the shell functions attempting this which happen to work in many cases but not all. Also clean up some of the error handling so its more legible. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/qemuimage-testlib-pythonhelper')
-rwxr-xr-xscripts/qemuimage-testlib-pythonhelper61
1 files changed, 61 insertions, 0 deletions
diff --git a/scripts/qemuimage-testlib-pythonhelper b/scripts/qemuimage-testlib-pythonhelper
new file mode 100755
index 0000000000..2ca61ca06a
--- /dev/null
+++ b/scripts/qemuimage-testlib-pythonhelper
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+
+import optparse
+import subprocess
+import sys
+
+parser = optparse.OptionParser(
+ usage = """
+ %prog [options]
+""")
+
+parser.add_option("-q", "--findqemu",
+ help = "find a qemu beneath the process <pid>",
+ action="store", dest="findqemu")
+
+options, args = parser.parse_args(sys.argv)
+
+if options.findqemu:
+ #
+ # Walk the process tree from the process specified looking for a qemu-system. Return its pid.
+ #
+ ps = subprocess.Popen(['ps', 'ax', '-o', 'pid,ppid,command'], stdout=subprocess.PIPE).communicate()[0]
+ processes = ps.split('\n')
+ nfields = len(processes[0].split()) - 1
+ pids = {}
+ commands = {}
+ for row in processes[1:]:
+ data = row.split(None, nfields)
+ if len(data) != 3:
+ continue
+ if data[1] not in pids:
+ pids[data[1]] = []
+ pids[data[1]].append(data[0])
+ commands[data[0]] = data[2]
+
+ if options.findqemu not in pids:
+ print "No children found matching %s" % options.findqemu
+ sys.exit(1)
+
+ parents = []
+ newparents = pids[options.findqemu]
+ while newparents:
+ next = []
+ for p in newparents:
+ if p in pids:
+ for n in pids[p]:
+ if n not in parents and n not in next:
+ next.append(n)
+
+ if p not in parents:
+ parents.append(p)
+ newparents = next
+ #print "Children matching %s:" % str(parents)
+ for p in parents:
+ if "qemu-system" in commands[p]:
+ print p
+ sys.exit(0)
+ sys.exit(1)
+else:
+ parser.print_help()
+