blob: 3d90b21f134b322cb09d2e07f3e6a1211cc56ad6 [file] [log] [blame]
Brian Silvermanaf784862014-05-13 08:14:55 -07001#include "aos/common/libc/aos_strsignal.h"
2
3#include <signal.h>
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
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;
Brian Silverman8d981f92014-12-29 21:38:08 -080035#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 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}
44
45} // namespace testing
46} // namespace libc
47} // namespace aos