blob: d8802697173c0cb7d2a1475a3c9840cb8e10e286 [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;
35 ::std::thread thread(::std::ref(t));
36 thread.join();
Brian Silvermanaf784862014-05-13 08:14:55 -070037}
38
39} // namespace testing
40} // namespace libc
41} // namespace aos