[18/63] shader_runner: Add command to query the resource name

Submitted by apinheiro on Feb. 23, 2019, 11:45 p.m.

Details

Message ID 20190223234551.21111-19-apinheiro@igalia.com
State New
Headers show
Series "ARB_gl_spirv full series" ( rev: 1 ) in Piglit

Not browsing as part of any series.

Commit Message

apinheiro Feb. 23, 2019, 11:45 p.m.
From: Antia Puentes <apuentes@igalia.com>

Tests glGetProgramResourceName().
---
 tests/shaders/shader_runner.c | 74 ++++++++++++++++++++++++++++++++++-
 1 file changed, 73 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c
index 51c31c9d8..893a99422 100644
--- a/tests/shaders/shader_runner.c
+++ b/tests/shaders/shader_runner.c
@@ -2991,6 +2991,26 @@  query_check_error_int(const char *query_str, int expected, int got)
 	}
 }
 
+static void
+query_check_error_name(const char *query_str,
+		       int expected_length, int got_length,
+		       const char *expected_name, const char *got_name)
+{
+	if (!piglit_check_gl_error(GL_NO_ERROR)) {
+		fprintf(stderr, "%s error\n", query_str);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	if (got_length != expected_length || strcmp(got_name, expected_name)) {
+		fprintf(stderr,
+			"%s: expected (length = %d, name = \"%s\"),"
+			"got (length = %d, name = \"%s\")\n", query_str,
+			expected_length, expected_name,
+			got_length, got_name);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+}
+
 static int
 resource_info_get_block_or_atomic_buffer_index(struct resource_info *resource)
 {
@@ -3209,6 +3229,21 @@  query_resource_by_name(unsigned interface_type, const char *name, unsigned prop,
 	return;
 }
 
+static void
+query_resource_name(unsigned interface_type, GLuint index,
+		    GLsizei expected_length, const char *expected_name,
+		    const char *query_str)
+{
+	GLsizei got_length;
+	char got_name[512];
+
+	glGetProgramResourceName(prog, interface_type, index, sizeof(got_name),
+				 &got_length, got_name);
+
+	query_check_error_name(query_str, expected_length, got_length,
+			       expected_name, got_name);
+}
+
 static void
 parse_resource_info(const char **line, unsigned interface_type,
 		    struct resource_info *resource)
@@ -3589,12 +3624,49 @@  verify_program_interface_query(const char *line,
 					       expected, query_str, block_data);
 		}
 
+	}
+		break;
+	case QUERY_RESOURCE_NAME: {
+		struct resource_info resource = {GL_NONE, -1, -1, -1, -1, false};
+		GLuint index;
+		GLsizei expected_length;
+		char expected_name[512];
+
+		parse_resource_info(&line, interface_type, &resource);
+		index = resource_info_get_index(&resource);
+
+		REQUIRE(parse_int(line, &expected_length, &line),
+			"Bad expected length at: %s\n", line);
+
+		if (parse_str(line, "\"\"", &line))
+			expected_name[0] = '\0';
+		else
+			REQUIRE(parse_word_copy(line, expected_name,
+						sizeof(expected_name), &line),
+				"Bad expected name at: %s\n", line);
+
+		if (strlen(expected_name) != expected_length) {
+			fprintf(stderr,
+				"Expected values for length and name do not "
+				"match: length = %d, name = \"%s\" "
+				"(name's real length = %zu)\n",
+				expected_length, expected_name,
+				strlen(expected_name));
+			piglit_report_result(PIGLIT_FAIL);
+		}
+
+		snprintf(query_str, sizeof(query_str),
+			 "glGetProgramResourceName(%s, %d)",
+			 piglit_get_gl_enum_name(interface_type),
+			 index);
+
+		query_resource_name(interface_type, index,
+				    expected_length, expected_name, query_str);
 	}
 		break;
 	case QUERY_RESOURCE_INDEX:
 	case QUERY_RESOURCE_LOCATION:
 	case QUERY_RESOURCE_LOCATION_INDEX:
-	case QUERY_RESOURCE_NAME:
 		assert(!"Not implemented.");
 		break;
 	default: