Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1160341rbb; Sun, 25 Feb 2024 23:59:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWQkzGXUbkqNnpiR0qArKErC30YNcKQpQMkpZVqvjyyF0yRoR7K9OFUqenNoT+y3L0HToVnvFZSMj2j225ql4I1yRvNfkEmt7wAWXAFrQ== X-Google-Smtp-Source: AGHT+IGgeEPoyHHGaG1ZwPbrkk+v/3viOkHQ0vBN4E1IxZIdFW/4HSbkmzCEBitkzvtSTwca31ef X-Received: by 2002:a05:6214:5287:b0:68f:301b:5482 with SMTP id kj7-20020a056214528700b0068f301b5482mr8860851qvb.8.1708934391577; Sun, 25 Feb 2024 23:59:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708934391; cv=pass; d=google.com; s=arc-20160816; b=ZGfDGVENMOdMLrS5p2HBTj0jRi/FAADiIxzj3N1UdCuUmmgBqGKWwCoduyUAHDlu7U W5oYGfz/G2t0ZGM1XKa+GsvE8ZFwiXUNnqHUJXea1agypwx6sVJbJuC0UP4wcJf3+NmT eY0yTK+oTc2W3TP7t3ymKQgc5V0TWSh/nmlQn5PmU1mwooKCwZC5SObBx2Pb0H67nf5t YhagXh1WdRhHiQUY6kMuOOXW97rQ+5lqrZC8WeBvPEsrhNU9tr6l+1WcShWyYGzKwj6i 1EU0g0H5PWMUoNcMaXujJNb7zJTGdJfjctH6zKgsV4H0YMTfep3xJ0t0EMNLsVbDN578 smXA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=5ZDeV/udH/h728mjVMEg+JdAC7gb6plRiltaXMzLehs=; fh=3ITA+hG5KH7F/YE3za0C4YE3vOQC6OhXaAYfDI4ufbk=; b=UtmTRp8w4tbI4vrDYgW4r8s5C9r0pbmleEQa/aAGmQl5YRs0FZS1uQKezRtYIqVV27 T4KMay4wiwUApdVxAYQDstQUJMZS6gBpbrdBmqpfLWaCGdGEckmAPKJg+VeArkYS+Xvp K5Y0aW9FPJHvuMvg3RL6KsWwcpmZcuJtuQtj0z/GSB4uNP2iuAK4wbHwJPyns9CsUJ+m 5FJlqu0NcSFLFaFMadGLY5/EwvEK26zpg0xukIbOsTKz47YJmC6kIgfBQiXqnHKjzOPc 6NtbZRRZ2+FKYJ05Q2Px1BdPJt2DPSLwa6u0Q9zoYGfJnrKnL86Hd159SXcIHOBx/NF2 epCA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=5WokXGds; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-80712-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80712-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jf9-20020a0562142a4900b0068f1bdbb045si4604966qvb.126.2024.02.25.23.59.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 23:59:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80712-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=5WokXGds; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-80712-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80712-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4969A1C20A4F for ; Mon, 26 Feb 2024 07:59:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 303C91C68C; Mon, 26 Feb 2024 07:59:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="5WokXGds" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 348361C28F; Mon, 26 Feb 2024 07:59:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708934384; cv=none; b=mGzH6rnkb+U+TKFoRR3rAP4Ua9wcf+ef0XtKe1Xf9Jol2ACONFqldrXHawBUYVnK7sgD2h+0jrOMo0Qgs+SBnt9v853qC9U7v6P5SW3ef08byUc7IzroV+WXecqa3zs6KKKHPZDeX/L9zNE2UqrMUYZXSyBhHiskZ2VcPxSX8IU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708934384; c=relaxed/simple; bh=koA9/dII/EjEHHfN+tGyNpqaeb7YedB8BnmVF3WeRkE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=rOkxgrlT219g3xsmJjHR6Bv+vhbLtMxdoSJA/9iAtTnsghxe+jLpTqbi1iCGs2uQupmL8aPxv3RzvgsdDQIJKKRkq0TQtwkQbFAk+Y7YTWf9lQ5L2uiVqJ4sOUMj2O70J8sHh078AwWo0ryaqGpd2KMJNxtdOnu53efk1n0bIZA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=5WokXGds; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1708934380; bh=koA9/dII/EjEHHfN+tGyNpqaeb7YedB8BnmVF3WeRkE=; h=From:To:Cc:Subject:Date:From; b=5WokXGds5jFYqtZluGjwNgDXWs8er528U82X3tL+odhWoi5t1mNZOCNEz1ndZkrQZ 0fJzCcKW8kt/xbL977jOE50E+1y9laDftW5AcKqRCjGSEX9oqg8TyMv/UJOXoSbm/8 Wa6hFBC5rTGiYQpCMM2LmmkjZeEOdeDyh0TswusA7r8UJhybIYLSG2nen0mwUmDx98 kNzeAV2LLNVfgPF0CrYb1jBlLQe6W2z/3xDmKk9U1AyPRQ1JvgD+srn7y/k5TH5fs/ 2OwyKWL9Z+UtDtOt4W9Ws2VeqKGSn0VbY+JnisicQ+sjXuwExzM1d7kk5YnkkluL1f s8PC0n1Ol6OgQ== Received: from localhost.localdomain (ec2-34-240-57-77.eu-west-1.compute.amazonaws.com [34.240.57.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 511673780B5F; Mon, 26 Feb 2024 07:59:38 +0000 (UTC) From: Muhammad Usama Anjum To: Shuah Khan , Muhammad Usama Anjum Cc: kernel@collabora.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] selftests/dmabuf-heap: conform test to TAP format output Date: Mon, 26 Feb 2024 12:59:54 +0500 Message-ID: <20240226080003.4094089-1-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. Signed-off-by: Muhammad Usama Anjum --- .../selftests/dmabuf-heaps/dmabuf-heap.c | 194 +++++++----------- 1 file changed, 77 insertions(+), 117 deletions(-) diff --git a/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c index 890a8236a8ba7..6e538e346cb8f 100644 --- a/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c +++ b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c @@ -15,6 +15,7 @@ #include #include #include +#include "../kselftest.h" #define DEVPATH "/dev/dma_heap" @@ -90,14 +91,13 @@ static int dmabuf_heap_open(char *name) char buf[256]; ret = snprintf(buf, 256, "%s/%s", DEVPATH, name); - if (ret < 0) { - printf("snprintf failed!\n"); - return ret; - } + if (ret < 0) + ksft_exit_fail_msg("snprintf failed!\n"); fd = open(buf, O_RDWR); if (fd < 0) - printf("open %s failed!\n", buf); + ksft_exit_fail_msg("open %s failed: %s\n", buf, strerror(errno)); + return fd; } @@ -140,7 +140,7 @@ static int dmabuf_sync(int fd, int start_stop) #define ONE_MEG (1024 * 1024) -static int test_alloc_and_import(char *heap_name) +static void test_alloc_and_import(char *heap_name) { int heap_fd = -1, dmabuf_fd = -1, importer_fd = -1; uint32_t handle = 0; @@ -148,16 +148,12 @@ static int test_alloc_and_import(char *heap_name) int ret; heap_fd = dmabuf_heap_open(heap_name); - if (heap_fd < 0) - return -1; - printf(" Testing allocation and importing: "); + ksft_print_msg("Testing allocation and importing:\n"); ret = dmabuf_heap_alloc(heap_fd, ONE_MEG, 0, &dmabuf_fd); - if (ret) { - printf("FAIL (Allocation Failed!)\n"); - ret = -1; - goto out; - } + if (ret) + ksft_exit_fail_msg("FAIL (Allocation Failed!)\n"); + /* mmap and write a simple pattern */ p = mmap(NULL, ONE_MEG, @@ -166,7 +162,7 @@ static int test_alloc_and_import(char *heap_name) dmabuf_fd, 0); if (p == MAP_FAILED) { - printf("FAIL (mmap() failed)\n"); + ksft_print_msg("FAIL (mmap() failed)\n"); ret = -1; goto out; } @@ -179,31 +175,28 @@ static int test_alloc_and_import(char *heap_name) importer_fd = open_vgem(); if (importer_fd < 0) { ret = importer_fd; - printf("(Could not open vgem - skipping): "); + ksft_test_result_skip("Could not open vgem\n"); } else { ret = import_vgem_fd(importer_fd, dmabuf_fd, &handle); - if (ret < 0) { - printf("FAIL (Failed to import buffer)\n"); - goto out; - } + ksft_test_result(ret >= 0, "Import buffer\n"); } ret = dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START); if (ret < 0) { - printf("FAIL (DMA_BUF_SYNC_START failed!)\n"); + ksft_print_msg("FAIL (DMA_BUF_SYNC_START failed!)\n"); goto out; } memset(p, 0xff, ONE_MEG); ret = dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_END); if (ret < 0) { - printf("FAIL (DMA_BUF_SYNC_END failed!)\n"); + ksft_print_msg("FAIL (DMA_BUF_SYNC_END failed!)\n"); goto out; } close_handle(importer_fd, handle); - ret = 0; - printf(" OK\n"); + ksft_test_result_pass("%s\n", __func__); + return; out: if (p) munmap(p, ONE_MEG); @@ -214,32 +207,29 @@ static int test_alloc_and_import(char *heap_name) if (heap_fd >= 0) close(heap_fd); - return ret; + ksft_test_result_fail("%s\n", __func__); } -static int test_alloc_zeroed(char *heap_name, size_t size) +static void test_alloc_zeroed(char *heap_name, size_t size) { int heap_fd = -1, dmabuf_fd[32]; int i, j, ret; void *p = NULL; char *c; - printf(" Testing alloced %ldk buffers are zeroed: ", size / 1024); + ksft_print_msg("Testing alloced %ldk buffers are zeroed:\n", size / 1024); heap_fd = dmabuf_heap_open(heap_name); - if (heap_fd < 0) - return -1; /* Allocate and fill a bunch of buffers */ for (i = 0; i < 32; i++) { ret = dmabuf_heap_alloc(heap_fd, size, 0, &dmabuf_fd[i]); - if (ret < 0) { - printf("FAIL (Allocation (%i) failed)\n", i); - goto out; - } + if (ret) + ksft_exit_fail_msg("FAIL (Allocation (%i) failed)\n", i); + /* mmap and fill with simple pattern */ p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, dmabuf_fd[i], 0); if (p == MAP_FAILED) { - printf("FAIL (mmap() failed!)\n"); + ksft_print_msg("FAIL (mmap() failed!)\n"); ret = -1; goto out; } @@ -255,15 +245,13 @@ static int test_alloc_zeroed(char *heap_name, size_t size) /* Allocate and validate all buffers are zeroed */ for (i = 0; i < 32; i++) { ret = dmabuf_heap_alloc(heap_fd, size, 0, &dmabuf_fd[i]); - if (ret < 0) { - printf("FAIL (Allocation (%i) failed)\n", i); - goto out; - } + if (ret < 0) + ksft_exit_fail_msg("FAIL (Allocation (%i) failed)\n", i); /* mmap and validate everything is zero */ p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, dmabuf_fd[i], 0); if (p == MAP_FAILED) { - printf("FAIL (mmap() failed!)\n"); + ksft_print_msg("FAIL (mmap() failed!)\n"); ret = -1; goto out; } @@ -271,7 +259,7 @@ static int test_alloc_zeroed(char *heap_name, size_t size) c = (char *)p; for (j = 0; j < size; j++) { if (c[j] != 0) { - printf("FAIL (Allocated buffer not zeroed @ %i)\n", j); + ksft_print_msg("FAIL (Allocated buffer not zeroed @ %i)\n", j); break; } } @@ -283,8 +271,8 @@ static int test_alloc_zeroed(char *heap_name, size_t size) close(dmabuf_fd[i]); close(heap_fd); - printf("OK\n"); - return 0; + ksft_test_result_pass("%s\n", __func__); + return; out: while (i > 0) { @@ -292,7 +280,7 @@ static int test_alloc_zeroed(char *heap_name, size_t size) i--; } close(heap_fd); - return ret; + ksft_test_result_fail("%s\n", __func__); } /* Test the ioctl version compatibility w/ a smaller structure then expected */ @@ -360,126 +348,98 @@ static int dmabuf_heap_alloc_newer(int fd, size_t len, unsigned int flags, return ret; } -static int test_alloc_compat(char *heap_name) +static void test_alloc_compat(char *heap_name) { - int heap_fd = -1, dmabuf_fd = -1; - int ret; + int ret, heap_fd = -1, dmabuf_fd = -1; heap_fd = dmabuf_heap_open(heap_name); - if (heap_fd < 0) - return -1; - printf(" Testing (theoretical)older alloc compat: "); + ksft_print_msg("Testing (theoretical)older alloc compat:\n"); ret = dmabuf_heap_alloc_older(heap_fd, ONE_MEG, 0, &dmabuf_fd); - if (ret) { - printf("FAIL (Older compat allocation failed!)\n"); - ret = -1; - goto out; - } - close(dmabuf_fd); - printf("OK\n"); + if (dmabuf_fd >= 0) + close(dmabuf_fd); + ksft_test_result(!ret, "dmabuf_heap_alloc_older\n"); - printf(" Testing (theoretical)newer alloc compat: "); + ksft_print_msg("Testing (theoretical)newer alloc compat:\n"); ret = dmabuf_heap_alloc_newer(heap_fd, ONE_MEG, 0, &dmabuf_fd); - if (ret) { - printf("FAIL (Newer compat allocation failed!)\n"); - ret = -1; - goto out; - } - printf("OK\n"); -out: if (dmabuf_fd >= 0) close(dmabuf_fd); - if (heap_fd >= 0) - close(heap_fd); + ksft_test_result(!ret, "dmabuf_heap_alloc_newer\n"); - return ret; + close(heap_fd); } -static int test_alloc_errors(char *heap_name) +static void test_alloc_errors(char *heap_name) { int heap_fd = -1, dmabuf_fd = -1; int ret; heap_fd = dmabuf_heap_open(heap_name); - if (heap_fd < 0) - return -1; - printf(" Testing expected error cases: "); + ksft_print_msg("Testing expected error cases:\n"); ret = dmabuf_heap_alloc(0, ONE_MEG, 0x111111, &dmabuf_fd); - if (!ret) { - printf("FAIL (Did not see expected error (invalid fd)!)\n"); - ret = -1; - goto out; - } + ksft_test_result(ret, "Error expected on invalid fd\n"); ret = dmabuf_heap_alloc(heap_fd, ONE_MEG, 0x111111, &dmabuf_fd); - if (!ret) { - printf("FAIL (Did not see expected error (invalid heap flags)!)\n"); - ret = -1; - goto out; - } + ksft_test_result(ret, "Error expected on invalid heap flags\n"); ret = dmabuf_heap_alloc_fdflags(heap_fd, ONE_MEG, ~(O_RDWR | O_CLOEXEC), 0, &dmabuf_fd); - if (!ret) { - printf("FAIL (Did not see expected error (invalid fd flags)!)\n"); - ret = -1; - goto out; - } + ksft_test_result(ret, "Error expected on invalid heap flags\n"); - printf("OK\n"); - ret = 0; -out: if (dmabuf_fd >= 0) close(dmabuf_fd); if (heap_fd >= 0) close(heap_fd); +} - return ret; +static int numer_of_heaps(void) +{ + DIR *d = opendir(DEVPATH); + struct dirent *dir; + int heaps = 0; + + while ((dir = readdir(d))) { + if (!strncmp(dir->d_name, ".", 2)) + continue; + if (!strncmp(dir->d_name, "..", 3)) + continue; + heaps++; + } + + return heaps; } int main(void) { - DIR *d; struct dirent *dir; - int ret = -1; + DIR *d; + + ksft_print_header(); d = opendir(DEVPATH); if (!d) { - printf("No %s directory?\n", DEVPATH); - return -1; + ksft_print_msg("No %s directory?\n", DEVPATH); + return KSFT_SKIP; } - while ((dir = readdir(d)) != NULL) { + ksft_set_plan(9 * numer_of_heaps()); + + while ((dir = readdir(d))) { if (!strncmp(dir->d_name, ".", 2)) continue; if (!strncmp(dir->d_name, "..", 3)) continue; - printf("Testing heap: %s\n", dir->d_name); - printf("=======================================\n"); - ret = test_alloc_and_import(dir->d_name); - if (ret) - break; - - ret = test_alloc_zeroed(dir->d_name, 4 * 1024); - if (ret) - break; - - ret = test_alloc_zeroed(dir->d_name, ONE_MEG); - if (ret) - break; - - ret = test_alloc_compat(dir->d_name); - if (ret) - break; - - ret = test_alloc_errors(dir->d_name); - if (ret) - break; + ksft_print_msg("Testing heap: %s\n", dir->d_name); + ksft_print_msg("=======================================\n"); + test_alloc_and_import(dir->d_name); + test_alloc_zeroed(dir->d_name, 4 * 1024); + test_alloc_zeroed(dir->d_name, ONE_MEG); + test_alloc_compat(dir->d_name); + test_alloc_errors(dir->d_name); } closedir(d); - return ret; + ksft_finished(); } -- 2.42.0