John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 1 | #include "aos/libc/aos_strsignal.h" |
Brian Silverman | af78486 | 2014-05-13 08:14:55 -0700 | [diff] [blame] | 2 | |
| 3 | #include <signal.h> |
Austin Schuh | 9fd93e5 | 2014-10-21 22:26:16 -0700 | [diff] [blame] | 4 | #include <thread> |
Brian Silverman | af78486 | 2014-05-13 08:14:55 -0700 | [diff] [blame] | 5 | |
| 6 | #include "gtest/gtest.h" |
| 7 | |
| 8 | namespace aos { |
| 9 | namespace libc { |
| 10 | namespace testing { |
| 11 | |
| 12 | // Tries a couple of easy ones. |
| 13 | TEST(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 Schuh | 9fd93e5 | 2014-10-21 22:26:16 -0700 | [diff] [blame] | 20 | class 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 | |
Brian Silverman | af78486 | 2014-05-13 08:14:55 -0700 | [diff] [blame] | 29 | // Tests that all the signals give the same result as strsignal(3). |
| 30 | TEST(StrsignalTest, All) { |
Austin Schuh | 9fd93e5 | 2014-10-21 22:26:16 -0700 | [diff] [blame] | 31 | // 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; |
Brian Silverman | 8d981f9 | 2014-12-29 21:38:08 -0800 | [diff] [blame] | 35 | #ifdef AOS_SANITIZER_thread |
| 36 | // 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 Schuh | 9fd93e5 | 2014-10-21 22:26:16 -0700 | [diff] [blame] | 40 | ::std::thread thread(::std::ref(t)); |
| 41 | thread.join(); |
Brian Silverman | 8d981f9 | 2014-12-29 21:38:08 -0800 | [diff] [blame] | 42 | #endif |
Brian Silverman | af78486 | 2014-05-13 08:14:55 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | } // namespace testing |
| 46 | } // namespace libc |
| 47 | } // namespace aos |