summaryrefslogtreecommitdiff
path: root/framework/summary/feature.py
blob: cd903c2ee2982133409810e012e802a7222fd61d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Copyright (c) 2015-2016 Intel Corporation

# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# This permission notice shall be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHOR(S) BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from __future__ import (
    absolute_import, division, print_function, unicode_literals
)

try:
    import simplejson as json
except ImportError:
    import json

from framework import options, exceptions, profile, status


class FeatResults(object):  # pylint: disable=too-few-public-methods
    """Container object for results.

    Has the results, feature profiles and feature computed results.

    """
    def __init__(self, results, json_file):

        with open(json_file) as data:
            feature_data = json.load(data)

        self.feat_fractions = {}
        self.feat_status = {}
        self.features = set()
        self.results = results

        profiles = {}

        # we expect all the result sets to be for the same profile
        profile_orig = profile.load_test_profile(results[0].options['profile'][0])

        for feature in feature_data:
            self.features.add(feature)

            incl_str = feature_data[feature]["include_tests"]
            excl_str = feature_data[feature]["exclude_tests"]

            include_filter = [incl_str] if incl_str and not incl_str.isspace() else []
            exclude_filter = [excl_str] if excl_str and not excl_str.isspace() else []

            options.OPTIONS.exclude_filter = exclude_filter
            options.OPTIONS.include_filter = include_filter

            profiles[feature] = profile.TestProfile()
            profiles[feature].update(profile_orig)

            # An empty list will raise PiglitFatalError exception
            # But for reporting we need to handle this situation
            try:
                profiles[feature]._prepare_test_list()
            except exceptions.PiglitFatalError:
                pass

        for results in self.results:
            self.feat_fractions[results.name] = {}
            self.feat_status[results.name] = {}

            for feature in feature_data:
                result_set = set(results.tests)
                profile_set = set(profiles[feature].test_list)

                common_set = profile_set & result_set
                passed_list = [x for x in common_set if results.tests[x].result == status.PASS]

                total = len(common_set)
                passed = len(passed_list)

                self.feat_fractions[results.name][feature] = (passed, total)
                if total == 0:
                    self.feat_status[results.name][feature] = status.NOTRUN
                else:
                    if 100 * passed // total >= feature_data[feature]["target_rate"]:
                        self.feat_status[results.name][feature] = status.PASS
                    else:
                        self.feat_status[results.name][feature] = status.FAIL