Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id E8EF310F49F for ; Thu, 24 Feb 2022 07:54:30 +0000 (UTC) From: =?UTF-8?q?Zbigniew=20Kempczy=C5=84ski?= To: igt-dev@lists.freedesktop.org Date: Thu, 24 Feb 2022 08:54:15 +0100 Message-Id: <20220224075415.18663-3-zbigniew.kempczynski@intel.com> In-Reply-To: <20220224075415.18663-1-zbigniew.kempczynski@intel.com> References: <20220224075415.18663-1-zbigniew.kempczynski@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [igt-dev] [PATCH i-g-t 2/2] tests/api_intel_allocator: Add default-alignment test List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: Test verifies that intel-allocator uses caller default-alignment setting during open() instead of choosing safe alignment instead. Also check does alloc() can overwrite default setting used by the allocator. v2: rename allocator -> default-allocator test name Signed-off-by: Zbigniew KempczyƄski Cc: Ashutosh Dixit --- tests/i915/api_intel_allocator.c | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/i915/api_intel_allocator.c b/tests/i915/api_intel_allocator.c index 7ae4a00b7..32d1aad70 100644 --- a/tests/i915/api_intel_allocator.c +++ b/tests/i915/api_intel_allocator.c @@ -120,6 +120,34 @@ static void reserve(int fd, uint8_t type) igt_assert_eq(intel_allocator_close(ahnd), true); } +static void default_alignment(int fd) +{ + struct test_obj obj[3]; + uint64_t ahnd, default_alignment = 0x4000; + + ahnd = intel_allocator_open_full(fd, 0, 0, 0, INTEL_ALLOCATOR_SIMPLE, + ALLOC_STRATEGY_LOW_TO_HIGH, + default_alignment); + + for (int i = 0; i < ARRAY_SIZE(obj); i++) { + obj[i].handle = gem_handle_gen(); + obj[i].offset = intel_allocator_alloc(ahnd, obj[i].handle, 4096, + i == 2 ? 4096 : 0); + igt_debug("obj[%d].offset: %llx, handle: %u\n", i, + (long long) obj[i].offset, obj[i].handle); + } + + igt_assert_eq(obj[1].offset - obj[0].offset, default_alignment); + /* obj[2] should be between obj[0] and obj[1] */ + igt_assert(obj[0].offset < obj[2].offset); + igt_assert(obj[2].offset < obj[1].offset); + + for (int i = 0; i < ARRAY_SIZE(obj); i++) + intel_allocator_free(ahnd, obj[i].handle); + + igt_assert_eq(intel_allocator_close(ahnd), true); +} + static bool overlaps(struct test_obj *buf1, struct test_obj *buf2) { uint64_t begin1 = buf1->offset; @@ -692,6 +720,11 @@ igt_main igt_subtest_f("reserve") reserve(fd, INTEL_ALLOCATOR_SIMPLE); + igt_describe("For simple allocator check does default alignment is " + "properly handled in open and alloc functions"); + igt_subtest_f("default-alignment") + default_alignment(fd); + for (a = als; a->name; a++) { igt_subtest_with_dynamic_f("%s-allocator", a->name) { igt_dynamic("basic") -- 2.32.0