[Intel-gfx] [PATCH i-g-t] tests: add i915 query tests
Lionel Landwerlin
lionel.g.landwerlin at intel.com
Mon Dec 18 15:36:35 UTC 2017
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
---
tests/Makefile.sources | 1 +
tests/meson.build | 1 +
tests/query.c | 262 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 264 insertions(+)
create mode 100644 tests/query.c
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index e4e06d01..390cc82b 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -227,6 +227,7 @@ TESTS_progs = \
prime_self_import \
prime_udl \
prime_vgem \
+ query \
sw_sync \
syncobj_basic \
syncobj_wait \
diff --git a/tests/meson.build b/tests/meson.build
index 191ac4ce..f3ef6198 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -204,6 +204,7 @@ test_progs = [
'prime_self_import',
'prime_udl',
'prime_vgem',
+ 'query',
'sw_sync',
'syncobj_basic',
'syncobj_wait',
diff --git a/tests/query.c b/tests/query.c
new file mode 100644
index 00000000..6da500f7
--- /dev/null
+++ b/tests/query.c
@@ -0,0 +1,262 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "igt.h"
+
+IGT_TEST_DESCRIPTION("Testing the query uAPI.");
+
+static bool has_query_supports(int fd)
+{
+ struct drm_i915_query query = {};
+
+ return igt_ioctl(fd, DRM_IOCTL_I915_QUERY, &query) == 0;
+}
+
+static void test_query_garbage(int fd)
+{
+ struct drm_i915_query query;
+ struct drm_i915_query_item items[2];
+
+ memset(&query, 0, sizeof(query));
+ query.num_items = 1;
+ query.items_ptr = 0xffffffff;
+ do_ioctl_err(fd, DRM_IOCTL_I915_QUERY, &query, EFAULT);
+
+ memset(&query, 0, sizeof(query));
+ query.num_items = 1;
+ query.items_ptr = 0;
+ do_ioctl_err(fd, DRM_IOCTL_I915_QUERY, &query, EFAULT);
+
+ memset(&query, 0, sizeof(query));
+ query.num_items = 2;
+ query.items_ptr = (uintptr_t) items;
+ memset(items, 0, sizeof(items));
+ items[0].query_id = 0xffffffff;
+ do_ioctl_err(fd, DRM_IOCTL_I915_QUERY, &query, EINVAL);
+
+ memset(&query, 0, sizeof(query));
+ query.num_items = 2;
+ query.items_ptr = (uintptr_t) items;
+ memset(items, 0, sizeof(items));
+ do_ioctl_err(fd, DRM_IOCTL_I915_QUERY, &query, EINVAL);
+
+ memset(&query, 0, sizeof(query));
+ query.num_items = 2;
+ query.items_ptr = (uintptr_t) items;
+ memset(items, 0, sizeof(items));
+ items[0].query_id = DRM_I915_QUERY_ID_SLICES_MASK;
+ items[0].length = 0xffffffff;
+ items[1].query_id = DRM_I915_QUERY_ID_SUBSLICES_MASK;
+ do_ioctl_err(fd, DRM_IOCTL_I915_QUERY, &query, EINVAL);
+}
+
+static bool query_topology_supported(int fd)
+{
+ struct drm_i915_query query;
+ struct drm_i915_query_item item;
+
+ memset(&query, 0, sizeof(query));
+ query.num_items = 1;
+ query.items_ptr = (uintptr_t) &item;
+
+ memset(&item, 0, sizeof(item));
+ item.query_id = DRM_I915_QUERY_ID_SLICES_MASK;
+
+ return igt_ioctl(fd, DRM_IOCTL_I915_QUERY, &query) == 0;
+}
+
+static void test_query_topology_pre_gen8(int fd)
+{
+ struct drm_i915_query query;
+ struct drm_i915_query_item item;
+
+ memset(&query, 0, sizeof(query));
+ query.num_items = 1;
+ query.items_ptr = (uintptr_t) &item;
+
+ memset(&item, 0, sizeof(item));
+ item.query_id = DRM_I915_QUERY_ID_SLICES_MASK;
+
+ do_ioctl_err(fd, DRM_IOCTL_I915_QUERY, &query, ENODEV);
+}
+
+static void
+test_query_topology_coherent_slice_mask(int fd)
+{
+ struct drm_i915_query query;
+ struct drm_i915_query_item item;
+ struct drm_i915_query_slices_mask *slices_mask;
+ struct drm_i915_query_subslices_mask *subslices_mask;
+ drm_i915_getparam_t gp;
+ int slice_mask, subslice_mask;
+ int i, topology_slices, topology_subslices_slice0;
+
+ gp.param = I915_PARAM_SLICE_MASK;
+ gp.value = &slice_mask;
+ do_ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
+
+ gp.param = I915_PARAM_SUBSLICE_MASK;
+ gp.value = &subslice_mask;
+ do_ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
+
+ igt_debug("slice_mask=0x%x subslice_mask=0x%x\n", slice_mask, subslice_mask);
+
+ /* Slices */
+ memset(&query, 0, sizeof(query));
+ query.num_items = 1;
+ query.items_ptr = (uintptr_t) &item;
+ memset(&item, 0, sizeof(item));
+ item.query_id = DRM_I915_QUERY_ID_SLICES_MASK;
+ do_ioctl(fd, DRM_IOCTL_I915_QUERY, &query);
+
+ slices_mask = (struct drm_i915_query_slices_mask *) calloc(1, item.length);
+
+ item.data_ptr = (uintptr_t) slices_mask;
+ do_ioctl(fd, DRM_IOCTL_I915_QUERY, &query);
+
+ topology_slices = 0;
+ for (i = 0; i < slices_mask->n_slices / 8 + (slices_mask->n_slices % 8) ? 1: 0; i++)
+ topology_slices += __builtin_popcount(slices_mask->data[i]);
+
+ /* These 2 should always match. */
+ igt_assert(__builtin_popcount(slice_mask) == topology_slices);
+
+ free(slices_mask);
+
+ /* Subslices */
+ memset(&query, 0, sizeof(query));
+ query.num_items = 1;
+ query.items_ptr = (uintptr_t) &item;
+ memset(&item, 0, sizeof(item));
+ item.query_id = DRM_I915_QUERY_ID_SUBSLICES_MASK;
+ do_ioctl(fd, DRM_IOCTL_I915_QUERY, &query);
+
+ subslices_mask = (struct drm_i915_query_subslices_mask *) calloc(1, item.length);
+
+ item.data_ptr = (uintptr_t) subslices_mask;
+ do_ioctl(fd, DRM_IOCTL_I915_QUERY, &query);
+
+ topology_subslices_slice0 = 0;
+ for (i = 0; i < subslices_mask->slice_stride; i++)
+ topology_subslices_slice0 += __builtin_popcount(subslices_mask->data[i]);
+
+ /* I915_PARAM_SUBSLICE_MASK returns the value for slice0, we
+ * should match the values for the first slice of the
+ * topology.
+ */
+ igt_assert(__builtin_popcount(subslice_mask) == topology_subslices_slice0);
+
+ free(subslices_mask);
+}
+
+static void
+test_query_topology_matches_eu_total(int fd)
+{
+ struct drm_i915_query query;
+ struct drm_i915_query_item item;
+ struct drm_i915_query_eus_mask *eus_mask;
+ drm_i915_getparam_t gp;
+ int n_eus, n_eus_topology, s;
+
+ gp.param = I915_PARAM_EU_TOTAL;
+ gp.value = &n_eus;
+ do_ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
+ igt_debug("n_eus=%i\n", n_eus);
+
+ memset(&query, 0, sizeof(query));
+ query.num_items = 1;
+ query.items_ptr = (uintptr_t) &item;
+ memset(&item, 0, sizeof(item));
+ item.query_id = DRM_I915_QUERY_ID_EUS_MASK;
+ do_ioctl(fd, DRM_IOCTL_I915_QUERY, &query);
+
+ eus_mask = (struct drm_i915_query_eus_mask *) calloc(1, item.length);
+
+ item.data_ptr = (uintptr_t) eus_mask;
+ do_ioctl(fd, DRM_IOCTL_I915_QUERY, &query);
+
+ igt_debug("n_slices=%u slice_stride=%u subslice_stride=%u\n",
+ eus_mask->n_slices, eus_mask->slice_stride, eus_mask->subslice_stride);
+
+ n_eus_topology = 0;
+ for (s = 0; s < eus_mask->n_slices; s++) {
+ int ss;
+
+ igt_debug("slice%i:\n", s);
+
+ for (ss = 0; ss < eus_mask->slice_stride / eus_mask->subslice_stride; ss++) {
+ int eu, n_subslice_eus = 0;
+
+ igt_debug("\tsubslice: %i\n", ss);
+
+ igt_debug("\t\teu_mask:");
+ for (eu = 0; eu < eus_mask->subslice_stride; eu++) {
+ uint8_t val = eus_mask->data[s * eus_mask->slice_stride +
+ ss * eus_mask->subslice_stride + eu];
+ igt_debug(" 0x%hhx", val);
+ n_subslice_eus += __builtin_popcount(val);
+ n_eus_topology += __builtin_popcount(val);
+ }
+ igt_debug(" (%i)\n", n_subslice_eus);
+ }
+ }
+
+ igt_assert(n_eus_topology == n_eus);
+}
+
+igt_main
+{
+ int fd = -1;
+ int devid;
+
+ igt_fixture {
+ fd = drm_open_driver(DRIVER_INTEL);
+ igt_require(has_query_supports(fd));
+ devid = intel_get_drm_devid(fd);
+ }
+
+ igt_subtest("query-garbage")
+ test_query_garbage(fd);
+
+ igt_subtest("query-topology-pre-gen8") {
+ igt_require(intel_gen(devid) < 8);
+ igt_require(query_topology_supported(fd));
+ test_query_topology_pre_gen8(fd);
+ }
+
+ igt_subtest("query-topology-coherent-slice-mask") {
+ igt_require(AT_LEAST_GEN(devid, 8));
+ igt_require(query_topology_supported(fd));
+ test_query_topology_coherent_slice_mask(fd);
+ }
+
+ igt_subtest("query-topology-matches-eu-total") {
+ igt_require(AT_LEAST_GEN(devid, 8));
+ igt_require(query_topology_supported(fd));
+ test_query_topology_matches_eu_total(fd);
+ }
+
+ igt_fixture {
+ close(fd);
+ }
+}
--
2.15.1
More information about the Intel-gfx
mailing list