• Home
Name Date Size #Lines LOC

..--

kernel_space/03-May-2024-448163

user_space/03-May-2024-331145

READMED03-May-20243.8 KiB11876

README

1author: Sean Ruyle (srruyle@us.ibm.com)
2
3RUNTIME:
4To run the test case simply enter the user_space directory, type make
5to compile the program, and run ./test_mod in this case, or whatver
6you have named your program. However, the test kernel module must be
7loaded before the test case can work. If the module is not loaded you
8will receive an error when attempting to open the module.
9
10Enter the kernel_space directory, and again type make to compile the
11module. After successful compilation use the load script to load the
12module into the system (./load_tmod.sh). The reason for the script
13instead of just using insmod to load the module is to ensure that
14there is a correct node in /dev, by parsing /proc/devices to get the
15right major number.
16
17Check that the module has been loaded by using the lsmod command.
18You should see ouput similar to this:
19
20ausag:~ # lsmod
21Module                  Size  Used by
22tmod                    3812  0
23gcov_prof               8292  0
24uhci_hcd               51812  0
25
26
27To unload the module use the rmmod command. A module cannot be
28unloaded if it is still in use by the system or a program.
29
30
31
32
33USER SPACE:
34Ive tried to abstract user space as much as possible so that if
35a new test does not need any additional setup of parameters
36before the ioctl call, ki_generic can be used by passing in
37the file_descriptor and the ioctl flag corresponding to the
38current test.
39
40Examples have been provided for correct usage of passing in
41structures to the ioctl call if they are needed for a given
42test. These are fuond at the bottom of tmod_ki.c file.
43
44If a test does call for a structure to be passed in to
45kernel space or a structure to be returned you will need to
46setup the tif pointer. Use the examples I just mentioned
47and it should be easy. The ioctl call is setup so that it
48will check if the values passed in need a copy_from_user
49or a copy_to_user before moving on. The tif pointer
50allows the kernel space ioctl function to handle all
51calls in a similar function without depending on the test
52that is to be run, in regards to copy_from_user and
53copy_to_user.
54
55
56
57
58KERNEL SPACE:
59I strongly suggest that when creating a Makefile for your
60test modules you use the one provided here, and just change
61the name of the .o file. Little differences can throw a
62compiler off even if you dont see a problem.
63
64The test functions and the ioctl call, as well as init and
65exit functions are located in the tmod.c file. Most of it
66should be streamlined so that all you need to do to add a
67new test function is add an ioctl flag in tmod.h, a function
68prototype, a new case in the ioctl switch, and the actual
69function itself.
70
71Two header files are needed in kernel space so that we may
72seperate what can be used in user space programs from
73what can only be used in kernel space. I put my #defines
74and ioctl flags in tmod.h, along with the tif structure.
75This is because all of these will need to be used by both
76the user space program as well as the kernel module.
77
78Any extern definitions from the kernel or structures that
79will have pointers in them that will differ in user space,
80should go in another header file. I used str_mod.h for this,
81and for example in my pci testcase, I need a struct pci_dev *
82for most of my tests, along with several other pointers.
83This structure will allow you to hold the pointers from one
84test to another without having to use copy_to_user to
85return the pointers to user space program.
86
87
88
89
90
91
92On naming:
93For this example I just called everything tmod (short for test_mod),
94so if you are using these files as a base for your testcases, make
95sure that you change tmod and other such inferences, so that it
96will be easier to tell in the kernel which module is performing
97which action.
98
99
100
101
102
103
104Hope this helps. Send me an email if you have any problems
105Thanks and gigem,
106Sean Ruyle
107
108srruyle@us.ibm.com
109
110
111
112
113
114
115
116
117
118