~pwlars/ubuntu-test-cases/krillin-recovery

« back to all changes in this revision

Viewing changes to scripts/combine_results

  • Committer: Andy Doan
  • Date: 2013-09-10 13:21:26 UTC
  • mto: (19.1.3 touch)
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: andy.doan@canonical.com-20130910132126-04w924583tmqd5k9
update the memevent test to use a configurable "probe" directory

We've had to change this in the past and will need to change it in
the future to support a writeable directory for read-only images.
This allows us to change run_utah_phablet.py's default probe directory
in the future w/o having the change this repo in lock-step.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python3
2
 
 
3
 
"""
4
 
We always run the system-settle test before and after an autopilot test. This
5
 
script takes the results of the before/after results and combines them in with
6
 
the junit xml results from the autopilot test so we have one unified report.
7
 
"""
8
 
 
9
 
 
10
 
import os
11
 
import sys
12
 
 
13
 
from xml.etree import ElementTree
14
 
 
15
 
 
16
 
PRE_COMBINE = [
17
 
    ('settle_before', 'settle_before'),
18
 
    ('setup_setup', 'setup'),
19
 
]
20
 
 
21
 
POST_COMBINE = [
22
 
    ('settle_after', 'settle_after'),
23
 
    ('setup_teardown', 'teardown'),
24
 
]
25
 
 
26
 
 
27
 
def _build_node(classname, name, rcfile, stdout):
28
 
    e = ElementTree.Element('testcase')
29
 
    e.attrib['classname'] = classname
30
 
    e.attrib['name'] = name
31
 
 
32
 
    if not os.path.exists(rcfile):
33
 
        return None, False
34
 
 
35
 
    rc = int(open(rcfile).read())
36
 
    if rc != 0:
37
 
        f = ElementTree.Element('failure')
38
 
        e.append(f)
39
 
        f.attrib['type'] = 'testtools.testresult.real._StringException'
40
 
        f.text = open(stdout).read()
41
 
    return e, rc != 0
42
 
 
43
 
 
44
 
def _get_results(apfile):
45
 
    try:
46
 
        tree = ElementTree.parse(apfile)
47
 
    except Exception as ex:
48
 
        e = ElementTree.Element('testsuite')
49
 
        tree = ElementTree.ElementTree(e)
50
 
        e.attrib['errors'] = '1'
51
 
        e.attrib['failures'] = '0'
52
 
        e.attrib['tests'] = '1'
53
 
 
54
 
        # make a guess at the classname:
55
 
        classname = os.path.basename(os.path.dirname(apfile))
56
 
 
57
 
        t = ElementTree.Element('testcase')
58
 
        e.append(t)
59
 
        t.attrib['classname'] = classname
60
 
        t.attrib['name'] = 'phablet-test-run'
61
 
 
62
 
        f = ElementTree.Element('failure')
63
 
        t.append(f)
64
 
        f.attrib['type'] = 'testtools.testresult.real._StringException'
65
 
        f.text = str(ex)
66
 
 
67
 
    return tree
68
 
 
69
 
 
70
 
def _get_classname(results):
71
 
    if len(results) < 1:
72
 
        return '???'
73
 
 
74
 
    cname = results[0].attrib.get('classname')
75
 
    if cname:
76
 
        cname = cname.split('.')[0]
77
 
    else:
78
 
        cname = '???'
79
 
    return cname
80
 
 
81
 
 
82
 
def combine(resdir):
83
 
    ap_file = os.path.join(resdir, 'test_results.xml')
84
 
    tree = _get_results(ap_file)
85
 
    ap_results = tree.getroot()
86
 
    added_results = 0
87
 
 
88
 
    errors = int(ap_results.attrib['errors'])
89
 
 
90
 
    classname = _get_classname(ap_results)
91
 
 
92
 
    for basename, label in PRE_COMBINE:
93
 
        rc = os.path.join(resdir, basename + '.rc')
94
 
        log = os.path.join(resdir, basename + '.log')
95
 
        node, failed = _build_node(classname, label, rc, log)
96
 
        if node is not None:
97
 
            ap_results.insert(0, node)
98
 
            if failed:
99
 
                errors += 1
100
 
            added_results += 1
101
 
 
102
 
    for basename, label in POST_COMBINE:
103
 
        rc = os.path.join(resdir, basename + '.rc')
104
 
        log = os.path.join(resdir, basename + '.log')
105
 
        node, failed = _build_node(classname, label, rc, log)
106
 
        if node is not None:
107
 
            ap_results.append(node)
108
 
            if failed:
109
 
                errors += 1
110
 
            added_results += 1
111
 
 
112
 
    num = int(ap_results.attrib['tests']) + added_results
113
 
    ap_results.attrib['tests'] = str(num)
114
 
    ap_results.attrib['errors'] = str(errors)
115
 
 
116
 
    tree.write(ap_file)
117
 
 
118
 
 
119
 
if __name__ == '__main__':
120
 
    if len(sys.argv) != 2:
121
 
        print('usage: {} <results directory>'.format(sys.argv[0]))
122
 
        sys.exit(1)
123
 
 
124
 
    combine(sys.argv[1])