diff --git a/.travis.yml b/.travis.yml index 95e89bc9ae..f1535ba8e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -132,3 +132,4 @@ script: after_script: - if [ -f run/tshark ]; then run/tshark --version; fi - if [ -f run/RelWithDebInfo/tshark.exe ]; then run/RelWithDebInfo/tshark.exe --version; fi + - ../test/travis-upload-artifacts.sh 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 +# 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 < $output <