1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Helper Library
3 * -------------------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Debug output utilities.
22 *//*--------------------------------------------------------------------*/
24 #include "qpDebugOut.h"
26 #include "qpCrashHandler.h" /*!< for QP_USE_SIGNAL_HANDLER */
31 typedef enum MessageType_e
39 static void printRaw (MessageType type, const char* msg);
40 static void printFmt (MessageType type, const char* fmt, va_list args);
41 static void exitProcess (void);
43 void qpPrint (const char* message)
45 printRaw(MESSAGETYPE_INFO, message);
48 void qpPrintf (const char* format, ...)
51 va_start(args, format);
52 printFmt(MESSAGETYPE_INFO, format, args);
56 void qpPrintv (const char* format, va_list args)
58 printFmt(MESSAGETYPE_INFO, format, args);
61 void qpDief (const char* format, ...)
64 va_start(args, format);
65 printFmt(MESSAGETYPE_ERROR, format, args);
71 void qpDiev (const char* format, va_list args)
73 printFmt(MESSAGETYPE_ERROR, format, args);
77 /* print() implementation. */
78 #if (DE_OS == DE_OS_ANDROID)
80 #include <android/log.h>
82 static android_LogPriority getLogPriority (MessageType type)
86 case MESSAGETYPE_INFO: return ANDROID_LOG_INFO;
87 case MESSAGETYPE_ERROR: return ANDROID_LOG_FATAL;
88 default: return ANDROID_LOG_DEBUG;
92 void printRaw (MessageType type, const char* message)
94 __android_log_write(getLogPriority(type), "dEQP", message);
97 void printFmt (MessageType type, const char* format, va_list args)
99 __android_log_vprint(getLogPriority(type), "dEQP", format, args);
104 static FILE* getOutFile (MessageType type)
106 if (type == MESSAGETYPE_ERROR)
112 void printRaw (MessageType type, const char* message)
114 FILE* out = getOutFile(type);
116 if (type == MESSAGETYPE_ERROR)
117 fprintf(out, "FATAL ERROR: ");
121 if (type == MESSAGETYPE_ERROR)
128 void printFmt (MessageType type, const char* format, va_list args)
130 FILE* out = getOutFile(type);
132 if (type == MESSAGETYPE_ERROR)
133 fprintf(out, "FATAL ERROR: ");
135 vfprintf(out, format, args);
137 if (type == MESSAGETYPE_ERROR)
146 /* exitProcess() implementation. */
147 #if (DE_OS == DE_OS_WIN32)
151 #define WIN32_LEAN_AND_MEAN
154 static void exitProcess (void)
156 /* Some API implementations register atexit() functions that may hang.
157 By using TerminateProcess() we can avoid calling any potentially hanging exit routines. */
158 HANDLE curProc = GetCurrentProcess();
159 TerminateProcess(curProc, -1);
164 #if (DE_OS == DE_OS_IOS)
165 # include "deThread.h" /*!< for deSleep() */
168 #if defined(QP_USE_SIGNAL_HANDLER)
172 static void exitProcess (void)
174 #if (DE_OS == DE_OS_IOS)
175 /* Since tests are in the same process as execserver, we want to give it
176 a chance to stream complete log data before terminating. */
180 #if defined(QP_USE_SIGNAL_HANDLER)
181 /* QP_USE_SIGNAL_HANDLER defined, this means this function could have
182 been called from a signal handler. Calling exit() inside a signal
183 handler is not safe. */
185 /* Flush all open FILES */
188 /* Kill without calling any _at_exit handlers as those might hang */