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: 159715 Delivered-To: patches@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp5410440jad; Tue, 5 Mar 2019 12:54:50 -0800 (PST) X-Received: by 2002:a65:4c01:: with SMTP id u1mr3171724pgq.116.1551819290221; Tue, 05 Mar 2019 12:54:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551819290; cv=none; d=google.com; s=arc-20160816; b=hIBFmH647m2UD3fX8RsFCNC/JbA8dorZQ8b4QUa/GUxqrzUfEfYY7K7SeVdYIs65Ga uTve9LcO3g41Vk0ts7+6Sj0sBuVTJUqfJ0KY/iTu1rOudKhdwTDHd0oLNZntmLXBrDVF XnRAPSJbsH3xSFli7yuWhpgFEH6qoAn4cw1P5LOawPDoUOWs/NubX5HWM1I5kuptIRoV qikArnIATOvySyzOCCypVThMeGpdQr0HcAK47krGLNUm8z/x0oKkRJzaYNLANpFNlAkj FFsv0GCRAp8X+AEjcwOmOvy2ksvMFZ/iSyeUZrjLMWYQM/G4dGvlXZORA7IikNLtRovZ /qaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yRzxxqyWBOZSHUPCrEH0/twSX4oAAXNjDpDvvJwFuKY=; b=BlXoZnLeYLEnHn+CgkC+8Dihk0OFlJakCiiccWUt/PJ9XTGwn5m66qjLh0zFACJNtB BPYesOiG4Lj1Dy9KYz7lx5d3rX2vs1gbXZFmcYaXD2F7nusqgTMqQ6MleqinLU613rOC YHuiVzdOCf48Rrz0LMQWYsqeu/xT6T1L/PFt3eFN1ocP2zOSXK2DLthzETE4D3KgqjB3 Gj579RZ6VHKpjxcYlzTeqdKd5HaZRnJmz843A/hSTA9beRQHy2CA9ZtmtsRygvDmlUwa PPs6UcmHtR6yi6aTnJU2HR9h5Ui4yP8Q7/JVK68teQ9Ys9VWGPLfV52h0m7Bx8GOAw2D aYgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ig9NrpoL; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id i184sor15480414pge.78.2019.03.05.12.54.50 for (Google Transport Security); Tue, 05 Mar 2019 12:54:50 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ig9NrpoL; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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-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=Qrv/bOrtV1KhLn2aQn/2/lvl4/Alw4e94ObNF5BJtEVfl+Oif7DBYr3KCcLiPGys/r 0shAHq6MEJLYRKk8P+FYe6B1k4R1Bf2BFWVm1D3049l3aeW2MW6UyFFm7jv9aYX/wNt6 ldQ/qTNE/ClatgauL5kG13A3m0H4vc+SwYp/bTNsIYaPJI62RscQ8G/urMt6dMI6iM7i Xm+RuPNnfK1uF5sxaX8JmFPROLl1e03m7BGJQC9/Bmgyk8xiZDeJusrTK3azhVDfD7fK UGpdcYtodzngsCG9ycHyjZNMVB0jwvUEtsPNbjZ1GzW2SQs6pCtE3qFcuyTopdkr+DK+ AlxA== X-Gm-Message-State: APjAAAVr8tW9Lbf9ezmlk7rYokZnqwhZbjkJvPgKHLjeMZ5Rjv7Au5Pg K2RBgce156+yjpTLdHsnmKoSIhwX 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) Return-Path: 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 Cc: John Stultz , Laura Abbott , Benjamin Gaignard , Greg KH , Sumit Semwal , Liam Mark , Brian Starkey , "Andrew F . Davis" , Chenbo Feng , Alistair Strachan , dri-devel@lists.freedesktop.org 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> 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 -- 2.7.4 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; +}