From fcb51615f9ccd2146d6523f405ff829ec626f58a Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 9 Oct 2024 17:17:36 -0700 Subject: [PATCH] Fix test_utf32. NFC (#22698) This test was never actually being run with `-fshort-wchar` because it was being passed as `args` rather than `emcc_args`, ever since the test was added back in c33af789. When actually running with `-fshort-wchar` the test fails under the sanitizers I believe because wcslen (which is part of libc) would also need to be built with this flag. --- test/test_core.py | 7 +++++-- test/utf32.cpp | 10 ++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/test/test_core.py b/test/test_core.py index afbf5b376d84..d9a97c6cb9b2 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -5680,8 +5680,11 @@ def test_utf(self): self.do_core_test('test_utf.c') def test_utf32(self): - self.do_runf('utf32.cpp', 'OK.') - self.do_runf('utf32.cpp', 'OK.', args=['-fshort-wchar']) + self.do_runf('utf32.cpp', 'OK (long).\n') + + @no_sanitize('requires libc to be built with -fshort-char') + def test_utf32_short_wchar(self): + self.do_runf('utf32.cpp', 'OK (short).\n', emcc_args=['-fshort-wchar']) @crossplatform def test_utf16(self): diff --git a/test/utf32.cpp b/test/utf32.cpp index 01f7feac87e1..2c145ce722ac 100644 --- a/test/utf32.cpp +++ b/test/utf32.cpp @@ -12,7 +12,7 @@ typedef unsigned int utf32; typedef unsigned short utf16; -EM_JS_DEPS(deps, "$UTF32ToString,$stringToUTF32"); +EM_JS_DEPS(deps, "$UTF32ToString,$stringToUTF32,$UTF16ToString,$stringToUTF16"); // This code tests that Unicode std::wstrings can be marshalled between C++ and JS. int main() { @@ -51,14 +51,16 @@ int main() { assert(memory[5] == 0); delete[] memory; + printf("OK (long).\n"); } else { + assert(sizeof(wchar_t) == 2); // sizeof(wchar_t) == 2, and we're building with -fshort-wchar. utf16 *memory = new utf16[2*wstr.length()+1]; EM_ASM({ var str = UTF16ToString($0); out(str); - var numBytesWritten = stringToUTF16(str, $1, $2); + var numBytesWritten = stringToUTF16(str, $1, Number($2)); if (numBytesWritten != 25*2) throw 'stringToUTF16 wrote an invalid length ' + numBytesWritten; }, wstr.c_str(), memory, (2*wstr.length()+1)*sizeof(utf16)); @@ -74,13 +76,13 @@ int main() { EM_ASM({ var str = UTF16ToString($0); out(str); - var numBytesWritten = stringToUTF16(str, $1, $2); + var numBytesWritten = stringToUTF16(str, $1, Number($2)); if (numBytesWritten != 5*2) throw 'stringToUTF16 wrote an invalid length ' + numBytesWritten; }, wstr.c_str(), memory, 6*sizeof(utf16)); assert(memory[5] == 0); delete[] memory; + printf("OK (short).\n"); } - printf("OK.\n"); }