From: José Fonseca Date: Thu, 6 Dec 2012 07:09:48 +0000 (+0000) Subject: cli: Use python differ. Fix failures. X-Git-Url: https://git.cworth.org/git?p=apitrace-tests;a=commitdiff_plain;h=b2cfdb1056b50c01e54384b6d34499e4df712229 cli: Use python differ. Fix failures. Tests were failure due to off by one difference in line nos. --- diff --git a/cli/.gitignore b/cli/.gitignore index 214d7f2..cc6da65 100644 --- a/cli/.gitignore +++ b/cli/.gitignore @@ -4,4 +4,4 @@ tri-out glxsimple-ref glxsimple-out glxsimple-trim.trace - +glxsimple-trim-unused-textures.trace diff --git a/cli/cli-trim-unused-shaders.script b/cli/cli-trim-unused-shaders.script index 2fb53df..8d461b0 100644 --- a/cli/cli-trim-unused-shaders.script +++ b/cli/cli-trim-unused-shaders.script @@ -12,8 +12,97 @@ apitrace trim --auto --calls=10,47,50,71,87,88 glxsimple.trace # Verify that we actually trimmed what we wanted to -apitrace diff --diff=diff glxsimple.trace glxsimple-trim.trace -expect "12,40d11\n< glCreateShader(GL_VERTEX_SHADER) = 7\n< glShaderSource(7, 1, &\"void main()\n< {\n< gl_Position = ftransform();\n< }\n< \", NULL)\n< glCompileShader(7)\n< glCreateShader(GL_FRAGMENT_SHADER) = 8\n< glShaderSource(8, 1, &\"#version 120\n< uniform vec4 color;\n< void main()\n< {\n< gl_FragColor = color;\n< }\n< \", NULL)\n< glCompileShader(8)\n< glCreateProgram() = 9\n< glAttachShader(9, 7)\n< glAttachShader(9, 8)\n< glLinkProgram(9)\n< glUseProgram(9)\n< glGetUniformLocation(9, \"color\") = 0\n< glUniform4f(0, 0, 1, 0, 1)\n< glBegin(GL_QUADS)\n< glVertex2f(0, 0)\n< glVertex2f(64, 0)\n< glVertex2f(64, 64)\n< glVertex2f(0, 64)\n< glEnd()\n42,43d12\n< glXSwapBuffers(0x236a280, 41943041)\n< \n" +apitrace diff --diff=python glxsimple.trace glxsimple-trim.trace +expect r""" glXChooseVisual(37134976, 0, (GLX_RGBA, GLX_RED_SIZE, GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_RED_SIZE, GLX_BLUE_SIZE, GLX_RED_SIZE, GLX_ALPHA_SIZE, GLX_RED_SIZE, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, GLX_RED_SIZE, GLX_X_VISUAL_TYPE, GLX_DIRECT_COLOR, 0)) = ([37179128, 34, 0, 24, 5, 16711680, 65280, 255, 256, 8]) + glXCreateContext(37134976, ([37179128, 34, 0, 24, 5, 16711680, 65280, 255, 256, 8]), 0, True) = 37241648 + glXMakeCurrent(37134976, 41943041, 37241648) = True + glViewport(0, 0, 64, 64) + glMatrixMode(GL_PROJECTION) + glLoadIdentity() + glOrtho(0.0, 64.0, 64.0, 0.0, 0.0, 1.0) + glMatrixMode(GL_MODELVIEW) + glClearColor(0.0, 0.0, 1.0, 1.0) + glClear((GL_COLOR_BUFFER_BIT)) + glXSwapBuffers(37134976, 41943041) +- glCreateShader(GL_VERTEX_SHADER) = 7 +- glShaderSource(7, 1, ('void main()\n{\n gl_Position = ftransform();\n}\n'), 0) +- glCompileShader(7) +- glCreateShader(GL_FRAGMENT_SHADER) = 8 +- glShaderSource(8, 1, ('#version 120\nuniform vec4 color;\nvoid main()\n{\n gl_FragColor = color;\n}\n'), 0) +- glCompileShader(8) +- glCreateProgram() = 9 +- glAttachShader(9, 7) +- glAttachShader(9, 8) +- glLinkProgram(9) +- glUseProgram(9) +- glGetUniformLocation(9, color) = 0 +- glUniform4f(0, 0.0, 1.0, 0.0, 1.0) +- glBegin(GL_QUADS) +- glVertex2f(0.0, 0.0) +- glVertex2f(64.0, 0.0) +- glVertex2f(64.0, 64.0) +- glVertex2f(0.0, 64.0) +- glEnd() + glUseProgram(0) +- glXSwapBuffers(37134976, 41943041) + glGenTextures(1, (1)) + glBindTexture(GL_TEXTURE_2D, 1) + glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, blob(3)) + glEnable(GL_TEXTURE_2D) + glBegin(GL_QUADS) + glTexCoord2f(0.0, 0.0) + glVertex2f(0.0, 0.0) + glTexCoord2f(1.0, 0.0) + glVertex2f(64.0, 0.0) + glTexCoord2f(1.0, 1.0) + glVertex2f(64.0, 64.0) + glTexCoord2f(0.0, 1.0) + glVertex2f(0.0, 64.0) + glEnd() + glDisable(GL_TEXTURE_2D) + glXSwapBuffers(37134976, 41943041) + glClearColor(1.0, 0.0, 0.0, 1.0) + glClear((GL_COLOR_BUFFER_BIT)) + glXSwapBuffers(37134976, 41943041) + glCreateShader(GL_VERTEX_SHADER) = 10 + glShaderSource(10, 1, ('void main()\n{\n gl_Position = ftransform();\n}\n'), 0) + glCompileShader(10) + glCreateShader(GL_FRAGMENT_SHADER) = 11 + glShaderSource(11, 1, ('#version 120\nuniform vec4 color;\nvoid main()\n{\n gl_FragColor = color;\n}\n'), 0) + glCompileShader(11) + glCreateProgram() = 12 + glAttachShader(12, 10) + glAttachShader(12, 11) + glLinkProgram(12) + glUseProgram(12) + glGetUniformLocation(12, color) = 0 + glUniform4f(0, 1.0, 0.0, 1.0, 1.0) + glBegin(GL_QUADS) + glVertex2f(0.0, 0.0) + glVertex2f(64.0, 0.0) + glVertex2f(64.0, 64.0) + glVertex2f(0.0, 64.0) + glEnd() + glUseProgram(0) + glXSwapBuffers(37134976, 41943041) + glGenTextures(1, (2)) + glBindTexture(GL_TEXTURE_2D, 2) + glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, blob(3)) + glEnable(GL_TEXTURE_2D) + glBegin(GL_QUADS) + glTexCoord2f(0.0, 0.0) + glVertex2f(0.0, 0.0) + glTexCoord2f(1.0, 0.0) + glVertex2f(64.0, 0.0) + glTexCoord2f(1.0, 1.0) + glVertex2f(64.0, 64.0) + glTexCoord2f(0.0, 1.0) + glVertex2f(0.0, 64.0) + glEnd() + glDisable(GL_TEXTURE_2D) + glXSwapBuffers(37134976, 41943041) + glXDestroyContext(37134976, 37241648) +""" # Generate output images for all frames in the trimmed trace @@ -23,4 +112,9 @@ apitrace dump-images --call-nos=no -o ./glxsimple-out/ glxsimple-trim.trace # Compare output to reference images apitrace diff-images -v ./glxsimple-ref ./glxsimple-out -expect "Comparing ./glxsimple-ref/0000000000.png and ./glxsimple-out/0000000000.png ... MATCH\nComparing ./glxsimple-ref/0000000001.png and ./glxsimple-out/0000000001.png ... MATCH\nComparing ./glxsimple-ref/0000000002.png and ./glxsimple-out/0000000002.png ... MATCH\nComparing ./glxsimple-ref/0000000003.png and ./glxsimple-out/0000000003.png ... MATCH\nComparing ./glxsimple-ref/0000000004.png and ./glxsimple-out/0000000004.png ... MATCH\n" +expect r"""Comparing ./glxsimple-ref/0000000000.png and ./glxsimple-out/0000000000.png ... MATCH +Comparing ./glxsimple-ref/0000000001.png and ./glxsimple-out/0000000001.png ... MATCH +Comparing ./glxsimple-ref/0000000002.png and ./glxsimple-out/0000000002.png ... MATCH +Comparing ./glxsimple-ref/0000000003.png and ./glxsimple-out/0000000003.png ... MATCH +Comparing ./glxsimple-ref/0000000004.png and ./glxsimple-out/0000000004.png ... MATCH +""" diff --git a/cli/cli-trim-unused-textures.script b/cli/cli-trim-unused-textures.script index e902042..96ab853 100644 --- a/cli/cli-trim-unused-textures.script +++ b/cli/cli-trim-unused-textures.script @@ -8,19 +8,113 @@ apitrace dump-images --calls=10,31,50,71,87,88 --call-nos=no -o ./glxsimple-ref/ # Trim to the same callset used to generate reference images -apitrace trim --auto --calls=10,31,50,71,87,88 glxsimple.trace +apitrace trim --auto -o glxsimple-trim-unused-textures.trace --calls=10,31,50,71,87,88 glxsimple.trace # Verify that we actually trimmed what we wanted to -apitrace diff --diff=diff glxsimple.trace glxsimple-trim.trace -expect "44d43\n< glGenTextures(1, &1)\n46d44\n< glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, blob(3))\n48,57d45\n< glBegin(GL_QUADS)\n< glTexCoord2f(0, 0)\n< glVertex2f(0, 0)\n< glTexCoord2f(1, 0)\n< glVertex2f(64, 0)\n< glTexCoord2f(1, 1)\n< glVertex2f(64, 64)\n< glTexCoord2f(0, 1)\n< glVertex2f(0, 64)\n< glEnd()\n59,60d46\n< glXSwapBuffers(0x236a280, 41943041)\n< \n" +apitrace diff --diff=python glxsimple.trace glxsimple-trim-unused-textures.trace +expect r""" glXChooseVisual(37134976, 0, (GLX_RGBA, GLX_RED_SIZE, GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_RED_SIZE, GLX_BLUE_SIZE, GLX_RED_SIZE, GLX_ALPHA_SIZE, GLX_RED_SIZE, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, GLX_RED_SIZE, GLX_X_VISUAL_TYPE, GLX_DIRECT_COLOR, 0)) = ([37179128, 34, 0, 24, 5, 16711680, 65280, 255, 256, 8]) + glXCreateContext(37134976, ([37179128, 34, 0, 24, 5, 16711680, 65280, 255, 256, 8]), 0, True) = 37241648 + glXMakeCurrent(37134976, 41943041, 37241648) = True + glViewport(0, 0, 64, 64) + glMatrixMode(GL_PROJECTION) + glLoadIdentity() + glOrtho(0.0, 64.0, 64.0, 0.0, 0.0, 1.0) + glMatrixMode(GL_MODELVIEW) + glClearColor(0.0, 0.0, 1.0, 1.0) + glClear((GL_COLOR_BUFFER_BIT)) + glXSwapBuffers(37134976, 41943041) + glCreateShader(GL_VERTEX_SHADER) = 7 + glShaderSource(7, 1, ('void main()\n{\n gl_Position = ftransform();\n}\n'), 0) + glCompileShader(7) + glCreateShader(GL_FRAGMENT_SHADER) = 8 + glShaderSource(8, 1, ('#version 120\nuniform vec4 color;\nvoid main()\n{\n gl_FragColor = color;\n}\n'), 0) + glCompileShader(8) + glCreateProgram() = 9 + glAttachShader(9, 7) + glAttachShader(9, 8) + glLinkProgram(9) + glUseProgram(9) + glGetUniformLocation(9, color) = 0 + glUniform4f(0, 0.0, 1.0, 0.0, 1.0) + glBegin(GL_QUADS) + glVertex2f(0.0, 0.0) + glVertex2f(64.0, 0.0) + glVertex2f(64.0, 64.0) + glVertex2f(0.0, 64.0) + glEnd() + glUseProgram(0) + glXSwapBuffers(37134976, 41943041) +- glGenTextures(1, (1)) + glBindTexture(GL_TEXTURE_2D, 1) +- glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, blob(3)) + glEnable(GL_TEXTURE_2D) +- glBegin(GL_QUADS) +- glTexCoord2f(0.0, 0.0) +- glVertex2f(0.0, 0.0) +- glTexCoord2f(1.0, 0.0) +- glVertex2f(64.0, 0.0) +- glTexCoord2f(1.0, 1.0) +- glVertex2f(64.0, 64.0) +- glTexCoord2f(0.0, 1.0) +- glVertex2f(0.0, 64.0) +- glEnd() + glDisable(GL_TEXTURE_2D) +- glXSwapBuffers(37134976, 41943041) + glClearColor(1.0, 0.0, 0.0, 1.0) + glClear((GL_COLOR_BUFFER_BIT)) + glXSwapBuffers(37134976, 41943041) + glCreateShader(GL_VERTEX_SHADER) = 10 + glShaderSource(10, 1, ('void main()\n{\n gl_Position = ftransform();\n}\n'), 0) + glCompileShader(10) + glCreateShader(GL_FRAGMENT_SHADER) = 11 + glShaderSource(11, 1, ('#version 120\nuniform vec4 color;\nvoid main()\n{\n gl_FragColor = color;\n}\n'), 0) + glCompileShader(11) + glCreateProgram() = 12 + glAttachShader(12, 10) + glAttachShader(12, 11) + glLinkProgram(12) + glUseProgram(12) + glGetUniformLocation(12, color) = 0 + glUniform4f(0, 1.0, 0.0, 1.0, 1.0) + glBegin(GL_QUADS) + glVertex2f(0.0, 0.0) + glVertex2f(64.0, 0.0) + glVertex2f(64.0, 64.0) + glVertex2f(0.0, 64.0) + glEnd() + glUseProgram(0) + glXSwapBuffers(37134976, 41943041) + glGenTextures(1, (2)) + glBindTexture(GL_TEXTURE_2D, 2) + glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, blob(3)) + glEnable(GL_TEXTURE_2D) + glBegin(GL_QUADS) + glTexCoord2f(0.0, 0.0) + glVertex2f(0.0, 0.0) + glTexCoord2f(1.0, 0.0) + glVertex2f(64.0, 0.0) + glTexCoord2f(1.0, 1.0) + glVertex2f(64.0, 64.0) + glTexCoord2f(0.0, 1.0) + glVertex2f(0.0, 64.0) + glEnd() + glDisable(GL_TEXTURE_2D) + glXSwapBuffers(37134976, 41943041) + glXDestroyContext(37134976, 37241648) +""" # Generate output images for all frames in the trimmed trace rm_and_mkdir glxsimple-out -apitrace dump-images --call-nos=no -o ./glxsimple-out/ glxsimple-trim.trace +apitrace dump-images --call-nos=no -o ./glxsimple-out/ glxsimple-trim-unused-textures.trace # Compare output to reference images apitrace diff-images -v ./glxsimple-ref ./glxsimple-out -expect "Comparing ./glxsimple-ref/0000000000.png and ./glxsimple-out/0000000000.png ... MATCH\nComparing ./glxsimple-ref/0000000001.png and ./glxsimple-out/0000000001.png ... MATCH\nComparing ./glxsimple-ref/0000000002.png and ./glxsimple-out/0000000002.png ... MATCH\nComparing ./glxsimple-ref/0000000003.png and ./glxsimple-out/0000000003.png ... MATCH\nComparing ./glxsimple-ref/0000000004.png and ./glxsimple-out/0000000004.png ... MATCH\n" +expect r"""Comparing ./glxsimple-ref/0000000000.png and ./glxsimple-out/0000000000.png ... MATCH +Comparing ./glxsimple-ref/0000000001.png and ./glxsimple-out/0000000001.png ... MATCH +Comparing ./glxsimple-ref/0000000002.png and ./glxsimple-out/0000000002.png ... MATCH +Comparing ./glxsimple-ref/0000000003.png and ./glxsimple-out/0000000003.png ... MATCH +Comparing ./glxsimple-ref/0000000004.png and ./glxsimple-out/0000000004.png ... MATCH +""" diff --git a/cli_driver.py b/cli_driver.py index 8016d18..6c1bfd0 100644 --- a/cli_driver.py +++ b/cli_driver.py @@ -51,7 +51,7 @@ class CliDriver(Driver): fail("Command failed (returned non-zero):\n " + " ".join(cmd)) def do_expect(self, args): - expected = json.loads(args) + expected = eval(args) if (self.output != expected): differ = difflib.Differ() diff = differ.compare(expected.splitlines(1), self.output.splitlines(1)) @@ -101,6 +101,11 @@ class CliDriver(Driver): if " " in line: (cmd, args) = line.split(None,1) + if args.startswith('r"""'): + while not line.endswith('"""'): + line = script.readline() + line = line.rstrip() + args += '\n' + line else: cmd = line args = ''