~le-chi-thu/lava-test/add-verbose-argument

« back to all changes in this revision

Viewing changes to lava_test/test_definitions/insanity.py

  • Committer: Paul Larson
  • Date: 2011-10-14 20:29:26 UTC
  • mfrom: (100.1.1 insanity)
  • Revision ID: paul.larson@canonical.com-20111014202926-ew4lk0wv9xrr3jn5
Merge Insanity multimedia tests from Collabora

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2010 Linaro
 
2
#
 
3
# This program is free software: you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation, either version 3 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
#
 
16
 
 
17
import os
 
18
import re
 
19
import subprocess
 
20
import simplejson
 
21
import gzip
 
22
import base64
 
23
 
 
24
from lava_test.core.installers import TestInstaller
 
25
from lava_test.core.parsers import TestParser
 
26
from lava_test.core.runners import TestRunner
 
27
from lava_test.core.tests import Test
 
28
 
 
29
 
 
30
MAX_TEST_CASE_ID_LEN = 100
 
31
MAX_ATTR_KEY_LEN = 32
 
32
MAX_ATTR_VAL_LEN = 512
 
33
 
 
34
MAX_ATTACHMENT_SIZE = 10 * 1024 * 1024
 
35
 
 
36
SETTINGS = "/usr/share/insanity/web/settings.py"
 
37
 
 
38
# Re-running failing tests is expensive, as it produces very large log files.
 
39
# Only remove --no-reruns if you have a small number of failing tests.
 
40
RUNSTEPS = ["rm -f testrun.db",
 
41
        "gst-media-test --no-reruns -t playbin-test --settings %s" % SETTINGS,
 
42
        "gst-media-test --no-reruns -t full-gnlfilesource-scenario " \
 
43
            "--settings %s" % SETTINGS,
 
44
        "gst-media-test --no-reruns -t simple-encoder-scenario",
 
45
        "echo ////////////////////",
 
46
        "insanity-dumpresults-json testrun.db --all",
 
47
    ]
 
48
 
 
49
class InsanityParser(TestParser):
 
50
    def parse(self, artifacts):
 
51
        filename = "testoutput.log"
 
52
        with open(filename, 'r') as stream:
 
53
            while not stream.readline().startswith("//////////"):
 
54
                pass
 
55
            results = simplejson.load(stream)
 
56
 
 
57
        self._results = results
 
58
        self.fixresults({"pass": "pass", "fail": "fail",
 
59
                "skip": "skip", "expected-failure": "pass"})
 
60
        self.fixlengths()
 
61
        self.attach_logfiles()
 
62
 
 
63
 
 
64
    def fixlengths(self):
 
65
        for t in self.results['test_results']:
 
66
            if t.has_key("test_case_id"):
 
67
                if len(t["test_case_id"]) > MAX_TEST_CASE_ID_LEN:
 
68
                    t["test_case_id"] = \
 
69
                            t["test_case_id"][-MAX_TEST_CASE_ID_LEN:]
 
70
            if t.has_key("attributes"):
 
71
                attributes = t["attributes"]
 
72
                for k, v in attributes.items():
 
73
                    if len(k) > MAX_ATTR_KEY_LEN:
 
74
                        attributes.pop(k)
 
75
                        # start includes namespace info
 
76
                        k = k[:MAX_ATTR_KEY_LEN]
 
77
                        attributes[k] = v
 
78
                    if len(v) > MAX_ATTR_VAL_LEN:
 
79
                        # end tends to be more useful than the start.
 
80
                        attributes[k] = v[-MAX_ATTR_VAL_LEN:]
 
81
 
 
82
 
 
83
    def attach_logfiles(self):
 
84
        attachments = []
 
85
        mime_type = "text/plain"
 
86
        total_attachment_size = 0
 
87
 
 
88
        for test in self.results["test_results"]:
 
89
            pathname = test.get("log_filename", "")
 
90
            if not pathname:
 
91
                continue
 
92
            if not os.path.exists(pathname):
 
93
                print "%r not found: skipping." % pathname
 
94
                continue
 
95
 
 
96
            if pathname.endswith(".gz"):
 
97
                stream = gzip.open(pathname, 'rb')
 
98
            else:
 
99
                stream = open(pathname)
 
100
 
 
101
            output_text = stream.read()
 
102
            stream.close()
 
103
 
 
104
            total_attachment_size += len(output_text)
 
105
            if total_attachment_size > MAX_ATTACHMENT_SIZE:
 
106
                break
 
107
 
 
108
            attachments.append({
 
109
                    "pathname": pathname,
 
110
                    "mime_type": mime_type,
 
111
                    "content":  base64.standard_b64encode(output_text)
 
112
                })
 
113
 
 
114
        self.results.setdefault("attachments", []).extend(attachments)
 
115
 
 
116
    def fixresults(self, fixupdict):
 
117
        """Convert results to a known, standard format
 
118
 
 
119
        pass it a dict of keys/values to replace
 
120
        For instance:
 
121
            {"TPASS":"pass", "TFAIL":"fail"}
 
122
        This is really only used for qualitative tests
 
123
        """
 
124
        for t in self.results['test_results']:
 
125
            if t.has_key("result"):
 
126
                t['result'] = fixupdict[t['result']]
 
127
 
 
128
inst = TestInstaller(deps=["insanity-tools",
 
129
        "samplemedia-minimal",
 
130
        "gstreamer0.10-plugins-base", # videotestsrc et al
 
131
        "gstreamer0.10-plugins-good", # matroskademux et al
 
132
        "gstreamer0.10-plugins-bad", #
 
133
        "gstreamer0.10-plugins-ugly", # asfdemux et al
 
134
        "gstreamer0.10-ffmpeg", # ffdec_h264 et al
 
135
        "gstreamer0.10-gnonlin", # gnlfilesource
 
136
        "gdb", # debugging backtraces
 
137
        ])
 
138
run = TestRunner(RUNSTEPS)
 
139
parse = InsanityParser("")
 
140
 
 
141
testobj = Test(test_id="insanity", installer=inst, runner=run, parser=parse)