Regres: limit the number of GL tests opening X connections

Reduce the number of OpenGL and EGL tests to 16, to avoid exceeding the
maximum number of X clients.

Also make the attempts to open an X display back off exponentially
instead of linearly.

Bug: b/153322216
Change-Id: Ifb91d9b892dc4b5f6d26f369f2bece454b0bae87
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/48969
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/tests/regres/deqp-patches/deqp-x11.patch b/tests/regres/deqp-patches/deqp-x11.patch
index d9b760c..89d29bc 100644
--- a/tests/regres/deqp-patches/deqp-x11.patch
+++ b/tests/regres/deqp-patches/deqp-x11.patch
@@ -29,7 +29,7 @@
 +		m_display = XOpenDisplay((char*)name); // Won't modify argument string.
 +		if (m_display)
 +			break;
-+		deSleep(100*(1+i));
++		deSleep(100*(1<<i));
 +	}
  	if (!m_display)
  		throw ResourceError("Failed to open display", name, __FILE__, __LINE__);
diff --git a/tests/regres/deqp/deqp.go b/tests/regres/deqp/deqp.go
index 5975b64..818a6dc 100644
--- a/tests/regres/deqp/deqp.go
+++ b/tests/regres/deqp/deqp.go
@@ -179,9 +179,21 @@
 		// Build a chan for the test names to be run.
 		tests := make(chan string, len(list.Tests))
 
+		numParallelTests := c.NumParallelTests
+		if list.API != testlist.Vulkan {
+			// OpenGL tests attempt to open lots of X11 display connections,
+			// which may cause us to run out of handles. This maximum was
+			// determined experimentally on a 72-core system.
+			maxParallelGLTests := 16
+
+			if numParallelTests > maxParallelGLTests {
+				numParallelTests = maxParallelGLTests
+			}
+		}
+
 		// Start a number of go routines to run the tests.
-		wg.Add(c.NumParallelTests)
-		for i := 0; i < c.NumParallelTests; i++ {
+		wg.Add(numParallelTests)
+		for i := 0; i < numParallelTests; i++ {
 			go func(index int) {
 				c.TestRoutine(exe, tests, results, index, supportsCoverage)
 				wg.Done()