From 4e299d45f2552e2c98ffb4a34d499a1f41047a66 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 12 Aug 2017 18:03:45 +0200 Subject: [PATCH] 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. --- .gitignore | 3 ++- src/klayout.pri | 12 ++++++++++++ src/plugins/plugin.pri | 10 ++++++++++ src/plugins/plugin_ut.pri | 10 ++++++++++ src/plugins/plugins.pro | 2 ++ src/ut/utMain.cc | 39 ++++++++++++++++++++++++++++++++++++++- 6 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/plugins/plugin.pri create mode 100644 src/plugins/plugin_ut.pri diff --git a/.gitignore b/.gitignore index 49510d19a..f0a1a1901 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/src/klayout.pri b/src/klayout.pri index cfea85574..614911986 100644 --- a/src/klayout.pri +++ b/src/klayout.pri @@ -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) diff --git a/src/plugins/plugin.pri b/src/plugins/plugin.pri new file mode 100644 index 000000000..1d1002062 --- /dev/null +++ b/src/plugins/plugin.pri @@ -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 diff --git a/src/plugins/plugin_ut.pri b/src/plugins/plugin_ut.pri new file mode 100644 index 000000000..8be38ed3a --- /dev/null +++ b/src/plugins/plugin_ut.pri @@ -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 diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 0bb766b23..5089832df 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -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 diff --git a/src/ut/utMain.cc b/src/ut/utMain.cc index d2e350abb..99abb31e5 100644 --- a/src/ut/utMain.cc +++ b/src/ut/utMain.cc @@ -44,10 +44,11 @@ #include #include + #if !defined(_WIN32) # include +# include #endif - #if defined(_WIN32) # include #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 ());