blob: d854aab6edb8ff95df2af8c666b1e4b943dfe9b4 [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
8namespace aos {
9namespace libc {
10namespace testing {
11
12// Tries a couple of easy ones.
13TEST(StrsignalTest, Basic) {
14 EXPECT_STREQ("Hangup", aos_strsignal(SIGHUP));
15 EXPECT_STREQ("Broken pipe", aos_strsignal(SIGPIPE));
16 EXPECT_STREQ("Real-time signal 2", aos_strsignal(SIGRTMIN + 2));
17 EXPECT_STREQ("Unknown signal 155", aos_strsignal(155));
18}
19
Austin Schuh9fd93e52014-10-21 22:26:16 -070020class SignalNameTester {
21 public:
22 void operator()() {
23 for (int i = 0; i < SIGRTMAX + 5; ++i) {
24 EXPECT_STREQ(strsignal(i), aos_strsignal(i));
25 }
26 }
27};
28
James Kuszmaul89199182023-02-17 14:29:56 -080029// msan doesn't seem to like strsignal().
30#if !__has_feature(memory_sanitizer)
Brian Silvermanaf784862014-05-13 08:14:55 -070031// Tests that all the signals give the same result as strsignal(3).
32TEST(StrsignalTest, All) {
Austin Schuh9fd93e52014-10-21 22:26:16 -070033 // Sigh, strsignal allocates a buffer that uses pthread local storage. This
34 // interacts poorly with asan. Spawning a thread causes the storage to get
35 // cleaned up before asan checks.
36 SignalNameTester t;
James Kuszmaul89199182023-02-17 14:29:56 -080037#if defined(AOS_SANITIZER_thread)
Brian Silverman8d981f92014-12-29 21:38:08 -080038 // tsan doesn't like this usage of ::std::thread. It looks like
39 // <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57507>.
40 t();
41#else
Austin Schuh9fd93e52014-10-21 22:26:16 -070042 ::std::thread thread(::std::ref(t));
43 thread.join();
Brian Silverman8d981f92014-12-29 21:38:08 -080044#endif
Brian Silvermanaf784862014-05-13 08:14:55 -070045}
James Kuszmaul89199182023-02-17 14:29:56 -080046#endif
Brian Silvermanaf784862014-05-13 08:14:55 -070047
48} // namespace testing
49} // namespace libc
50} // namespace aos