Commit a1adef06 authored by Ben Joyce's avatar Ben Joyce Committed by Commit Bot

Add summary html to test results.

Bug: 1096591
Change-Id: I085c379c4189b3ed71943edeffa53aa4bf1cb10a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2385818Reviewed-by: default avatarPeter Wen <wnwen@chromium.org>
Reviewed-by: default avatarNodir Turakulov <nodir@chromium.org>
Reviewed-by: default avatarChan Li <chanli@chromium.org>
Commit-Queue: benjamin joyce <bjoyce@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803956}
parent 87a1499e
# Copyright 2020 The Chromium Authors. All rights reserved. # Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import base64
import cgi
import json import json
import os import os
from pylib.base import base_test_result from pylib.base import base_test_result
import requests # pylint: disable=import-error import requests # pylint: disable=import-error
# Comes from luci/resultdb/pbutil/test_result.go
# Slightly smaller to allow prepending <pre></pres>
MAX_REPORT_LEN = 4 * 1024
# Maps base_test_results to the luci test-result.proto. # Maps base_test_results to the luci test-result.proto.
# https://godoc.org/go.chromium.org/luci/resultdb/proto/v1#TestStatus # https://godoc.org/go.chromium.org/luci/resultdb/proto/v1#TestStatus
RESULT_MAP = { RESULT_MAP = {
...@@ -42,7 +48,6 @@ class ResultSinkClient(object): ...@@ -42,7 +48,6 @@ class ResultSinkClient(object):
This assumes that the rdb stream has been called already and that the This assumes that the rdb stream has been called already and that the
server is listening. server is listening.
""" """
def __init__(self, context): def __init__(self, context):
self.url = ('http://%s/prpc/luci.resultsink.v1.Sink/ReportTestResults' % self.url = ('http://%s/prpc/luci.resultsink.v1.Sink/ReportTestResults' %
context['address']) context['address'])
...@@ -52,7 +57,7 @@ class ResultSinkClient(object): ...@@ -52,7 +57,7 @@ class ResultSinkClient(object):
'Authorization': 'ResultSink %s' % context['auth_token'], 'Authorization': 'ResultSink %s' % context['auth_token'],
} }
def Post(self, test_id, status): def Post(self, test_id, status, test_log):
"""Uploads the test result to the ResultSink server. """Uploads the test result to the ResultSink server.
This assumes that the rdb stream has been called already and that This assumes that the rdb stream has been called already and that
...@@ -61,6 +66,7 @@ class ResultSinkClient(object): ...@@ -61,6 +66,7 @@ class ResultSinkClient(object):
Args: Args:
test_id: A string representing the test's name. test_id: A string representing the test's name.
status: A string representing if the test passed, failed, etc... status: A string representing if the test passed, failed, etc...
test_log: A string representing the test's output.
Returns: Returns:
N/A N/A
...@@ -69,11 +75,25 @@ class ResultSinkClient(object): ...@@ -69,11 +75,25 @@ class ResultSinkClient(object):
expected = status in (base_test_result.ResultType.PASS, expected = status in (base_test_result.ResultType.PASS,
base_test_result.ResultType.SKIP) base_test_result.ResultType.SKIP)
status = RESULT_MAP[status] status = RESULT_MAP[status]
# Slightly smaller to allow addition of <pre> tags and message.
report_check_size = MAX_REPORT_LEN - 45
test_log_formatted = cgi.escape(test_log)
if len(test_log) > report_check_size:
test_log_formatted = ('<pre>' + test_log[:report_check_size] +
'...Full output in Artifact.</pre>')
else:
test_log_formatted = '<pre>' + test_log + '</pre>'
tr = { tr = {
'testId': test_id,
'status': status,
'expected': expected, 'expected': expected,
'status': status,
'summaryHtml': test_log_formatted,
'testId': test_id,
} }
if len(test_log) > report_check_size:
tr['artifacts'] = {'Test Log': {'contents': base64.b64encode(test_log)}}
requests.post(url=self.url, requests.post(url=self.url,
headers=self.headers, headers=self.headers,
data=json.dumps({'testResults': [tr]})) data=json.dumps({'testResults': [tr]}))
...@@ -915,7 +915,7 @@ def RunTestsInPlatformMode(args, result_sink_client=None): ...@@ -915,7 +915,7 @@ def RunTestsInPlatformMode(args, result_sink_client=None):
iteration_count += 1 iteration_count += 1
for r in iteration_results.GetAll(): for r in iteration_results.GetAll():
if result_sink_client: if result_sink_client:
result_sink_client.Post(r.GetName(), r.GetType()) result_sink_client.Post(r.GetName(), r.GetType(), r.GetLog())
result_counts[r.GetName()][r.GetType()] += 1 result_counts[r.GetName()][r.GetType()] += 1
report_results.LogFull( report_results.LogFull(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment