glx-multithread-texture: Avoid front-buffer rendering.
[piglit.git] / tests / util / piglit-log.c
blobec5afcd7e101dcd438f1b2ee1ef18880c1f5ed79
1 /*
2 * Copyright 2014 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 #include <inttypes.h>
25 #include <stdio.h>
26 #include <stdarg.h>
28 #include "piglit-log.h"
29 #include "piglit-util.h"
31 struct piglit_log_opt_list {
32 intptr_t val;
33 bool is_env_set;
36 /**
37 * Array of logging options, one entry for each value of enum piglit_log_opt.
39 static struct piglit_log_opt_list opts[PIGLIT_LOG_OPT_MAX + 1];
41 static void
42 get_env_overrides(void)
44 static bool once = true;
45 const char *env = NULL;
47 if (!once) {
48 return;
50 once = false;
52 env = getenv("PIGLIT_LOG_PRINT_TID");
53 if (env && !streq(env, "")) {
54 opts[PIGLIT_LOG_PRINT_TID].is_env_set = true;
55 opts[PIGLIT_LOG_PRINT_TID].val = atoi(env);
59 /** Is option out of bounds? */
60 static bool
61 is_opt_oob(enum piglit_log_opt opt)
63 return opt > PIGLIT_LOG_OPT_MAX;
66 intptr_t
67 piglit_log_get_opt(enum piglit_log_opt opt)
69 get_env_overrides();
71 if (is_opt_oob(opt)) {
72 return 0;
75 return opts[opt].val;
78 void
79 piglit_log_set_opt(enum piglit_log_opt opt, intptr_t value) {
80 get_env_overrides();
82 if (is_opt_oob(opt) || opts[opt].is_env_set) {
83 return;
86 opts[opt].val = value;
89 static void
90 piglit_log_tagv(const char *tag, const char *fmt, va_list ap)
92 printf("piglit");
93 if (piglit_log_get_opt(PIGLIT_LOG_PRINT_TID)) {
94 printf("(%"PRIu64")", piglit_gettid());
96 printf(": %s: ", tag);
97 vprintf(fmt, ap);
98 printf("\n");
101 void
102 piglit_loge(const char *fmt, ...)
104 va_list ap;
105 va_start(ap, fmt);
106 piglit_log_tagv("error", fmt, ap);
107 va_end(ap);
110 void
111 piglit_logi(const char *fmt, ...)
113 va_list ap;
114 va_start(ap, fmt);
115 piglit_log_tagv("info", fmt, ap);
116 va_end(ap);
119 void
120 piglit_logd(const char *fmt, ...)
122 static bool once = true;
123 static bool debug = false;
124 va_list ap;
126 if (once) {
127 const char *env;
129 once = false;
130 env = getenv("PIGLIT_DEBUG");
132 if (env == NULL
133 || streq(env, "")
134 || streq(env, "0")
135 || streq(env, "false")) {
136 debug = false;
137 } else if (streq(env, "1")
138 || streq(env, "true")) {
139 debug = true;
140 } else {
141 piglit_loge("PIGLIT_DEBUG has invalid value: "
142 "%s\n", env);
143 abort();
147 if (!debug) {
148 return;
151 va_start(ap, fmt);
152 piglit_log_tagv("debug", fmt, ap);
153 va_end(ap);