Merge pull request #667 from ferdnyc/debug-envvar

Settings: Support LIBOPENSHOT_DEBUG envvar
This commit is contained in:
Frank Dana
2021-05-15 07:37:17 -04:00
committed by GitHub
5 changed files with 40 additions and 19 deletions

View File

@@ -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")

View File

@@ -28,14 +28,14 @@
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cstdlib> // 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;

View File

@@ -31,19 +31,7 @@
#ifndef OPENSHOT_SETTINGS_H
#define OPENSHOT_SETTINGS_H
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <string>
#include <sstream>
#include <cstdio>
#include <ctime>
#include <zmq.hpp>
#include <unistd.h>
#include <OpenShotAudio.h>
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;

View File

@@ -24,6 +24,11 @@
# along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
################################################################################
# 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)

View File

@@ -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);
}