[RFC] dma-buf: Implement test module
diff mbox

Message ID 20140325161722.GA23842@ulmo
State New, archived
Headers show

Commit Message

Thierry Reding March 25, 2014, 4:17 p.m. UTC
On Thu, Dec 12, 2013 at 06:02:58PM -0800, Greg Kroah-Hartman wrote:
> On Thu, Dec 12, 2013 at 03:42:12PM +0100, Thierry Reding wrote:
> > On Thu, Dec 12, 2013 at 03:36:29PM +0100, Thierry Reding wrote:
> > > This is a simple test module that can be used to allocate, export and
> > > delete DMA-BUF objects. It can be used to test DMA-BUF sharing in
> > > systems that lack a real second driver.
> > > 
> > > Signed-off-by: Thierry Reding <treding@nvidia.com>
> > > ---
> > >  drivers/base/Kconfig        |   4 +
> > >  drivers/base/Makefile       |   1 +
> > >  drivers/base/dma-buf-test.c | 308 ++++++++++++++++++++++++++++++++++++++++++++
> > >  3 files changed, 313 insertions(+)
> > >  create mode 100644 drivers/base/dma-buf-test.c
> > 
> > And attached is a small test program that I've been using to test this
> > new module. It can be built with:
> > 
> > 	$ gcc -O2 -g -Wall -Werror -I/usr/include/libdrm -o dma-buf-test dma-buf-test.c -ldrm
> 
> Please put this in the patch as well (scripts/tests/ ?)

Sorry for taking so long to get back on this. I've tried various ways to
make this work, but always ended up with something that didn't quite
work.

What I attempted was to put the test program into the samples/dma-buf
subdirectory and use something along these lines:


There are two things that don't work too well with this. First this
causes the build to break if the build machine doesn't have the new
public header (include/uapi/linux/dma-buf.h) installed yet. So the only
way to make this work would be by building the kernel once with SAMPLES
disabled, install the headers and then build again with SAMPLES enabled.
Which really isn't very nice.

One other option that I've tried is to modify the include path so that
the test program would get the in-tree copy of the public header file,
but that didn't build properly either because the header files aren't
properly sanitized and therefore the compiler complains about it
(include/uapi/linux/types.h).

One other disadvantage of carrying the sample program in the tree is
that there's only infrastructure to build programs natively on the build
machine. That's somewhat unfortunate because if you want to run the test
program on a different architecture you have to either compile the
kernel natively on that architecture (which isn't very practical on many
embedded devices) or cross-compile manually.

I think a much nicer solution would be to add infrastructure to cross-
compile these test programs, so that they end up being built for the
same architecture as the kernel image (i.e. using CROSS_COMPILE).

Adding Michal and the linux-kbuild mailing list, perhaps this has been
discussed before, or maybe somebody has a better idea on how to solve
this.

Thierry

Comments

Sam Ravnborg March 25, 2014, 6:01 p.m. UTC | #1
> 
> There are two things that don't work too well with this. First this
> causes the build to break if the build machine doesn't have the new
> public header (include/uapi/linux/dma-buf.h) installed yet. So the only
> way to make this work would be by building the kernel once with SAMPLES
> disabled, install the headers and then build again with SAMPLES enabled.
> Which really isn't very nice.
> 
> One other option that I've tried is to modify the include path so that
> the test program would get the in-tree copy of the public header file,
> but that didn't build properly either because the header files aren't
> properly sanitized and therefore the compiler complains about it
> (include/uapi/linux/types.h).
> 
> One other disadvantage of carrying the sample program in the tree is
> that there's only infrastructure to build programs natively on the build
> machine. That's somewhat unfortunate because if you want to run the test
> program on a different architecture you have to either compile the
> kernel natively on that architecture (which isn't very practical on many
> embedded devices) or cross-compile manually.
> 
> I think a much nicer solution would be to add infrastructure to cross-
> compile these test programs, so that they end up being built for the
> same architecture as the kernel image (i.e. using CROSS_COMPILE).
> 
> Adding Michal and the linux-kbuild mailing list, perhaps this has been
> discussed before, or maybe somebody has a better idea on how to solve
> this.
I actually looked into this some time ago.
May try to dust off the patch.
IIRC the kernel provided headers were used for building - not the one installed on the machine.
And crosscompile were supported.

	Sam
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Thierry Reding March 26, 2014, 8:32 a.m. UTC | #2
On Tue, Mar 25, 2014 at 07:01:10PM +0100, Sam Ravnborg wrote:
> > 
> > There are two things that don't work too well with this. First this
> > causes the build to break if the build machine doesn't have the new
> > public header (include/uapi/linux/dma-buf.h) installed yet. So the only
> > way to make this work would be by building the kernel once with SAMPLES
> > disabled, install the headers and then build again with SAMPLES enabled.
> > Which really isn't very nice.
> > 
> > One other option that I've tried is to modify the include path so that
> > the test program would get the in-tree copy of the public header file,
> > but that didn't build properly either because the header files aren't
> > properly sanitized and therefore the compiler complains about it
> > (include/uapi/linux/types.h).
> > 
> > One other disadvantage of carrying the sample program in the tree is
> > that there's only infrastructure to build programs natively on the build
> > machine. That's somewhat unfortunate because if you want to run the test
> > program on a different architecture you have to either compile the
> > kernel natively on that architecture (which isn't very practical on many
> > embedded devices) or cross-compile manually.
> > 
> > I think a much nicer solution would be to add infrastructure to cross-
> > compile these test programs, so that they end up being built for the
> > same architecture as the kernel image (i.e. using CROSS_COMPILE).
> > 
> > Adding Michal and the linux-kbuild mailing list, perhaps this has been
> > discussed before, or maybe somebody has a better idea on how to solve
> > this.
> I actually looked into this some time ago.
> May try to dust off the patch.
> IIRC the kernel provided headers were used for building - not the one installed on the machine.
> And crosscompile were supported.

That sounds exactly like what I'd want for this. If you need any help,
please let me know.

Thanks,
Thierry
Thierry Reding July 10, 2014, 9:55 a.m. UTC | #3
On Wed, Mar 26, 2014 at 09:32:47AM +0100, Thierry Reding wrote:
> On Tue, Mar 25, 2014 at 07:01:10PM +0100, Sam Ravnborg wrote:
> > > 
> > > There are two things that don't work too well with this. First this
> > > causes the build to break if the build machine doesn't have the new
> > > public header (include/uapi/linux/dma-buf.h) installed yet. So the only
> > > way to make this work would be by building the kernel once with SAMPLES
> > > disabled, install the headers and then build again with SAMPLES enabled.
> > > Which really isn't very nice.
> > > 
> > > One other option that I've tried is to modify the include path so that
> > > the test program would get the in-tree copy of the public header file,
> > > but that didn't build properly either because the header files aren't
> > > properly sanitized and therefore the compiler complains about it
> > > (include/uapi/linux/types.h).
> > > 
> > > One other disadvantage of carrying the sample program in the tree is
> > > that there's only infrastructure to build programs natively on the build
> > > machine. That's somewhat unfortunate because if you want to run the test
> > > program on a different architecture you have to either compile the
> > > kernel natively on that architecture (which isn't very practical on many
> > > embedded devices) or cross-compile manually.
> > > 
> > > I think a much nicer solution would be to add infrastructure to cross-
> > > compile these test programs, so that they end up being built for the
> > > same architecture as the kernel image (i.e. using CROSS_COMPILE).
> > > 
> > > Adding Michal and the linux-kbuild mailing list, perhaps this has been
> > > discussed before, or maybe somebody has a better idea on how to solve
> > > this.
> > I actually looked into this some time ago.
> > May try to dust off the patch.
> > IIRC the kernel provided headers were used for building - not the one installed on the machine.
> > And crosscompile were supported.
> 
> That sounds exactly like what I'd want for this. If you need any help,
> please let me know.

Did you have any time to look into dusting off the patch? If not I'll
gladly take whatever you have and dust it off myself.

Thierry
Sam Ravnborg July 11, 2014, 8:33 p.m. UTC | #4
On Thu, Jul 10, 2014 at 11:55:26AM +0200, Thierry Reding wrote:
> On Wed, Mar 26, 2014 at 09:32:47AM +0100, Thierry Reding wrote:
> > On Tue, Mar 25, 2014 at 07:01:10PM +0100, Sam Ravnborg wrote:
> > > > 
> > > > There are two things that don't work too well with this. First this
> > > > causes the build to break if the build machine doesn't have the new
> > > > public header (include/uapi/linux/dma-buf.h) installed yet. So the only
> > > > way to make this work would be by building the kernel once with SAMPLES
> > > > disabled, install the headers and then build again with SAMPLES enabled.
> > > > Which really isn't very nice.
> > > > 
> > > > One other option that I've tried is to modify the include path so that
> > > > the test program would get the in-tree copy of the public header file,
> > > > but that didn't build properly either because the header files aren't
> > > > properly sanitized and therefore the compiler complains about it
> > > > (include/uapi/linux/types.h).
> > > > 
> > > > One other disadvantage of carrying the sample program in the tree is
> > > > that there's only infrastructure to build programs natively on the build
> > > > machine. That's somewhat unfortunate because if you want to run the test
> > > > program on a different architecture you have to either compile the
> > > > kernel natively on that architecture (which isn't very practical on many
> > > > embedded devices) or cross-compile manually.
> > > > 
> > > > I think a much nicer solution would be to add infrastructure to cross-
> > > > compile these test programs, so that they end up being built for the
> > > > same architecture as the kernel image (i.e. using CROSS_COMPILE).
> > > > 
> > > > Adding Michal and the linux-kbuild mailing list, perhaps this has been
> > > > discussed before, or maybe somebody has a better idea on how to solve
> > > > this.
> > > I actually looked into this some time ago.
> > > May try to dust off the patch.
> > > IIRC the kernel provided headers were used for building - not the one installed on the machine.
> > > And crosscompile were supported.
> > 
> > That sounds exactly like what I'd want for this. If you need any help,
> > please let me know.
> 
> Did you have any time to look into dusting off the patch? If not I'll
> gladly take whatever you have and dust it off myself.
Thanks for the reminder.
I got it almost working after simplifying it a lot.
I will be travelling for the next few days but will continue to work on this
after the weekend.

	Sam
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/samples/dma-buf/Makefile b/samples/dma-buf/Makefile
new file mode 100644
index 000000000000..bcaa117474d7
--- /dev/null
+++ b/samples/dma-buf/Makefile
@@ -0,0 +1,8 @@ 
+obj- := dummy.o
+
+HOSTCFLAGS_dma-buf-test.o += $(shell pkg-config --cflags libdrm)
+HOSTLOADLIBES_dma-buf-test += $(shell pkg-config --libs libdrm)
+
+hostprogs-y := dma-buf-test
+
+always := $(hostprogs-y)