[libcxx][tests] Unit tests fail for std::chrono
I have three LIT tests failing from ninja check-cxx on upstream main on my local machine. I am uncertain whether the tests or code are wrong, but the check fails because the expected time zones in the tests do not match the output. I ran the tests on an AMD EPYC 7402 with Red Hat Enterprise Linux 8.8 and I am currently in GMT-7. The failed tests are
Failed Tests (3):
llvm-libc++-shared.cfg.in :: std/time/time.syn/formatter.file_time.pass.cpp
llvm-libc++-shared.cfg.in :: std/time/time.syn/formatter.local_time.pass.cpp
llvm-libc++-shared.cfg.in :: std/time/time.syn/formatter.sys_time.pass.cpp
and the output is
# .---command stderr------------
# |
# | Format string {:L%%c='%c'%t%%Ec='%Ec'%n}
# | Expected output %c='jeu. 01 janv. 1970 00:00:00 GMT' %Ec='jeu. 01 janv. 1970 00:00:00 GMT'
# |
# | Actual output %c='jeu. 01 janv. 1970 00:00:00 UTC' %Ec='jeu. 01 janv. 1970 00:00:00 UTC'
# |
# | t.tmp.exe: /g/g92/rydahl1/LLVM_FORK/llvm-project/libcxx/test/std/time/time.syn/formatter_tests.h:41: void check(std::basic_string_view<CharT>, test_format_string<CharT, Args...>, Args &&...) [CharT = char, Args = <std::chrono::time_point<std::chrono::system_clock, std::chrono::duration<long long>>>]: Assertion `out == expected' failed.
# `-----------------------------
# error: command failed with exit status: 250
...
# .---command stderr------------
# |
# | Format string {:L%%c='%c'%t%%Ec='%Ec'%n}
# | Expected output %c='jeu. 01 janv. 1970 00:00:00 GMT' %Ec='jeu. 01 janv. 1970 00:00:00 GMT'
# |
# | Actual output %c='jeu. 01 janv. 1970 00:00:00 UTC' %Ec='jeu. 01 janv. 1970 00:00:00 UTC'
# |
# | t.tmp.exe: /g/g92/rydahl1/LLVM_FORK/llvm-project/libcxx/test/std/time/time.syn/formatter_tests.h:41: void check(std::basic_string_view<CharT>, test_format_string<CharT, Args...>, Args &&...) [CharT = char, Args = <std::chrono::time_point<std::filesystem::_FilesystemClock, std::chrono::duration<long long>>>]: Assertion `out == expected' failed.
# `-----------------------------
# error: command failed with exit status: 250
...
# .---command stderr------------
# |
# | Format string {:L%%c='%c'%t%%Ec='%Ec'%n}
# | Expected output %c='jeu. 01 janv. 1970 00:00:00 GMT' %Ec='jeu. 01 janv. 1970 00:00:00 GMT'
# |
# | Actual output %c='jeu. 01 janv. 1970 00:00:00 UTC' %Ec='jeu. 01 janv. 1970 00:00:00 UTC'
# |
# | t.tmp.exe: /g/g92/rydahl1/LLVM_FORK/llvm-project/libcxx/test/std/time/time.syn/formatter_tests.h:41: void check(std::basic_string_view<CharT>, test_format_string<CharT, Args...>, Args &&...) [CharT = char, Args = <std::chrono::time_point<std::chrono::local_t, std::chrono::duration<long long>>>]: Assertion `out == expected' failed.
# `-----------------------------
# error: command failed with exit status: 250
Oh, and it fails when building with Clang 17. I don't know if that is also important.
The output of std::format to serialize std::chrono::time_point in some locale/environment is not correct now.
See: https://godbolt.org/z/6v4v9EWGj. The behavior of std::format is different from std::time_put/std::strftime.
The reason is that libc++ use a function call convert_to_tm(not convert to time_t then to tm), then set the time_zone hard coding as UTC.
https://github.com/llvm/llvm-project/blob/cdc37325669c0321328a7245083c427b229e79e9/libcxx/include/__chrono/convert_to_tm.h#L65
Maybe change it to "GMT" could fix the problem.