blob: 7e91d460a468347cca15afcb20a47a23cc3fca43 [file] [log] [blame]
John Park33858a32018-09-28 23:05:48 -07001#include "aos/libc/aos_strsignal.h"
Brian Silvermanaf784862014-05-13 08:14:55 -07002
Tyler Chatowbf0609c2021-07-31 16:13:27 -07003#include <csignal>
Austin Schuh9fd93e52014-10-21 22:26:16 -07004#include <thread>
Brian Silvermanaf784862014-05-13 08:14:55 -07005
6#include "gtest/gtest.h"
7
Stephan Pleinesf63bde82024-01-13 15:59:33 -08008namespace aos::libc::testing {
Brian Silvermanaf784862014-05-13 08:14:55 -07009
10// Tries a couple of easy ones.
11TEST(StrsignalTest, Basic) {
12 EXPECT_STREQ("Hangup", aos_strsignal(SIGHUP));
13 EXPECT_STREQ("Broken pipe", aos_strsignal(SIGPIPE));
14 EXPECT_STREQ("Real-time signal 2", aos_strsignal(SIGRTMIN + 2));
15 EXPECT_STREQ("Unknown signal 155", aos_strsignal(155));
16}
17
Austin Schuh9fd93e52014-10-21 22:26:16 -070018class SignalNameTester {
19 public:
20 void operator()() {
21 for (int i = 0; i < SIGRTMAX + 5; ++i) {
22 EXPECT_STREQ(strsignal(i), aos_strsignal(i));
23 }
24 }
25};
26
James Kuszmaul89199182023-02-17 14:29:56 -080027// msan doesn't seem to like strsignal().
28#if !__has_feature(memory_sanitizer)
Brian Silvermanaf784862014-05-13 08:14:55 -070029// Tests that all the signals give the same result as strsignal(3).
30TEST(StrsignalTest, All) {
Austin Schuh9fd93e52014-10-21 22:26:16 -070031 // Sigh, strsignal allocates a buffer that uses pthread local storage. This
32 // interacts poorly with asan. Spawning a thread causes the storage to get
33 // cleaned up before asan checks.
34 SignalNameTester t;
James Kuszmaul89199182023-02-17 14:29:56 -080035#if defined(AOS_SANITIZER_thread)
Brian Silverman8d981f92014-12-29 21:38:08 -080036 // tsan doesn't like this usage of ::std::thread. It looks like
37 // <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57507>.
38 t();
39#else
Austin Schuh9fd93e52014-10-21 22:26:16 -070040 ::std::thread thread(::std::ref(t));
41 thread.join();
Brian Silverman8d981f92014-12-29 21:38:08 -080042#endif
Brian Silvermanaf784862014-05-13 08:14:55 -070043}
James Kuszmaul89199182023-02-17 14:29:56 -080044#endif
Brian Silvermanaf784862014-05-13 08:14:55 -070045
Stephan Pleinesf63bde82024-01-13 15:59:33 -080046} // namespace aos::libc::testing