summaryrefslogtreecommitdiff
path: root/tests/auto/blackbox
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2022-02-19 17:07:41 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2022-02-21 11:49:36 +0000
commit5a7aac60df8000bd4c5ed255f69eaf4b9d5b92db (patch)
tree319c41d0a90e659f2d2d3afb0b473a254b579c65 /tests/auto/blackbox
parentdb584fbfc491b5bb065913699d604f68ef58673e (diff)
downloadqbs-5a7aac60df8000bd4c5ed255f69eaf4b9d5b92db.tar.gz
baremetal: Add simple test for linking with shared libraries
As we use the baremetal tests for non-baremetal compilers (for example, for `watcom` and `dmc`), then we need a test for linking the application and the shared library. We cannot use the existing tests for `watcom` and `dmc` toolchains, because these toolchains have specific behavior and also do not fully support the STL. Therefore, the simplest dependency linking test is used here. Also fixed the shared library creation for these toolchains. Change-Id: I0e5d5ede39fa0c9b4bf7db54adc3f161e0aea91c Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'tests/auto/blackbox')
-rw-r--r--tests/auto/blackbox/testdata-baremetal/shared-libraries/app.c12
-rw-r--r--tests/auto/blackbox/testdata-baremetal/shared-libraries/shared-libraries.qbs34
-rw-r--r--tests/auto/blackbox/testdata-baremetal/shared-libraries/shared.c19
-rw-r--r--tests/auto/blackbox/tst_blackboxbaremetal.cpp14
-rw-r--r--tests/auto/blackbox/tst_blackboxbaremetal.h2
5 files changed, 81 insertions, 0 deletions
diff --git a/tests/auto/blackbox/testdata-baremetal/shared-libraries/app.c b/tests/auto/blackbox/testdata-baremetal/shared-libraries/app.c
new file mode 100644
index 000000000..f2ecb5f55
--- /dev/null
+++ b/tests/auto/blackbox/testdata-baremetal/shared-libraries/app.c
@@ -0,0 +1,12 @@
+#include "../dllexport.h"
+
+#include <stdio.h>
+
+DLL_IMPORT void foo(void);
+
+int main(void)
+{
+ printf("Hello from app\n");
+ foo();
+ return 0;
+}
diff --git a/tests/auto/blackbox/testdata-baremetal/shared-libraries/shared-libraries.qbs b/tests/auto/blackbox/testdata-baremetal/shared-libraries/shared-libraries.qbs
new file mode 100644
index 000000000..f55b4d400
--- /dev/null
+++ b/tests/auto/blackbox/testdata-baremetal/shared-libraries/shared-libraries.qbs
@@ -0,0 +1,34 @@
+import "../BareMetalApplication.qbs" as BareMetalApplication
+
+Project {
+ condition: {
+ if (qbs.targetPlatform === "windows" && qbs.architecture === "x86") {
+ if (qbs.toolchainType === "watcom")
+ return true;
+ if (qbs.toolchainType === "dmc")
+ return true;
+ }
+
+ if (qbs.toolchainType === "msvc")
+ return true;
+ if (qbs.toolchainType === "gcc")
+ return true;
+
+ console.info("unsupported toolset: %%"
+ + qbs.toolchainType + "%%, %%" + qbs.architecture + "%%");
+ return false;
+ }
+
+ DynamicLibrary {
+ Depends { name: "cpp" }
+ destinationDirectory: "bin"
+ name: "shared"
+ files: ["shared.c"]
+ }
+ BareMetalApplication {
+ Depends { name: "shared" }
+ destinationDirectory: "bin"
+ name: "app"
+ files: ["app.c"]
+ }
+}
diff --git a/tests/auto/blackbox/testdata-baremetal/shared-libraries/shared.c b/tests/auto/blackbox/testdata-baremetal/shared-libraries/shared.c
new file mode 100644
index 000000000..ab0c110fb
--- /dev/null
+++ b/tests/auto/blackbox/testdata-baremetal/shared-libraries/shared.c
@@ -0,0 +1,19 @@
+#include "../dllexport.h"
+
+#include <stdio.h>
+
+#ifdef __DMC__
+#include <windows.h>
+#define EXPORT_FUN _export
+BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
+{
+ return TRUE;
+}
+#else
+#define EXPORT_FUN
+#endif // __DMC__
+
+DLL_EXPORT void EXPORT_FUN foo(void)
+{
+ printf("Hello from lib\n");
+}
diff --git a/tests/auto/blackbox/tst_blackboxbaremetal.cpp b/tests/auto/blackbox/tst_blackboxbaremetal.cpp
index fda544b8b..740b9c463 100644
--- a/tests/auto/blackbox/tst_blackboxbaremetal.cpp
+++ b/tests/auto/blackbox/tst_blackboxbaremetal.cpp
@@ -139,6 +139,20 @@ void TestBlackboxBareMetal::externalStaticLibraries()
QCOMPARE(runQbs(), 0);
}
+void TestBlackboxBareMetal::sharedLibraries()
+{
+ QDir::setCurrent(testDataDir + "/shared-libraries");
+ QCOMPARE(runQbs(QbsRunParameters("resolve", QStringList("-n"))), 0);
+ if (m_qbsStdout.contains("unsupported toolset:"))
+ QSKIP(unsupportedToolsetMessage(m_qbsStdout));
+ QCOMPARE(runQbs(QbsRunParameters("build")), 0);
+ if (m_qbsStdout.contains("targetPlatform differs from hostPlatform"))
+ QSKIP("Cannot run binaries in cross-compiled build");
+ QCOMPARE(runQbs(QbsRunParameters("run")), 0);
+ QVERIFY2(m_qbsStdout.contains("Hello from app"), m_qbsStdout.constData());
+ QVERIFY2(m_qbsStdout.contains("Hello from lib"), m_qbsStdout.constData());
+}
+
void TestBlackboxBareMetal::userIncludePaths()
{
QDir::setCurrent(testDataDir + "/user-include-paths");
diff --git a/tests/auto/blackbox/tst_blackboxbaremetal.h b/tests/auto/blackbox/tst_blackboxbaremetal.h
index 39d2f36c9..8e9e29e8b 100644
--- a/tests/auto/blackbox/tst_blackboxbaremetal.h
+++ b/tests/auto/blackbox/tst_blackboxbaremetal.h
@@ -49,6 +49,8 @@ private slots:
void staticLibraryDependencies();
void externalStaticLibraries();
+ void sharedLibraries();
+
void userIncludePaths();
void systemIncludePaths();
void distributionIncludePaths();