glsl-1.10: test mesa bug with forward declaration
[piglit.git] / tests / util / piglit-util-waffle.c
blob139500d9c73ca68310bf0d3abccaa4a639c610bb
1 /*
2 * Copyright © 2012 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 <assert.h>
25 #include <stdio.h>
27 #include "piglit-util-gl.h"
28 #include "piglit-util-waffle.h"
30 static void
31 wfl_log(FILE *out, const char *tag, const char *func_name)
33 const struct waffle_error_info *info = waffle_error_get_info();
35 assert(tag != NULL);
36 assert(info->code != WAFFLE_NO_ERROR);
38 if (out != stdout)
39 fflush(stdout);
40 fprintf(out, "piglit: %s: %s failed due to %s",
41 tag, func_name, waffle_error_to_string(info->code));
42 if (info->message_length > 0)
43 fprintf(out, ": %s", info->message);
44 fprintf(out, "\n");
47 void
48 wfl_log_debug(const char *func_name)
50 static int debug = -1;
52 if (debug == -1) {
53 const char *env = getenv("PIGLIT_DEBUG");
54 if (env == NULL) {
55 debug = 0;
56 } else if (strcmp(env, "0") == 0) {
57 debug = 0;
58 } else if (strcmp(env, "1") == 0) {
59 debug = 1;
60 } else {
61 fprintf(stderr, "PIGLIT_DEBUG has invalid value:"
62 " %s\n", env);
63 abort();
67 if (debug == 1)
68 wfl_log(stderr, "debug", func_name);
71 void
72 wfl_log_error(const char *func_name)
74 wfl_log(stderr, "error", func_name);
77 void
78 wfl_log_error_stdout(const char *func_name)
80 wfl_log(stdout, "error", func_name);
83 void
84 wfl_fatal_error(const char *func_name)
86 const struct waffle_error_info *info = waffle_error_get_info();
88 assert(info->code != WAFFLE_NO_ERROR);
90 wfl_log_error(func_name);
92 if (info->code == WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM ||
93 info->code == WAFFLE_ERROR_BUILT_WITHOUT_SUPPORT)
94 piglit_report_result(PIGLIT_SKIP);
95 else
96 piglit_report_result(PIGLIT_FAIL);