GCC Code Coverage Report


Directory: ./
File: Os/Posix/error.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 79 176 44.9%
Functions: 7 8 87.5%
Branches: 17 48 35.4%

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 9231 File::Status errno_to_file_status(int errno_input) {
12 9231 File::Status status = File::Status::OP_OK;
13
8/9
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 9099 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.
9231 switch (errno_input) {
14 63 case 0:
15 63 status = File::Status::OP_OK;
16 63 break;
17 // Fallthrough intended
18 1 case ENOSPC:
19 case EFBIG:
20 1 status = File::Status::NO_SPACE;
21 1 break;
22 9099 case ENOENT:
23 9099 status = File::Status::DOESNT_EXIST;
24 9099 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 9231 return status;
49 }
50
51 6765 FileSystem::Status errno_to_filesystem_status(int errno_input) {
52 6765 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 6762 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.
6765 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 6762 case ELOOP:
70 case ENOENT:
71 6762 status = FileSystem::Status::DOESNT_EXIST;
72 6762 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 6765 return status;
104 }
105
106 242 Directory::Status errno_to_directory_status(int errno_input) {
107 242 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 239 times.
✗ Branch 5 not taken.
242 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 239 case EEXIST:
122 239 status = Directory::Status::ALREADY_EXISTS;
123 239 break;
124 default:
125 status = Directory::Status::OTHER_ERROR;
126 break;
127 }
128 242 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 1459 Task::Status posix_status_to_task_status(int posix_status) {
148 1459 Task::Status status = Task::Status::OP_OK;
149
1/5
✓ Branch 0 taken 1459 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1459 switch (posix_status) {
150 1459 case 0:
151 1459 status = Task::Status::OP_OK;
152 1459 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 1459 return status;
167 }
168
169 26439221 Mutex::Status posix_status_to_mutex_status(int posix_status) {
170 26439221 Mutex::Status status = Mutex::Status::ERROR_OTHER;
171
1/4
✓ Branch 0 taken 35356057 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
26439221 switch (posix_status) {
172 35356057 case 0:
173 35356057 status = Mutex::Status::OP_OK;
174 35356057 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 26439221 return status;
186 }
187
188 12 ConditionVariable::Status posix_status_to_conditional_status(int posix_status) {
189 12 ConditionVariable::Status status = ConditionVariable::Status::ERROR_OTHER;
190
1/3
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
12 switch (posix_status) {
191 12 case 0:
192 12 status = ConditionVariable::Status::OP_OK;
193 12 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 12 return status;
202 }
203
204 13 CountingSemaphore::Status posix_status_to_semaphore_status(int posix_status) {
205 13 CountingSemaphore::Status status = CountingSemaphore::Status::ERROR_OTHER;
206
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
13 switch (posix_status) {
207 case 0:
208 status = CountingSemaphore::Status::OP_OK;
209 break;
210 13 case ETIMEDOUT:
211 case EAGAIN:
212 13 status = CountingSemaphore::Status::ERROR_TIMEOUT;
213 13 break;
214 case EINVAL:
215 status = CountingSemaphore::Status::ERROR_INVALID;
216 break;
217 default:
218 status = CountingSemaphore::Status::ERROR_OTHER;
219 break;
220 }
221 13 return status;
222 }
223 } // namespace Posix
224 } // namespace Os
225