From d7bbe384f51b99b03694db811f48cf5a098ad65c Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Thu, 13 Feb 2020 15:18:14 -0800 Subject: [PATCH] Test+Qt: Add an automatic update check. Add software_update_info() to the software update module, which returns the name of our update library if we have one. Use it to add automatic update information to the compiled information in `wireshark --version`. Add a "release" test suite, which contains a test for automatic updates. Ping-Bug: 16381 Change-Id: I867a96bdcfde8be541eca2dc0e84b5000276e7dd Reviewed-on: https://code.wireshark.org/review/36107 Reviewed-by: Gerald Combs Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- CMakeLists.txt | 1 + test/suite_release.py | 47 +++++++++++++++++++++++++++++++++++++++++++ test/test.py | 2 ++ ui/qt/main.cpp | 11 +++++++++- ui/software_update.c | 13 +++++++++++- ui/software_update.h | 6 ++++++ 6 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 test/suite_release.py diff --git a/CMakeLists.txt b/CMakeLists.txt index bd736ff6c1..331ce349f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3338,6 +3338,7 @@ set(_test_group_list suite_mergecap suite_nameres suite_outputformats + suite_release suite_text2pcap suite_sharkd suite_unittests diff --git a/test/suite_release.py b/test/suite_release.py new file mode 100644 index 0000000000..8775f1f982 --- /dev/null +++ b/test/suite_release.py @@ -0,0 +1,47 @@ +# +# -*- coding: utf-8 -*- +# Wireshark tests +# +# Copyright (c) 2019 Gerald Combs +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +'''Release tests''' + +import fixtures +import re +import subprocess +import subprocesstest +import types + +@fixtures.fixture +def wireshark_features(request, cmd_wireshark, make_env): + ''' + Returns an object describing available features in Wireshark. Tests + will be skipped unless --enable-release is passed on the command line. + ''' + enabled = request.config.getoption('--enable-release', default=False) + if not enabled: + fixtures.skip('Release tests are not enabled via --enable-release') + + try: + wireshark_v = subprocess.check_output( + (cmd_wireshark, '--version'), + stderr=subprocess.PIPE, + universal_newlines=True, + env=make_env() + ) + wireshark_v = re.sub(r'\s+', ' ', wireshark_v) + except subprocess.CalledProcessError as ex: + print('Failed to detect Wireshark features: %s' % (ex,)) + wireshark_v = '' + return types.SimpleNamespace( + have_automatic_updates='with automatic updates' in wireshark_v, + ) + +@fixtures.uses_fixtures +class case_release_automatic_updates(subprocesstest.SubprocessTestCase): + def test_automatic_updates_present(self, wireshark_features): + '''Checks whether Wireshark was built with automatic updates.''' + + self.assertTrue(wireshark_features.have_automatic_updates); diff --git a/test/test.py b/test/test.py index df3e9337aa..fa6a543057 100755 --- a/test/test.py +++ b/test/test.py @@ -54,6 +54,8 @@ def main(): parser = argparse.ArgumentParser(description='Wireshark unit tests') cap_group = parser.add_mutually_exclusive_group() cap_group.add_argument('-E', '--disable-capture', action='store_true', help='Disable capture tests') + release_group = parser.add_mutually_exclusive_group() + release_group.add_argument('--enable-release', action='store_true', help='Enable release tests') parser.add_argument('-p', '--program-path', default=os.path.curdir, help='Path to Wireshark executables.') parser.add_argument('--skip-missing-programs', help='Skip tests that lack programs from this list instead of failing' diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp index 96f26191dd..abb3a728e4 100644 --- a/ui/qt/main.cpp +++ b/ui/qt/main.cpp @@ -79,6 +79,7 @@ #include "ui/commandline.h" #include "ui/capture_ui_utils.h" #include "ui/preference_utils.h" +#include "ui/software_update.h" #include "ui/taps.h" #include "ui/qt/conversation_dialog.h" @@ -137,8 +138,8 @@ # INFO = 64 # DEBUG = 128 -*/ #define DEBUG_STARTUP_TIME_LOGLEVEL 252 +*/ /* update the main window */ void main_window_update(void) @@ -226,6 +227,14 @@ get_gui_compiled_info(GString *str) g_string_append(str, "without QtMultimedia"); #endif + g_string_append(str, ", "); + const char *update_info = software_update_info(); + if (update_info) { + g_string_append_printf(str, "with automatic updates using %s", update_info); + } else { + g_string_append_printf(str, "without automatic updates"); + } + #ifdef _WIN32 g_string_append(str, ", "); #ifdef HAVE_AIRPCAP diff --git a/ui/software_update.c b/ui/software_update.c index 44217ea4aa..0f8f8b4507 100644 --- a/ui/software_update.c +++ b/ui/software_update.c @@ -123,6 +123,10 @@ extern void software_update_cleanup(void) { win_sparkle_cleanup(); } +const char *software_update_info(void) { + return "WinSparkle " WIN_SPARKLE_VERSION_STRING; +} + #elif defined (__APPLE__) /** Initialize software updates. */ @@ -146,6 +150,10 @@ software_update_check(void) { */ void software_update_cleanup(void) { } + +const char *software_update_info(void) { + return "Sparkle"; +} #endif #else /* No updates */ @@ -167,6 +175,10 @@ software_update_check(void) { void software_update_cleanup(void) { } +const char *software_update_info(void) { + return NULL; +} + #endif /* defined(HAVE_SOFTWARE_UPDATE) && defined (_WIN32) */ /* @@ -181,4 +193,3 @@ void software_update_cleanup(void) { * ex: set shiftwidth=4 tabstop=8 expandtab: * :indentSize=4:tabSize=8:noTabs=true: */ - diff --git a/ui/software_update.h b/ui/software_update.h index b764c5b5b4..a5a72b3939 100644 --- a/ui/software_update.h +++ b/ui/software_update.h @@ -41,6 +41,12 @@ extern void software_update_check(void); */ extern void software_update_cleanup(void); +/** Fetch a description of the software update mechanism. + * + * @return NULL, "Sparkle", or "WinSparkle". + */ +extern const char *software_update_info(void); + #ifdef _WIN32 /** Check to see if Wireshark can shut down safely (e.g. offer to save the * current capture). Called from a separate thread.