[Piglit] [PATCH 06/15] Convert more older tests to use piglit-framework.c.

Paul Berry stereotype441 at gmail.com
Fri Mar 2 15:40:24 PST 2012


This patch converts the following tests to use the main() function in
piglit-frmework.c rather than define their own main() function.

- crash-cubemap-order
- crash-texparameter-before-teximage
- fdo10370
- fdo23489
- fdo9833
- copytexsubimage
---
 tests/bugs/crash-cubemap-order.c                |   27 ++++---------
 tests/bugs/crash-texparameter-before-teximage.c |   26 ++++--------
 tests/bugs/fdo10370.c                           |   43 +++++---------------
 tests/bugs/fdo23489.c                           |   30 +++-----------
 tests/bugs/fdo9833.c                            |   23 ++++-------
 tests/texturing/copytexsubimage.c               |   48 +++++++----------------
 6 files changed, 56 insertions(+), 141 deletions(-)

diff --git a/tests/bugs/crash-cubemap-order.c b/tests/bugs/crash-cubemap-order.c
index b323a5f..d8a59d2 100644
--- a/tests/bugs/crash-cubemap-order.c
+++ b/tests/bugs/crash-cubemap-order.c
@@ -8,20 +8,23 @@
 
 #include "piglit-util.h"
 
-static int Width = 100, Height = 100;
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGBA;
 
-static void Display(void)
+enum piglit_result
+piglit_display(void)
 {
-	piglit_report_result(PIGLIT_PASS);
+	return PIGLIT_PASS;
 }
 
-static void init(void)
+void
+piglit_init(int argc, char **argv)
 {
 	GLubyte data[4096]; /* 32*32*4 */
 
 	memset(data, 0, sizeof(data));
 	
-	glViewport(0, 0, Width, Height);
+	glViewport(0, 0, piglit_width, piglit_height);
 
 	glBindTexture(GL_TEXTURE_CUBE_MAP, 1);
 	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
@@ -39,17 +42,3 @@ static void init(void)
 	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
 	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
 }
-
-
-int main(int argc, char**argv)
-{
-	glutInit(&argc, argv);
-	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
-	glutInitWindowSize(Width, Height);
-	glutCreateWindow(argv[0]);
-	glutDisplayFunc(Display);
-	init();
-	glutMainLoop();
-	return 0;
-}
-
diff --git a/tests/bugs/crash-texparameter-before-teximage.c b/tests/bugs/crash-texparameter-before-teximage.c
index 987de00..d35f348 100644
--- a/tests/bugs/crash-texparameter-before-teximage.c
+++ b/tests/bugs/crash-texparameter-before-teximage.c
@@ -10,16 +10,19 @@
 #include "piglit-util.h"
 
 
-static int Width = 100, Height = 100;
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGBA;
 
-static void Display(void)
+enum piglit_result
+piglit_display(void)
 {
-	piglit_report_result(PIGLIT_PASS);
+	return PIGLIT_PASS;
 }
 
-static void init(void)
+void
+piglit_init(int argc, char **argv)
 {
-	glViewport(0, 0, Width, Height);
+	glViewport(0, 0, piglit_width, piglit_height);
 
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
@@ -32,16 +35,3 @@ static void init(void)
 	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, -4);
 	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4);
 }
-
-
-int main(int argc, char**argv)
-{
-	glutInit(&argc, argv);
-	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
-	glutInitWindowSize(Width, Height);
-	glutCreateWindow(argv[0]);
-	glutDisplayFunc(Display);
-	init();
-	glutMainLoop();
-	return 0;
-}
diff --git a/tests/bugs/fdo10370.c b/tests/bugs/fdo10370.c
index c89cfe4..4705357 100644
--- a/tests/bugs/fdo10370.c
+++ b/tests/bugs/fdo10370.c
@@ -5,10 +5,8 @@
 
 #include "piglit-util.h"
 
-static int Automatic = 0;
-
-#define WIN_WIDTH 128
-#define WIN_HEIGHT 128
+int piglit_width = 128, piglit_height = 128;
+int piglit_window_mode = GLUT_SINGLE | GLUT_RGB;
 #define BITMAP_WIDTH 1
 #define BITMAP_HEIGHT 1
 #define ALIGN 1
@@ -21,12 +19,13 @@ static GLubyte data[] = { 0x8f, 0xff, 0x7f, 0x70 };
 
 static GLuint tex_name;
 
-void init(void)
+void
+piglit_init(int argc, char **argv)
 {
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
 	glTranslatef(-1.0, -1.0, 0.0);
-	glScalef(2.0/WIN_WIDTH, 2.0/WIN_HEIGHT, 1.0);
+	glScalef(2.0/piglit_width, 2.0/piglit_height, 1.0);
 
 	glDisable(GL_DITHER);
 	glClearColor(1, 1, 1, 1);
@@ -53,7 +52,8 @@ void init(void)
 
 
 
-void display(void)
+enum piglit_result
+piglit_display(void)
 {
 	int i, j, k, col, pixel;
 	GLfloat expected[4];
@@ -145,29 +145,8 @@ void display(void)
 
 	printf("max delta: %f\n", dmax);
 
-	if (Automatic) {
-		if (dmax > 0.02)
-			printf("PIGLIT: {'result': 'fail' }\n");
-		else
-			printf("PIGLIT: {'result': 'pass' }\n");
-
-		exit(0);
-	}
-}
-
-
-int main(int argc, char**argv)
-{
-	glutInit(&argc, argv);
-	if (argc == 2 && !strcmp(argv[1], "-auto"))
-		Automatic = 1;
-	glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
-	glutInitWindowSize (WIN_WIDTH, WIN_HEIGHT);
-	glutInitWindowPosition (100, 100);
-	glutCreateWindow ("fdo10370");
-	init();
-	glutDisplayFunc(display);
-	glutMainLoop();
-
-	return 0;
+	if (dmax > 0.02)
+		return PIGLIT_FAIL;
+	else
+		return PIGLIT_PASS;
 }
diff --git a/tests/bugs/fdo23489.c b/tests/bugs/fdo23489.c
index e28befd..8269d1a 100644
--- a/tests/bugs/fdo23489.c
+++ b/tests/bugs/fdo23489.c
@@ -5,9 +5,11 @@
 
 #include "piglit-util.h"
 
-static int Automatic = 0;
+int piglit_width = 250, piglit_height = 250;
+int piglit_window_mode = GLUT_SINGLE | GLUT_RGB;
 
-static void display(void)
+enum piglit_result
+piglit_display(void)
 {
 	int i;
 
@@ -17,32 +19,14 @@ static void display(void)
 	}
 	glFlush();
 
-	if (Automatic) {
-		piglit_report_result(PIGLIT_PASS);
-	}
+	return PIGLIT_PASS;
 }
 
-static void init(void)
+void
+piglit_init(int argc, char **argv)
 {
 	glClearColor(0.0, 0.0, 0.0, 0.0);
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
 	glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
 }
-
-int main(int argc, char** argv)
-{
-	glutInit(&argc, argv);
-	if (argc == 2 && !strcmp(argv[1], "-auto"))
-		Automatic = 1;
-	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
-	glutInitWindowSize(250, 250);
-	glutInitWindowPosition(100, 100);
-	glutCreateWindow("fdo23489");
-	glutKeyboardFunc(piglit_escape_exit_key);
-	init();
-	glutDisplayFunc(display);
-	glutMainLoop();
-	return 0;
-}
-
diff --git a/tests/bugs/fdo9833.c b/tests/bugs/fdo9833.c
index b75a48e..eade55e 100644
--- a/tests/bugs/fdo9833.c
+++ b/tests/bugs/fdo9833.c
@@ -5,9 +5,11 @@
 
 #include "piglit-util.h"
 
-static int Automatic = 0;
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGBA;
 
-static void display(void)
+enum piglit_result
+piglit_display(void)
 {
 	static int goterrors = 0;
 	static int frame = 0;
@@ -29,21 +31,12 @@ static void display(void)
 		goterrors++;
 	}
 
-	if (Automatic && frame > 2) {
-		printf("PIGLIT: {'result': '%s' }\n", goterrors ? "fail" : "pass");
-		exit(0);
-	}
+	piglit_present_results();
 
-	glutPostRedisplay();
+	return goterrors ? PIGLIT_FAIL : PIGLIT_PASS;
 }
 
-int main(int argc, char **argv)
+void
+piglit_init(int argc, char **argv)
 {
-	glutInit(&argc, argv);
-	if (argc == 2 && !strcmp(argv[1], "-auto"))
-		Automatic = 1;
-	glutCreateWindow("fdo9833");
-	glutDisplayFunc(display);
-	glutMainLoop();
-	return 0;
 }
diff --git a/tests/texturing/copytexsubimage.c b/tests/texturing/copytexsubimage.c
index 51241de..c12cc5b 100644
--- a/tests/texturing/copytexsubimage.c
+++ b/tests/texturing/copytexsubimage.c
@@ -27,10 +27,8 @@
 
 #include "piglit-util.h"
 
-#define WIN_WIDTH 200
-#define WIN_HEIGHT 200
-
-static GLboolean Automatic = GL_FALSE;
+int piglit_width = 200, piglit_height = 200;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB;
 
 /** Should GL_TEXTURE_RECTANGLE_ARB be tested? */
 int have_rect = 0;
@@ -219,7 +217,8 @@ do_row(int srcy, int srcw, int srch, GLenum target)
 }
 
 
-static void display(void)
+enum piglit_result
+piglit_display(void)
 {
 	GLboolean pass;
 	int srcy = 5;
@@ -253,23 +252,20 @@ static void display(void)
 		srcy += 35 + 5;
 	}
 
-	if (Automatic) {
-		printf("PIGLIT: {'result': '%s' }\n",
-		       pass ? "pass" : "fail");
-		exit(pass ? 0 : 1);
-	}
+	piglit_present_results();
 
-	glutSwapBuffers();
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
 }
 
-static void init(void)
+void
+piglit_init(int argc, char **argv)
 {
 	glDisable(GL_DITHER);
 
 	glMatrixMode( GL_PROJECTION );
 	glPushMatrix();
 	glLoadIdentity();
-	glOrtho( 0, WIN_WIDTH, 0, WIN_HEIGHT, -1, 1 );
+	glOrtho( 0, piglit_width, 0, piglit_height, -1, 1 );
 
 	glMatrixMode( GL_MODELVIEW );
 	glPushMatrix();
@@ -277,26 +273,10 @@ static void init(void)
 
 	glClearColor(0.5, 0.5, 0.5, 1.0);
 
-	have_NPOT = ((atof((const char *) glGetString(GL_VERSION)) >= 2.0)
-		|| (glutExtensionSupported("GL_ARB_texture_non_power_of_two")));
+	have_NPOT = (piglit_get_gl_version() >= 20
+		|| (piglit_is_extension_supported("GL_ARB_texture_non_power_of_two")));
 
-	have_rect = ((glutExtensionSupported("GL_ARB_texture_rectangle"))
-		|| (glutExtensionSupported("GL_EXT_texture_rectangle"))
-		|| (glutExtensionSupported("GL_NV_texture_rectangle")));
-}
-
-int main(int argc, char**argv)
-{
-	glutInit(&argc, argv);
-	if (argc == 2 && !strcmp(argv[1], "-auto"))
-		Automatic = 1;
-	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
-	glutInitWindowSize (WIN_WIDTH, WIN_HEIGHT);
-	glutInitWindowPosition (100, 100);
-	glutCreateWindow ("copytexsubimage");
-	init();
-	glutDisplayFunc(display);
-	glutMainLoop();
-
-	return 0;
+	have_rect = ((piglit_is_extension_supported("GL_ARB_texture_rectangle"))
+		|| (piglit_is_extension_supported("GL_EXT_texture_rectangle"))
+		|| (piglit_is_extension_supported("GL_NV_texture_rectangle")));
 }
-- 
1.7.7.6



More information about the Piglit mailing list