~ubuntu-branches/ubuntu/oneiric/checkbox/oneiric-updates

« back to all changes in this revision

Viewing changes to scripts/phoronix_filter

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug, Marc Tardif
  • Date: 2010-03-09 16:58:36 UTC
  • Revision ID: james.westby@ubuntu.com-20100309165836-26f22oe6ubppzx0d
Tags: 0.9
[ Marc Tardif ]
New upstream release (LP: #532882):
* Introduced job_prompt plugin to treat all jobs (suites, tests, etc.) as composites.
* Replaced the registry and resource scripts and centralized job iteration.
* Replaced dependency on dbus by using sudo/gksu/kdesudo instead.
* Replaced mktemp with mkdtemp for security purposes.
* Fixed strings in fingerprint and modem tests (LP: #457759)
* Fixed client side validation of Launchpad form (LP: #438671)
* Added device information to tags when reporting bugs with apport.
* Added shorthands for blacklist-file and whitelist-file.
* Added support for apport default configuration (LP: #465447)
* Added support for scrolled options list (LP: #411526)
* Added support for tests generated by suites to run as root.
* Added support for requirements in attachments.
* Added support for armv7l processor
* Added Autotest integration
* Added LTP integration
* Added Phoronix integration
* Added qa-regression-testing integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import os
 
4
import sys
 
5
 
 
6
import logging
 
7
import pexpect
 
8
import posixpath
 
9
 
 
10
from logging import StreamHandler, FileHandler, Formatter
 
11
 
 
12
from optparse import OptionParser
 
13
 
 
14
from xml.dom import minidom
 
15
 
 
16
 
 
17
DEFAULT_DIRECTORY = "/var/cache/checkbox/phoronix"
 
18
DEFAULT_LOG_LEVEL = "critical"
 
19
DEFAULT_SAVE_NAME = "checkbox"
 
20
DEFAULT_TIMEOUT = 900
 
21
 
 
22
UNIQUE_NAME_CHARACTERS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
23
 
 
24
 
 
25
def unique_name(length=15):
 
26
    l = len(UNIQUE_NAME_CHARACTERS)
 
27
    return "".join([UNIQUE_NAME_CHARACTERS[ord(c)%l] for c in os.urandom(length)])
 
28
 
 
29
def get_benchmark(node, name):
 
30
    for benchmark in node.getElementsByTagName("Benchmark"):
 
31
        for child in benchmark.childNodes:
 
32
            if child.nodeName == "TestName" \
 
33
               and child.firstChild.data == name:
 
34
                return benchmark
 
35
 
 
36
    return None
 
37
 
 
38
def get_result(node, name):
 
39
    for entry in node.getElementsByTagName("Entry"):
 
40
        for child in entry.childNodes:
 
41
            if child.nodeName == "Identifier" \
 
42
               and child.firstChild.data == name:
 
43
                return entry
 
44
 
 
45
    return None
 
46
 
 
47
def parse_phoronix(options, suite):
 
48
    file = posixpath.expanduser("~/.phoronix-test-suite/test-results/%s/composite.xml"
 
49
        % options.save_name)
 
50
    tree = minidom.parse(file)
 
51
    benchmark = get_benchmark(tree, suite)
 
52
    if benchmark:
 
53
        result = get_result(benchmark, options.run_name)
 
54
        if result:
 
55
            value = result.getElementsByTagName("Value")[0]
 
56
            return value.firstChild.data
 
57
 
 
58
    return None
 
59
 
 
60
def run_phoronix(options, suite):
 
61
    question_answer = [
 
62
        ("Enter a name to save these results: ", options.save_name),
 
63
        ("Enter a unique name for this test run: ", options.run_name)]
 
64
 
 
65
    command = posixpath.join(options.directory, "phoronix-test-suite")
 
66
    args = ["batch-benchmark", suite]
 
67
    connection = pexpect.spawn(command, args=args,
 
68
        cwd=options.directory,
 
69
        timeout=options.timeout)
 
70
    if logging.getLogger().getEffectiveLevel() == logging.DEBUG:
 
71
        # Backward compatibility for pexpect
 
72
        if hasattr(connection, "logfile"):
 
73
            connection.logfile = sys.stdout
 
74
        else:
 
75
            connection.setlog(sys.stdout)
 
76
 
 
77
    while True:
 
78
        questions = [qa[0] for qa in question_answer]
 
79
        index = connection.expect_exact(questions + [pexpect.EOF])
 
80
        if index >= len(question_answer):
 
81
            break
 
82
 
 
83
        answer = question_answer[index][1]
 
84
        if answer is None:
 
85
            answer = unique_name()
 
86
 
 
87
        connection.send("%s\n" % answer)
 
88
 
 
89
    return parse_phoronix(options, suite)
 
90
 
 
91
def main(args):
 
92
    usage = "Usage: %prog [OPTIONS] SUITE"
 
93
    parser = OptionParser(usage=usage)
 
94
    parser.add_option("-l", "--log", metavar="FILE",
 
95
        help="log file where to send output")
 
96
    parser.add_option("--log-level",
 
97
        default=DEFAULT_LOG_LEVEL,
 
98
        help="one of debug, info, warning, error or critical")
 
99
    parser.add_option("-d", "--directory",
 
100
        default=DEFAULT_DIRECTORY,
 
101
        help="Directory where phoronix was cloned (default %default)")
 
102
    parser.add_option("-r", "--run-name",
 
103
        default=unique_name(),
 
104
        help="Unique name for this test run (default is random)")
 
105
    parser.add_option("-s", "--save-name",
 
106
        default=DEFAULT_SAVE_NAME,
 
107
        help="Name to save these results (default %default)")
 
108
    parser.add_option("-t", "--timeout",
 
109
        default=DEFAULT_TIMEOUT,
 
110
        help="Timeout to run the tests (default %default)")
 
111
    (options, args) = parser.parse_args(args)
 
112
 
 
113
    # Set logging early
 
114
    log_level = logging.getLevelName(options.log_level.upper())
 
115
    log_handlers = []
 
116
    log_handlers.append(StreamHandler())
 
117
    if options.log:
 
118
        log_filename = options.log
 
119
        log_handlers.append(FileHandler(log_filename))
 
120
 
 
121
    format = ("%(asctime)s %(levelname)-8s %(message)s")
 
122
    if log_handlers:
 
123
        for handler in log_handlers:
 
124
            handler.setFormatter(Formatter(format))
 
125
            logging.getLogger().addHandler(handler)
 
126
        if log_level:
 
127
            logging.getLogger().setLevel(log_level)
 
128
    elif not logging.getLogger().handlers:
 
129
        logging.disable(logging.CRITICAL)
 
130
 
 
131
    # Parse args
 
132
    if not args:
 
133
        parser.error("Must specify a SUITE")
 
134
    elif len(args) > 1:
 
135
        parser.error("Must specify a single SUITE")
 
136
 
 
137
    suite = args[0]
 
138
    value = run_phoronix(options, suite)
 
139
    if value is None:
 
140
        return 1
 
141
 
 
142
    print value
 
143
 
 
144
    return 0
 
145
 
 
146
 
 
147
if __name__ == "__main__":
 
148
    sys.exit(main(sys.argv[1:]))