From a9060bb67deb51c196f5c96755c9d61177a2f75b Mon Sep 17 00:00:00 2001 From: Kyle Brenneman Date: Thu, 28 Nov 2019 08:30:38 -0700 Subject: [PATCH] tests: Add tests for the end of the dispatch table. Add a '-l' flag to testgldispatch, which tells it to test a generated stub at the very end of the dispatch table. On PPC, looking up a function past index 4096 requires more than just a simple register+immediate load, so this makes sure that it's correct. --- tests/testgldispatch.c | 31 ++++++++++++++++++++++++++- tests/testgldispatch_generated.sh | 5 ++++- tests/testgldispatch_generated_thr.sh | 5 ++++- tests/testgldispatch_patched.sh | 5 ++++- tests/testgldispatch_patched_thr.sh | 5 ++++- 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/tests/testgldispatch.c b/tests/testgldispatch.c index 139204d..1b9341c 100644 --- a/tests/testgldispatch.c +++ b/tests/testgldispatch.c @@ -107,13 +107,14 @@ static GLboolean enableStaticTest = GL_FALSE; static GLboolean enableGeneratedTest = GL_FALSE; static GLboolean enablePatching = GL_FALSE; static GLboolean forceMultiThreaded = GL_FALSE; +static GLboolean useLastGenerated = GL_FALSE; int main(int argc, char **argv) { int i; while (1) { - int opt = getopt(argc, argv, "sgpt"); + int opt = getopt(argc, argv, "sgptl"); if (opt == -1) { break; } @@ -130,6 +131,9 @@ int main(int argc, char **argv) case 't': forceMultiThreaded = GL_TRUE; break; + case 'l': + useLastGenerated = GL_TRUE; + break; default: return 1; } @@ -163,9 +167,34 @@ int main(int argc, char **argv) } if (enableGeneratedTest) { + if (useLastGenerated) { + // Get enough dispatch stubs so that the one we test is at the very + // end of the dispatch table. On some architectures, loading from a + // high index can be more complicated than a low index, so make + // sure we got it right. + for (i=0; i<4095; i++) { + char name[32]; + snprintf(name, sizeof(name), "glDummyTestPaddingGLVND_%d", i); + __GLdispatchProc proc = __glDispatchGetProcAddress(name); + if (proc == NULL) { + printf("Can't find padding dispatch function for %d\n", i); + return 1; + } + } + } ptr_glDummyTestProc = (pfn_glVertex3fv) __glDispatchGetProcAddress(GENERATED_FUNCTION_NAME); if (ptr_glDummyTestProc == NULL) { printf("Can't find dispatch function for %s\n", GENERATED_FUNCTION_NAME); + return 1; + } + if (useLastGenerated) { + // We should have reached the end of the dispatch table by now, so + // another __glDispatchGetProcAddress call should return NULL. + __GLdispatchProc proc = __glDispatchGetProcAddress("glDummyTestPaddingGLVND_last"); + if (proc != NULL) { + printf("Got dispatch function past the end of the dispatch table.\n"); + return 1; + } } } diff --git a/tests/testgldispatch_generated.sh b/tests/testgldispatch_generated.sh index 8e98bc1..f729cf6 100755 --- a/tests/testgldispatch_generated.sh +++ b/tests/testgldispatch_generated.sh @@ -1,4 +1,7 @@ #!/bin/sh -./testgldispatch -g +set -e + +./testgldispatch -g +./testgldispatch -g -l diff --git a/tests/testgldispatch_generated_thr.sh b/tests/testgldispatch_generated_thr.sh index bf74be8..1379180 100755 --- a/tests/testgldispatch_generated_thr.sh +++ b/tests/testgldispatch_generated_thr.sh @@ -1,4 +1,7 @@ #!/bin/sh -./testgldispatch -g -t +set -e + +./testgldispatch -g -t +./testgldispatch -g -t -l diff --git a/tests/testgldispatch_patched.sh b/tests/testgldispatch_patched.sh index 78e4288..3795904 100755 --- a/tests/testgldispatch_patched.sh +++ b/tests/testgldispatch_patched.sh @@ -1,4 +1,7 @@ #!/bin/sh -./testgldispatch -s -g -p +set -e + +./testgldispatch -s -g -p +./testgldispatch -s -g -p -l diff --git a/tests/testgldispatch_patched_thr.sh b/tests/testgldispatch_patched_thr.sh index 484944a..bacd4c1 100755 --- a/tests/testgldispatch_patched_thr.sh +++ b/tests/testgldispatch_patched_thr.sh @@ -1,4 +1,7 @@ #!/bin/sh -./testgldispatch -s -g -p -t +set -e + +./testgldispatch -s -g -p -t +./testgldispatch -s -g -p -t -l