[COMMIT osv master] tests: make tst-string.cc work with glibc

3 views
Skip to first unread message

Commit Bot

unread,
Dec 14, 2023, 11:32:47 PM12/14/23
to osv...@googlegroups.com, Waldemar Kozaczuk
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

tests: make tst-string.cc work with glibc

The musl version of strsignal() used by OSv returns slightly different
message string than glibc. More specifically glibc appends the signal
number to the string.

We could change musl version to behave exactly like glibc, but instead
we tweak the tst-string.cc with ifdef to test correct message version
depending how it is compiled.

In the end, the test now works on Linux and on OSv with Linux dynamic
linker.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>

---
diff --git a/tests/tst-string.cc b/tests/tst-string.cc
--- a/tests/tst-string.cc
+++ b/tests/tst-string.cc
@@ -75,25 +75,43 @@ TEST(STRING_TEST, strsignal) {
//ASSERT_STREQ("Real-time signal 14", strsignal(SIGRTMIN + 14));

// Errors.
+#ifdef __OSV__
ASSERT_STREQ("Unknown signal", strsignal(-1)); // Too small.
ASSERT_STREQ("Unknown signal", strsignal(0)); // Still too small.
ASSERT_STREQ("Unknown signal", strsignal(1234)); // Too large.
+#else
+ ASSERT_STREQ("Unknown signal -1", strsignal(-1)); // Too small.
+ ASSERT_STREQ("Unknown signal 0", strsignal(0)); // Still too small.
+ ASSERT_STREQ("Unknown signal 1234", strsignal(1234)); // Too large.
+#endif
}

static void* ConcurrentStrSignalFn(void*) {
+#ifdef __OSV__
bool equal = (strcmp("Unknown signal", strsignal(2002)) == 0);
+#else
+ bool equal = (strcmp("Unknown signal 2002", strsignal(2002)) == 0);
+#endif
return reinterpret_cast<void*>(equal);
}

TEST(STRING_TEST, strsignal_concurrent) {
const char* strsignal1001 = strsignal(1001);
+#ifdef __OSV__
ASSERT_STREQ("Unknown signal", strsignal1001);
+#else
+ ASSERT_STREQ("Unknown signal 1001", strsignal1001);
+#endif

pthread_t t;
ASSERT_EQ(0, pthread_create(&t, nullptr, ConcurrentStrSignalFn, nullptr));
void* result;
ASSERT_EQ(0, pthread_join(t, &result));
ASSERT_TRUE(static_cast<bool>(result));

+#ifdef __OSV__
ASSERT_STREQ("Unknown signal", strsignal1001);
+#else
+ ASSERT_STREQ("Unknown signal 1001", strsignal1001);
+#endif
}
Reply all
Reply to author
Forward
0 new messages