• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thetic / cpputest / 14350937103

09 Apr 2025 06:30AM UTC coverage: 96.186%. Remained the same
14350937103

push

github

thetic
no WorkingEnvironment

6254 of 6502 relevant lines covered (96.19%)

17609.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.07
/CppUTest/Platforms/Gcc/UtestPlatform.cpp
1
/*
2
 * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *     * Redistributions of source code must retain the above copyright
8
 *       notice, this list of conditions and the following disclaimer.
9
 *     * Redistributions in binary form must reproduce the above copyright
10
 *       notice, this list of conditions and the following disclaimer in the
11
 *       documentation and/or other materials provided with the distribution.
12
 *     * Neither the name of the <organization> nor the
13
 *       names of its contributors may be used to endorse or promote products
14
 *       derived from this software without specific prior written permission.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY
17
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
 * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
20
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 */
27

28
#include "CppUTest/TestHarness.h"
29

30
#include "CppUTest/PlatformSpecificFunctions.h"
31

32
#ifdef CPPUTEST_HAVE_GETTIMEOFDAY
33
#include <sys/time.h>
34
#endif
35

36
#include <ctype.h>
37
#include <math.h>
38
#include <setjmp.h>
39
#include <stdarg.h>
40
#include <stdio.h>
41
#include <stdlib.h>
42
#include <string.h>
43
#include <time.h>
44

45
static jmp_buf test_exit_jmp_buf[10];
46
static int jmp_buf_index = 0;
47

48
extern "C" {
49

50
static int PlatformSpecificSetJmpImplementation(void (*function) (void* data), void* data)
6,002✔
51
{
52
    if (0 == setjmp(test_exit_jmp_buf[jmp_buf_index])) {
6,002✔
53
        jmp_buf_index++;
6,002✔
54
        function(data);
6,002✔
55
        jmp_buf_index--;
5,846✔
56
        return 1;
5,846✔
57
    }
58
    return 0;
43✔
59
}
60

61
[[noreturn]] static void PlatformSpecificLongJmpImplementation()
43✔
62
{
63
    jmp_buf_index--;
43✔
64
    longjmp(test_exit_jmp_buf[jmp_buf_index], 1);
43✔
65
}
66

67
static void PlatformSpecificRestoreJumpBufferImplementation()
111✔
68
{
69
    jmp_buf_index--;
111✔
70
}
111✔
71

72
void (*PlatformSpecificLongJmp)() = PlatformSpecificLongJmpImplementation;
73
int (*PlatformSpecificSetJmp)(void (*)(void*), void*) = PlatformSpecificSetJmpImplementation;
74
void (*PlatformSpecificRestoreJumpBuffer)() = PlatformSpecificRestoreJumpBufferImplementation;
75

76
///////////// Time in millis
77

78
static unsigned long TimeInMillisImplementation()
9,936✔
79
{
80
#ifdef CPPUTEST_HAVE_GETTIMEOFDAY
81
    struct timeval tv;
82
    gettimeofday(&tv, NULL);
83
    return (((unsigned long)tv.tv_sec * 1000) + ((unsigned long)tv.tv_usec / 1000));
84
#else
85
    return 0;
9,936✔
86
#endif
87
}
88

89
static const char* TimeStringImplementation()
1✔
90
{
91
    time_t theTime = time(nullptr);
1✔
92
    static char dateTime[80];
93
#ifdef STDC_WANT_SECURE_LIB
94
    static struct tm lastlocaltime;
95
    localtime_s(&lastlocaltime, &theTime);
96
    struct tm *tmp = &lastlocaltime;
97
#else
98
    struct tm *tmp = localtime(&theTime);
1✔
99
#endif
100
    strftime(dateTime, 80, "%Y-%m-%dT%H:%M:%S", tmp);
1✔
101
    return dateTime;
1✔
102
}
103

104
unsigned long (*GetPlatformSpecificTimeInMillis)() = TimeInMillisImplementation;
105
const char* (*GetPlatformSpecificTimeString)() = TimeStringImplementation;
106

107
/* Wish we could add an attribute to the format for discovering mis-use... but the __attribute__(format) seems to not work on va_list */
108
#ifdef __clang__
109
#pragma clang diagnostic ignored "-Wformat-nonliteral"
110
#endif
111

112
#ifdef __clang__
113
#pragma clang diagnostic ignored "-Wused-but-marked-unused"
114
#endif
115
int (*PlatformSpecificVSNprintf)(char *str, size_t size, const char* format, va_list va_args_list) = vsnprintf;
116

117
static PlatformSpecificFile PlatformSpecificFOpenImplementation(const char* filename, const char* flag)
×
118
{
119
#ifdef STDC_WANT_SECURE_LIB
120
  FILE* file;
121
   fopen_s(&file, filename, flag);
122
   return file;
123
#else
124
   return fopen(filename, flag);
×
125
#endif
126
}
127

128
static void PlatformSpecificFPutsImplementation(const char* str, PlatformSpecificFile file)
6,524✔
129
{
130
   fputs(str, (FILE*)file);
6,524✔
131
}
6,524✔
132

133
static void PlatformSpecificFCloseImplementation(PlatformSpecificFile file)
×
134
{
135
   fclose((FILE*)file);
×
136
}
×
137

138
static void PlatformSpecificFlushImplementation()
6,590✔
139
{
140
  fflush(stdout);
6,590✔
141
}
6,590✔
142

143
PlatformSpecificFile PlatformSpecificStdOut = stdout;
144

145
PlatformSpecificFile (*PlatformSpecificFOpen)(const char*, const char*) = PlatformSpecificFOpenImplementation;
146
void (*PlatformSpecificFPuts)(const char*, PlatformSpecificFile) = PlatformSpecificFPutsImplementation;
147
void (*PlatformSpecificFClose)(PlatformSpecificFile) = PlatformSpecificFCloseImplementation;
148

149
void (*PlatformSpecificFlush)() = PlatformSpecificFlushImplementation;
150

151
void* (*PlatformSpecificMalloc)(size_t size) = malloc;
152
void* (*PlatformSpecificRealloc)(void*, size_t) = realloc;
153
void (*PlatformSpecificFree)(void* memory) = free;
154
void* (*PlatformSpecificMemCpy)(void*, const void*, size_t) = memcpy;
155
void* (*PlatformSpecificMemset)(void*, int, size_t) = memset;
156

157
/* GCC 4.9.x introduces -Wfloat-conversion, which causes a warning / error
158
 * in GCC's own (macro) implementation of isnan() and isinf().
159
 */
160
#if defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ > 8))
161
#pragma GCC diagnostic ignored "-Wfloat-conversion"
162
#endif
163

164
static int IsNanImplementation(double d)
287✔
165
{
166
    return isnan(d);
287✔
167
}
168

169
static int IsInfImplementation(double d)
119✔
170
{
171
    return isinf(d);
119✔
172
}
173

174
double (*PlatformSpecificFabs)(double) = fabs;
175
void (*PlatformSpecificSrand)(unsigned int) = srand;
176
int (*PlatformSpecificRand)(void) = rand;
177
int (*PlatformSpecificIsNan)(double) = IsNanImplementation;
178
int (*PlatformSpecificIsInf)(double) = IsInfImplementation;
179
int (*PlatformSpecificAtExit)(void(*func)(void)) = atexit;  /// this was undefined before
180

181
static PlatformSpecificMutex PThreadMutexCreate(void)
123✔
182
{
183
#ifdef CPPUTEST_HAVE_PTHREAD_MUTEX_LOCK
184
    pthread_mutex_t *mutex = new pthread_mutex_t;
185

186
    pthread_mutex_init(mutex, nullptr);
187
    return (PlatformSpecificMutex)mutex;
188
#else
189
    return nullptr;
123✔
190
#endif
191

192
}
193

194
#ifdef CPPUTEST_HAVE_PTHREAD_MUTEX_LOCK
195
static void PThreadMutexLock(PlatformSpecificMutex mtx)
196
{
197
    pthread_mutex_lock((pthread_mutex_t *)mtx);
198
}
199
#else
200
static void PThreadMutexLock(PlatformSpecificMutex)
×
201
{
202
}
×
203
#endif
204

205
#ifdef CPPUTEST_HAVE_PTHREAD_MUTEX_LOCK
206
static void PThreadMutexUnlock(PlatformSpecificMutex mtx)
207
{
208
    pthread_mutex_unlock((pthread_mutex_t *)mtx);
209
}
210
#else
211
static void PThreadMutexUnlock(PlatformSpecificMutex)
×
212
{
213
}
×
214
#endif
215

216
#ifdef CPPUTEST_HAVE_PTHREAD_MUTEX_LOCK
217
static void PThreadMutexDestroy(PlatformSpecificMutex mtx)
218
{
219
    pthread_mutex_t *mutex = (pthread_mutex_t *)mtx;
220
    pthread_mutex_destroy(mutex);
221
    delete mutex;
222
}
223
#else
224
static void PThreadMutexDestroy(PlatformSpecificMutex)
123✔
225
{
226
}
123✔
227
#endif
228

229
PlatformSpecificMutex (*PlatformSpecificMutexCreate)(void) = PThreadMutexCreate;
230
void (*PlatformSpecificMutexLock)(PlatformSpecificMutex) = PThreadMutexLock;
231
void (*PlatformSpecificMutexUnlock)(PlatformSpecificMutex) = PThreadMutexUnlock;
232
void (*PlatformSpecificMutexDestroy)(PlatformSpecificMutex) = PThreadMutexDestroy;
233
void (*PlatformSpecificAbort)(void) = abort;
234

235
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc