1//===-- Unittests for strerror --------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#include "src/string/strerror.h"
10#include "test/UnitTest/Test.h"
11
12TEST(LlvmLibcStrErrorTest, KnownErrors) {
13 ASSERT_STREQ(LIBC_NAMESPACE::strerror(0), "Success");
14
15 const char *message_array[] = {
16 "Success",
17 "Operation not permitted",
18 "No such file or directory",
19 "No such process",
20 "Interrupted system call",
21 "Input/output error",
22 "No such device or address",
23 "Argument list too long",
24 "Exec format error",
25 "Bad file descriptor",
26 "No child processes",
27 "Resource temporarily unavailable",
28 "Cannot allocate memory",
29 "Permission denied",
30 "Bad address",
31 "Block device required",
32 "Device or resource busy",
33 "File exists",
34 "Invalid cross-device link",
35 "No such device",
36 "Not a directory",
37 "Is a directory",
38 "Invalid argument",
39 "Too many open files in system",
40 "Too many open files",
41 "Inappropriate ioctl for device",
42 "Text file busy",
43 "File too large",
44 "No space left on device",
45 "Illegal seek",
46 "Read-only file system",
47 "Too many links",
48 "Broken pipe",
49 "Numerical argument out of domain",
50 "Numerical result out of range",
51 "Resource deadlock avoided",
52 "File name too long",
53 "No locks available",
54 "Function not implemented",
55 "Directory not empty",
56 "Too many levels of symbolic links",
57 "Unknown error 41", // Unknown
58 "No message of desired type",
59 "Identifier removed",
60 "Channel number out of range",
61 "Level 2 not synchronized",
62 "Level 3 halted",
63 "Level 3 reset",
64 "Link number out of range",
65 "Protocol driver not attached",
66 "No CSI structure available",
67 "Level 2 halted",
68 "Invalid exchange",
69 "Invalid request descriptor",
70 "Exchange full",
71 "No anode",
72 "Invalid request code",
73 "Invalid slot",
74 "Unknown error 58", // Unknown
75 "Bad font file format",
76 "Device not a stream",
77 "No data available",
78 "Timer expired",
79 "Out of streams resources",
80 "Machine is not on the network",
81 "Package not installed",
82 "Object is remote",
83 "Link has been severed",
84 "Advertise error",
85 "Srmount error",
86 "Communication error on send",
87 "Protocol error",
88 "Multihop attempted",
89 "RFS specific error",
90 "Bad message",
91 "Value too large for defined data type",
92 "Name not unique on network",
93 "File descriptor in bad state",
94 "Remote address changed",
95 "Can not access a needed shared library",
96 "Accessing a corrupted shared library",
97 ".lib section in a.out corrupted",
98 "Attempting to link in too many shared libraries",
99 "Cannot exec a shared library directly",
100 "Invalid or incomplete multibyte or wide character",
101 "Interrupted system call should be restarted",
102 "Streams pipe error",
103 "Too many users",
104 "Socket operation on non-socket",
105 "Destination address required",
106 "Message too long",
107 "Protocol wrong type for socket",
108 "Protocol not available",
109 "Protocol not supported",
110 "Socket type not supported",
111 "Operation not supported",
112 "Protocol family not supported",
113 "Address family not supported by protocol",
114 "Address already in use",
115 "Cannot assign requested address",
116 "Network is down",
117 "Network is unreachable",
118 "Network dropped connection on reset",
119 "Software caused connection abort",
120 "Connection reset by peer",
121 "No buffer space available",
122 "Transport endpoint is already connected",
123 "Transport endpoint is not connected",
124 "Cannot send after transport endpoint shutdown",
125 "Too many references: cannot splice",
126 "Connection timed out",
127 "Connection refused",
128 "Host is down",
129 "No route to host",
130 "Operation already in progress",
131 "Operation now in progress",
132 "Stale file handle",
133 "Structure needs cleaning",
134 "Not a XENIX named type file",
135 "No XENIX semaphores available",
136 "Is a named type file",
137 "Remote I/O error",
138 "Disk quota exceeded",
139 "No medium found",
140 "Wrong medium type",
141 "Operation canceled",
142 "Required key not available",
143 "Key has expired",
144 "Key has been revoked",
145 "Key was rejected by service",
146 "Owner died",
147 "State not recoverable",
148 "Operation not possible due to RF-kill",
149 "Memory page has hardware error",
150 };
151
152 for (size_t i = 0; i < (sizeof(message_array) / sizeof(char *)); ++i) {
153 EXPECT_STREQ(LIBC_NAMESPACE::strerror(static_cast<int>(i)),
154 message_array[i]);
155 }
156}
157
158TEST(LlvmLibcStrErrorTest, UnknownErrors) {
159 ASSERT_STREQ(LIBC_NAMESPACE::strerror(-1), "Unknown error -1");
160 ASSERT_STREQ(LIBC_NAMESPACE::strerror(134), "Unknown error 134");
161 ASSERT_STREQ(LIBC_NAMESPACE::strerror(2147483647),
162 "Unknown error 2147483647");
163 ASSERT_STREQ(LIBC_NAMESPACE::strerror(-2147483648),
164 "Unknown error -2147483648");
165}
166

source code of libc/test/src/string/strerror_test.cpp