Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp4324729imb; Wed, 6 Mar 2019 10:32:47 -0800 (PST) X-Google-Smtp-Source: APXvYqz8jpRw3N6WNxBMDOmou2LdVIAcQmmlYbO3Jonl0ktwWu3/S2E6McCV/8mJqVfaWNUtWxp6 X-Received: by 2002:a63:6b03:: with SMTP id g3mr7516045pgc.239.1551897167685; Wed, 06 Mar 2019 10:32:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551897167; cv=none; d=google.com; s=arc-20160816; b=Z/FMLlnIG5Nhl3d5oft4LYuOvrKIu4YDjzRmvMjlkSlZdry/U2Xc1F3Q1jCxPmX/TJ lYb4Csk9TSkx/Dis5AOceWUAkwyqxgCu/w57tcVjqKqkeCeqcC9OmhXZf8GuAV/MW2QL UgEpshOvas6prwsHtWMBPcCxl8y+nNAR7L0CyJK/1p7xDnBy4MSGIUcMeMT7/Yvwci+5 bfMvdZtD+fI4IfBm0G+kpKffsiT5G+g+lDZn94wzhdBzNgJ26ynCYrSmxr4Ay3rVHdX4 i4xTymnG7poe9nJrv7GeM+5lC2coq9Px+ApQ/qYz7jfe741q7voUAS5JwlLbqcF+2ZMT e2bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=+NyjXpvPvY1gbMytdUJvxlZjmbe1R0SCy//cwga7IuY=; b=MtEw0Z+F8bRJQBpZkKKxsow0H5Cep1NNUQOFMWe6FEGAroQzBMoJNWuUjLR0aZ0SlY 1H+WADnqAGPG/iSujWuelS74c3a0X5185AkUPi46HxMpfhB9/1EDXE0IIKasi6fCXEXO rmhoxDriWTeuXPA3U9QpOp1S6BwwMzrWAi3uvuflEGQR0dK3bbUKsEr120ajVxjSXwmY tzhGfagB5oPbOOljjnDoJd4uITKjm4Ut0V8NrmvevUgRYnR0lXAWZkBmVtGGt/nyzzlG xEn+oYKNP+xJtbw00iHvmViepLVxw1DGCtpgRfXC76Jt8NiWBeNhm2fpezHfiUpSaSJx i1xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=JARs0q7a; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l84si2270542pfi.35.2019.03.06.10.32.32; Wed, 06 Mar 2019 10:32:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=JARs0q7a; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729889AbfCFQfy (ORCPT + 99 others); Wed, 6 Mar 2019 11:35:54 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:49988 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727436AbfCFQfy (ORCPT ); Wed, 6 Mar 2019 11:35:54 -0500 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id x26GZTdS122582; Wed, 6 Mar 2019 10:35:29 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1551890129; bh=+NyjXpvPvY1gbMytdUJvxlZjmbe1R0SCy//cwga7IuY=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=JARs0q7a1pnZs7yiPa5EYRAsA4DeAfpybPU8cuIfdzdjWAZwzXqn5Z0dpmJlO+lF1 NXjv10qCuCTsRGLq8Wr7e+0wH1rcYky4rf1Z5lfrmOeJvs+s/vWgzgQ8/V1f5E+j5L vfHp1P8tMgVon+3j20UdRB8adnisK63LfpU5qm7c= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x26GZTKg077850 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 6 Mar 2019 10:35:29 -0600 Received: from DLEE110.ent.ti.com (157.170.170.21) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Wed, 6 Mar 2019 10:35:28 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE110.ent.ti.com (157.170.170.21) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Wed, 6 Mar 2019 10:35:28 -0600 Received: from [172.22.114.173] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id x26GZSEP025964; Wed, 6 Mar 2019 10:35:28 -0600 Subject: Re: [RFC][PATCH 5/5 v2] kselftests: Add dma-heap test To: Benjamin Gaignard , John Stultz CC: lkml , Laura Abbott , Greg KH , Sumit Semwal , Liam Mark , Brian Starkey , Chenbo Feng , Alistair Strachan , ML dri-devel References: <1551819273-640-1-git-send-email-john.stultz@linaro.org> <1551819273-640-6-git-send-email-john.stultz@linaro.org> From: "Andrew F. Davis" Message-ID: <7deadc25-c8b2-3b58-1867-86f7db3188fa@ti.com> Date: Wed, 6 Mar 2019 10:35:27 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/6/19 10:14 AM, Benjamin Gaignard wrote: > Le mar. 5 mars 2019 à 21:54, John Stultz a écrit : >> >> 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? */ > > You can do a call to mmap and write a pattern in the buffer. > mmap is optional for DMA-BUFs, only attach/map are required. To test those we would need a dummy device, so a test kernel module may be needed to really exercise this. I have one I use for ION buffer testing, it consumes a DMA-BUF passed from userspace, attach/maps it to a dummy device then return the physical address of the first page of the buffer for validation. Might be a good test, but dummy devices don't always have the proper dma attributes set like a real device does, so it may also fail for some otherwise valid buffers. Andrew > Benjamin >> + >> +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; >> +} >> -- >> 2.7.4 >> > >