GCC Code Coverage Report


Directory: ./
File: Os/Posix/error.cpp
Date: 2026-09-23 21:11:01
Exec Total Coverage
Lines: 89 176 50.6%
Functions: 8 8 100.0%
Branches: 19 48 39.6%

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 9673 File::Status errno_to_file_status(int errno_input) {
12 9673 File::Status status = File::Status::OP_OK;
13
8/9
✓ Branch 0 taken 71 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 9533 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 63 times.
✓ Branch 8 taken 1 times.
9673 switch (errno_input) {
14 71 case 0:
15 71 status = File::Status::OP_OK;
16 71 break;
17 // Fallthrough intended
18 1 case ENOSPC:
19 case EFBIG:
20 1 status = File::Status::NO_SPACE;
21 1 break;
22 9533 case ENOENT:
23 9533 status = File::Status::DOESNT_EXIST;
24 9533 break;
25 // Fallthrough intended
26 1 case EPERM:
27 case EACCES:
28 1 status = File::Status::NO_PERMISSION;
29 1 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 63 case EINVAL:
42 63 status = File::Status::INVALID_ARGUMENT;
43 63 break;
44 1 default:
45 1 status = File::Status::OTHER_ERROR;
46 1 break;
47 }
48 9673 return status;
49 }
50
51 7067 FileSystem::Status errno_to_filesystem_status(int errno_input) {
52 7067 FileSystem::Status status = FileSystem::Status::OP_OK;
53
3/14
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 7064 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.
7067 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 2 case EACCES:
59 2 status = FileSystem::Status::NO_PERMISSION;
60 2 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 7064 case ELOOP:
70 case ENOENT:
71 7064 status = FileSystem::Status::DOESNT_EXIST;
72 7064 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 7067 return status;
104 }
105
106 255 Directory::Status errno_to_directory_status(int errno_input) {
107 255 Directory::Status status = Directory::Status::OP_OK;
108
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 252 times.
✗ Branch 5 not taken.
255 switch (errno_input) {
109 ✗ case 0:
110 ✗ status = Directory::Status::OP_OK;
111 ✗ break;
112 3 case ENOENT:
113 3 status = Directory::Status::DOESNT_EXIST;
114 3 break;
115 ✗ case EACCES:
116 ✗ status = Directory::Status::NO_PERMISSION;
117 ✗ break;
118 ✗ case ENOTDIR:
119 ✗ status = Directory::Status::NOT_DIR;
120 ✗ break;
121 252 case EEXIST:
122 252 status = Directory::Status::ALREADY_EXISTS;
123 252 break;
124 ✗ default:
125 ✗ status = Directory::Status::OTHER_ERROR;
126 ✗ break;
127 }
128 255 return status;
129 }
130
131 1 RawTime::Status errno_to_rawtime_status(int errno_input) {
132 1 RawTime::Status status = RawTime::Status::OP_OK;
133
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 switch (errno_input) {
134 ✗ case 0:
135 ✗ status = RawTime::Status::OP_OK;
136 ✗ break;
137 1 case EINVAL:
138 1 status = RawTime::Status::INVALID_PARAMS;
139 1 break;
140 ✗ default:
141 ✗ status = RawTime::Status::OTHER_ERROR;
142 ✗ break;
143 }
144 1 return status;
145 }
146
147 1448 Task::Status posix_status_to_task_status(int posix_status) {
148 1448 Task::Status status = Task::Status::OP_OK;
149
2/5
✓ Branch 0 taken 1447 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1448 switch (posix_status) {
150 1447 case 0:
151 1447 status = Task::Status::OP_OK;
152 1447 break;
153 ✗ case EINVAL:
154 ✗ status = Task::Status::INVALID_PARAMS;
155 ✗ break;
156 1 case EPERM:
157 1 status = Task::Status::ERROR_PERMISSION;
158 1 break;
159 ✗ case EAGAIN:
160 ✗ status = Task::Status::ERROR_RESOURCES;
161 ✗ break;
162 ✗ default:
163 ✗ status = Task::Status::UNKNOWN_ERROR;
164 ✗ break;
165 }
166 1448 return status;
167 }
168
169 10199907 Mutex::Status posix_status_to_mutex_status(int posix_status) {
170 10199907 Mutex::Status status = Mutex::Status::ERROR_OTHER;
171
1/4
✓ Branch 0 taken 13709691 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10199907 switch (posix_status) {
172 13709691 case 0:
173 13709691 status = Mutex::Status::OP_OK;
174 13709691 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 10199907 return status;
186 }
187
188 14 ConditionVariable::Status posix_status_to_conditional_status(int posix_status) {
189 14 ConditionVariable::Status status = ConditionVariable::Status::ERROR_OTHER;
190
1/3
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
14 switch (posix_status) {
191 14 case 0:
192 14 status = ConditionVariable::Status::OP_OK;
193 14 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 14 return status;
202 }
203
204 16 CountingSemaphore::Status posix_status_to_semaphore_status(int posix_status) {
205 16 CountingSemaphore::Status status = CountingSemaphore::Status::ERROR_OTHER;
206
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
16 switch (posix_status) {
207 ✗ case 0:
208 ✗ status = CountingSemaphore::Status::OP_OK;
209 ✗ break;
210 16 case ETIMEDOUT:
211 case EAGAIN:
212 16 status = CountingSemaphore::Status::ERROR_TIMEOUT;
213 16 break;
214 ✗ case EINVAL:
215 ✗ status = CountingSemaphore::Status::ERROR_INVALID;
216 ✗ break;
217 ✗ default:
218 ✗ status = CountingSemaphore::Status::ERROR_OTHER;
219 ✗ break;
220 }
221 16 return status;
222 }
223 } // namespace Posix
224 } // namespace Os
225