Debian Codegraph @

src/Platforms/Keil/UtestPlatform.cpp

raw symbols SCIP
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 <stdlib.h>
29 #include "CppUTest/TestHarness.h"
30 #undef malloc
31 #undef free
32 #undef calloc
33 #undef realloc
34 #undef strdup
35 #undef strndup
36
37 #define far // eliminate "meaningless type qualifier" warning
38 #include <time.h>
39 #include <stdio.h>
40 #include <stdarg.h>
41 #include <setjmp.h>
42 #include <string.h>
43 #include <math.h>
44 #include <ctype.h>
45
46 #include "CppUTest/PlatformSpecificFunctions.h"
47
48 static jmp_buf test_exit_jmp_buf[10];
49 static int jmp_buf_index = 0;
50
51 TestOutput::WorkingEnvironment PlatformSpecificGetWorkingEnvironment()
52 {
53 return TestOutput::eclipse;
54 }
55
56 static void DummyRunTestInASeperateProcess(UtestShell* shell, TestPlugin* plugin, TestResult* result)
57 {
58 result->addFailure(TestFailure(shell, "-p doesn't work on this platform, as it is lacking fork.\b"));
59 }
60
61 static int DummyPlatformSpecificFork(void)
62 {
63 return 0;
64 }
65
66 static int DummyPlatformSpecificWaitPid(int, int*, int)
67 {
68 return 0;
69 }
70
71 void (*PlatformSpecificRunTestInASeperateProcess)(UtestShell*, TestPlugin*, TestResult*) = DummyRunTestInASeperateProcess;
72 int (*PlatformSpecificFork)() = DummyPlatformSpecificFork;
73 int (*PlatformSpecificWaitPid)(int, int*, int) = DummyPlatformSpecificWaitPid;
74
75 extern "C"
76 {
77
78 static int PlatformSpecificSetJmpImplementation(void (*function) (void* data), void* data)
79 {
80 if (0 == setjmp(test_exit_jmp_buf[jmp_buf_index])) {
81 jmp_buf_index++;
82 function(data);
83 jmp_buf_index--;
84 return 1;
85 }
86 return 0;
87 }
88
89 static void PlatformSpecificLongJmpImplementation()
90 {
91 jmp_buf_index--;
92 longjmp(test_exit_jmp_buf[jmp_buf_index], 1);
93 }
94
95 static void PlatformSpecificRestoreJumpBufferImplementation()
96 {
97 jmp_buf_index--;
98 }
99
100 void (*PlatformSpecificLongJmp)() = PlatformSpecificLongJmpImplementation;
101 int (*PlatformSpecificSetJmp)(void (*function)(void*), void*) = PlatformSpecificSetJmpImplementation;
102 void (*PlatformSpecificRestoreJumpBuffer)() = PlatformSpecificRestoreJumpBufferImplementation;
103
104
105
106 ///////////// Time in millis
107 /*
108 * In Keil MDK-ARM, clock() default implementation used semihosting.
109 * Resolutions is user adjustable (1 ms for now)
110 */
111 static long TimeInMillisImplementation()
112 {
113 clock_t t = clock();
114
115 t = t * 10;
116
117 return t;
118 }
119
120 long (*GetPlatformSpecificTimeInMillis)() = TimeInMillisImplementation;
121
122 static const char* TimeStringImplementation()
123 {
124 time_t tm = 0;//time(NULL); // todo
125 return ctime(&tm);
126 }
127
128 const char* (*GetPlatformSpecificTimeString)() = TimeStringImplementation;
129
130 int PlatformSpecificAtoI(const char* str)
131 {
132 return atoi(str);
133 }
134
135 /* The ARMCC compiler will compile this function with C++ linkage, unless
136 * we specifically tell it to use C linkage again, in the function definiton.
137 */
138 extern int (*PlatformSpecificVSNprintf)(char *str, size_t size, const char* format, va_list args) = vsnprintf;
139
140 static PlatformSpecificFile PlatformSpecificFOpenImplementation(const char* filename, const char* flag)
141 {
142 return 0;
143 }
144
145 static void PlatformSpecificFPutsImplementation(const char* str, PlatformSpecificFile file)
146 {
147 printf("%s", str);
148 }
149
150 static void PlatformSpecificFCloseImplementation(PlatformSpecificFile file)
151 {
152 }
153
154 static void PlatformSpecificFlushImplementation()
155 {
156 }
157
158 PlatformSpecificFile (*PlatformSpecificFOpen)(const char*, const char*) = PlatformSpecificFOpenImplementation;
159 void (*PlatformSpecificFPuts)(const char*, PlatformSpecificFile) = PlatformSpecificFPutsImplementation;
160 void (*PlatformSpecificFClose)(PlatformSpecificFile) = PlatformSpecificFCloseImplementation;
161
162 int (*PlatformSpecificPutchar)(int) = putchar;
163 void (*PlatformSpecificFlush)() = PlatformSpecificFlushImplementation;
164 void* (*PlatformSpecificMalloc)(size_t) = malloc;
165 void* (*PlatformSpecificRealloc) (void*, size_t) = realloc;
166 void (*PlatformSpecificFree)(void*) = free;
167 void* (*PlatformSpecificMemCpy)(void* s1, const void* s2, size_t size) = memcpy;
168 void* (*PlatformSpecificMemset)(void*, int, size_t) = memset;
169
170 static int IsNanImplementation(double d)
171 {
172 # ifdef __MICROLIB
173 return 0;
174 # else
175 return isnan(d);
176 # endif
177 }
178
179 static int IsInfImplementation(double d)
180 {
181 # ifdef __MICROLIB
182 return 0;
183 # else
184 return isinf(d);
185 # endif
186 }
187
188 int DummyAtExit(void(*)(void))
189 {
190 return 0;
191 }
192
193 double (*PlatformSpecificFabs)(double) = abs;
194 int (*PlatformSpecificIsNan)(double) = IsNanImplementation;
195 int (*PlatformSpecificIsInf)(double) = IsInfImplementation;
196 int (*PlatformSpecificAtExit)(void(*func)(void)) = DummyAtExit;
197
198 static PlatformSpecificMutex DummyMutexCreate(void)
199 {
200 return 0;
201 }
202
203 static void DummyMutexLock(PlatformSpecificMutex mtx)
204 {
205 }
206
207 static void DummyMutexUnlock(PlatformSpecificMutex mtx)
208 {
209 }
210
211 static void DummyMutexDestroy(PlatformSpecificMutex mtx)
212 {
213 }
214
215 PlatformSpecificMutex (*PlatformSpecificMutexCreate)(void) = DummyMutexCreate;
216 void (*PlatformSpecificMutexLock)(PlatformSpecificMutex) = DummyMutexLock;
217 void (*PlatformSpecificMutexUnlock)(PlatformSpecificMutex) = DummyMutexUnlock;
218 void (*PlatformSpecificMutexDestroy)(PlatformSpecificMutex) = DummyMutexDestroy;
219
220 }