aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2019-01-22 23:15:55 +0100
committerPeter Wu <peter@lekensteyn.nl>2019-01-24 00:26:22 +0000
commitcbb5b78a7d9be756b9a3da27a7eccb119c0a6948 (patch)
treee910bebdc694fda7658a7de25beb9a109d9551de /test
parent8c698ffc99375e67809fb376d5090fcc2d535048 (diff)
test,travis: dump a screenshot for hanging GUI tests
For some reason the wireshark GUI tests hang on the Travis OS X builds, but I could not reproduce it locally. It turns out than an error dialog was present, but I could not know that without the screenshot. Change-Id: Idf897d33b4fddf3c19c69ebcea60b629f1ca9368 Reviewed-on: https://code.wireshark.org/review/31682 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'test')
-rw-r--r--test/fixtures_ws.py32
-rw-r--r--test/suite_capture.py20
-rwxr-xr-xtest/travis-upload-artifacts.sh34
3 files changed, 78 insertions, 8 deletions
diff --git a/test/fixtures_ws.py b/test/fixtures_ws.py
index 5b5d9b8061..a7d633ac35 100644
--- a/test/fixtures_ws.py
+++ b/test/fixtures_ws.py
@@ -8,6 +8,7 @@
#
'''Fixtures that are specific to Wireshark.'''
+from contextlib import contextmanager
import os
import re
import subprocess
@@ -302,3 +303,34 @@ def unicode_env(home_path, make_env):
env=env,
pluginsdir=pluginsdir
)
+
+
+@fixtures.fixture(scope='session')
+def make_screenshot():
+ '''Creates a screenshot and save it to a file. Intended for CI purposes.'''
+ def make_screenshot_real(filename):
+ try:
+ if sys.platform == 'darwin':
+ subprocess.check_call(['screencapture', filename])
+ else:
+ print("Creating a screenshot on this platform is not supported")
+ return
+ size = os.path.getsize(filename)
+ print("Created screenshot %s (%d bytes)" % (filename, size))
+ except (subprocess.CalledProcessError, OSError) as e:
+ print("Failed to take screenshot:", e)
+ return make_screenshot_real
+
+
+@fixtures.fixture
+def make_screenshot_on_error(request, make_screenshot):
+ '''Writes a screenshot when a process times out.'''
+ @contextmanager
+ def make_screenshot_on_error_real():
+ try:
+ yield
+ except subprocess.TimeoutExpired:
+ filename = request.instance.filename_from_id('screenshot.png')
+ make_screenshot(filename)
+ raise
+ return make_screenshot_on_error_real
diff --git a/test/suite_capture.py b/test/suite_capture.py
index 2522530668..eb0448ec47 100644
--- a/test/suite_capture.py
+++ b/test/suite_capture.py
@@ -471,26 +471,30 @@ def check_dumpcap_pcapng_sections(cmd_dumpcap, cmd_tshark, capture_file):
@fixtures.mark_usefixtures('test_env')
@fixtures.uses_fixtures
class case_wireshark_capture(subprocesstest.SubprocessTestCase):
- def test_wireshark_capture_10_packets_to_file(self, wireshark_k, check_capture_10_packets):
+ def test_wireshark_capture_10_packets_to_file(self, wireshark_k, check_capture_10_packets, make_screenshot_on_error):
'''Capture 10 packets from the network to a file using Wireshark'''
- check_capture_10_packets(self, cmd=wireshark_k)
+ with make_screenshot_on_error():
+ check_capture_10_packets(self, cmd=wireshark_k)
# Wireshark doesn't currently support writing to stdout while capturing.
# def test_wireshark_capture_10_packets_to_stdout(self, wireshark_k, check_capture_10_packets):
# '''Capture 10 packets from the network to stdout using Wireshark'''
# check_capture_10_packets(self, cmd=wireshark_k, to_stdout=True)
- def test_wireshark_capture_from_fifo(self, wireshark_k, check_capture_fifo):
+ def test_wireshark_capture_from_fifo(self, wireshark_k, check_capture_fifo, make_screenshot_on_error):
'''Capture from a fifo using Wireshark'''
- check_capture_fifo(self, cmd=wireshark_k)
+ with make_screenshot_on_error():
+ check_capture_fifo(self, cmd=wireshark_k)
- def test_wireshark_capture_from_stdin(self, wireshark_k, check_capture_stdin):
+ def test_wireshark_capture_from_stdin(self, wireshark_k, check_capture_stdin, make_screenshot_on_error):
'''Capture from stdin using Wireshark'''
- check_capture_stdin(self, cmd=wireshark_k)
+ with make_screenshot_on_error():
+ check_capture_stdin(self, cmd=wireshark_k)
- def test_wireshark_capture_snapshot_len(self, wireshark_k, check_capture_snapshot_len):
+ def test_wireshark_capture_snapshot_len(self, wireshark_k, check_capture_snapshot_len, make_screenshot_on_error):
'''Capture truncated packets using Wireshark'''
- check_capture_snapshot_len(self, cmd=wireshark_k)
+ with make_screenshot_on_error():
+ check_capture_snapshot_len(self, cmd=wireshark_k)
@fixtures.mark_usefixtures('test_env')
diff --git a/test/travis-upload-artifacts.sh b/test/travis-upload-artifacts.sh
new file mode 100755
index 0000000000..6f96b118a8
--- /dev/null
+++ b/test/travis-upload-artifacts.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+# Publishes artifacts from a Travis CI build.
+#
+# Copyright (C) 2019 Peter Wu <peter@lekensteyn.nl>
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Currently it dumps a base64-encoded xz-compressed tarball as Travis CI
+# does not have a nice way to publish artifacts (like Gitlab does).
+#
+
+shopt -s nullglob
+files=(*screenshot.png)
+
+if [ ${#files[@]} -eq 0 ]; then
+ echo "No artifacts found"
+ exit
+fi
+
+output=travis.tar.xz
+tar -cJvf "$output" "${files[@]}"
+
+# Print some details for an integrity check.
+ls -l "$output"
+openssl dgst -sha256 "$output"
+
+# Upload to other services just in case the log output is corrupted.
+curl -F 'f:1=<-' ix.io < "$output"
+
+# Dump the contents to the log (note: Travis has a 4MiB limit)
+cat <<EOF
+base64 -d > $output <<ARTIFACTS_BASE64
+$(base64 < "$output" | tr -d '\n' | fold -w200)
+ARTIFACTS_BASE64
+EOF