diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-03-19 11:44:27 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-03-19 11:48:30 +0000 |
commit | 6c9743d9b9754db97b3447d6d3e172c828aa0185 (patch) | |
tree | f21e26c2e4c9a9b90b4f0eca001a5a2ed2b7df52 /scripts/qemuimage-testlib-pythonhelper | |
parent | 87cfde2559daec564731c5c25df04eec27eaf7d5 (diff) | |
download | poky-6c9743d9b9754db97b3447d6d3e172c828aa0185.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.
(From OE-Core rev: b9e052ed6b604f0049bcfa968a57f15d6e3d6395)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/qemuimage-testlib-pythonhelper')
-rwxr-xr-x | scripts/qemuimage-testlib-pythonhelper | 61 |
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 @@ | |||
1 | #!/usr/bin/env python | ||
2 | |||
3 | import optparse | ||
4 | import subprocess | ||
5 | import sys | ||
6 | |||
7 | parser = optparse.OptionParser( | ||
8 | usage = """ | ||
9 | %prog [options] | ||
10 | """) | ||
11 | |||
12 | parser.add_option("-q", "--findqemu", | ||
13 | help = "find a qemu beneath the process <pid>", | ||
14 | action="store", dest="findqemu") | ||
15 | |||
16 | options, args = parser.parse_args(sys.argv) | ||
17 | |||
18 | if options.findqemu: | ||
19 | # | ||
20 | # Walk the process tree from the process specified looking for a qemu-system. Return its pid. | ||
21 | # | ||
22 | ps = subprocess.Popen(['ps', 'ax', '-o', 'pid,ppid,command'], stdout=subprocess.PIPE).communicate()[0] | ||
23 | processes = ps.split('\n') | ||
24 | nfields = len(processes[0].split()) - 1 | ||
25 | pids = {} | ||
26 | commands = {} | ||
27 | for row in processes[1:]: | ||
28 | data = row.split(None, nfields) | ||
29 | if len(data) != 3: | ||
30 | continue | ||
31 | if data[1] not in pids: | ||
32 | pids[data[1]] = [] | ||
33 | pids[data[1]].append(data[0]) | ||
34 | commands[data[0]] = data[2] | ||
35 | |||
36 | if options.findqemu not in pids: | ||
37 | print "No children found matching %s" % options.findqemu | ||
38 | sys.exit(1) | ||
39 | |||
40 | parents = [] | ||
41 | newparents = pids[options.findqemu] | ||
42 | while newparents: | ||
43 | next = [] | ||
44 | for p in newparents: | ||
45 | if p in pids: | ||
46 | for n in pids[p]: | ||
47 | if n not in parents and n not in next: | ||
48 | next.append(n) | ||
49 | |||
50 | if p not in parents: | ||
51 | parents.append(p) | ||
52 | newparents = next | ||
53 | #print "Children matching %s:" % str(parents) | ||
54 | for p in parents: | ||
55 | if "qemu-system" in commands[p]: | ||
56 | print p | ||
57 | sys.exit(0) | ||
58 | sys.exit(1) | ||
59 | else: | ||
60 | parser.print_help() | ||
61 | |||