[Piglit] [PATCH 1/2] Convert older tests to use piglit-framework.c

Paul Berry stereotype441 at gmail.com
Wed Feb 22 13:29:05 PST 2012


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

- asmparsertest
- fdo14575
- fdo20701
- fdo22540
- fdo31934
- glslparsertest
- texunits
---
 tests/asmparsertest/asmparsertest.c   |   44 +++++++----------
 tests/bugs/fdo14575.c                 |   29 ++++-------
 tests/bugs/fdo20701.c                 |   53 ++++-----------------
 tests/bugs/fdo22540.c                 |   31 +++---------
 tests/bugs/fdo31934.c                 |   25 ++++------
 tests/general/texunits.c              |   84 +++++++--------------------------
 tests/glslparsertest/glslparsertest.c |   23 ++++-----
 7 files changed, 87 insertions(+), 202 deletions(-)

diff --git a/tests/asmparsertest/asmparsertest.c b/tests/asmparsertest/asmparsertest.c
index 357be3b..4c36aa0 100644
--- a/tests/asmparsertest/asmparsertest.c
+++ b/tests/asmparsertest/asmparsertest.c
@@ -30,7 +30,8 @@
 #define TRUE    (!FALSE)
 #endif
 
-int automatic = FALSE;
+int piglit_width = 250, piglit_height = 250;
+int piglit_window_mode = GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH;
 
 char *
 unix_line_endings(const char *input, size_t length)
@@ -106,7 +107,7 @@ compile(const char *filename, GLenum target, int use_ARB)
 	unsigned i;
 
 
-	if (!automatic) {
+	if (!piglit_automatic) {
 		printf("%s:\n", filename);
 	}
 
@@ -186,7 +187,7 @@ compile(const char *filename, GLenum target, int use_ARB)
 			GLint errorpos;
 
 			glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
-			if (!automatic) {
+			if (!piglit_automatic) {
 				printf("glGetError = 0x%04x\n", err);
 				printf("errorpos: %d\n", errorpos);
 				printf("%s\n",
@@ -206,44 +207,31 @@ compile(const char *filename, GLenum target, int use_ARB)
 }
 
 
-int
-main(int argc, char **argv)
+void
+piglit_init(int argc, char **argv)
 {
 	GLenum target;
 	unsigned i;
 	int use_ARB;
 
 
-	glutInit(&argc, argv);
-	glutInitWindowPosition(0, 0);
-	glutInitWindowSize(250, 250);
-	glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH);
-	glutCreateWindow("assembler test");
-	glewInit();
-
-	i = 1;
-	if (((argc - 1) >= 1) && (strcmp(argv[i], "-auto") == 0)) {
-		automatic = TRUE;
-		i++;
-	}
-
-	if ((argc - i) < 2) {
+	if (argc < 3) {
 		piglit_report_result(PIGLIT_FAIL);
 	}
 
 
 	use_ARB = 1;
-	if (strcmp(argv[i], "ARBvp1.0") == 0) {
+	if (strcmp(argv[1], "ARBvp1.0") == 0) {
 		target = GL_VERTEX_PROGRAM_ARB;
 		piglit_require_extension("GL_ARB_vertex_program");
-	} else if (strcmp(argv[i], "ARBfp1.0") == 0) {
+	} else if (strcmp(argv[1], "ARBfp1.0") == 0) {
 		target = GL_FRAGMENT_PROGRAM_ARB;
 		piglit_require_extension("GL_ARB_fragment_program");
-	} else if (strcmp(argv[i], "NVvp1.0") == 0) {
+	} else if (strcmp(argv[1], "NVvp1.0") == 0) {
 		target = GL_VERTEX_PROGRAM_NV;
 		piglit_require_extension("GL_NV_vertex_program");
 		use_ARB = 0;
-	} else if (strcmp(argv[i], "NVfp1.0") == 0) {
+	} else if (strcmp(argv[1], "NVfp1.0") == 0) {
 		target = GL_FRAGMENT_PROGRAM_NV;
 		piglit_require_extension("GL_NV_fragment_program");
 		use_ARB = 0;
@@ -251,10 +239,16 @@ main(int argc, char **argv)
 		piglit_report_result(PIGLIT_FAIL);
 	}
 
-	for (i++; i < argc; i++) {
+	for (i = 2; i < argc; i++) {
 		compile(argv[i], target, use_ARB);
 	}
 
 	piglit_report_result(PIGLIT_PASS);
-	return 0;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	/* Should never be reached */
+	return PIGLIT_FAIL;
 }
diff --git a/tests/bugs/fdo14575.c b/tests/bugs/fdo14575.c
index 77f6b84..4a7942a 100644
--- a/tests/bugs/fdo14575.c
+++ b/tests/bugs/fdo14575.c
@@ -32,27 +32,16 @@
  */
 #include "piglit-util.h"
 
-static int Automatic = 0;
+int piglit_width = 128, piglit_height = 128;
+int piglit_window_mode = GLUT_SINGLE | GLUT_RGB;
 
-#define WIN_WIDTH 128
-#define WIN_HEIGHT 128
-
-int main(int argc, char**argv)
+void
+piglit_init(int argc, char**argv)
 {
 	GLfloat data = 1.0;
 	GLfloat *v;
 	GLuint buf;
 
-	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");
-
-	glewInit();
-
 	piglit_require_extension("GL_ARB_vertex_buffer_object");
 
 	glGenBuffersARB(1, &buf);
@@ -80,8 +69,12 @@ int main(int argc, char**argv)
 	glDeleteBuffersARB(1, &buf);
 	assert(glGetError() == 0);
 
-	if (Automatic)
-		printf("PIGLIT: {'result': 'pass' }\n");
+	piglit_report_result(PIGLIT_PASS);
+}
 
-	return 0;
+enum piglit_result
+piglit_display(void)
+{
+	/* Should never be reached */
+	return PIGLIT_FAIL;
 }
diff --git a/tests/bugs/fdo20701.c b/tests/bugs/fdo20701.c
index 279de10..6bab980 100644
--- a/tests/bugs/fdo20701.c
+++ b/tests/bugs/fdo20701.c
@@ -36,12 +36,14 @@
 
 #include "piglit-util.h"
 
-static int Automatic = 0;
-static int Width = 128, Height = 128;
+int piglit_width = 128, piglit_height = 128;
+int piglit_window_mode = GLUT_RGB;
+
 static GLuint fb;
 static GLuint tex;
 
-static void Display(void)
+enum piglit_result
+piglit_display(void)
 {
 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
 	glClearColor(1.0, 0.0, 0.0, 1.0);
@@ -49,30 +51,8 @@ static void Display(void)
 	glClear(GL_COLOR_BUFFER_BIT);
 	glFinish();
 
-	if (Automatic) {
-		printf("PIGLIT: {'result': 'pass' }\n");
-		exit(0);
-	}
-}
-
-
-static void Reshape(int width, int height)
-{
-	(void) width;
-	(void) height;
-}
-
-
-static void Key(unsigned char key, int x, int y)
-{
-	(void) x;
-	(void) y;
-	switch (key) {
-	case 27:
-		exit(0);
-		break;
-	}
-	glutPostRedisplay();
+	// If the test doesn't crash, then it passes.
+	return PIGLIT_PASS;
 }
 
 
@@ -81,8 +61,6 @@ init(void)
 {
 	GLenum status;
 
-	glewInit();
-	
 	piglit_require_extension("GL_EXT_framebuffer_object");
 
 	glGenFramebuffersEXT(1, &fb);
@@ -110,20 +88,7 @@ init(void)
 }
 
 
-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;
-	glutInitDisplayMode(GLUT_RGB);
-	glutInitWindowSize(Width, Height);
-	glutCreateWindow("FD.O bug #20701 test");
-	glutReshapeFunc(Reshape);
-	glutKeyboardFunc(Key);
-	glutDisplayFunc(Display);
-	if (!Automatic)
-		printf("If the test doesn't crash, then it passes.\n");
-	init();
-	glutMainLoop();
-	return 0;
 }
diff --git a/tests/bugs/fdo22540.c b/tests/bugs/fdo22540.c
index f9f09a5..5ed7b01 100644
--- a/tests/bugs/fdo22540.c
+++ b/tests/bugs/fdo22540.c
@@ -25,13 +25,14 @@
 
 #include "piglit-util.h"
 
-static GLboolean Automatic = GL_FALSE;
+int piglit_width = 400, piglit_height = 300;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB;
+
 static GLuint vBuffer;
 
 static void
 Init(void)
 {
-	glewInit();
 	piglit_require_extension("GL_ARB_vertex_buffer_object");
 	glMatrixMode(GL_PROJECTION);
 	glPushMatrix();
@@ -67,8 +68,8 @@ vboMap(void)
 	return (glGetError() == 0);
 }
 
-static void
-display(void)
+enum piglit_result
+piglit_display(void)
 {
 	GLfloat gray[3] = {0.5, 0.5, 0.5};
 	GLboolean pass;
@@ -87,28 +88,12 @@ display(void)
 	glFinish();
 	glutSwapBuffers();
 
-	if (Automatic)
-		piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
-
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
 }
 
-int main(int argc, char  **argv)
+void
+piglit_init(int argc, char  **argv)
 {
-	glutInit(&argc, argv);
-	if(argc==2 && !strncmp(argv[1],"-auto", 5))
-		Automatic = GL_TRUE;
-
-	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
-	glutInitWindowSize(400, 300);
-	glutCreateWindow("VBO map");
-	glutDisplayFunc(display);
-	glutKeyboardFunc(piglit_escape_exit_key);
-
 	Init();
 	vboInit();
-
-	glutMainLoop();
-
-	glDeleteBuffersARB(1, &vBuffer);
-	return 0;
 }
diff --git a/tests/bugs/fdo31934.c b/tests/bugs/fdo31934.c
index 0098f4c..f4dfd62 100644
--- a/tests/bugs/fdo31934.c
+++ b/tests/bugs/fdo31934.c
@@ -1,20 +1,13 @@
 #include "piglit-util.h"
 
-static int Automatic = 0;
+int piglit_width = 512, piglit_height = 512;
+int piglit_window_mode = GLUT_RGBA;
 
-int main (int argc, char *argv[])
+void
+piglit_init(int argc, char *argv[])
 {
     GLuint id;
 
-    glutInit(&argc, argv);
-    if (argc == 2 && !strcmp(argv[1], "-auto"))
-        Automatic = 1;
-    glutInitDisplayMode(GLUT_RGBA);
-    glutInitWindowSize(512,512);
-    glutCreateWindow("fdo31934");
-
-    glewInit();
-
     if (!GLEW_VERSION_1_5) {
         printf("Requires OpenGL 1.5\n");
         piglit_report_result(PIGLIT_SKIP);
@@ -31,8 +24,12 @@ int main (int argc, char *argv[])
     glMapBuffer(GL_ARRAY_BUFFER_ARB, GL_READ_WRITE_ARB); /* CRASH! */
     glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
 
-    if (Automatic)
-        printf("PIGLIT: {'result': 'pass' }\n");
+    piglit_report_result(PIGLIT_PASS);
+}
 
-    return 0;
+enum piglit_result
+piglit_display(void)
+{
+	/* Should never be reached */
+	return PIGLIT_FAIL;
 }
diff --git a/tests/general/texunits.c b/tests/general/texunits.c
index 394e7f5..e691724 100644
--- a/tests/general/texunits.c
+++ b/tests/general/texunits.c
@@ -31,8 +31,8 @@
 #include "piglit-util.h"
 
 
-static int Width = 128, Height = 128;
-static int Automatic = 0;
+int piglit_width = 128, piglit_height = 128;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
 
 
 /** random number for checking state */
@@ -332,50 +332,17 @@ report_info(void)
 }
 
 
-static void
-redisplay(void)
+enum piglit_result
+piglit_display(void)
 {
-   if (Automatic) {
-      GLboolean pass = GL_TRUE;
-
-      pass = test_rasterpos() && pass;
-      pass = test_texture_matrix() && pass;
-      pass = test_texture_params() && pass;
-      pass = test_texture_env() && pass;
-
-      if (pass) {
-         piglit_report_result(PIGLIT_PASS);
-      }
-      else {
-         report_info();
-         piglit_report_result(PIGLIT_FAIL);
-      }
-      exit(1);
-   }
-}
-
-
-static void
-reshape(int width, int height)
-{
-   Width = width;
-   Height = height;
-   glViewport(0, 0, width, height);
-   glMatrixMode(GL_PROJECTION);
-   glLoadIdentity();
-   glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
-   glMatrixMode(GL_MODELVIEW);
-   glLoadIdentity();
-}
+	GLboolean pass = GL_TRUE;
 
+	pass = test_rasterpos() && pass;
+	pass = test_texture_matrix() && pass;
+	pass = test_texture_params() && pass;
+	pass = test_texture_env() && pass;
 
-static void
-key(unsigned char key, int x, int y)
-{
-   if (key == 27) {
-      exit(0);
-   }
-   glutPostRedisplay();
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
 }
 
 
@@ -402,41 +369,26 @@ init(void)
       MaxTextureVertexUnits = 0;
    }
 
-   if (0)
-      report_info();
+   report_info();
 
    generate_random_numbers();
 
-   reshape(Width, Height);
+   glMatrixMode(GL_PROJECTION);
+   glLoadIdentity();
+   glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
+   glMatrixMode(GL_MODELVIEW);
+   glLoadIdentity();
 }
 
 
-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;
-
-   glutInitWindowPosition(0, 0);
-   glutInitWindowSize(Width, Height);
-   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
-   glutCreateWindow(argv[0]);
-
-   glewInit();
-
    if (!GLEW_VERSION_1_3) {
 	   printf("Requires OpenGL 1.3\n");
 	   piglit_report_result(PIGLIT_SKIP);
    }
 
-   glutReshapeFunc(reshape);
-   glutDisplayFunc(redisplay);
-   if (!Automatic) {
-      glutKeyboardFunc(key);
-   }
    init();
-   glutMainLoop();
-   return 0;
 }
 
diff --git a/tests/glslparsertest/glslparsertest.c b/tests/glslparsertest/glslparsertest.c
index 4109ede..2777c0d 100644
--- a/tests/glslparsertest/glslparsertest.c
+++ b/tests/glslparsertest/glslparsertest.c
@@ -35,8 +35,8 @@
 
 #include "piglit-util.h"
 
-#define WIN_WIDTH 200
-#define WIN_HEIGHT 100
+int piglit_width = 200, piglit_height = 100;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB;
 
 static char *filename;
 static int expected_pass;
@@ -259,13 +259,13 @@ int process_options(int argc, char **argv)
 	return new_argc;
 }
 
-int main(int argc, char**argv)
+void
+piglit_init(int argc, char**argv)
 {
 	const char *glsl_version_string;
 	float glsl_version;
 	int i;
 
-	piglit_glutInit(argc, argv);
 	argc = process_options(argc, argv);
 	if (argc < 3)
 		usage(argv[0]);
@@ -284,15 +284,8 @@ int main(int argc, char**argv)
 	if (argc > 3)
 		requested_version = strtod(argv[3], NULL);
 
-	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
-	glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);
-	glutCreateWindow("glslparsertest");
 	gl_version_times_10 = piglit_get_gl_version();
 
-#ifdef USE_OPENGL
-	glewInit();
-#endif
-
 	if (gl_version_times_10 < 20
 	    && !piglit_is_extension_supported("GL_ARB_shader_objects")) {
 		printf("Requires OpenGL 2.0\n");
@@ -320,5 +313,11 @@ int main(int argc, char**argv)
 	}
 
 	test();
-	return 0;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	/* Should never be reached */
+	return PIGLIT_FAIL;
 }
-- 
1.7.7.6



More information about the Piglit mailing list