1 //===-- Unittests for strsignal -------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/string/strsignal.h"
10 #include "test/UnitTest/Test.h"
14 TEST(LlvmLibcStrSignalTest
, KnownSignals
) {
15 ASSERT_STREQ(LIBC_NAMESPACE::strsignal(1), "Hangup");
17 const char *message_array
[] = {
18 "Unknown signal 0", // unknown
22 "Illegal instruction",
23 "Trace/breakpoint trap",
26 "Floating point exception",
28 "User defined signal 1",
30 "User defined signal 2",
39 "Stopped (tty input)",
40 "Stopped (tty output)",
41 "Urgent I/O condition",
42 "CPU time limit exceeded",
43 "File size limit exceeded",
44 "Virtual timer expired",
45 "Profiling timer expired",
52 // There are supposed to be 32 of these, but sometimes SIGRTMIN is shifted to
54 const char *rt_message_array
[] = {
55 "Real-time signal 0", "Real-time signal 1", "Real-time signal 2",
56 "Real-time signal 3", "Real-time signal 4", "Real-time signal 5",
57 "Real-time signal 6", "Real-time signal 7", "Real-time signal 8",
58 "Real-time signal 9", "Real-time signal 10", "Real-time signal 11",
59 "Real-time signal 12", "Real-time signal 13", "Real-time signal 14",
60 "Real-time signal 15", "Real-time signal 16", "Real-time signal 17",
61 "Real-time signal 18", "Real-time signal 19", "Real-time signal 20",
62 "Real-time signal 21", "Real-time signal 22", "Real-time signal 23",
63 "Real-time signal 24", "Real-time signal 25", "Real-time signal 26",
64 "Real-time signal 27", "Real-time signal 28", "Real-time signal 29",
65 "Real-time signal 30", "Real-time signal 31", "Real-time signal 32",
68 for (size_t i
= 0; i
< (sizeof(message_array
) / sizeof(char *)); ++i
) {
69 ASSERT_EQ(static_cast<size_t>(static_cast<int>(i
)), i
);
70 EXPECT_STREQ(LIBC_NAMESPACE::strsignal(static_cast<int>(i
)),
74 for (int i
= 0; i
< SIGRTMAX
- SIGRTMIN
; ++i
) {
75 EXPECT_STREQ(LIBC_NAMESPACE::strsignal(i
+ SIGRTMIN
), rt_message_array
[i
]);
79 TEST(LlvmLibcStrsignalTest
, UnknownSignals
) {
80 ASSERT_STREQ(LIBC_NAMESPACE::strsignal(-1), "Unknown signal -1");
81 ASSERT_STREQ(LIBC_NAMESPACE::strsignal(65), "Unknown signal 65");
82 ASSERT_STREQ(LIBC_NAMESPACE::strsignal(2147483647),
83 "Unknown signal 2147483647");
84 ASSERT_STREQ(LIBC_NAMESPACE::strsignal(-2147483648),
85 "Unknown signal -2147483648");