Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3569917imb; Tue, 5 Mar 2019 12:56:22 -0800 (PST) X-Google-Smtp-Source: APXvYqw2tJ6B58g8QXrBfSr8JCySeINEiG2/5Qer8YErBFstnoxSY2sdjwJaiMfmI4Opc5j3AtFb X-Received: by 2002:a65:6383:: with SMTP id h3mr3060700pgv.11.1551819382687; Tue, 05 Mar 2019 12:56:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551819382; cv=none; d=google.com; s=arc-20160816; b=BCf43mggHI9nfN6MBa+p5y8DpqwsocwzN4oTyHoHRzjKV+bTWk/Q6c5AY47t3G6ifE 9MbDstqjHFCREsUkGwNn9xkPIyEGuFg6BA5LejtAh2VCn60dtLMwutFVRoeo8aGIm6ur 3ZXGya/qhUgsXefTb06JDcgjxwnRVOgSIReAB5lDshG9pP1e9r7K1An1NoSDh0cxCsed 8VycCz0XlzNZLUumlBBBp36FWbGHI5PrsVp2RbJ4nWgfsmzXealwPTOar/t72j0FKmzG K/vqCg32wyyshA/VE32jf2tKxyrPmbfjp+kkI11LAFtQJiD1GnlkUZ2DsnrdHSK9+07z h/8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=yRzxxqyWBOZSHUPCrEH0/twSX4oAAXNjDpDvvJwFuKY=; b=nU+AtrzlIaH4rFnBQ4RRJMLAmJOKHShYUguQmS08rTGkDnzMno9AIKDxBVHLNPcVtn AW4Q90bsVp8Gl2zudZXryGywcYUVdicwrEnJeCXguyR+FSm6hfV6H+nZCjNZA7kMU1ft NvPl9RS0/k1klx9nlfynZBZNjF7YcbIDu0cpS5OGj1oLp3qzajEBJR19ga03yHYPSeDl zsfjDg7Ue0iztSz7r2IVTO/BNbmYiCaZPjMSd47wBSovKVwXi1UIWuBoMqYh93L/rrUO G6eq9yeqk2oSIzHFvUVI5QAAlxXxxEE0Inpjdu45bpycfBA1NrNt7HD0OENVHfuttaij /Ffw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ig9NrpoL; 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 z11si8846877pgj.140.2019.03.05.12.56.07; Tue, 05 Mar 2019 12:56:22 -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=Ig9NrpoL; 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 S1728651AbfCEUy4 (ORCPT + 99 others); Tue, 5 Mar 2019 15:54:56 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:45948 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728598AbfCEUyv (ORCPT ); Tue, 5 Mar 2019 15:54:51 -0500 Received: by mail-pg1-f194.google.com with SMTP id 125so6226274pgc.12 for ; Tue, 05 Mar 2019 12:54:50 -0800 (PST) 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=tn0gQzvba7cgZW7f7nr8hn12/PATQcAMk0yt5IWG38nN9MC0vynOJRUUSQtu52ZrIN fQFapS9a393h8tZfY+sbJBAaztrMAiEbtuTK+i6M60k157n/yiqaQxx7surWL3gZl+MM xVvUVF4s9+2CMN7kgW5kri9IExtNmFRsfSxCXy3BH3A8k88msjmUjhU4140wR/2BeAtR Ix4wVhZgxsvplKSFLGfmVxdL8DBMgx8oevWhAxymeW6yYEM0IB9kdTOXkHLoz65BWKoC gHwMKK3dWCeycukg90DZOFiXybjV8lIopzP7cXPnGYzDGTnDABK6P1R7BroCXakfdby2 IIRg== X-Gm-Message-State: APjAAAXRgEA7CjWtHhL2yk9r6jzUYRDFwPClWmjLUMUi88svtOLvJJSH sPq6lcVRjHurxTAEiypDs481NBb10gY= 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 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 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; +} -- 2.7.4