GCC Code Coverage Report


Directory: Os/Posix/
File: error.cpp
Date: 2026-09-03 21:16:08
Exec Total Coverage
Lines: 67 176 38.1%
Functions: 7 8 87.5%
Branches: 13 48 27.1%

Line Branch Exec Source
1 // ======================================================================
2 // \title Os/Posix/error.cpp
3 // \brief implementation for posix errno conversion
4 // ======================================================================
5 #include "Os/Posix/error.hpp"
6 #include <cerrno>
7
8 namespace Os {
9 namespace Posix {
10
11 127 File::Status errno_to_file_status(int errno_input) {
12 127 File::Status status = File::Status::OP_OK;
13
6/9
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 58 times.
✗ Branch 8 not taken.
127 switch (errno_input) {
14 54 case 0:
15 54 status = File::Status::OP_OK;
16 54 break;
17 // Fallthrough intended
18 1 case ENOSPC:
19 case EFBIG:
20 1 status = File::Status::NO_SPACE;
21 1 break;
22 11 case ENOENT:
23 11 status = File::Status::DOESNT_EXIST;
24 11 break;
25 // Fallthrough intended
26 case EPERM:
27 case EACCES:
28 status = File::Status::NO_PERMISSION;
29 break;
30 1 case EEXIST:
31 1 status = File::Status::FILE_EXISTS;
32 1 break;
33 2 case EBADF:
34 2 status = File::Status::NOT_OPENED;
35 2 break;
36 // Fallthrough intended
37 case ENOSYS:
38 case EOPNOTSUPP:
39 status = File::Status::NOT_SUPPORTED;
40 break;
41 58 case EINVAL:
42 58 status = File::Status::INVALID_ARGUMENT;
43 58 break;
44 default:
45 status = File::Status::OTHER_ERROR;
46 break;
47 }
48 127 return status;
49 }
50
51 694 FileSystem::Status errno_to_filesystem_status(int errno_input) {
52 694 FileSystem::Status status = FileSystem::Status::OP_OK;
53
2/14
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 693 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
694 switch (errno_input) {
54 case 0:
55 status = FileSystem::Status::OP_OK;
56 break;
57 // Adjacent cases below intentionally share a status via fallthrough
58 case EACCES:
59 status = FileSystem::Status::NO_PERMISSION;
60 break;
61 case EPERM:
62 case EROFS:
63 case EFAULT:
64 status = FileSystem::Status::NO_PERMISSION;
65 break;
66 case EEXIST:
67 status = FileSystem::Status::ALREADY_EXISTS;
68 break;
69 693 case ELOOP:
70 case ENOENT:
71 693 status = FileSystem::Status::DOESNT_EXIST;
72 693 break;
73 case ENAMETOOLONG:
74 status = FileSystem::Status::INVALID_PATH;
75 break;
76 case ENOTDIR:
77 status = FileSystem::Status::NOT_DIR;
78 break;
79 case EDQUOT:
80 status = FileSystem::Status::NO_SPACE;
81 break;
82 case EMLINK:
83 status = FileSystem::Status::FILE_LIMIT;
84 break;
85 case ENOSPC:
86 case EFBIG:
87 status = FileSystem::Status::NO_SPACE;
88 break;
89 case ENOSYS:
90 case EOPNOTSUPP:
91 status = FileSystem::Status::NOT_SUPPORTED;
92 break;
93 case ERANGE:
94 status = FileSystem::Status::BUFFER_TOO_SMALL;
95 break;
96 case EXDEV:
97 status = FileSystem::Status::EXDEV_ERROR;
98 break;
99 1 default:
100 1 status = FileSystem::Status::OTHER_ERROR;
101 1 break;
102 }
103 694 return status;
104 }
105
106 45 Directory::Status errno_to_directory_status(int errno_input) {
107 45 Directory::Status status = Directory::Status::OP_OK;
108
1/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 45 times.
✗ Branch 5 not taken.
45 switch (errno_input) {
109 case 0:
110 status = Directory::Status::OP_OK;
111 break;
112 case ENOENT:
113 status = Directory::Status::DOESNT_EXIST;
114 break;
115 case EACCES:
116 status = Directory::Status::NO_PERMISSION;
117 break;
118 case ENOTDIR:
119 status = Directory::Status::NOT_DIR;
120 break;
121 45 case EEXIST:
122 45 status = Directory::Status::ALREADY_EXISTS;
123 45 break;
124 default:
125 status = Directory::Status::OTHER_ERROR;
126 break;
127 }
128 45 return status;
129 }
130
131 RawTime::Status errno_to_rawtime_status(int errno_input) {
132 RawTime::Status status = RawTime::Status::OP_OK;
133 switch (errno_input) {
134 case 0:
135 status = RawTime::Status::OP_OK;
136 break;
137 case EINVAL:
138 status = RawTime::Status::INVALID_PARAMS;
139 break;
140 default:
141 status = RawTime::Status::OTHER_ERROR;
142 break;
143 }
144 return status;
145 }
146
147 425 Task::Status posix_status_to_task_status(int posix_status) {
148 425 Task::Status status = Task::Status::OP_OK;
149
1/5
✓ Branch 0 taken 425 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
425 switch (posix_status) {
150 425 case 0:
151 425 status = Task::Status::OP_OK;
152 425 break;
153 case EINVAL:
154 status = Task::Status::INVALID_PARAMS;
155 break;
156 case EPERM:
157 status = Task::Status::ERROR_PERMISSION;
158 break;
159 case EAGAIN:
160 status = Task::Status::ERROR_RESOURCES;
161 break;
162 default:
163 status = Task::Status::UNKNOWN_ERROR;
164 break;
165 }
166 425 return status;
167 }
168
169 16917598 Mutex::Status posix_status_to_mutex_status(int posix_status) {
170 16917598 Mutex::Status status = Mutex::Status::ERROR_OTHER;
171
1/4
✓ Branch 0 taken 21585064 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
16917598 switch (posix_status) {
172 21585064 case 0:
173 21585064 status = Mutex::Status::OP_OK;
174 21585064 break;
175 case EBUSY:
176 status = Mutex::Status::ERROR_BUSY;
177 break;
178 case EDEADLK:
179 status = Mutex::Status::ERROR_DEADLOCK;
180 break;
181 default:
182 status = Mutex::Status::ERROR_OTHER;
183 break;
184 }
185 16917598 return status;
186 }
187
188 10 ConditionVariable::Status posix_status_to_conditional_status(int posix_status) {
189 10 ConditionVariable::Status status = ConditionVariable::Status::ERROR_OTHER;
190
1/3
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
10 switch (posix_status) {
191 10 case 0:
192 10 status = ConditionVariable::Status::OP_OK;
193 10 break;
194 case EPERM:
195 status = ConditionVariable::Status::ERROR_MUTEX_NOT_HELD;
196 break;
197 default:
198 status = ConditionVariable::Status::ERROR_OTHER;
199 break;
200 }
201 10 return status;
202 }
203
204 4 CountingSemaphore::Status posix_status_to_semaphore_status(int posix_status) {
205 4 CountingSemaphore::Status status = CountingSemaphore::Status::ERROR_OTHER;
206
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4 switch (posix_status) {
207 case 0:
208 status = CountingSemaphore::Status::OP_OK;
209 break;
210 4 case ETIMEDOUT:
211 case EAGAIN:
212 4 status = CountingSemaphore::Status::ERROR_TIMEOUT;
213 4 break;
214 case EINVAL:
215 status = CountingSemaphore::Status::ERROR_INVALID;
216 break;
217 default:
218 status = CountingSemaphore::Status::ERROR_OTHER;
219 break;
220 }
221 4 return status;
222 }
223 } // namespace Posix
224 } // namespace Os
225