Browse Source

Put the runtime checks behind a DPF_RUNTIME_TESTING macro

Signed-off-by: falkTX <falktx@falktx.com>
pull/330/head
falkTX 4 years ago
parent
commit
71b4e5d1c5
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
3 changed files with 47 additions and 19 deletions
  1. +7
    -1
      Makefile.plugins.mk
  2. +28
    -0
      distrho/DistrhoInfo.hpp
  3. +12
    -18
      distrho/src/DistrhoPluginInternal.hpp

+ 7
- 1
Makefile.plugins.mk View File

@@ -33,7 +33,6 @@ endif


BUILD_C_FLAGS += -I. BUILD_C_FLAGS += -I.
BUILD_CXX_FLAGS += -I. -I$(DPF_PATH)/distrho -I$(DPF_PATH)/dgl BUILD_CXX_FLAGS += -I. -I$(DPF_PATH)/distrho -I$(DPF_PATH)/dgl
BUILD_CXX_FLAGS += -Wno-pmf-conversions


ifeq ($(HAVE_ALSA),true) ifeq ($(HAVE_ALSA),true)
BASE_FLAGS += -DHAVE_ALSA BASE_FLAGS += -DHAVE_ALSA
@@ -224,6 +223,13 @@ endif
# TODO split dsp and ui object build flags # TODO split dsp and ui object build flags
BASE_FLAGS += $(DGL_FLAGS) BASE_FLAGS += $(DGL_FLAGS)


# ---------------------------------------------------------------------------------------------------------------------
# Runtime test build

ifeq ($(DPF_RUNTIME_TESTING),true)
BUILD_CXX_FLAGS += -DDPF_RUNTIME_TESTING -Wno-pmf-conversions
endif

# --------------------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------------------
# all needs to be first # all needs to be first




+ 28
- 0
distrho/DistrhoInfo.hpp View File

@@ -615,6 +615,34 @@ START_NAMESPACE_DISTRHO


/** @} */ /** @} */


/* ------------------------------------------------------------------------------------------------------------
* Plugin Macros */

/**
@defgroup ExtraPluginMacros Extra Plugin Macros

C Macros to customize DPF behaviour.

These are macros that do not set plugin features or information, but instead change DPF internals.@n
They are all optional, none are enabled by default.

All values are a simple define, their value is meaningless (and unused).
@{
*/

/**
Whether to enable runtime plugin tests.@n
This will check, during initialization of the plugin, if parameters, programs and states are setup properly.@n
Useful to enable as part of CI, can safely be skipped.@n
Under DPF makefiles can be enabled by using `make DPF_RUNTIME_TESTING=true`.

@note Some checks are only available with the GCC compiler,
for detecting if a virtual function has been reimplemented.
*/
#define DPF_RUNTIME_TESTING

/** @} */

// ----------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------


END_NAMESPACE_DISTRHO END_NAMESPACE_DISTRHO


+ 12
- 18
distrho/src/DistrhoPluginInternal.hpp View File

@@ -247,30 +247,26 @@ public:
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,); DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr,); DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr,);


/* Verify that virtual functions are overriden if parameters, programs or states are in use.
#if defined(DPF_RUNTIME_TESTING) && defined(__GNUC__) && !defined(__clang__)
/* Run-time testing build.
* Verify that virtual functions are overriden if parameters, programs or states are in use.
* This does not work on all compilers, but we use it purely as informational check anyway. */ * This does not work on all compilers, but we use it purely as informational check anyway. */
#if defined(__GNUC__) && !defined(__clang__)
# ifdef DPF_ABORT_ON_ERROR
# define DPF_ABORT abort();
# else
# define DPF_ABORT
# endif
if (fData->parameterCount != 0) if (fData->parameterCount != 0)
{ {
if ((void*)(fPlugin->*(&Plugin::initParameter)) == (void*)&Plugin::initParameter) if ((void*)(fPlugin->*(&Plugin::initParameter)) == (void*)&Plugin::initParameter)
{ {
d_stderr2("DPF warning: Plugins with parameters must implement `initParameter`"); d_stderr2("DPF warning: Plugins with parameters must implement `initParameter`");
DPF_ABORT
abort();
} }
if ((void*)(fPlugin->*(&Plugin::getParameterValue)) == (void*)&Plugin::getParameterValue) if ((void*)(fPlugin->*(&Plugin::getParameterValue)) == (void*)&Plugin::getParameterValue)
{ {
d_stderr2("DPF warning: Plugins with parameters must implement `getParameterValue`"); d_stderr2("DPF warning: Plugins with parameters must implement `getParameterValue`");
DPF_ABORT
abort();
} }
if ((void*)(fPlugin->*(&Plugin::setParameterValue)) == (void*)&Plugin::setParameterValue) if ((void*)(fPlugin->*(&Plugin::setParameterValue)) == (void*)&Plugin::setParameterValue)
{ {
d_stderr2("DPF warning: Plugins with parameters must implement `setParameterValue`"); d_stderr2("DPF warning: Plugins with parameters must implement `setParameterValue`");
DPF_ABORT
abort();
} }
} }


@@ -280,12 +276,12 @@ public:
if ((void*)(fPlugin->*(&Plugin::initProgramName)) == (void*)&Plugin::initProgramName) if ((void*)(fPlugin->*(&Plugin::initProgramName)) == (void*)&Plugin::initProgramName)
{ {
d_stderr2("DPF warning: Plugins with programs must implement `initProgramName`"); d_stderr2("DPF warning: Plugins with programs must implement `initProgramName`");
DPF_ABORT
abort();
} }
if ((void*)(fPlugin->*(&Plugin::loadProgram)) == (void*)&Plugin::loadProgram) if ((void*)(fPlugin->*(&Plugin::loadProgram)) == (void*)&Plugin::loadProgram)
{ {
d_stderr2("DPF warning: Plugins with programs must implement `loadProgram`"); d_stderr2("DPF warning: Plugins with programs must implement `loadProgram`");
DPF_ABORT
abort();
} }
} }
# endif # endif
@@ -296,13 +292,13 @@ public:
if ((void*)(fPlugin->*(&Plugin::initState)) == (void*)&Plugin::initState) if ((void*)(fPlugin->*(&Plugin::initState)) == (void*)&Plugin::initState)
{ {
d_stderr2("DPF warning: Plugins with state must implement `initState`"); d_stderr2("DPF warning: Plugins with state must implement `initState`");
DPF_ABORT
abort();
} }


if ((void*)(fPlugin->*(&Plugin::setState)) == (void*)&Plugin::setState) if ((void*)(fPlugin->*(&Plugin::setState)) == (void*)&Plugin::setState)
{ {
d_stderr2("DPF warning: Plugins with state must implement `setState`"); d_stderr2("DPF warning: Plugins with state must implement `setState`");
DPF_ABORT
abort();
} }
} }
# endif # endif
@@ -313,17 +309,15 @@ public:
if ((void*)(fPlugin->*(&Plugin::getState)) == (void*)&Plugin::getState) if ((void*)(fPlugin->*(&Plugin::getState)) == (void*)&Plugin::getState)
{ {
d_stderr2("DPF warning: Plugins with full state must implement `getState`"); d_stderr2("DPF warning: Plugins with full state must implement `getState`");
DPF_ABORT
abort();
} }
} }
else else
{ {
d_stderr2("DPF warning: Plugins with full state must have at least 1 state"); d_stderr2("DPF warning: Plugins with full state must have at least 1 state");
DPF_ABORT
abort();
} }
# endif # endif

# undef DPF_ABORT
#endif #endif


#if DISTRHO_PLUGIN_NUM_INPUTS+DISTRHO_PLUGIN_NUM_OUTPUTS > 0 #if DISTRHO_PLUGIN_NUM_INPUTS+DISTRHO_PLUGIN_NUM_OUTPUTS > 0


Loading…
Cancel
Save