* Kernel Mocking
@ 2015-02-20 19:51 Kenneth Adam Miller
2015-02-20 20:24 ` Greg KH
0 siblings, 1 reply; 6+ messages in thread
From: Kenneth Adam Miller @ 2015-02-20 19:51 UTC (permalink / raw)
To: kernelnewbies
So, in userland development, the idea of mocking is used to isolate context
management and machine configuration into a single class or set of
functions that can be reused, and also facilitate testing much easier.
Google mock is a great example.
Say I develop a kernel module, and I want that module to have some result X
after some returned result, whatever that might be. Is there anything
similar for kernel code?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150220/b396b6cb/attachment.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Kernel Mocking
2015-02-20 19:51 Kernel Mocking Kenneth Adam Miller
@ 2015-02-20 20:24 ` Greg KH
2015-02-20 20:26 ` Kenneth Adam Miller
0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2015-02-20 20:24 UTC (permalink / raw)
To: kernelnewbies
On Fri, Feb 20, 2015 at 02:51:25PM -0500, Kenneth Adam Miller wrote:
> So, in userland development, the idea of mocking is used to isolate context
> management and machine configuration into a single class or set of functions
> that can be reused, and also facilitate testing much easier. Google mock is a
> great example.
>
> Say I develop a kernel module, and I want that module to have some result X
> after some returned result, whatever that might be. Is there anything similar
> for kernel code??
Not really, sorry. Running in the kernel means you don't have much room
for "simulation". But you can use qemu, or other virtual machines and a
debugger to test your code if you really want to.
Good luck!
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Kernel Mocking
2015-02-20 20:24 ` Greg KH
@ 2015-02-20 20:26 ` Kenneth Adam Miller
2015-02-20 20:45 ` Greg KH
0 siblings, 1 reply; 6+ messages in thread
From: Kenneth Adam Miller @ 2015-02-20 20:26 UTC (permalink / raw)
To: kernelnewbies
Thanks for your expedient answer!
So, I was discussing an alternative to mocking; function hooking. But in a
benign way. Is there any way to, at runtime replace the functionality of
code in order that you specify what it does for any given kernel function?
On Fri, Feb 20, 2015 at 3:24 PM, Greg KH <greg@kroah.com> wrote:
> On Fri, Feb 20, 2015 at 02:51:25PM -0500, Kenneth Adam Miller wrote:
> > So, in userland development, the idea of mocking is used to isolate
> context
> > management and machine configuration into a single class or set of
> functions
> > that can be reused, and also facilitate testing much easier. Google mock
> is a
> > great example.
> >
> > Say I develop a kernel module, and I want that module to have some
> result X
> > after some returned result, whatever that might be. Is there anything
> similar
> > for kernel code?
>
> Not really, sorry. Running in the kernel means you don't have much room
> for "simulation". But you can use qemu, or other virtual machines and a
> debugger to test your code if you really want to.
>
> Good luck!
>
> greg k-h
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150220/ef666b1b/attachment.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Kernel Mocking
2015-02-20 20:26 ` Kenneth Adam Miller
@ 2015-02-20 20:45 ` Greg KH
2015-02-20 20:49 ` Kenneth Adam Miller
0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2015-02-20 20:45 UTC (permalink / raw)
To: kernelnewbies
On Fri, Feb 20, 2015 at 03:26:40PM -0500, Kenneth Adam Miller wrote:
> Thanks for your expedient answer!
>
> So, I was discussing an alternative to mocking; function hooking. But in a
> benign way. Is there any way to, at runtime replace the functionality of code
> in order that you specify what it does for any given kernel function?
Not really, but there are some hacks you can do if you _really_ know
what you are doing.
Hint, don't do this, just write "normal" tests for your kernel code, we
have lots of them already in the source tree, look in tools/selftests/.
Best of luck,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Kernel Mocking
2015-02-20 20:45 ` Greg KH
@ 2015-02-20 20:49 ` Kenneth Adam Miller
2015-02-20 22:58 ` Jeff Haran
0 siblings, 1 reply; 6+ messages in thread
From: Kenneth Adam Miller @ 2015-02-20 20:49 UTC (permalink / raw)
To: kernelnewbies
Well I think that a function or system call semantics replacement facility
would be useful to unit testers everywhere. It would be benign of course,
requiring that the unit testing framework request of the kernel that it
replace the kernel facilities specified prior to the test, and
automatically replace them afterward. So, this isn't anything akin to doing
anything malicious, it requires user cooperation in order to hook. It's not
like something forcibly done. I'm thinking of an intel pin for kernel level
code.
On Fri, Feb 20, 2015 at 3:45 PM, Greg KH <greg@kroah.com> wrote:
> On Fri, Feb 20, 2015 at 03:26:40PM -0500, Kenneth Adam Miller wrote:
> > Thanks for your expedient answer!
> >
> > So, I was discussing an alternative to mocking; function hooking. But in
> a
> > benign way. Is there any way to, at runtime replace the functionality of
> code
> > in order that you specify what it does for any given kernel function?
>
> Not really, but there are some hacks you can do if you _really_ know
> what you are doing.
>
> Hint, don't do this, just write "normal" tests for your kernel code, we
> have lots of them already in the source tree, look in tools/selftests/.
>
> Best of luck,
>
> greg k-h
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150220/f9e32173/attachment.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Kernel Mocking
2015-02-20 20:49 ` Kenneth Adam Miller
@ 2015-02-20 22:58 ` Jeff Haran
0 siblings, 0 replies; 6+ messages in thread
From: Jeff Haran @ 2015-02-20 22:58 UTC (permalink / raw)
To: kernelnewbies
From: kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies-bounces at kernelnewbies.org] On Behalf Of Kenneth Adam Miller
Sent: Friday, February 20, 2015 12:49 PM
To: kernelnewbies at kernelnewbies.org
Subject: Re: Kernel Mocking
Well I think that a function or system call semantics replacement facility would be useful to unit testers everywhere. It would be benign of course, requiring that the unit testing framework request of the kernel that it replace the kernel facilities specified prior to the test, and automatically replace them afterward. So, this isn't anything akin to doing anything malicious, it requires user cooperation in order to hook. It's not like something forcibly done. I'm thinking of an intel pin for kernel level code.
Kenneth,
Please refrain from top posting. 8^)
I was just thinking you might be able to leverage that gcc profiling mcount() function trick that ftrace uses.
I don?t understand that well enough to say whether it would be applicable for what you want to do,
but it would be something you could look into. You should check out ftrace in any case if you are
interested in this kind of thing. It?s a way cool facility and comes already enabled on many distros.
Jeff Haran
On Fri, Feb 20, 2015 at 3:45 PM, Greg KH <greg at kroah.com<mailto:greg@kroah.com>> wrote:
On Fri, Feb 20, 2015 at 03:26:40PM -0500, Kenneth Adam Miller wrote:
> Thanks for your expedient answer!
>
> So, I was discussing an alternative to mocking; function hooking. But in a
> benign way. Is there any way to, at runtime replace the functionality of code
> in order that you specify what it does for any given kernel function?
Not really, but there are some hacks you can do if you _really_ know
what you are doing.
Hint, don't do this, just write "normal" tests for your kernel code, we
have lots of them already in the source tree, look in tools/selftests/.
Best of luck,
greg k-h
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150220/e6cd92ba/attachment-0001.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-02-20 22:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-20 19:51 Kernel Mocking Kenneth Adam Miller
2015-02-20 20:24 ` Greg KH
2015-02-20 20:26 ` Kenneth Adam Miller
2015-02-20 20:45 ` Greg KH
2015-02-20 20:49 ` Kenneth Adam Miller
2015-02-20 22:58 ` Jeff Haran
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.