Provisions for self-contained plugin tests

Plugin tests are not placed into a "*.klp_ut" shared object
and are executed by the unit test runner.
This commit is contained in:
Matthias Koefferlein 2017-08-12 18:03:45 +02:00
parent eea686a5b9
commit 4e299d45f2
6 changed files with 74 additions and 2 deletions

3
.gitignore vendored
View File

@ -36,7 +36,8 @@ mkqtdecl.tmp
# private data
private
src/plugins/*
!src/plugins/plugins.pro
!src/plugins/*.pro
!src/plugins/*.pri
# QTCreator files
src/klayout.pro.user

View File

@ -53,3 +53,15 @@ win32 {
} else {
QMAKE_CXXFLAGS += -fvisibility=hidden
}
# define our own shared object extension since QMAKE_EXTENSION_SHLIB is blank on
# Linux
win32 {
SHLIB_EXT = dll
SHLIB_PREFIX =
} else {
SHLIB_EXT = so
SHLIB_PREFIX = lib
}
export(SHLIB_EXT)
export(SHLIB_PREFIX)

10
src/plugins/plugin.pri Normal file
View File

@ -0,0 +1,10 @@
DESTDIR_KLP = $$OUT_PWD/../../..
TEMPLATE = lib
INCLUDEPATH += ../../../db ../../../tl ../../../gsi ../../../laybasic ../../../lay ../../../common
DEPENDPATH += ../../../db ../../../tl ../../../gsi ../../../laybasic ../../../lay ../../../common
LIBS += -L$$DESTDIR_KLP -lklayout_db -lklayout_tl -lklayout_gsi -lklayout_laybasic -lklayout_lay
QMAKE_POST_LINK += $(COPY) $$OUT_PWD/$${SHLIB_PREFIX}$${TARGET}.$${SHLIB_EXT} $$DESTDIR_KLP/$${TARGET}.klp

10
src/plugins/plugin_ut.pri Normal file
View File

@ -0,0 +1,10 @@
DESTDIR_KLP = $$OUT_PWD/../../..
TEMPLATE = lib
INCLUDEPATH += ../src ../../../db ../../../tl ../../../gsi ../../../laybasic ../../../lay ../../../common ../../../ut
DEPENDPATH += ../src ../../../db ../../../tl ../../../gsi ../../../laybasic ../../../lay ../../../common ../../../ut
LIBS += -L$$DESTDIR_KLP -lklayout_db -lklayout_tl -lklayout_gsi -lklayout_laybasic -lklayout_lay -lklayout_ut
QMAKE_POST_LINK += $(COPY) $$OUT_PWD/$${SHLIB_PREFIX}$${TARGET}.$${SHLIB_EXT} $$DESTDIR_KLP/$${TARGET}.klp_ut

View File

@ -3,5 +3,7 @@ TEMPLATE = subdirs
# Automatically include all sub-folders, but not the .pro file
SUBDIR_LIST = $$files($$PWD/*)
SUBDIR_LIST -= $$PWD/plugins.pro
SUBDIR_LIST -= $$PWD/plugin.pri
SUBDIR_LIST -= $$PWD/plugin_ut.pri
SUBDIRS = $$SUBDIR_LIST

View File

@ -44,10 +44,11 @@
#include <cstdio>
#include <unistd.h>
#if !defined(_WIN32)
# include <sys/ioctl.h>
# include <dlfcn.h>
#endif
#if defined(_WIN32)
# include <Windows.h>
#endif
@ -799,6 +800,42 @@ main_cont (int argc, char **argv)
pya::PythonInterpreter::initialize ();
gsi::initialize_external ();
// Search and initialize plugin unit tests
QStringList name_filters;
name_filters << QString::fromUtf8 ("*.klp_ut");
QDir inst_dir (tl::to_qstring (tl::get_inst_path ()));
QStringList inst_modules = inst_dir.entryList (name_filters);
inst_modules.sort ();
for (QStringList::const_iterator im = inst_modules.begin (); im != inst_modules.end (); ++im) {
QFileInfo klp_file (inst_dir.path (), *im);
if (klp_file.exists () && klp_file.isReadable ()) {
std::string pp = tl::to_string (klp_file.absoluteFilePath ());
tl::log << "Loading plugin unit tests " << pp;
// NOTE: since we are using a different suffix ("*.klp_ut"), we can't use QLibrary.
#ifdef _WIN32
// there is no "dlopen" on mingw, so we need to emulate it.
HINSTANCE handle = LoadLibraryW ((const wchar_t *) tl::to_qstring (pp).constData ());
if (! handle) {
throw tl::Exception (tl::to_string (QObject::tr ("Unable to load plugin tests: %s with error message: %s ")), pp, GetLastError ());
}
#else
void *handle;
handle = dlopen (tl::string_to_system (pp).c_str (), RTLD_LAZY);
if (! handle) {
throw tl::Exception (tl::to_string (QObject::tr ("Unable to load plugin tests: %s")), pp);
}
#endif
}
}
// No side effects
tl::set_klayout_path (std::vector<std::string> ());