Merge changes Iac46bc9c,I4f853107 into main
* changes:
Invert over-long UTF-8 bool for readability.
Add musl handling in run-on-host.sh.
diff --git a/README.md b/README.md
index 113ffd7..aafbcff 100644
--- a/README.md
+++ b/README.md
@@ -374,6 +374,19 @@
$ ./tests/run-on-host.sh glibc
+### Against musl
+
+Another way to verify test behavior is to run against musl on the host. glibc
+musl don't always match, so this can be a good way to find the more complicated
+corners of the spec. If they *do* match, bionic probably should too!
+
+ $ OUT_DIR=$(ANDROID_BUILD_TOP)/musl-out ./tests/run-on-host.sh musl
+
+Note: the alternate OUT_DIR is used to avoid causing excessive rebuilding when
+switching between glibc and musl. The first musl test run will be expensive
+because it will not reuse any already built artifacts, but subsequent runs will
+be cheaper than if you hadn't used it.
+
## Gathering test coverage
To get test coverage for bionic, use `//bionic/build/coverage.sh`. Before
diff --git a/tests/run-on-host.sh b/tests/run-on-host.sh
index fe2c25a..19bbacf 100755
--- a/tests/run-on-host.sh
+++ b/tests/run-on-host.sh
@@ -2,9 +2,14 @@
. $(dirname $0)/../build/run-on-host.sh
-if [ "$1" = glibc ]; then
+if [ "$1" = glibc -o "$1" = musl ]; then
+ if [ "$1" = musl ]; then
+ BUILD_ARGS=USE_HOST_MUSL=true
+ else
+ BUILD_ARGS=
+ fi
shift
- m -j bionic-unit-tests-glibc
+ m -j $BUILD_ARGS bionic-unit-tests-glibc
(
cd ${ANDROID_BUILD_TOP}
export ANDROID_DATA=${TARGET_OUT_DATA}
@@ -13,7 +18,7 @@
)
exit 0
elif [ "$1" != 32 -a "$1" != 64 ]; then
- echo "Usage: $0 [ 32 | 64 | glibc ] [gtest flags]"
+ echo "Usage: $0 [ 32 | 64 | glibc | musl ] [gtest flags]"
exit 1
fi
diff --git a/tests/uchar_test.cpp b/tests/uchar_test.cpp
index 793a5b3..d7174bd 100644
--- a/tests/uchar_test.cpp
+++ b/tests/uchar_test.cpp
@@ -33,11 +33,11 @@
// excluded, so it has never supported them. Other implementations (at least
// as of glibc 2.36), do support those sequences.
#if defined(__ANDROID__) || defined(ANDROID_HOST_MUSL)
-constexpr bool kLibcSupportsLongUtf8Sequences = 0;
+constexpr bool kLibcRejectsOverLongUtf8Sequences = true;
#elif defined(__GLIBC__)
-constexpr bool kLibcSupportsLongUtf8Sequences = 1;
+constexpr bool kLibcRejectsOverLongUtf8Sequences = false;
#else
-#error kLibcSupportsLongUtf8Sequences must be configured for this platform
+#error kLibcRejectsOverLongUtf8Sequences must be configured for this platform
#endif
// C23 7.30.1 (for each `mbrtoc*` function) says:
@@ -196,14 +196,14 @@
char16_t out = u'\0';
errno = 0;
auto result = mbrtoc16(&out, "\xf8\xa1\xa2\xa3\xa4", 5, nullptr);
- if (kLibcSupportsLongUtf8Sequences) {
- EXPECT_EQ(5U, result);
- EXPECT_EQ(0, errno);
- EXPECT_EQ(u'\uf94a', out);
- } else {
+ if (kLibcRejectsOverLongUtf8Sequences) {
EXPECT_EQ(static_cast<size_t>(-1), result);
EXPECT_EQ(EILSEQ, errno);
EXPECT_EQ(u'\0', out);
+ } else {
+ EXPECT_EQ(5U, result);
+ EXPECT_EQ(0, errno);
+ EXPECT_EQ(u'\uf94a', out);
}
}
@@ -323,14 +323,14 @@
char32_t out = U'\0';
errno = 0;
auto result = mbrtoc32(&out, "\xf5\x80\x80\x80", 4, nullptr);
- if (kLibcSupportsLongUtf8Sequences) {
- EXPECT_EQ(4U, result);
- EXPECT_EQ(0, errno);
- EXPECT_EQ(U'\x140000', out);
- } else {
+ if (kLibcRejectsOverLongUtf8Sequences) {
EXPECT_EQ(static_cast<size_t>(-1), result);
EXPECT_EQ(EILSEQ, errno);
EXPECT_EQ(U'\0', out);
+ } else {
+ EXPECT_EQ(4U, result);
+ EXPECT_EQ(0, errno);
+ EXPECT_EQ(U'\x140000', out);
}
}