GCC Code Coverage Report


Directory: src/gate/
File: src/gate/results.c
Date: 2026-03-20 22:56:14
Exec Total Coverage
Lines: 21 61 34.4%
Functions: 2 2 100.0%
Branches: 12 52 23.1%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/results.h"
30 #include "gate/debugging.h"
31 #include "gate/strings.h"
32 #include "gate/platforms.h"
33
34 #if defined(GATE_SYS_ARDUINO)
35 # include <Arduino.h>
36 #else
37 # define PROGMEM
38 #endif
39
40 49 char const* gate_result_text(gate_result_t resultcode)
41 {
42 static char const STR_OK[] PROGMEM = "Succeeded";
43 static char const STR_OK_PARTIAL[] PROGMEM = "Partial success";
44
45 static char const STR_ERROR[] PROGMEM = "Error";
46 static char const STR_FAILED[] PROGMEM = "Operation failed";
47 static char const STR_CANCELED[] PROGMEM = "Operation canceled";
48 static char const STR_INVALIDARG[] PROGMEM = "Invalid argument";
49 static char const STR_ACCESSDENIED[] PROGMEM = "Access denied";
50 static char const STR_PERMISSIONDENIED[] PROGMEM = "Permission denied";
51 static char const STR_NOTDEFINED[] PROGMEM = "Not defined";
52 static char const STR_NOTAVAILABLE[] PROGMEM = "Not available";
53 static char const STR_NOTIMPLEMENTED[] PROGMEM = "Not implemented";
54 static char const STR_NOMATCH[] PROGMEM = "No match";
55 static char const STR_NOTSUPPORTED[] PROGMEM = "Not supported";
56 static char const STR_NOTREQUIRED[] PROGMEM = "Not required";
57 static char const STR_NOTREADY[] PROGMEM = "Not ready";
58 static char const STR_SECURITYBREACH[] PROGMEM = "Security breach";
59 static char const STR_ALREADYEXISTS[] PROGMEM = "Already exists";
60 static char const STR_INVALIDSTATE[] PROGMEM = "Invalid state";
61
62 static char const STR_OUTOFMEMORY[] PROGMEM = "Out of memory";
63 static char const STR_OUTOFRESOURCES[] PROGMEM = "Out of resources";
64 static char const STR_OUTOFBOUNDS[] PROGMEM = "Out of bounds";
65 static char const STR_NULLPOINTER[] PROGMEM = "Null pointer";
66 static char const STR_BADCAST[] PROGMEM = "Bad cast";
67 static char const STR_ARITHMETICERROR[] PROGMEM = "Arithmetic error";
68 static char const STR_OVERFLOW[] PROGMEM = "Overflow";
69 static char const STR_UNDERFLOW[] PROGMEM = "Underflow";
70 static char const STR_LOCKED[] PROGMEM = "Resource locked";
71 static char const STR_TIMEOUT[] PROGMEM = "Timeout reached";
72 static char const STR_BADADDRESS[] PROGMEM = "Bad address";
73 static char const STR_BLOCKED[] PROGMEM = "Resource blocked";
74
75 static char const STR_EXECUTIONFAILED[] PROGMEM = "Execution failed";
76 static char const STR_EXECUTIONINTERRUPTED[] PROGMEM = "Execution interrupted";
77 static char const STR_CRITICALERROR[] PROGMEM = "Critical error";
78 static char const STR_UNKNOWNEXCEPTION[] PROGMEM = "Unknown exception";
79
80 static char const STR_INVALIDHEADER[] PROGMEM = "Invalid header";
81 static char const STR_INVALIDDATA[] PROGMEM = "Invalid data";
82 static char const STR_INVALIDCONTENT[] PROGMEM = "Invalid content";
83 static char const STR_INCORRECTSIZE[] PROGMEM = "Incorrect size";
84 static char const STR_INCORRECTTYPE[] PROGMEM = "Incorrect type";
85 static char const STR_ENDOFSTREAM[] PROGMEM = "End of stream";
86 static char const STR_INVALIDINPUT[] PROGMEM = "Invalid input";
87 static char const STR_INVALIDOUTPUT[] PROGMEM = "Invalid output";
88 static char const STR_NODATA[] PROGMEM = "No data";
89
90 static char const STR_APPLICATIONERROR[] PROGMEM = "Application error";
91 static char const STR_LOGICALERROR[] PROGMEM = "Logical error";
92 static char const STR_USERERROR[] PROGMEM = "User error";
93
94 static char const STR_UNKNOWNERROR[] PROGMEM = "Unknown error";
95
96
10/48
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 21 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 7 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✓ Branch 32 taken 2 times.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
49 switch (resultcode)
97 {
98 1 case GATE_RESULT_OK: return STR_OK;
99 case GATE_RESULT_OK_PARTIAL: return STR_OK_PARTIAL;
100
101 case GATE_RESULT_ERROR: return STR_ERROR;
102 12 case GATE_RESULT_FAILED: return STR_FAILED;
103 1 case GATE_RESULT_CANCELED: return STR_CANCELED;
104 case GATE_RESULT_INVALIDARG: return STR_INVALIDARG;
105 case GATE_RESULT_ACCESSDENIED: return STR_ACCESSDENIED;
106 case GATE_RESULT_PERMISSIONDENIED: return STR_PERMISSIONDENIED;
107 case GATE_RESULT_NOTDEFINED: return STR_NOTDEFINED;
108 case GATE_RESULT_NOTAVAILABLE: return STR_NOTAVAILABLE;
109 2 case GATE_RESULT_NOTIMPLEMENTED: return STR_NOTIMPLEMENTED;
110 case GATE_RESULT_NOMATCH: return STR_NOMATCH;
111 21 case GATE_RESULT_NOTSUPPORTED: return STR_NOTSUPPORTED;
112 case GATE_RESULT_NOTREQUIRED: return STR_NOTREQUIRED;
113 case GATE_RESULT_NOTREADY: return STR_NOTREADY;
114 case GATE_RESULT_SECURITYBREACH: return STR_SECURITYBREACH;
115 case GATE_RESULT_ALREADYEXISTS: return STR_ALREADYEXISTS;
116 7 case GATE_RESULT_INVALIDSTATE: return STR_INVALIDSTATE;
117
118 /* RESOURCE ACCESS ERRORS */
119 case GATE_RESULT_OUTOFMEMORY: return STR_OUTOFMEMORY;
120 case GATE_RESULT_OUTOFRESOURCES: return STR_OUTOFRESOURCES;
121 case GATE_RESULT_OUTOFBOUNDS: return STR_OUTOFBOUNDS;
122 case GATE_RESULT_NULLPOINTER: return STR_NULLPOINTER;
123 case GATE_RESULT_BADCAST: return STR_BADCAST;
124 case GATE_RESULT_ARITHMETICERROR: return STR_ARITHMETICERROR;
125 case GATE_RESULT_OVERFLOW: return STR_OVERFLOW;
126 case GATE_RESULT_UNDERFLOW: return STR_UNDERFLOW;
127 case GATE_RESULT_LOCKED: return STR_LOCKED;
128 1 case GATE_RESULT_TIMEOUT: return STR_TIMEOUT;
129 case GATE_RESULT_BADADDRESS: return STR_BADADDRESS;
130 case GATE_RESULT_BLOCKED: return STR_BLOCKED;
131
132 /* EXECUTION ERRORS */
133 case GATE_RESULT_EXECUTIONFAILED: return STR_EXECUTIONFAILED;
134 case GATE_RESULT_EXECUTIONINTERRUPTED: return STR_EXECUTIONINTERRUPTED;
135 2 case GATE_RESULT_CRITICALERROR: return STR_CRITICALERROR;
136 1 case GATE_RESULT_UNKNOWNEXCEPTION: return STR_UNKNOWNEXCEPTION;
137
138 /* DATA ERRORS */
139 case GATE_RESULT_INVALIDHEADER: return STR_INVALIDHEADER;
140 case GATE_RESULT_INVALIDDATA: return STR_INVALIDDATA;
141 1 case GATE_RESULT_INVALIDCONTENT: return STR_INVALIDCONTENT;
142 case GATE_RESULT_INCORRECTSIZE: return STR_INCORRECTSIZE;
143 case GATE_RESULT_INCORRECTTYPE: return STR_INCORRECTTYPE;
144 case GATE_RESULT_ENDOFSTREAM: return STR_ENDOFSTREAM;
145 case GATE_RESULT_INVALIDINPUT: return STR_INVALIDINPUT;
146 case GATE_RESULT_INVALIDOUTPUT: return STR_INVALIDOUTPUT;
147 case GATE_RESULT_NODATA: return STR_NODATA;
148
149 case GATE_RESULT_APPLICATIONERROR: return STR_APPLICATIONERROR;
150 case GATE_RESULT_LOGICALERROR: return STR_LOGICALERROR;
151 case GATE_RESULT_USERERROR: return STR_USERERROR;
152
153 case GATE_RESULT_UNKNOWNERROR: return STR_UNKNOWNERROR;
154 }
155 return NULL;
156 }
157
158
159 2 void gate_panic(gate_result_t resultcode, char const* message)
160 {
161 #if defined(GATE_DEBUG_MODE)
162 char const* messages[4];
163 2 gate_size_t message_len = gate_str_length(message);
164 gate_size_t messages_count;
165
166 2 messages[0] = gate_result_text(resultcode);
167
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (message_len > 0)
168 {
169 2 messages[1] = ": ";
170 2 messages[2] = message;
171 2 messages_count = 3;
172 }
173 else
174 {
175 messages_count = 1;
176 }
177
178 2 gate_debug_trace_messages(messages, messages_count);
179 #endif
180
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 gate_platform_exit(GATE_RESULT_TO_EXITCODE(resultcode));
181 }
182