From: Sandeep Patil <sspatil@android.com>
To: John Stultz <john.stultz@linaro.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
Benjamin Gaignard <benjamin.gaignard@linaro.org>,
Sumit Semwal <sumit.semwal@linaro.org>,
Liam Mark <lmark@codeaurora.org>,
Pratik Patel <pratikp@codeaurora.org>,
Brian Starkey <Brian.Starkey@arm.com>,
Vincent Donnefort <Vincent.Donnefort@arm.com>,
Sudipto Paul <Sudipto.Paul@arm.com>,
"Andrew F . Davis" <afd@ti.com>,
Christoph Hellwig <hch@infradead.org>,
Chenbo Feng <fengc@google.com>,
Alistair Strachan <astrachan@google.com>,
Hridya Valsaraju <hridya@google.com>,
Hillf Danton <hdanton@sina.com>, Dave Airlie <airlied@gmail.com>,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v14 5/5] kselftests: Add dma-heap test
Date: Sun, 3 Nov 2019 08:25:45 -0800 [thread overview]
Message-ID: <20191103162545.GB116247@google.com> (raw)
In-Reply-To: <20191101214238.78015-6-john.stultz@linaro.org>
On Fri, Nov 01, 2019 at 09:42:38PM +0000, John Stultz wrote:
> Add very trivial allocation and import test for dma-heaps,
> utilizing the vgem driver as a test importer.
>
> A good chunk of this code taken from:
> tools/testing/selftests/android/ion/ionmap_test.c
> Originally by Laura Abbott <labbott@redhat.com>
>
> Cc: Benjamin Gaignard <benjamin.gaignard@linaro.org>
> Cc: Sumit Semwal <sumit.semwal@linaro.org>
> Cc: Liam Mark <lmark@codeaurora.org>
> Cc: Pratik Patel <pratikp@codeaurora.org>
> Cc: Brian Starkey <Brian.Starkey@arm.com>
> Cc: Vincent Donnefort <Vincent.Donnefort@arm.com>
> Cc: Sudipto Paul <Sudipto.Paul@arm.com>
> Cc: Andrew F. Davis <afd@ti.com>
> Cc: Christoph Hellwig <hch@infradead.org>
> Cc: Chenbo Feng <fengc@google.com>
> Cc: Alistair Strachan <astrachan@google.com>
> Cc: Hridya Valsaraju <hridya@google.com>
> Cc: Sandeep Patil <sspatil@google.com>
> Cc: Hillf Danton <hdanton@sina.com>
> Cc: Dave Airlie <airlied@gmail.com>
> Cc: dri-devel@lists.freedesktop.org
> Reviewed-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
> Reviewed-by: Brian Starkey <brian.starkey@arm.com>
> Acked-by: Laura Abbott <labbott@redhat.com>
> Tested-by: Ayan Kumar Halder <ayan.halder@arm.com>
> Signed-off-by: John Stultz <john.stultz@linaro.org>
> ---
> v2:
> * Switched to use reworked dma-heap apis
> v3:
> * Add simple mmap
> * Utilize dma-buf testdev to test importing
> v4:
> * Rework to use vgem
> * Pass in fd_flags to match interface changes
> * Skip . and .. dirs
> v6:
> * Number of style/cleanups suggested by Brian
> v7:
> * Whitespace fixup for checkpatch
> v8:
> * More checkpatch whitespace fixups
> v9:
> * Better handling error returns out to main, suggested
> by Brian Starkey
> * Switch to using snprintf, suggested by Brian
> v14:
> * Fix a missing return value
> * Add calls to test the GET_FEATURES ioctl
> * Build fix reported by kernel test robot <lkp@intel.com>
> and fixed by Xiao Yang <ice_yangxiao@163.com>
> * Minor Makefile cleanups
> ---
> tools/testing/selftests/dmabuf-heaps/Makefile | 6 +
> .../selftests/dmabuf-heaps/dmabuf-heap.c | 255 ++++++++++++++++++
> 2 files changed, 261 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 000000000000..607c2acd2082
> --- /dev/null
> +++ b/tools/testing/selftests/dmabuf-heaps/Makefile
> @@ -0,0 +1,6 @@
> +# SPDX-License-Identifier: GPL-2.0
> +CFLAGS += -static -O3 -Wl,-no-as-needed -Wall -I../../../../usr/include
> +
> +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 000000000000..ec47901ef2e2
> --- /dev/null
> +++ b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
> @@ -0,0 +1,255 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <dirent.h>
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <stdint.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <sys/ioctl.h>
> +#include <sys/mman.h>
> +#include <sys/types.h>
> +
> +#include <linux/dma-buf.h>
> +#include <drm/drm.h>
> +
> +#include "../../../../include/uapi/linux/dma-heap.h"
> +
> +#define DEVPATH "/dev/dma_heap"
> +
> +static int check_vgem(int fd)
> +{
> + drm_version_t version = { 0 };
> + char name[5];
> + int ret;
> +
> + version.name_len = 4;
> + version.name = name;
> +
> + ret = ioctl(fd, DRM_IOCTL_VERSION, &version);
> + if (ret)
> + return 0;
> +
> + return !strcmp(name, "vgem");
> +}
> +
> +static int open_vgem(void)
> +{
> + int i, fd;
> + const char *drmstr = "/dev/dri/card";
> +
> + fd = -1;
> + for (i = 0; i < 16; i++) {
> + char name[80];
> +
> + snprintf(name, 80, "%s%u", drmstr, i);
> +
> + fd = open(name, O_RDWR);
> + if (fd < 0)
> + continue;
> +
> + if (!check_vgem(fd)) {
> + close(fd);
> + fd = -1;
> + continue;
> + } else {
> + break;
> + }
> + }
> + return fd;
> +}
> +
> +static int import_vgem_fd(int vgem_fd, int dma_buf_fd, uint32_t *handle)
> +{
> + struct drm_prime_handle import_handle = {
> + .fd = dma_buf_fd,
> + .flags = 0,
> + .handle = 0,
> + };
> + int ret;
> +
> + ret = ioctl(vgem_fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &import_handle);
> + if (ret == 0)
> + *handle = import_handle.handle;
> + return ret;
> +}
> +
> +static void close_handle(int vgem_fd, uint32_t handle)
> +{
> + struct drm_gem_close close = {
> + .handle = handle,
> + };
> +
> + ioctl(vgem_fd, DRM_IOCTL_GEM_CLOSE, &close);
> +}
> +
> +static int dmabuf_heap_open(char *name)
> +{
> + int ret, fd;
> + char buf[256];
> +
> + ret = snprintf(buf, 256, "%s/%s", DEVPATH, name);
> + if (ret < 0) {
> + printf("snprintf failed!\n");
> + return ret;
> + }
> +
> + fd = open(buf, O_RDWR);
> + if (fd < 0)
> + printf("open %s failed!\n", buf);
> + return fd;
> +}
> +
> +static int dmabuf_heap_get_features(int fd, unsigned long long *features)
> +{
> + struct dma_heap_get_features_data data = {0};
I'm curious if the test continues to work if you don't zero initialize here?
(See my comment in patch 1/5)
Acked-by: Sandeep Patil <sspatil@android.com>
next prev parent reply other threads:[~2019-11-03 16:25 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-01 21:42 [PATCH v14 0/5] DMA-BUF Heaps (destaging ION) John Stultz
2019-11-01 21:42 ` [PATCH v14 1/5] dma-buf: Add dma-buf heaps framework John Stultz
2019-11-03 16:02 ` sspatil
2019-11-04 18:32 ` John Stultz
2019-11-04 10:24 ` Brian Starkey
2019-11-04 16:58 ` Dave Airlie
2019-11-04 17:43 ` Brian Starkey
2019-11-04 18:30 ` Daniel Vetter
2019-11-04 18:44 ` John Stultz
2019-11-01 21:42 ` [PATCH v14 2/5] dma-buf: heaps: Add heap helpers John Stultz
2019-11-03 16:13 ` sspatil
2019-11-04 19:34 ` John Stultz
2019-11-04 19:36 ` John Stultz
2019-11-01 21:42 ` [PATCH v14 3/5] dma-buf: heaps: Add system heap to dmabuf heaps John Stultz
2019-11-03 16:19 ` Sandeep Patil
2019-11-01 21:42 ` [PATCH v14 4/5] dma-buf: heaps: Add CMA " John Stultz
2019-11-03 16:22 ` Sandeep Patil
2019-11-01 21:42 ` [PATCH v14 5/5] kselftests: Add dma-heap test John Stultz
2019-11-03 16:25 ` Sandeep Patil [this message]
2019-11-04 8:18 ` [PATCH v14 0/5] DMA-BUF Heaps (destaging ION) Pekka Paalanen
2019-11-04 19:21 ` John Stultz
2019-11-05 8:19 ` Pekka Paalanen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191103162545.GB116247@google.com \
--to=sspatil@android.com \
--cc=Brian.Starkey@arm.com \
--cc=Sudipto.Paul@arm.com \
--cc=Vincent.Donnefort@arm.com \
--cc=afd@ti.com \
--cc=airlied@gmail.com \
--cc=astrachan@google.com \
--cc=benjamin.gaignard@linaro.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=fengc@google.com \
--cc=hch@infradead.org \
--cc=hdanton@sina.com \
--cc=hridya@google.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lmark@codeaurora.org \
--cc=pratikp@codeaurora.org \
--cc=sumit.semwal@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).