From patchwork Tue Mar 5 20:54:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 10840119 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D64E117E0 for ; Tue, 5 Mar 2019 20:54:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C48AF2CDE6 for ; Tue, 5 Mar 2019 20:54:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B88972CECD; Tue, 5 Mar 2019 20:54:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4D9B42CDE6 for ; Tue, 5 Mar 2019 20:54:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E1B4A89DE5; Tue, 5 Mar 2019 20:54:51 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8FEF789DE5 for ; Tue, 5 Mar 2019 20:54:50 +0000 (UTC) Received: by mail-pf1-x443.google.com with SMTP id i19so6623781pfd.0 for ; Tue, 05 Mar 2019 12:54:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yRzxxqyWBOZSHUPCrEH0/twSX4oAAXNjDpDvvJwFuKY=; b=Dv8VcA8XXxxx96WPoGcLlOg//a+7/2BZlbhjcLO98tHAtAD9ET9UGA1+M/Q2nelNaY 5c9m+A+RHRuGfwZT0WP2SP6OfyN76h77Lhzl0dhG7JP54o0Q3GnmSuNdEGzgBEHSd2eP 7ArQ5N+MsxXS+4v0hlbkq/yNvZ0sm8cv9kxtFd2whxJzxsM27bJhPc0KPQv29uvx7p5S enxVo51czuMmBwyXz5Y8CgmFsQrryd3lsADSj+ZcZvJOuBseKjDI9iXWP2z1rCRURKTB YtYjClXKlc1WehcOfPl7mdnTVARlIDf7SAOx5uUb8igHMQJyWpn8zzqLfnSjte6LYpHu rdeQ== X-Gm-Message-State: APjAAAWsglNXVdBub/nKuJhniNnMKDp/ivROaX5h0KYLpcCfwyw8OKMB O4a6M3OEoVcRzvHWHLcLa1OF+g== X-Google-Smtp-Source: APXvYqxF7ykA/kf99QruolBopZYp5p4PGISA/FBp9efQscn5LVLJvQ9HEnAdWkYDlooRd84lKgzCzQ== X-Received: by 2002:a63:7444:: with SMTP id e4mr3119864pgn.398.1551819289844; Tue, 05 Mar 2019 12:54:49 -0800 (PST) Received: from localhost.localdomain ([2601:1c2:680:1319:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id i4sm13411788pfo.158.2019.03.05.12.54.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Mar 2019 12:54:48 -0800 (PST) From: John Stultz To: lkml Subject: [RFC][PATCH 5/5 v2] kselftests: Add dma-heap test Date: Tue, 5 Mar 2019 12:54:33 -0800 Message-Id: <1551819273-640-6-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1551819273-640-1-git-send-email-john.stultz@linaro.org> References: <1551819273-640-1-git-send-email-john.stultz@linaro.org> X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yRzxxqyWBOZSHUPCrEH0/twSX4oAAXNjDpDvvJwFuKY=; b=Ig9NrpoLNuMDfa1+uWlGupfOqBCwIQ+ARCCn0xpftFCT3CL10AADvXWK6+JhSnvz4W p3k6GJJ2Z1mlHzqRsm5OHk/PK4cC6Dk23pAfM300lbS6bVkUcxds/Pspgzvci2Si0/bJ y2o8svN7nDilfgoFvx4QdJvS7od2QiEIx6knwSOtqD18tZf3je3SQirbipJ1VicIE/YN 5YqWpTO+nOXUaf8LIxcqMDMEnEXrvTQue+vlk1lS0l+KCI+3g8eR/oiEmcNmeTkHFKAJ kM3pIRH9pB6Zwzc6w2xAocRDCHT/LJ7HDwAS7pjS4XowquDPevvezNeVxmLOQSos47n3 OjqQ== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg KH , Chenbo Feng , Alistair Strachan , Liam Mark , dri-devel@lists.freedesktop.org, "Andrew F . Davis" MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add very trivial allocation test for dma-heaps. TODO: Need to actually do some validation on the returned dma-buf. Cc: Laura Abbott Cc: Benjamin Gaignard Cc: Greg KH Cc: Sumit Semwal Cc: Liam Mark Cc: Brian Starkey Cc: Andrew F. Davis Cc: Chenbo Feng Cc: Alistair Strachan Cc: dri-devel@lists.freedesktop.org Signed-off-by: John Stultz --- v2: Switched to use reworked dma-heap apis --- tools/testing/selftests/dmabuf-heaps/Makefile | 11 +++ tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c | 96 ++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 tools/testing/selftests/dmabuf-heaps/Makefile create mode 100644 tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c diff --git a/tools/testing/selftests/dmabuf-heaps/Makefile b/tools/testing/selftests/dmabuf-heaps/Makefile new file mode 100644 index 0000000..c414ad3 --- /dev/null +++ b/tools/testing/selftests/dmabuf-heaps/Makefile @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 +CFLAGS += -static -O3 -Wl,-no-as-needed -Wall +#LDLIBS += -lrt -lpthread -lm + +# these are all "safe" tests that don't modify +# system time or require escalated privileges +TEST_GEN_PROGS = dmabuf-heap + + +include ../lib.mk + diff --git a/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c new file mode 100644 index 0000000..06837a4 --- /dev/null +++ b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../../../include/uapi/linux/dma-heap.h" + +#define DEVPATH "/dev/dma_heap" + +int dmabuf_heap_open(char *name) +{ + int ret, fd; + char buf[256]; + + ret = sprintf(buf, "%s/%s", DEVPATH, name); + if (ret < 0) { + printf("sprintf failed!\n"); + return ret; + } + + fd = open(buf, O_RDWR); + if (fd < 0) + printf("open %s failed!\n", buf); + return fd; +} + +int dmabuf_heap_alloc(int fd, size_t len, unsigned int flags, int *dmabuf_fd) +{ + struct dma_heap_allocation_data data = { + .len = len, + .flags = flags, + }; + int ret; + + if (dmabuf_fd == NULL) + return -EINVAL; + + ret = ioctl(fd, DMA_HEAP_IOC_ALLOC, &data); + if (ret < 0) + return ret; + *dmabuf_fd = (int)data.fd; + return ret; +} + +#define ONE_MEG (1024*1024) + +void do_test(char *heap_name) +{ + int heap_fd = -1, dmabuf_fd = -1; + int ret; + + printf("Testing heap: %s\n", heap_name); + + heap_fd = dmabuf_heap_open(heap_name); + if (heap_fd < 0) + return; + + printf("Allocating 1 MEG\n"); + ret = dmabuf_heap_alloc(heap_fd, ONE_MEG, 0, &dmabuf_fd); + if (ret) + goto out; + + /* DO SOMETHING WITH THE DMABUF HERE? */ + +out: + if (dmabuf_fd >= 0) + close(dmabuf_fd); + if (heap_fd >= 0) + close(heap_fd); +} + + +int main(void) +{ + DIR *d; + struct dirent *dir; + + d = opendir(DEVPATH); + if (!d) { + printf("No %s directory?\n", DEVPATH); + return -1; + } + + while ((dir = readdir(d)) != NULL) + do_test(dir->d_name); + + + return 0; +}