[igt-dev] [PATCH i-g-t] tests/i915/query: Test invalid TOPO_INFO flags

Stuart Summers stuart.summers at intel.com
Fri Jun 21 19:15:50 UTC 2019


Current tests only check for invalid flags in the i915_query_ioctl
itself. A user might add invalid flags in the actual TOPO_INFO data,
though, so adding a test cast to confirm the kernel appropriately
rejects this.

Signed-off-by: Stuart Summers <stuart.summers at intel.com>
---
 tests/i915/i915_query.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/tests/i915/i915_query.c b/tests/i915/i915_query.c
index ecbec3ae..8a84d867 100644
--- a/tests/i915/i915_query.c
+++ b/tests/i915/i915_query.c
@@ -33,6 +33,8 @@ IGT_TEST_DESCRIPTION("Testing the i915 query uAPI.");
  */
 #define MIN_TOPOLOGY_ITEM_SIZE (sizeof(struct drm_i915_query_topology_info) + 3)
 
+#define INVALID_FLAGS 42
+
 static int
 __i915_query(int fd, struct drm_i915_query *q)
 {
@@ -80,7 +82,7 @@ static void test_query_garbage(int fd)
 	 * change in the future.
 	 */
 	memset(&query, 0, sizeof(query));
-	query.flags = 42;
+	query.flags = INVALID_FLAGS;
 	igt_assert_eq(__i915_query(fd, &query), -EINVAL);
 
 	/* Test a couple of invalid pointers. */
@@ -96,6 +98,7 @@ static void test_query_garbage_items(int fd)
 {
 	struct drm_i915_query_item items[2];
 	struct drm_i915_query_item *items_ptr;
+	struct drm_i915_query_topology_info *topo_info;
 	int i, n_items;
 
 	/*
@@ -104,9 +107,24 @@ static void test_query_garbage_items(int fd)
 	 */
 	memset(items, 0, sizeof(items));
 	items[0].query_id = DRM_I915_QUERY_TOPOLOGY_INFO;
-	items[0].flags = 42;
+	items[0].flags = INVALID_FLAGS;
+	i915_query_items(fd, items, 1);
+	igt_assert_eq(items[0].length, -EINVAL);
+
+	/*
+	 * Currently no TopologyInfo item flags are valid.
+	 * Subject to change in the future.
+	 */
+	memset(items, 0, sizeof(items));
+	items[0].query_id = DRM_I915_QUERY_TOPOLOGY_INFO;
+	items[0].flags = 0;
+	i915_query_items(fd, items, 1);
+	topo_info = calloc(1, items[0].length);
+	topo_info->flags = INVALID_FLAGS;
+	items[0].data_ptr = to_user_pointer(topo_info);
 	i915_query_items(fd, items, 1);
 	igt_assert_eq(items[0].length, -EINVAL);
+	free(topo_info);
 
 	/*
 	 * Test an invalid query id in the second item and verify that the first
-- 
2.21.0.5.gaeb582a983



More information about the igt-dev mailing list