summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@qt.io>2024-02-21 04:46:48 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-02-22 09:41:04 +0000
commit910527a8a0d473b6573314ff4e224600b74d1ebf (patch)
tree6542ab423497553e70a5fd4ba74d2fe601560851
parent60cb52f8379bee6d172f9e2784fd06f4c4f49e83 (diff)
tests: add a test for Architecture detection
The test binaries are compressed because you cannot make them as small as possible. Especially macOS enforces the minimum size to be the page size (16KB). The README.md has all the details on how to generate and compress test binaries. Change-Id: I8636772f2f94ac35e8d4fa51b6b76b0c84ad3d7b Reviewed-by: Bernd Weimer <bernd.weimer@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> (cherry picked from commit 6ea1e4d528e6ab6ced1674f2d9fe50489d8f2e0c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--.gitattributes1
-rw-r--r--tests/auto/CMakeLists.txt2
-rw-r--r--tests/auto/architecture/CMakeLists.txt10
-rw-r--r--tests/auto/architecture/tst_architecture.cpp69
-rw-r--r--tests/auto/utilities/CMakeLists.txt16
-rw-r--r--tests/auto/utilities/tst_utilities.cpp29
-rw-r--r--tests/data/CMakeLists.txt1
-rw-r--r--tests/data/binaries/README.md52
-rw-r--r--tests/data/binaries/android-elf.so.zzbin0 -> 2040 bytes
-rw-r--r--tests/data/binaries/macos-macho.zzbin0 -> 696 bytes
-rw-r--r--tests/data/binaries/macos-universal.zzbin0 -> 1262 bytes
-rw-r--r--tests/data/binaries/windows-pe.exe.zzbin0 -> 619 bytes
12 files changed, 134 insertions, 46 deletions
diff --git a/.gitattributes b/.gitattributes
index 98e17a15..723cab5b 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -6,6 +6,7 @@
*.crt binary
*.bin binary
+*.zz binary
.tag export-subst
.gitignore export-ignore
diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt
index f4b5442a..c507b4b5 100644
--- a/tests/auto/CMakeLists.txt
+++ b/tests/auto/CMakeLists.txt
@@ -22,7 +22,7 @@ if (NOT ANDROID)
endif()
add_subdirectory(runtime)
add_subdirectory(signature)
-add_subdirectory(utilities)
+add_subdirectory(architecture)
add_subdirectory(yaml)
if (LINUX)
diff --git a/tests/auto/architecture/CMakeLists.txt b/tests/auto/architecture/CMakeLists.txt
new file mode 100644
index 00000000..92eea7a6
--- /dev/null
+++ b/tests/auto/architecture/CMakeLists.txt
@@ -0,0 +1,10 @@
+
+qt_internal_add_test(tst_architecture
+ SOURCES
+ ../error-checking.h
+ tst_architecture.cpp
+ DEFINES
+ AM_TESTDATA_DIR="${CMAKE_CURRENT_BINARY_DIR}/../../data/"
+ LIBRARIES
+ Qt::AppManCommonPrivate
+)
diff --git a/tests/auto/architecture/tst_architecture.cpp b/tests/auto/architecture/tst_architecture.cpp
new file mode 100644
index 00000000..db8d4055
--- /dev/null
+++ b/tests/auto/architecture/tst_architecture.cpp
@@ -0,0 +1,69 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#include <QtCore>
+#include <QtTest>
+#include <QtEndian>
+#include <QString>
+
+#include "architecture.h"
+
+QT_USE_NAMESPACE_AM
+using namespace Qt::StringLiterals;
+
+class tst_Architecture : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_Architecture() = default;
+
+private slots:
+ void initTestCase();
+ void architecture_data();
+ void architecture();
+};
+
+
+void tst_Architecture::initTestCase()
+{
+ if (!QDir(QString::fromLatin1(AM_TESTDATA_DIR "/binaries")).exists())
+ QSKIP("No test binaries available in the data/ directory");
+}
+
+void tst_Architecture::architecture_data()
+{
+ QTest::addColumn<QString>("path");
+ QTest::addColumn<QString>("archId");
+
+ QTest::newRow("android-elf") << "android-elf.so.zz" << "android_arm_32";
+ QTest::newRow("windows-pe") << "windows-pe.exe.zz" << "windows_x86_64";
+ QTest::newRow("macos-macho") << "macos-macho.zz" << "macos_arm_64";
+ QTest::newRow("macos-universal") << "macos-universal.zz" << "macos_universal_arm_64+x86_64";
+}
+
+void tst_Architecture::architecture()
+{
+ QFETCH(QString, path);
+ QFETCH(QString, archId);
+
+ QString fullPath = QString::fromLatin1(AM_TESTDATA_DIR) + u"/binaries/"_s + path;
+ QFile src(fullPath);
+ QVERIFY(src.open(QIODevice::ReadOnly));
+ auto content = src.readAll();
+ quint32 contentLen = content.size();
+ QVERIFY(contentLen > 0);
+ content = qUncompress(content);
+ QVERIFY(content.size() > 0);
+ QTemporaryFile dst;
+ QVERIFY(dst.open());
+ QVERIFY(dst.write(content) == content.size());
+ dst.close();
+ QString id = Architecture::identify(dst.fileName());
+
+ QCOMPARE(id, archId);
+}
+
+QTEST_APPLESS_MAIN(tst_Architecture)
+
+#include "tst_architecture.moc"
diff --git a/tests/auto/utilities/CMakeLists.txt b/tests/auto/utilities/CMakeLists.txt
deleted file mode 100644
index 7e202ebe..00000000
--- a/tests/auto/utilities/CMakeLists.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-
-qt_internal_add_test(tst_utilities
- SOURCES
- ../error-checking.h
- tst_utilities.cpp
- DEFINES
- AM_TESTDATA_DIR="${CMAKE_CURRENT_BINARY_DIR}/../../data/"
- LIBRARIES
- Qt::Network
- Qt::AppManCommonPrivate
-)
-
-qt_internal_extend_target(tst_utilities CONDITION TARGET Qt::DBus
- LIBRARIES
- Qt::DBus
-)
diff --git a/tests/auto/utilities/tst_utilities.cpp b/tests/auto/utilities/tst_utilities.cpp
deleted file mode 100644
index 3c9b05e4..00000000
--- a/tests/auto/utilities/tst_utilities.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// Copyright (C) 2019 Luxoft Sweden AB
-// Copyright (C) 2018 Pelagicore AG
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#include <QtCore>
-#include <QtTest>
-
-#include "utilities.h"
-
-QT_USE_NAMESPACE_AM
-
-class tst_Utilities : public QObject
-{
- Q_OBJECT
-
-public:
- tst_Utilities();
-
-private slots:
-};
-
-
-tst_Utilities::tst_Utilities()
-{ }
-
-QTEST_APPLESS_MAIN(tst_Utilities)
-
-#include "tst_utilities.moc"
diff --git a/tests/data/CMakeLists.txt b/tests/data/CMakeLists.txt
index b057bce2..101fe3cd 100644
--- a/tests/data/CMakeLists.txt
+++ b/tests/data/CMakeLists.txt
@@ -17,6 +17,7 @@ file(GLOB_RECURSE TEST_DATA_FILES
info.yaml
testfile
utilities.sh
+ binaries/*.zz
)
add_custom_target(Test-Data-Files SOURCES
diff --git a/tests/data/binaries/README.md b/tests/data/binaries/README.md
new file mode 100644
index 00000000..199c55c7
--- /dev/null
+++ b/tests/data/binaries/README.md
@@ -0,0 +1,52 @@
+## Generation
+
+Here's how to (re)generate the test binaries in this directory:
+
+- `android-elf.so`:
+
+ This is a copy of `Qt/6.7.0/android_armv7/lib/libQt6QuickParticles_armeabi-v7a.so`
+
+- `windows-pe.exe`:
+
+ This is a minimal C program, compiled with cmake + MSVC:
+ - `main.c`:
+ ```
+ int __stdcall WinMainCRTStartup() { return 0; }
+ ```
+
+ - `CMakeLists.txt`:
+ ```
+ cmake_minimum_required(VERSION 3.5)
+ project(windows-pe LANGUAGES C)
+ add_executable(windows-pe WIN32 main.c)
+ set_target_properties(windows-pe PROPERTIES LINK_FLAGS "/NODEFAULTLIB")
+ ```
+
+- `macos-macho` and `macos-macho-universal`:
+
+ This is a minimal C program, compiled on the command line:
+ - `main.c`:
+ ```
+ int main() { return 0; }
+ ```
+
+ - Compile with:
+ ```
+ clang main.c -o macos-macho
+ clang main.c -arch x86_64 -arch arm64 -o macos-macho-universal
+ ```
+
+
+## Compression
+
+The .zz files here are in Qt's `qCompress` format.
+
+- compress `${file}` on the command line:
+ ```
+ $ printf "0: %08x" `stat -c "%s" $file` | xxd -r > $file.zz ; pigz -z <$file >>$file.zz
+ ```
+
+- decompress `${file}.zz` on the command line:
+ ```
+ $ dd if=${file}.zz bs=4 skip=1 | pigz -d >${file}
+ ```
diff --git a/tests/data/binaries/android-elf.so.zz b/tests/data/binaries/android-elf.so.zz
new file mode 100644
index 00000000..a06f8341
--- /dev/null
+++ b/tests/data/binaries/android-elf.so.zz
Binary files differ
diff --git a/tests/data/binaries/macos-macho.zz b/tests/data/binaries/macos-macho.zz
new file mode 100644
index 00000000..db91c82a
--- /dev/null
+++ b/tests/data/binaries/macos-macho.zz
Binary files differ
diff --git a/tests/data/binaries/macos-universal.zz b/tests/data/binaries/macos-universal.zz
new file mode 100644
index 00000000..b91409f2
--- /dev/null
+++ b/tests/data/binaries/macos-universal.zz
Binary files differ
diff --git a/tests/data/binaries/windows-pe.exe.zz b/tests/data/binaries/windows-pe.exe.zz
new file mode 100644
index 00000000..c3fd3454
--- /dev/null
+++ b/tests/data/binaries/windows-pe.exe.zz
Binary files differ