diff options
author | Blaž Tomažič <blaz.tomazic@gmail.com> | 2012-06-28 02:44:49 +0200 |
---|---|---|
committer | Blaž Tomažič <blaz.tomazic@gmail.com> | 2012-06-28 03:52:38 +0200 |
commit | c06e719fb247b548644be9fb9b6603e8a06fbe0e (patch) | |
tree | e47244bf83f97abe58169156c19c4982b3086cdf | |
parent | 2d3c6e51c25a6915d1fc74a13d2b57591bcf4ea8 (diff) |
util: Move API-independent code to piglit-util
Move API-independent code from piglit-util-gl-common.c and
piglit-util-gl-common.h to piglit-util.c and piglit-util.h respectively.
Signed-off-by: Blaž Tomažič <blaz.tomazic@gmail.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
-rw-r--r-- | tests/util/CMakeLists.gl.txt | 1 | ||||
-rw-r--r-- | tests/util/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/util/piglit-util-gl-common.c | 198 | ||||
-rw-r--r-- | tests/util/piglit-util-gl-common.h | 96 | ||||
-rw-r--r-- | tests/util/piglit-util.c | 223 | ||||
-rw-r--r-- | tests/util/piglit-util.h | 133 |
6 files changed, 359 insertions, 293 deletions
diff --git a/tests/util/CMakeLists.gl.txt b/tests/util/CMakeLists.gl.txt index 82231497a..f6ec83af1 100644 --- a/tests/util/CMakeLists.gl.txt +++ b/tests/util/CMakeLists.gl.txt @@ -28,6 +28,7 @@ IF(BUILD_GLX_TESTS) piglit-shader.c piglit-shader-gl.c piglit-transform-feedback.c + piglit-util.c piglit-util-gl-common.c piglit-util-enum.c piglit-util-gl.c diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt index d56efcc78..237949f58 100644 --- a/tests/util/CMakeLists.txt +++ b/tests/util/CMakeLists.txt @@ -13,6 +13,7 @@ endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(UTIL_SOURCES fdo-bitmap.c + piglit-util.c piglit-util-gl-common.c piglit-util-enum.c shader-load.c diff --git a/tests/util/piglit-util-gl-common.c b/tests/util/piglit-util-gl-common.c index a70928d99..661fae032 100644 --- a/tests/util/piglit-util-gl-common.c +++ b/tests/util/piglit-util-gl-common.c @@ -21,76 +21,9 @@ * USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#if defined(_WIN32) -#include <windows.h> -#endif - -#include <assert.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> - -#include "config.h" -#if defined(HAVE_SYS_TIME_H) && defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_SETRLIMIT) -#include <sys/time.h> -#include <sys/resource.h> -#define USE_SETRLIMIT -#endif - #include "piglit-util-gl-common.h" -#if defined(_WIN32) - -/* Some versions of MinGW are missing _vscprintf's declaration, although they - * still provide the symbol in the import library. - */ -#ifdef __MINGW32__ -_CRTIMP int _vscprintf(const char *format, va_list argptr); -#endif - -int asprintf(char **strp, const char *fmt, ...) -{ - va_list args; - va_list args_copy; - int length; - size_t size; - - va_start(args, fmt); - - va_copy(args_copy, args); - -#ifdef _WIN32 - /* We need to use _vcsprintf to calculate the length as vsnprintf returns -1 - * if the number of characters to write is greater than count. - */ - length = _vscprintf(fmt, args_copy); -#else - char dummy; - length = vsnprintf(&dummy, sizeof dummy, fmt, args_copy); -#endif - - va_end(args_copy); - - assert(length >= 0); - size = length + 1; - - *strp = malloc(size); - if (!*strp) { - return -1; - } - - va_start(args, fmt); - vsnprintf(*strp, size, fmt, args); - va_end(args); - - return length; -} - -#endif /* _WIN32 */ - bool piglit_is_gles() { const char *version_string = (const char *) glGetString(GL_VERSION); @@ -122,35 +55,6 @@ int piglit_get_gl_version() return 10*major+minor; } -bool piglit_is_extension_in_string(const char *haystack, const char *needle) -{ - const unsigned needle_len = strlen(needle); - - if (needle_len == 0) - return false; - - while (true) { - const char *const s = strstr(haystack, needle); - - if (s == NULL) - return false; - - if (s[needle_len] == ' ' || s[needle_len] == '\0') { - return true; - } - - /* strstr found an extension whose name begins with - * needle, but whose name is not equal to needle. - * Restart the search at s + needle_len so that we - * don't just find the same extension again and go - * into an infinite loop. - */ - haystack = s + needle_len; - } - - return false; -} - bool piglit_is_extension_supported(const char *name) { const char *const extensions = @@ -310,43 +214,6 @@ const GLenum cube_face_targets[6] = { GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, }; -/** Returns the line in the program string given the character position. */ -int FindLine(const char *program, int position) -{ - int i, line = 1; - for (i = 0; i < position; i++) { - if (program[i] == '0') - return -1; /* unknown line */ - if (program[i] == '\n') - line++; - } - return line; -} - -void -piglit_report_result(enum piglit_result result) -{ - fflush(stderr); - - if (result == PIGLIT_PASS) { - printf("PIGLIT: {'result': 'pass' }\n"); - fflush(stdout); - exit(0); - } else if (result == PIGLIT_SKIP) { - printf("PIGLIT: {'result': 'skip' }\n"); - fflush(stdout); - exit(0); - } else if (result == PIGLIT_WARN) { - printf("PIGLIT: {'result': 'warn' }\n"); - fflush(stdout); - exit(0); - } else { - printf("PIGLIT: {'result': 'fail' }\n"); - fflush(stdout); - exit(1); - } -} - float piglit_tolerance[4] = { 0.01, 0.01, 0.01, 0.01 }; void @@ -367,71 +234,6 @@ piglit_set_tolerance_for_bits(int rbits, int gbits, int bbits, int abits) } } - -#ifndef HAVE_STRCHRNUL -char *strchrnul(const char *s, int c) -{ - char *t = strchr(s, c); - - return (t == NULL) ? ((char *) s + strlen(s)) : t; -} -#endif - - -void -piglit_set_rlimit(unsigned long lim) -{ -#if defined(USE_SETRLIMIT) - struct rlimit rl; - if (getrlimit(RLIMIT_AS, &rl) != -1) { - printf("Address space limit = %lu, max = %lu\n", - (unsigned long) rl.rlim_cur, - (unsigned long) rl.rlim_max); - - if (rl.rlim_max > lim) { - printf("Resetting limit to %lu.\n", lim); - - rl.rlim_cur = lim; - rl.rlim_max = lim; - if (setrlimit(RLIMIT_AS, &rl) == -1) { - printf("Could not set rlimit " - "due to: %s (%d)\n", - strerror(errno), errno); - } - } - } - - printf("\n"); -#else - printf("Cannot reset rlimit on this platform.\n\n"); -#endif -} - -/* Merges the PASS/FAIL/SKIP for @subtest into the overall result - * @all. - * - * The @all should start out initialized to PIGLIT_SKIP. - */ -void -piglit_merge_result(enum piglit_result *all, enum piglit_result subtest) -{ - switch (subtest) { - case PIGLIT_FAIL: - *all = PIGLIT_FAIL; - break; - case PIGLIT_WARN: - if (*all == PIGLIT_SKIP || *all == PIGLIT_PASS) - *all = PIGLIT_WARN; - break; - case PIGLIT_PASS: - if (*all == PIGLIT_SKIP) - *all = PIGLIT_PASS; - break; - case PIGLIT_SKIP: - break; - } -} - typedef union { GLfloat f; GLint i; } fi_type; /** diff --git a/tests/util/piglit-util-gl-common.h b/tests/util/piglit-util-gl-common.h index 6cac7e220..ca30e6d41 100644 --- a/tests/util/piglit-util-gl-common.h +++ b/tests/util/piglit-util-gl-common.h @@ -29,88 +29,17 @@ extern "C" { #endif -#include "config.h" - -#if defined(_WIN32) -#include <windows.h> -#endif - -#if defined(_MSC_VER) -#define log2(x) (log(x) / log(2)) -#endif - -#include <assert.h> -#include <stdbool.h> -#include <stdint.h> -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -#include <math.h> -#include <float.h> +#include "piglit-util.h" #include <piglit/gl_wrap.h> #include <piglit/glut_wrap.h> -#if defined(_MSC_VER) - -#define snprintf sprintf_s - -static __inline double -round(double x) { - return x >= 0.0 ? floor(x + 0.5) : ceil(x - 0.5); -} - -static __inline float -roundf(float x) { - return x >= 0.0f ? floorf(x + 0.5f) : ceilf(x - 0.5f); -} - -#ifndef va_copy -#ifdef __va_copy -#define va_copy(dest, src) __va_copy((dest), (src)) -#else -#define va_copy(dest, src) (dest) = (src) -#endif -#endif - -#endif /* defined(_MSC_VER) */ - -#ifdef _WIN32 -int asprintf(char **strp, const char *fmt, ...) -#ifdef __GNUC__ - __attribute__ ((format (printf, 2, 3))) -#endif -; -#endif /* _WIN32 */ - -// Trick from http://tdistler.com/2011/03/24/how-to-define-nan-not-a-number-on-windows -#ifndef INFINITY -# define INFINITY (FLT_MAX + FLT_MAX) -#endif -#ifndef NAN -# define NAN (INFINITY - INFINITY) -#endif - #define piglit_get_proc_address(x) piglit_dispatch_resolve_function(x) -enum piglit_result { - PIGLIT_PASS, - PIGLIT_FAIL, - PIGLIT_SKIP, - PIGLIT_WARN -}; - #include "piglit-framework.h" #include "piglit-shader.h" #include "piglit-transform-feedback.h" -#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) - -#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) ) -#define MIN2(a, b) ((a) > (b) ? (b) : (a)) -#define MAX2(a, b) ((a) > (b) ? (a) : (b)) - extern const uint8_t fdo_bitmap[]; extern const unsigned int fdo_bitmap_width; extern const unsigned int fdo_bitmap_height; @@ -129,18 +58,6 @@ bool piglit_is_gles(); int piglit_get_gl_version(); /** - * Determine if an extension is listed in an extension string - * - * \param haystack List of all extensions to be searched - * \param needle Extension whose presens is to be detected - * - * \precondition \c haystack is not null - * - * \sa piglit_is_extension_supported, piglit_is_glx_extension_supported - */ -bool piglit_is_extension_in_string(const char *haystack, const char *needle); - -/** * \precondition name is not null */ bool piglit_is_extension_supported(const char *name); @@ -182,9 +99,6 @@ piglit_check_gl_error_(GLenum expected_error, const char *file, unsigned line); */ void piglit_reset_gl_error(void); -int FindLine(const char *program, int position); -void piglit_merge_result(enum piglit_result *all, enum piglit_result subtest); -void piglit_report_result(enum piglit_result result); void piglit_require_gl_version(int required_version_times_10); void piglit_require_extension(const char *name); void piglit_require_not_extension(const char *name); @@ -239,8 +153,6 @@ unsigned short piglit_half_from_float(float val); void piglit_escape_exit_key(unsigned char key, int x, int y); -char *piglit_load_text_file(const char *file_name, unsigned *size); - void piglit_gen_ortho_projection(double left, double right, double bottom, double top, double near_val, double far_val, GLboolean push); @@ -284,12 +196,6 @@ extern const GLenum cube_face_targets[6]; */ extern GLint piglit_ARBfp_pass_through; -#ifndef HAVE_STRCHRNUL -char *strchrnul(const char *s, int c); -#endif - -extern void piglit_set_rlimit(unsigned long lim); - static const GLint PIGLIT_ATTRIB_POS = 0; static const GLint PIGLIT_ATTRIB_TEX = 1; diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c new file mode 100644 index 000000000..705f05511 --- /dev/null +++ b/tests/util/piglit-util.c @@ -0,0 +1,223 @@ +/* + * Copyright (c) The Piglit project 2007 + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#if defined(_WIN32) +#include <windows.h> +#endif + +#include <assert.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "config.h" +#if defined(HAVE_SYS_TIME_H) && defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_SETRLIMIT) +#include <sys/time.h> +#include <sys/resource.h> +#define USE_SETRLIMIT +#endif + +#include "piglit-util.h" + + +#if defined(_WIN32) + +/* Some versions of MinGW are missing _vscprintf's declaration, although they + * still provide the symbol in the import library. + */ +#ifdef __MINGW32__ +_CRTIMP int _vscprintf(const char *format, va_list argptr); +#endif + +int asprintf(char **strp, const char *fmt, ...) +{ + va_list args; + va_list args_copy; + int length; + size_t size; + + va_start(args, fmt); + + va_copy(args_copy, args); + +#ifdef _WIN32 + /* We need to use _vcsprintf to calculate the length as vsnprintf returns -1 + * if the number of characters to write is greater than count. + */ + length = _vscprintf(fmt, args_copy); +#else + char dummy; + length = vsnprintf(&dummy, sizeof dummy, fmt, args_copy); +#endif + + va_end(args_copy); + + assert(length >= 0); + size = length + 1; + + *strp = malloc(size); + if (!*strp) { + return -1; + } + + va_start(args, fmt); + vsnprintf(*strp, size, fmt, args); + va_end(args); + + return length; +} + +#endif /* _WIN32 */ + +bool piglit_is_extension_in_string(const char *haystack, const char *needle) +{ + const unsigned needle_len = strlen(needle); + + if (needle_len == 0) + return false; + + while (true) { + const char *const s = strstr(haystack, needle); + + if (s == NULL) + return false; + + if (s[needle_len] == ' ' || s[needle_len] == '\0') { + return true; + } + + /* strstr found an extension whose name begins with + * needle, but whose name is not equal to needle. + * Restart the search at s + needle_len so that we + * don't just find the same extension again and go + * into an infinite loop. + */ + haystack = s + needle_len; + } + + return false; +} + +/** Returns the line in the program string given the character position. */ +int FindLine(const char *program, int position) +{ + int i, line = 1; + for (i = 0; i < position; i++) { + if (program[i] == '0') + return -1; /* unknown line */ + if (program[i] == '\n') + line++; + } + return line; +} + +void +piglit_report_result(enum piglit_result result) +{ + fflush(stderr); + + if (result == PIGLIT_PASS) { + printf("PIGLIT: {'result': 'pass' }\n"); + fflush(stdout); + exit(0); + } else if (result == PIGLIT_SKIP) { + printf("PIGLIT: {'result': 'skip' }\n"); + fflush(stdout); + exit(0); + } else if (result == PIGLIT_WARN) { + printf("PIGLIT: {'result': 'warn' }\n"); + fflush(stdout); + exit(0); + } else { + printf("PIGLIT: {'result': 'fail' }\n"); + fflush(stdout); + exit(1); + } +} + +#ifndef HAVE_STRCHRNUL +char *strchrnul(const char *s, int c) +{ + char *t = strchr(s, c); + + return (t == NULL) ? ((char *) s + strlen(s)) : t; +} +#endif + + +void +piglit_set_rlimit(unsigned long lim) +{ +#if defined(USE_SETRLIMIT) + struct rlimit rl; + if (getrlimit(RLIMIT_AS, &rl) != -1) { + printf("Address space limit = %lu, max = %lu\n", + (unsigned long) rl.rlim_cur, + (unsigned long) rl.rlim_max); + + if (rl.rlim_max > lim) { + printf("Resetting limit to %lu.\n", lim); + + rl.rlim_cur = lim; + rl.rlim_max = lim; + if (setrlimit(RLIMIT_AS, &rl) == -1) { + printf("Could not set rlimit " + "due to: %s (%d)\n", + strerror(errno), errno); + } + } + } + + printf("\n"); +#else + printf("Cannot reset rlimit on this platform.\n\n"); +#endif +} + +/* Merges the PASS/FAIL/SKIP for @subtest into the overall result + * @all. + * + * The @all should start out initialized to PIGLIT_SKIP. + */ +void +piglit_merge_result(enum piglit_result *all, enum piglit_result subtest) +{ + switch (subtest) { + case PIGLIT_FAIL: + *all = PIGLIT_FAIL; + break; + case PIGLIT_WARN: + if (*all == PIGLIT_SKIP || *all == PIGLIT_PASS) + *all = PIGLIT_WARN; + break; + case PIGLIT_PASS: + if (*all == PIGLIT_SKIP) + *all = PIGLIT_PASS; + break; + case PIGLIT_SKIP: + break; + } +} + diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h new file mode 100644 index 000000000..661078f4a --- /dev/null +++ b/tests/util/piglit-util.h @@ -0,0 +1,133 @@ +/* + * Copyright (c) The Piglit project 2007 + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#ifndef PIGLIT_UTIL_H +#define PIGLIT_UTIL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "config.h" + +#if defined(_WIN32) +#include <windows.h> +#endif + +#if defined(_MSC_VER) +#define log2(x) (log(x) / log(2)) +#endif + +#include <assert.h> +#include <stdbool.h> +#include <stdint.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <math.h> +#include <float.h> + +#if defined(_MSC_VER) + +#define snprintf sprintf_s + +static __inline double +round(double x) { + return x >= 0.0 ? floor(x + 0.5) : ceil(x - 0.5); +} + +static __inline float +roundf(float x) { + return x >= 0.0f ? floorf(x + 0.5f) : ceilf(x - 0.5f); +} + +#ifndef va_copy +#ifdef __va_copy +#define va_copy(dest, src) __va_copy((dest), (src)) +#else +#define va_copy(dest, src) (dest) = (src) +#endif +#endif + +#endif /* defined(_MSC_VER) */ + +#ifdef _WIN32 +int asprintf(char **strp, const char *fmt, ...) +#ifdef __GNUC__ + __attribute__ ((format (printf, 2, 3))) +#endif +; +#endif /* _WIN32 */ + +// Trick from http://tdistler.com/2011/03/24/how-to-define-nan-not-a-number-on-windows +#ifndef INFINITY +# define INFINITY (FLT_MAX + FLT_MAX) +#endif +#ifndef NAN +# define NAN (INFINITY - INFINITY) +#endif + +enum piglit_result { + PIGLIT_PASS, + PIGLIT_FAIL, + PIGLIT_SKIP, + PIGLIT_WARN +}; + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) + +#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) ) +#define MIN2(a, b) ((a) > (b) ? (b) : (a)) +#define MAX2(a, b) ((a) > (b) ? (a) : (b)) + +/** + * Determine if an extension is listed in an extension string + * + * \param haystack List of all extensions to be searched + * \param needle Extension whose presens is to be detected + * + * \precondition \c haystack is not null + * + * \sa piglit_is_extension_supported, piglit_is_glx_extension_supported + */ +bool piglit_is_extension_in_string(const char *haystack, const char *needle); + +int FindLine(const char *program, int position); +void piglit_merge_result(enum piglit_result *all, enum piglit_result subtest); +void piglit_report_result(enum piglit_result result); + +#ifndef HAVE_STRCHRNUL +char *strchrnul(const char *s, int c); +#endif + +extern void piglit_set_rlimit(unsigned long lim); + +char *piglit_load_text_file(const char *file_name, unsigned *size); + +#ifdef __cplusplus +} /* end extern "C" */ +#endif + +#endif /* PIGLIT_UTIL_H */ |