Ejemplo n.º 1
0
 def __get_statistics(self):
     try:
         res = ArchiveFileContent(self.coverage_obj, 'archive',
                                  COVERAGE_FILE)
     except Exception as e:
         raise BridgeException(
             _("Error while extracting source file: %(error)s") %
             {'error': str(e)})
     data = json.loads(res.content.decode('utf8'))
     if data.get('format') != ETV_FORMAT:
         raise BridgeException(_('Code coverage format is not supported'))
     if 'coverage statistics' not in data:
         raise BridgeException(
             _('Common code coverage file does not contain statistics'))
     return data['coverage statistics'], data['data statistics']
Ejemplo n.º 2
0
    def collect(self):
        try:
            res = ArchiveFileContent(self.coverage, 'archive', COVERAGE_FILE)
        except Exception as e:
            raise BridgeException(
                _("Error while extracting source file: %(error)s") %
                {'error': str(e)})
        data = json.loads(res.content.decode('utf8'))

        for filename in data['coverage statistics']:
            if data['coverage statistics'][filename][0] > 0:
                self.__parse_file(filename)
        print("Max covered:", self._max_covered)
        statistics = {}
        for filename in self._statistics:
            for line_num, cov_num in self._statistics[filename]:
                statistics['{}:{}'.format(filename, line_num)] = cov_num
        return list(sorted(statistics, key=lambda x: (-statistics[x], x)))[:30]
Ejemplo n.º 3
0
    def get_context_data(self, **kwargs):
        if not JobAccess(self.request.user, self.object.decision.job).can_view:
            raise BridgeException(code=400)
        try:
            etv = GetETV(
                ArchiveFileContent(self.object, 'error_trace',
                                   ERROR_TRACE_FILE).content.decode('utf8'),
                self.request.user)
        except Exception as e:
            logger.exception(e)
            etv = None
        context = super().get_context_data(**kwargs)
        if self.object.decision.weight == DECISION_WEIGHT[0][0]:
            context['parents'] = get_parents(self.object)
        context['verifier_files_url'] = leaf_verifier_files_url(self.object)
        context.update({
            'include_jquery_ui':
            True,
            'report':
            self.object,
            'etv':
            etv,
            'SelfAttrsData':
            self.object.attrs.order_by('id').values_list(
                'id', 'name', 'value', 'data'),
            'MarkTable':
            UnsafeReportMarksTable(self.request.user, self.object,
                                   self.get_view(VIEW_TYPES[10])),
            'resources':
            report_resources(self.request.user, self.object)
        })

        # Get parent coverage if exists and parent is verification report
        cov_obj = CoverageArchive.objects.filter(
            report_id=self.object.parent_id,
            report__verification=True).first()
        if cov_obj:
            context['coverage'] = LeafCoverageStatistics(cov_obj)

        return context
Ejemplo n.º 4
0
    def __connect(self):
        self.report.markreport_set.all().delete()
        unknown_attrs = set(
            a_id for a_id, in self.report.attrs.values_list('attr_id'))

        try:
            problem_desc = ArchiveFileContent(self.report, 'problem_description', PROBLEM_DESC_FILE)\
                .content.decode('utf8')
        except Exception as e:
            logger.exception("Can't get problem desc for unknown '%s': %s" %
                             (self.report.id, e))
            return
        new_markreports = []
        problems = {}
        for mark in MarkUnknown.objects.filter(
                component=self.report.component):
            if mark.id in self._marks_attrs and not self._marks_attrs[
                    mark.id].issubset(unknown_attrs):
                continue

            problem = MatchUnknown(problem_desc, mark.function,
                                   mark.problem_pattern,
                                   mark.is_regexp).problem
            if problem is None:
                continue
            elif len(problem) > 20:
                problem = 'Too long!'
                logger.error("Generated problem '%s' for mark %s is too long" %
                             (problem, mark.identifier),
                             stack_info=True)
            if problem not in problems:
                problems[problem] = UnknownProblem.objects.get_or_create(
                    name=problem)[0]
            new_markreports.append(
                MarkUnknownReport(mark=mark,
                                  report=self.report,
                                  problem=problems[problem]))
        MarkUnknownReport.objects.bulk_create(new_markreports)
        if self._update_cache:
            update_unknowns_cache([self.report])
Ejemplo n.º 5
0
    def get_context_data(self, **kwargs):
        if not JobAccess(self.request.user, self.object.root.job).can_view():
            raise BridgeException(code=400)

        return {
            'report':
            self.object,
            'report_type':
            'unknown',
            'parents':
            reports.utils.get_parents(self.object),
            'resources':
            reports.utils.get_leaf_resources(self.request.user, self.object),
            'SelfAttrsData':
            reports.utils.report_attibutes(self.object),
            'main_content':
            ArchiveFileContent(self.object, 'problem_description',
                               PROBLEM_DESC_FILE).content.decode('utf8'),
            'MarkTable':
            ReportMarkTable(self.request.user, self.object,
                            self.get_view(VIEW_TYPES[12]))
        }
Ejemplo n.º 6
0
 def __get_coverage_data(self):
     try:
         res = ArchiveFileContent(self._coverage,
                                  'archive',
                                  self._file_name,
                                  not_exists_ok=True)
     except Exception as e:
         raise BridgeException(
             _("Error while extracting source file: %(error)s") %
             {'error': str(e)})
     if res.content is None:
         return None
     data = json.loads(res.content.decode('utf8'))
     if data.get('format') != ETV_FORMAT:
         raise BridgeException(_('Code coverage format is not supported'))
     if not data.get('data'):
         return None
     if not data['data'].get(self._line):
         return None
     return list({
         'name': data['name'],
         'value': json_to_html(data['value'])
     } for data in data['data'][self._line])
Ejemplo n.º 7
0
def etv_callstack(unsafe_id=None, file_name='test.txt'):
    if unsafe_id:
        unsafe = ReportUnsafe.objects.get(id=unsafe_id)
    else:
        unsafe = ReportUnsafe.objects.all().first()
    content = ArchiveFileContent(unsafe, 'error_trace',
                                 ERROR_TRACE_FILE).content.decode('utf8')
    data = json.loads(content)
    trace = ''
    double_returns = set()
    ind = 0
    for x in data['edges']:
        if 'enter' in x:
            if 'action' in x:
                trace += '%s%s(%s)[action_%s] {\n' % (' ' * ind, data['funcs'][
                    x['enter']], x['enter'], x['action'])
            else:
                trace += '%s%s(%s) {\n' % (
                    ' ' * ind, data['funcs'][x['enter']], x['enter'])
            ind += 2
            if 'return' in x:
                double_returns.add(x['enter'])
        elif 'return' in x:
            ind -= 2
            if 'action' in x:
                trace += '%s}(%s)[action_%s]\n' % (' ' * ind, x['return'],
                                                   x['action'])
            else:
                trace += '%s}(%s)\n' % (' ' * ind, x['return'])
            if x['return'] in double_returns:
                ind -= 2
                trace += '%s}(DOUBLE)\n' % (' ' * ind)
                double_returns.remove(x['return'])
        elif 'action' in x:
            trace += '%sACTION(%s)\n' % (' ' * ind, x['action'])
    with open(file_name, mode='w', encoding='utf8') as fp:
        fp.write(trace)
Ejemplo n.º 8
0
 def __get_error_trace(self):
     try:
         return ArchiveFileContent(self.unsafe, 'error_trace', ERROR_TRACE_FILE).content.decode('utf8')
     except Exception as e:
         logger.exception(e, stack_info=True)
         raise BridgeException("Can't exctract error trace for unsafe '%s' from archive" % self.unsafe.pk)
Ejemplo n.º 9
0
 def __init__(self, report):
     content = ArchiveFileContent(report, 'error_trace', ERROR_TRACE_FILE).content
     self.name = 'error trace.json'
     self.size = len(content)
     super().__init__(BytesIO(content), 8192)
Ejemplo n.º 10
0
 def get_generator(self):
     self.object = self.get_object()
     content = ArchiveFileContent(self.object, 'error_trace',
                                  ERROR_TRACE_FILE).content
     self.file_size = len(content)
     return FileWrapper(BytesIO(content), 8192)