Skip to content

Commit 899ed29

Browse files
committed
Run the test suite during package builds
debian/rules skipped dh_auto_test with a comment claiming no test targets were defined, which stopped being true when tests/test_toolmodel.cpp was added: every package build compiled the test binary and then discarded it without running it. Drop the override so dh_auto_test runs ctest. Make the filtering test independent of the build host first. It relied on isLiveEnvironment() returning false, which is derived from the filesystem type of /, so it would have failed inside any container whose root is an overlay mount. Add an MX_TOOLS_TEST_FORCE_LIVE override compiled in only when MX_TOOLS_TESTING is defined (the test target only, never the shipped binary), pin it in the test fixture, and use it to also cover the live session case where MX-OnlyLive and MX-OnlyInstalled swap over. Rename launchTracksAlreadyRunningToolsAndReapsZombies: it does not reach the zombie branch of isProcessRunning(), because QProcess::startDetached double-forks and the child is reparented to init and reaped as soon as it exits. It verifies that relaunch is blocked while running and allowed afterwards, so name it for that.
1 parent e0a3728 commit 899ed29

4 files changed

Lines changed: 31 additions & 11 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ if(BUILD_TESTING)
272272
endif()
273273
target_compile_definitions(test-toolmodel PRIVATE
274274
MX_TOOLS_APPLICATIONS_PATH="${CMAKE_CURRENT_BINARY_DIR}/test-applications"
275+
MX_TOOLS_TESTING
275276
)
276277
target_include_directories(test-toolmodel PRIVATE src)
277278
add_test(NAME toolmodel COMMAND test-toolmodel)

‎debian/rules‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ override_dh_shlibdeps:
2626
override_dh_dwz:
2727
@:
2828

29-
override_dh_auto_test:
30-
# Skip tests as no test targets are defined
31-
3229
override_dh_auto_install:
3330
# Install is handled by debian/install file
3431
dh_auto_install

‎src/toolmodel.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ QStringList currentDesktops()
5858

5959
bool isLiveEnvironment()
6060
{
61+
#ifdef MX_TOOLS_TESTING
62+
// The test suite must not depend on the build host's root filesystem: a
63+
// container root is an overlay mount, which would otherwise be detected
64+
// as a live session and silently invert the environment filtering.
65+
const QByteArray forcedLive = qgetenv("MX_TOOLS_TEST_FORCE_LIVE");
66+
if (!forcedLive.isEmpty()) {
67+
return forcedLive != "0";
68+
}
69+
#endif
6170
const QByteArray fileSystem = QStorageInfo(QStringLiteral("/")).fileSystemType();
6271
return fileSystem == "aufs" || fileSystem == "overlay";
6372
}

‎tests/test_toolmodel.cpp‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private slots:
3535
void init();
3636
void cleanup();
3737
void discoversAndFiltersTools();
38-
void launchTracksAlreadyRunningToolsAndReapsZombies();
38+
void launchBlocksRelaunchOnlyWhileRunning();
3939

4040
private:
4141
QScopedPointer<QTemporaryDir> m_home;
@@ -53,13 +53,17 @@ void TestToolModel::init()
5353
qputenv("XDG_CONFIG_HOME", (m_home->path() + QStringLiteral("/.config")).toUtf8());
5454
qunsetenv("XDG_CURRENT_DESKTOP");
5555
qunsetenv("XDG_SESSION_DESKTOP");
56+
// Pin the live/installed state instead of inheriting it from the root
57+
// filesystem, which is an overlay mount inside build containers.
58+
qputenv("MX_TOOLS_TEST_FORCE_LIVE", "0");
5659

5760
QVERIFY(QDir().mkpath(QStringLiteral(MX_TOOLS_APPLICATIONS_PATH)));
5861
}
5962

6063
void TestToolModel::cleanup()
6164
{
6265
QDir(QStringLiteral(MX_TOOLS_APPLICATIONS_PATH)).removeRecursively();
66+
qunsetenv("MX_TOOLS_TEST_FORCE_LIVE");
6367
m_home.reset();
6468
}
6569

@@ -87,10 +91,10 @@ void TestToolModel::discoversAndFiltersTools()
8791
ToolIconProvider iconProvider;
8892
ToolModel model(&iconProvider);
8993

90-
// The test process never runs on a live (aufs/overlay) root filesystem,
91-
// so MX-OnlyLive is excluded and MX-OnlyInstalled is kept; NotShowIn=XFCE
92-
// and OnlyShowIn=KDE both exclude their entries under XDG_CURRENT_DESKTOP=XFCE.
93-
// Only "Utility Tool" and "Installed Only Tool" should survive.
94+
// MX_TOOLS_TEST_FORCE_LIVE=0 means MX-OnlyLive is excluded and
95+
// MX-OnlyInstalled is kept; NotShowIn=XFCE and OnlyShowIn=KDE both exclude
96+
// their entries under XDG_CURRENT_DESKTOP=XFCE, so only "Utility Tool" and
97+
// "Installed Only Tool" should survive.
9498
QCOMPARE(model.totalCount(), 2);
9599
QCOMPARE(model.categories(), QStringList({QStringLiteral("All tools"), QStringLiteral("Maintenance"),
96100
QStringLiteral("Utilities")}));
@@ -109,9 +113,16 @@ void TestToolModel::discoversAndFiltersTools()
109113
model.setSearch(QStringLiteral("installed"));
110114
QCOMPARE(model.rowCount(), 1);
111115
QCOMPARE(model.data(model.index(0), ToolModel::CategoryRole).toString(), QStringLiteral("Maintenance"));
116+
117+
// On a live session the MX-OnlyLive/MX-OnlyInstalled pair swaps over.
118+
qputenv("MX_TOOLS_TEST_FORCE_LIVE", "1");
119+
ToolModel liveModel(&iconProvider);
120+
QCOMPARE(liveModel.totalCount(), 2);
121+
QCOMPARE(liveModel.categories(), QStringList({QStringLiteral("All tools"), QStringLiteral("Live"),
122+
QStringLiteral("Utilities")}));
112123
}
113124

114-
void TestToolModel::launchTracksAlreadyRunningToolsAndReapsZombies()
125+
void TestToolModel::launchBlocksRelaunchOnlyWhileRunning()
115126
{
116127
const QDir applications(QStringLiteral(MX_TOOLS_APPLICATIONS_PATH));
117128
writeDesktopFile(applications, QStringLiteral("sleeper.desktop"),
@@ -128,8 +139,10 @@ void TestToolModel::launchTracksAlreadyRunningToolsAndReapsZombies()
128139
QCOMPARE(errors.count(), 1);
129140
QCOMPARE(errors.constFirst().at(0).toString(), QStringLiteral("Tool already running"));
130141

131-
// Once the detached /bin/sleep 0.2 has exited, launching again must not
132-
// be blocked by a lingering zombie /proc entry for its old pid.
142+
// Once the detached /bin/sleep 0.2 has exited, launching again must be
143+
// allowed. Note this does not exercise the zombie branch of
144+
// isProcessRunning(): QProcess::startDetached double-forks, so the child
145+
// is reparented to init and reaped as soon as it exits.
133146
QTest::qWait(600);
134147
model.launch(fileName);
135148
QCOMPARE(errors.count(), 1);

0 commit comments

Comments
 (0)