forked from osmocom/wireshark
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>
This commit is contained in:
parent
8c698ffc99
commit
cbb5b78a7d
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue