-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] Fix tests on musl. #85085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc++] Fix tests on musl. #85085
Conversation
One or two of the tests need slight tweaks to make them pass when building with musl. rdar://118885724
@llvm/pr-subscribers-libcxx Author: Alastair Houghton (al45tair) ChangesOne or two of the tests need slight tweaks to make them pass when building with musl. rdar://118885724 Full diff: https://github.com/llvm/llvm-project/pull/85085.diff 3 Files Affected:
diff --git a/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/generic_category.pass.cpp b/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/generic_category.pass.cpp
index 068202c6e415085..d4bbde75ae88218 100644
--- a/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/generic_category.pass.cpp
+++ b/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/generic_category.pass.cpp
@@ -44,14 +44,19 @@ int main(int, char**)
errno = E2BIG; // something that message will never generate
const std::error_category& e_cat1 = std::generic_category();
const std::string msg = e_cat1.message(-1);
- // Exact message format varies by platform.
-#if defined(_AIX)
- LIBCPP_ASSERT(msg.rfind("Error -1 occurred", 0) == 0);
-#elif defined(_NEWLIB_VERSION)
- LIBCPP_ASSERT(msg.empty());
-#else
- LIBCPP_ASSERT(msg.rfind("Unknown error", 0) == 0);
+ // Exact message format varies by platform. We can't detect
+ // some of these (Musl in particular) using the preprocessor,
+ // so accept a few sensible messages. Newlib unfortunately
+ // responds with an empty message, which we probably want to
+ // treat as a failure code otherwise, but we can detect that
+ // with the preprocessor.
+ LIBCPP_ASSERT(msg.rfind("Error -1 occurred", 0) == 0 // AIX
+ || msg.rfind("No error information", 0) == 0 // Musl
+ || msg.rfind("Unknown error", 0) == 0 // Glibc
+#if defined(_NEWLIB_VERSION)
+ || msg.empty()
#endif
+ );
assert(errno == E2BIG);
}
diff --git a/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp b/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp
index 42fdd1cb3b91bdb..eefbddd27a7f538 100644
--- a/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp
+++ b/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp
@@ -50,14 +50,19 @@ int main(int, char**) {
errno = E2BIG; // something that message will never generate
const std::error_category& e_cat1 = std::system_category();
const std::string msg = e_cat1.message(-1);
- // Exact message format varies by platform.
-#if defined(_AIX)
- LIBCPP_ASSERT(msg.rfind("Error -1 occurred", 0) == 0);
-#elif defined(_NEWLIB_VERSION)
- LIBCPP_ASSERT(msg.empty());
-#else
- LIBCPP_ASSERT(msg.rfind("Unknown error", 0) == 0);
+ // Exact message format varies by platform. We can't detect
+ // some of these (Musl in particular) using the preprocessor,
+ // so accept a few sensible messages. Newlib unfortunately
+ // responds with an empty message, which we probably want to
+ // treat as a failure code otherwise, but we can detect that
+ // with the preprocessor.
+ LIBCPP_ASSERT(msg.rfind("Error -1 occurred", 0) == 0 // AIX
+ || msg.rfind("No error information", 0) == 0 // Musl
+ || msg.rfind("Unknown error", 0) == 0 // Glibc
+#if defined(_NEWLIB_VERSION)
+ || msg.empty()
#endif
+ );
assert(errno == E2BIG);
}
diff --git a/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.pass.cpp b/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.pass.cpp
index 8637a933008fb9d..215af3656bc7fef 100644
--- a/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.pass.cpp
@@ -22,6 +22,7 @@
#include <locale>
#include <ios>
#include <cassert>
+#include <cstdio>
#include <streambuf>
#include <cmath>
#include "test_macros.h"
@@ -8934,11 +8935,12 @@ void test4()
char str[200];
std::locale lc = std::locale::classic();
std::locale lg(lc, new my_numpunct);
-#ifdef _AIX
- std::string inf = "INF";
-#else
- std::string inf = "inf";
-#endif
+
+ std::string inf;
+
+ // This should match the underlying C library
+ std::sprintf(str, "%f", INFINITY);
+ inf = str;
const my_facet f(1);
{
@@ -10727,24 +10729,28 @@ void test5()
std::locale lc = std::locale::classic();
std::locale lg(lc, new my_numpunct);
const my_facet f(1);
-#if defined(_AIX)
- std::string nan= "NaNQ";
- std::string NaN = "NaNQ";
- std::string nan_padding25 = "*********************";
- std::string pnan_sign = "+";
- std::string pnan_padding25 = "********************";
-#else
- std::string nan= "nan";
- std::string NaN = "NAN";
- std::string nan_padding25 = "**********************";
-#if defined(TEST_HAS_GLIBC) || defined(_WIN32)
- std::string pnan_sign = "+";
- std::string pnan_padding25 = "*********************";
-#else
- std::string pnan_sign = "";
- std::string pnan_padding25 = "**********************";
-#endif
-#endif
+
+ std::string nan;
+ std::string NaN;
+ std::string pnan_sign;
+
+ // The output here depends on the underlying C library, so work out what
+ // that does.
+ std::sprintf(str, "%f", std::nan(""));
+ nan = str;
+
+ std::sprintf(str, "%F", std::nan(""));
+ NaN = str;
+
+ std::sprintf(str, "%+f", std::nan(""));
+ if (str[0] == '+') {
+ pnan_sign = "+";
+ }
+
+ std::string nan_padding25 = std::string(25 - nan.length(), '*');
+ std::string pnan_padding25 = std::string(25 - nan.length()
+ - pnan_sign.length(), '*');
+
{
long double v = std::nan("");
std::ios ios(0);
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really support Musl officially, however these changes are IMO not too strongly tied to Musl so it makes sense. In particular, the put_long_double.pass.cpp
changes are simply making the test more generic so I think it's an overall win.
LGTM with green CI.
Edit: It looks like you need to apply the diff in #85085 (comment) to pass the formatter test.
Fix the formatting to make clang-format happy. rdar://118885724
9a14990
to
f060188
Compare
This reverts commit b61fb18. This commit landed with build failures in the pre-commit CI https://buildkite.com/llvm-project/libcxx-ci/builds/34153
I just reverted this commit since it landed with a red CI |
Sorry about that @mordante, I'll try this again. |
One or two of the tests need slight tweaks to make them pass when building with musl. This patch is a re-application of b61fb18 which was reverted in 0847c90 because it broke the build. rdar://118885724
No problem, I just wanted to unbreak the CI. |
One or two of the tests need slight tweaks to make them pass when building with musl. This patch is a re-application of b61fb18 which was reverted in 0847c90 because it broke the build. rdar://118885724 Co-authored-by: Alastair Houghton <[email protected]>
…kokoro build failure. llvm/llvm-project#85085 fixed put_long_double.pass.cpp in libcxx tests to run in Android making the local patch unnecessary. bionic-includes-plus-sign-for-nan-v2.patch is no longer necessary after b966b224b32aada3d83fb6d58abe413b5c59f3c1. Test: 1. make sure v2 is skipped in the ToT llvm ./build.py --build-llvm-next --llvm-rev b966b224b32aada3d83fb6d58abe413b5c59f3c1 2. make sure v2 is applied in the current llvm ./build.py Change-Id: I8191219d7c194acc68b8c07aa2e15552734d4125
One or two of the tests need slight tweaks to make them pass when building with musl.
rdar://118885724