Re: kernel - Regarding tools/testing/ktests or selftests
On Tue, Oct 10, 2017 at 01:15:11PM +0530, Pintu Kumar wrote: > Hi All, > > Is anybody familiar with ktests of selftests framework under: tool/testing/ ? > I have some queries. > > 1) What is the difference between ktests and selftests ? How to choose ? It depends on what you want to do, but usually new things go in the selftest section. > 2) How to invoke a test under ktests? > For example: > I have some user space C program, that tests some kernel driver IOCTL > calls. > I have a Makefile to build 2 executable for the tests. > I invoke those executable from a bash shell script and execute all > the tests. > How can I do it automatically from ktests ? Have you read the documentation the kernel has for this: $ make help | grep test Kernel selftest: kselftest - Build and run kernel selftest (run as root) running kselftest on it kselftest-clean - Remove all generated kselftest files kselftest-merge - Merge all the config dependencies of kselftest to existed > 3) Similarly, how can I do it using selftests? > Using selftests looks much better option for me. > But the problem is I have some sub directories to execute the tests. > Example: > Under, tools/testing/selftests , I have created 2 sub folders. > selftests/folders/folder1/ > My test setup is under: folder1 > How to invoke selftests, for folder1 ? > > If anybody have added new tests under ktests of selftests, please > provide some reference. Have you looked at the many patches in the kernel source tree that show how the existing tests are added? That's the best thing to use as a template. Hope this helps, greg k-h ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: kernel - Regarding tools/testing/ktests or selftests
Hi, I am actually interested in kselftests. My requirement is: I have a sub folders for test. Example: tools/testing/selftests// I have my own Makefile, and some set of C source files under folder1 I also have a test script under folder1, that tests 2 executable generated out of 7 C files. I wanted to know about to make use of selftest framework to generate these 2 executable, and also execute by script to run the test. I have already includes in top level Makefile under selftests. TARGETS = Do, I need to create another Makefile under and invoke folder1/Makefile from there? Or is there another way? If anybody have already done a new addition in selftests, please let me know. Thanks, Pintu On Tue, Oct 10, 2017 at 1:15 PM, Pintu Kumarwrote: > Hi All, > > Is anybody familiar with ktests of selftests framework under: tool/testing/ ? > I have some queries. > > 1) What is the difference between ktests and selftests ? How to choose ? > 2) How to invoke a test under ktests? > For example: > I have some user space C program, that tests some kernel driver IOCTL > calls. > I have a Makefile to build 2 executable for the tests. > I invoke those executable from a bash shell script and execute all > the tests. > How can I do it automatically from ktests ? > 3) Similarly, how can I do it using selftests? > Using selftests looks much better option for me. > But the problem is I have some sub directories to execute the tests. > Example: > Under, tools/testing/selftests , I have created 2 sub folders. > selftests/folders/folder1/ > My test setup is under: folder1 > How to invoke selftests, for folder1 ? > > If anybody have added new tests under ktests of selftests, please > provide some reference. > > > Thanks, > Pintu ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: boot time variable
On Tue, Oct 10, 2017 at 09:08:30AM +0200, Greg KH wrote: > On Tue, Oct 10, 2017 at 10:17:09AM +1100, Tobin C. Harding wrote: > > Hi, > > > > I would like to create a boot time variable i.e a variable that is set once > > at boot time. Variable > > does not need to be globally accessible. (actually I am using two > > variables). > > static foo = 42; > > should be all you need, right? > > If not, what exactly do you mean by "boot time variable"? > > > Could any one point me to examples of this already intree please? > > > > I have tried the following but it has a race condition on the zero check > > and assignment of randval/oddval. > > > > /* Maps a pointer to a unique identifier. */ > > static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec > > spec) > > { > > long hashval; > > static long randval = 0; > > static long oddval = 0; > > > > if (oddval == 0 && randval == 0) { > > randval = get_random_long(); > > oddval = get_random_odd_long(); > > } > > > > hashval = ptr_obfuscate((unsigned long)ptr, randval, oddval); > > spec.base = 16; > > > > return number(buf, end, hashval, spec); > > } > > What's wrong with this code? Maybe I just have race conditions on the brain. > > And the compiler doesn't like > > > > static long randval = get_random_long(); > > static long oddval = get_random_odd_long(); > > Yeah, that will not work, static initializers are at link/load time, not > runtime. > > > I thought of wrapping oddval/randval in a struct and protecting it with a > > lock but I don't know > > how/where to initialize the lock in a race free manner? > > Put a local lock in the function when testing if the variables are == 0, > if you are worried that two different callers will enter it at the same > time. Okay. > hope this helps, > > greg k-h Cheers Greg ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: boot time variable
On Tue, 10 Oct 2017 10:17:09 +1100, "Tobin C. Harding" said: > I would like to create a boot time variable i.e a variable that is set once > at boot time. Variable > does not need to be globally accessible. (actually I am using two variables). The canonical way to have stuff happen at boot is usually declaring an initcall. > how/where to initialize the lock in a race free manner? Step 0: Figure out how once-at-boot code could *possibly* be called a second time. What are you worried about racing here? pgpXkbCtNa2Jt.pgp Description: PGP signature ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Hook Functions - Dynamic Instrumentation and Monitoring
Hi guys. I want to write a code (or library) which it used AFL and QEMU in order to monitor functions which called by an executable. I have worked with AFL for binary instrumentation and fuzzing. Also, I could find out multiple vulnerabilities in third-party libraries but I can't realize how is it possible I do the task - hooking functions and monitoring the behavior of a program with AFL and Qemu. Any ideas? ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
kernel - Regarding tools/testing/ktests or selftests
Hi All, Is anybody familiar with ktests of selftests framework under: tool/testing/ ? I have some queries. 1) What is the difference between ktests and selftests ? How to choose ? 2) How to invoke a test under ktests? For example: I have some user space C program, that tests some kernel driver IOCTL calls. I have a Makefile to build 2 executable for the tests. I invoke those executable from a bash shell script and execute all the tests. How can I do it automatically from ktests ? 3) Similarly, how can I do it using selftests? Using selftests looks much better option for me. But the problem is I have some sub directories to execute the tests. Example: Under, tools/testing/selftests , I have created 2 sub folders. selftests/folders/folder1/ My test setup is under: folder1 How to invoke selftests, for folder1 ? If anybody have added new tests under ktests of selftests, please provide some reference. Thanks, Pintu ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: boot time variable
On Tue, Oct 10, 2017 at 10:17:09AM +1100, Tobin C. Harding wrote: > Hi, > > I would like to create a boot time variable i.e a variable that is set once > at boot time. Variable > does not need to be globally accessible. (actually I am using two variables). static foo = 42; should be all you need, right? If not, what exactly do you mean by "boot time variable"? > Could any one point me to examples of this already intree please? > > I have tried the following but it has a race condition on the zero check and > assignment of randval/oddval. > > /* Maps a pointer to a unique identifier. */ > static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec > spec) > { > long hashval; > static long randval = 0; > static long oddval = 0; > > if (oddval == 0 && randval == 0) { > randval = get_random_long(); > oddval = get_random_odd_long(); > } > > hashval = ptr_obfuscate((unsigned long)ptr, randval, oddval); > spec.base = 16; > > return number(buf, end, hashval, spec); > } What's wrong with this code? > And the compiler doesn't like > > static long randval = get_random_long(); > static long oddval = get_random_odd_long(); Yeah, that will not work, static initializers are at link/load time, not runtime. > I thought of wrapping oddval/randval in a struct and protecting it with a > lock but I don't know > how/where to initialize the lock in a race free manner? Put a local lock in the function when testing if the variables are == 0, if you are worried that two different callers will enter it at the same time. hope this helps, greg k-h ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies