Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp4403219imb; Wed, 6 Mar 2019 12:32:26 -0800 (PST) X-Google-Smtp-Source: APXvYqwpNJ+p2j4b6p/wSNIZhJQX6McWkXJm+/34H3llhic+CV0L3sQ/Robnoq8iqXLkeiIiG9tl X-Received: by 2002:a65:63c1:: with SMTP id n1mr7856712pgv.339.1551904346905; Wed, 06 Mar 2019 12:32:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551904346; cv=none; d=google.com; s=arc-20160816; b=grxs7eeWeMxGZoY6PekY+PsnvuePPvibeDloDK4w2IzpVfr2+fTP6sEl4tgkL5WSBS 2MvChrlAK8v8CdM4pcSC/+SxWKpZ057DOQfSz2iOdS5/UdbERtZj00pVP+kDVp5plr1Y ZWF8e0lF+kFC+rD1bfrEjYoknArk43rmBSC2B/+uU6r2IwUUpr0NnZtViOZwTmeo8DOp ffYi2x3XgfdAFDK6H9Gh3JQklWYMmiBs3FP3uMVvOa0Pt2Y64quctxVEhQsY6UdWk9pD hwX/xOwErf/sfMeyGPpzqZlpHh6j377NUDN2WFGPYTz64nQrXPR6Y2myxwNeLZKyAx4X UTTA== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=KX1v2Gtz/AZRJmP5V/LEY6XIdQRknfHOkMJbmb6XVLo=; b=frjzup8zT471NSW9U7mI77OfX6966sXpXnmbs6vl0q3rh15+yIpV6YdRYG0YVEEvtd 2h2d0AJ4bKBOE9S9Xi7aTQ6A9nkLehd6DGqDldDPq6A4Is8KrwEpSIgudT09yt8yMSpE z+uO/h9p9nFDtAhkYpoL2whqw63Ute02liQ3ulSvOuLyMyyPkt4ZRjEdCZTjof75uJVX M+baJOEFzxS+a1X7bisrA1b3GVK7Hiad/cDv7L1EjAjFYJCFbVB1i9MZEeUCzuQ3kDmC ubFYkmoX9nlO7ubyRCCkjuN7NOshLrlY0iZ73UXQ6i50tLAoIwlzTq7DKZlBKFipwgA1 qy2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JFOzYHpN; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i10si2379753pfj.186.2019.03.06.12.32.08; Wed, 06 Mar 2019 12:32:26 -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=@linaro.org header.s=google header.b=JFOzYHpN; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729156AbfCFSTu (ORCPT + 99 others); Wed, 6 Mar 2019 13:19:50 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:37086 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726729AbfCFSTu (ORCPT ); Wed, 6 Mar 2019 13:19:50 -0500 Received: by mail-wm1-f67.google.com with SMTP id x10so6802378wmg.2 for ; Wed, 06 Mar 2019 10:19:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=KX1v2Gtz/AZRJmP5V/LEY6XIdQRknfHOkMJbmb6XVLo=; b=JFOzYHpNhz5IYNT4USkiUQPNxaOF6EBiEiMq4hLrACzrcpWBJlOYs76SdQnEyHBU2M bJiN2lRGakqGuoecRzNxXbtsjrt0KG+SnTCEEm3QbL1ar5wrPUN0iURB+tEweXN9CiSh fkG+K+ilLC361mifIE3aCVnZEIkLV+uqG0gPhJdQkwvooiZ9wgnldxlUrDjpj2IulT1u ksqNnZw/mJO8uYZi6+lRuhPMyi/2MQ3fLHP41Axz0WFzBgXaIzNWriRBZDXcsVFypxCy orEdKiNob7/Fsi3FKWNzxeZfKfdv+MnnVOaFl5ON/1Gl9GW1AVuNwSo0/VUSIY9QqZT/ 6iiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=KX1v2Gtz/AZRJmP5V/LEY6XIdQRknfHOkMJbmb6XVLo=; b=gGUuUwJATzLLLF4VMZiabR2rCJl9xkKRxFpKCiTmsAajYKW+hrACY3ut47z1XgNSr6 8PWb/HTF4PznAhncI4apaQhu4ULn0lRRqu8wJOBjxgdWVDJMPikYwx+uUKHKOSz9GtGf uEcM/K96EQ/a5/p3CFVqdB+MyxfJbnYxLvNX0I4/h3bCSCp3p/ALqQFfCAGBroSWDsBK j5pGZRbyJP9q74bfCnxTYe7X3Hb2m6KNp6R8cCUTLErDKiUIoF/Ntviwe/LiYaVjGycM Uw+JdM9aEyJBpQUtRgiWPRiTLHPmUymgMMMcwg02Vqczy8mMQB/hbVeSHCmADQicL0JT Rd7Q== X-Gm-Message-State: APjAAAXxqA58/6tqOUaOdh+VhnIH286vxfmvH9ErxwjylWzwt1E/PX/n wfAcWILQN87GZGomY2HOG5a9eUh0wwDJSy511Ejx3w== X-Received: by 2002:a1c:230e:: with SMTP id j14mr3418621wmj.9.1551896387131; Wed, 06 Mar 2019 10:19:47 -0800 (PST) MIME-Version: 1.0 References: <1551819273-640-1-git-send-email-john.stultz@linaro.org> <1551819273-640-6-git-send-email-john.stultz@linaro.org> <7deadc25-c8b2-3b58-1867-86f7db3188fa@ti.com> In-Reply-To: <7deadc25-c8b2-3b58-1867-86f7db3188fa@ti.com> From: John Stultz Date: Wed, 6 Mar 2019 10:19:36 -0800 Message-ID: Subject: Re: [RFC][PATCH 5/5 v2] kselftests: Add dma-heap test To: "Andrew F. Davis" Cc: Benjamin Gaignard , lkml , Laura Abbott , Greg KH , Sumit Semwal , Liam Mark , Brian Starkey , Chenbo Feng , Alistair Strachan , ML dri-devel Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 6, 2019 at 10:15 AM Andrew F. Davis wrote: > > On 3/6/19 10:14 AM, Benjamin Gaignard wrote: > > Le mar. 5 mars 2019 =C3=A0 21:54, John Stultz = a =C3=A9crit : > >> > >> 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/tes= ting/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 +=3D -static -O3 -Wl,-no-as-needed -Wall > >> +#LDLIBS +=3D -lrt -lpthread -lm > >> + > >> +# these are all "safe" tests that don't modify > >> +# system time or require escalated privileges > >> +TEST_GEN_PROGS =3D dmabuf-heap > >> + > >> + > >> +include ../lib.mk > >> + > >> diff --git a/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c b/tool= s/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 =3D sprintf(buf, "%s/%s", DEVPATH, name); > >> + if (ret < 0) { > >> + printf("sprintf failed!\n"); > >> + return ret; > >> + } > >> + > >> + fd =3D 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 *dm= abuf_fd) > >> +{ > >> + struct dma_heap_allocation_data data =3D { > >> + .len =3D len, > >> + .flags =3D flags, > >> + }; > >> + int ret; > >> + > >> + if (dmabuf_fd =3D=3D NULL) > >> + return -EINVAL; > >> + > >> + ret =3D ioctl(fd, DMA_HEAP_IOC_ALLOC, &data); > >> + if (ret < 0) > >> + return ret; > >> + *dmabuf_fd =3D (int)data.fd; > >> + return ret; > >> +} > >> + > >> +#define ONE_MEG (1024*1024) > >> + > >> +void do_test(char *heap_name) > >> +{ > >> + int heap_fd =3D -1, dmabuf_fd =3D -1; > >> + int ret; > >> + > >> + printf("Testing heap: %s\n", heap_name); > >> + > >> + heap_fd =3D dmabuf_heap_open(heap_name); > >> + if (heap_fd < 0) > >> + return; > >> + > >> + printf("Allocating 1 MEG\n"); > >> + ret =3D 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. Cool! Do you mind sharing that? I might try to rework and integrate it into this patchset? thanks -john