Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings: Support LIBOPENSHOT_DEBUG envvar #667

Merged
merged 3 commits into from
May 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
9 changes: 6 additions & 3 deletions src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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;
Expand Down
14 changes: 1 addition & 13 deletions src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;

Expand Down
17 changes: 17 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
13 changes: 11 additions & 2 deletions tests/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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);
}