Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3273616imc; Wed, 13 Mar 2019 13:24:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYpJOcBV1EHyB6GYPYjH+BghROEoZvaRishBmP+j9Ppqz98c9wjhW+BC3AfTPXhlJa2R52 X-Received: by 2002:a62:29c6:: with SMTP id p189mr46841595pfp.194.1552508652203; Wed, 13 Mar 2019 13:24:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552508652; cv=none; d=google.com; s=arc-20160816; b=VOsuoDqwTBh9mIyIk9Ed8opV4rjsyLgKNN66RRXTEewwhAt3LZX1EpPA4LBGPnnCws ML/jDYACY6jJ/dbnsL7WcuC25Ap2tCTCHpOkVtepCa/8DI6EoQQ4i1ylHoy9CmZepzQY FuJ+80J4CNykgPCA6Vz+is8FMzvmjhxM1tYt2irvvWVlmoyTTBDDN+mkn3dPpgUcRNgS BDsY0T5+62IdIXGo8dSknmMe5HJ+u+gi7fG/4R8RJo5jA5J3SzhJJ2FPdogq88RYX23U FfXn3n3gouFXyp3TJiBzF5tPetwXzFgIvzud6HIvYu00oPmMz17eVm8BAcULh9hsjV+l 6g0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dmarc-filter :dkim-signature:dkim-signature; bh=DchFCEygUa4kDIbg73oje5NgBnftU8f+KgaWqEeBXfk=; b=Kk1ycT/w0ovKlqkbIwiSNTK5LKqnloGmCh80qoWsg4RuxZSqCM8T/0FjYC9TeQrkwS cViBO3pGP4fyNvAQc6JwRenld5JqB7kppFv6YReEFBcG34Uo3qc167Wxm4/90Sd8XAV/ TwbsChBH5YF2xAZfOF+dJux+xnm2jgBQ4SUOQsg7hoNikmiPRKUXZ8C0Uc3Fag5gAoH4 A52WKIs7kRzYtK+QVxxaXgqRFTS0P/8a5Di7acthIPMmU/u0u63qyEIjTVyV2NPOwlYv gDdIblw34QIyaxROun31DCKF9ft738WFvGa1wADDrNXQfjRfsAY/RM28pmwBXHlo7GLC uHsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=oqs9gMBl; dkim=pass header.i=@codeaurora.org header.s=default header.b=ImopeHRx; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4si10779989pfa.13.2019.03.13.13.23.55; Wed, 13 Mar 2019 13:24:12 -0700 (PDT) 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=@codeaurora.org header.s=default header.b=oqs9gMBl; dkim=pass header.i=@codeaurora.org header.s=default header.b=ImopeHRx; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726939AbfCMUXg (ORCPT + 99 others); Wed, 13 Mar 2019 16:23:36 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:46878 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726656AbfCMUXg (ORCPT ); Wed, 13 Mar 2019 16:23:36 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id F2E9360312; Wed, 13 Mar 2019 20:23:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1552508615; bh=2XeLJVW3c4xz6ED8qGo20vKqCnmJdMzGpfyxomXHWRo=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=oqs9gMBlyryaNsH/goKRhLOFXgEB1w6YMTro7td4YfDrwKCPmyxG6dMC3rnUzMZO7 W1qgCJXuhA+rokm73/+qVT3ih4w1VRBYDgLIHiSc4HzBAzAZFVTNm1FS3KtwId7r2e xGgrwXSRlhJ+2g7IWi90679pllmm8EL5lJLL8A3Y= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from lmark-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: lmark@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 1523360208; Wed, 13 Mar 2019 20:23:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1552508613; bh=2XeLJVW3c4xz6ED8qGo20vKqCnmJdMzGpfyxomXHWRo=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=ImopeHRxswu0H0wi+2xZMBoFY4Oxa2YsHpUVFGAFJ5Tz2bgBoEgbBGZ+48NCvXY+u Owt9FtnbekDz1sND5R0SS3o9TA1awdoVL3GT8ZhIoQvsezk3mlXroAL++MkCEex8p9 4XKTKxBXNQrVRpIQg9SoRnYI2QMwZq2DpzFUPJP4= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 1523360208 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=lmark@codeaurora.org Date: Wed, 13 Mar 2019 13:23:32 -0700 (PDT) From: Liam Mark X-X-Sender: lmark@lmark-linux.qualcomm.com To: John Stultz cc: lkml , Laura Abbott , Benjamin Gaignard , Greg KH , Sumit Semwal , Brian Starkey , "Andrew F . Davis" , Chenbo Feng , Alistair Strachan , dri-devel@lists.freedesktop.org Subject: Re: [RFC][PATCH 5/5 v2] kselftests: Add dma-heap test In-Reply-To: <1551819273-640-6-git-send-email-john.stultz@linaro.org> Message-ID: References: <1551819273-640-1-git-send-email-john.stultz@linaro.org> <1551819273-640-6-git-send-email-john.stultz@linaro.org> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 5 Mar 2019, John Stultz wrote: > 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); Just be aware that some CMA heaps may already have all their memory allocated by the client, so you may see intermittent failures depending on when you run the test and failrues may be more common when run on certain platform. > + 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 > > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project