From 37f5e4dfbf398cf70a83855c7252c03b236b7dc6 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Tue, 27 Apr 2021 16:19:31 -0400 Subject: [PATCH 1/3] Settings: Support LIBOPENSHOT_DEBUG envvar - Setting LIBOPENSHOT_DEBUG to any value in the process environment activates debug logging to stderr. --- src/Settings.cpp | 9 ++++++--- src/Settings.h | 14 +------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/Settings.cpp b/src/Settings.cpp index cfbe2e2c..688eaae3 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -28,14 +28,14 @@ * along with OpenShot Library. If not, see . */ +#include // For std::getenv + #include "Settings.h" -using namespace std; using namespace openshot; - // Global reference to Settings -Settings *Settings::m_pInstance = NULL; +Settings *Settings::m_pInstance = nullptr; // Create or Get an instance of the settings singleton Settings *Settings::Instance() @@ -53,6 +53,9 @@ Settings *Settings::Instance() m_pInstance->HW_EN_DEVICE_SET = 0; m_pInstance->PLAYBACK_AUDIO_DEVICE_NAME = ""; m_pInstance->DEBUG_TO_STDERR = false; + auto env_debug = std::getenv("LIBOPENSHOT_DEBUG"); + if (env_debug != nullptr) + m_pInstance->DEBUG_TO_STDERR = true; } return m_pInstance; diff --git a/src/Settings.h b/src/Settings.h index 36ba2917..e21822a0 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -31,19 +31,7 @@ #ifndef OPENSHOT_SETTINGS_H #define OPENSHOT_SETTINGS_H - -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include - namespace openshot { @@ -118,7 +106,7 @@ namespace openshot { /// The current install path of OpenShot (needs to be set when using Timeline(path), since certain /// paths depend on the location of OpenShot transitions and files) std::string PATH_OPENSHOT_INSTALL = ""; - + /// Whether to dump ZeroMQ debug messages to stderr bool DEBUG_TO_STDERR = false; From 266455c6a2fdf48abcff9c643309de4c2809bc7d Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Fri, 14 May 2021 21:56:18 -0400 Subject: [PATCH 2/3] Settings: Unit test LIBOPENSHOT_DEBUG envvar --- tests/CMakeLists.txt | 17 +++++++++++++++++ tests/Settings.cpp | 13 +++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6c5c6d51..f519856b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,6 +24,11 @@ # along with OpenShot Library. If not, see . ################################################################################ +# Allow spaces in test names +if(POLICY CMP0110) + cmake_policy(SET CMP0110 NEW) +endif() + # Test media path, used by unit tests for input data file(TO_NATIVE_PATH "${PROJECT_SOURCE_DIR}/examples/" TEST_MEDIA_PATH) @@ -103,6 +108,18 @@ foreach(tname ${OPENSHOT_TESTS}) list(APPEND CATCH2_TEST_TARGETS openshot-${tname}-test) list(APPEND CATCH2_TEST_NAMES ${tname}) endforeach() +# Add an additional special-case test, for an envvar-dependent setting +add_test(NAME [=["Settings:Debug logging (enabled)"]=] + COMMAND + openshot-Settings-test "[environment]" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) +set_tests_properties([=["Settings:Debug logging (enabled)"]=] + PROPERTIES + LABELS Settings + ENVIRONMENT "LIBOPENSHOT_DEBUG=1" +) + # Export target list for coverage use set(UNIT_TEST_TARGETS ${CATCH2_TEST_TARGETS} PARENT_SCOPE) set(UNIT_TEST_NAMES ${CATCH2_TEST_NAMES} PARENT_SCOPE) diff --git a/tests/Settings.cpp b/tests/Settings.cpp index e974ffd4..13239819 100644 --- a/tests/Settings.cpp +++ b/tests/Settings.cpp @@ -34,7 +34,7 @@ using namespace openshot; -TEST_CASE( "Default_Constructor", "[libopenshot][settings]" ) +TEST_CASE( "Constructor", "[libopenshot][settings]" ) { // Create an empty color Settings *s = Settings::Instance(); @@ -43,7 +43,7 @@ TEST_CASE( "Default_Constructor", "[libopenshot][settings]" ) CHECK_FALSE(s->HIGH_QUALITY_SCALING); } -TEST_CASE( "Change_Settings", "[libopenshot][settings]" ) +TEST_CASE( "Change settings", "[libopenshot][settings]" ) { // Create an empty color Settings *s = Settings::Instance(); @@ -56,3 +56,12 @@ TEST_CASE( "Change_Settings", "[libopenshot][settings]" ) CHECK(Settings::Instance()->OMP_THREADS == 8); CHECK(Settings::Instance()->HIGH_QUALITY_SCALING == true); } + +TEST_CASE( "Debug logging", "[libopenshot][settings][environment]") +{ + // Check the environment + auto envvar = std::getenv("LIBOPENSHOT_DEBUG"); + const auto is_enabled = bool(envvar != nullptr); + + CHECK(Settings::Instance()->DEBUG_TO_STDERR == is_enabled); +} From 97c25300a6242a18d22f537c4555788439be3b1d Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Fri, 14 May 2021 22:49:51 -0400 Subject: [PATCH 3/3] CMake: VERBOSE_TESTS option (default off) --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d191757a..3ca96ed9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,7 @@ option(DISABLE_BUNDLED_JSONCPP "Don't fall back to bundled JsonCpp" OFF) option(ENABLE_IWYU "Enable 'Include What You Use' scanner (CMake 3.3+)" OFF) option(ENABLE_PARALLEL_CTEST "Run CTest using multiple processors" ON) +option(VERBOSE_TESTS "Run CTest with maximum verbosity" OFF) option(ENABLE_COVERAGE "Scan test coverage using gcov and report" OFF) option(ENABLE_DOCS "Build API documentation (requires Doxygen)" ON) @@ -187,9 +188,12 @@ if(BUILD_TESTING) ProcessorCount(CPU_COUNT) if(CPU_COUNT GREATER 1) add_feature_info("Parallel tests" TRUE "Unit tests can use ${CPU_COUNT} processors") - set(CTEST_OPTIONS "-j${CPU_COUNT}") + list(APPEND CTEST_OPTIONS "-j${CPU_COUNT}") endif() endif() + if(VERBOSE_TESTS) + list(APPEND CTEST_OPTIONS "-VV") + endif() add_subdirectory(tests) endif() add_feature_info("Unit tests" ${BUILD_TESTING} "Compile unit tests for library functions")