1/*
2 *
3 *   Copyright (c) International Business Machines  Corp., 2001
4 *
5 *   This program is free software;  you can redistribute it and/or modify
6 *   it under the terms of the GNU General Public License as published by
7 *   the Free Software Foundation; either version 2 of the License, or
8 *   (at your option) any later version.
9 *
10 *   This program is distributed in the hope that it will be useful,
11 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13 *   the GNU General Public License for more details.
14 *
15 *   You should have received a copy of the GNU General Public License
16 *   along with this program;  if not, write to the Free Software
17 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19
20 * This test is meant to hit
21 * many of the inline functions
22 * in various include files.
23 *
24 * Author: David Cruz <cruzd@us.ibm.com>
25 * Module: includeTest
26 *
27 */
28
29#include <linux/types.h>
30#include <linux/kernel.h>
31#include <linux/fs.h>
32#include <linux/ioctl.h>
33#include <linux/module.h>
34#include <linux/init.h>
35#include <linux/pm.h>
36#include <linux/genhd.h>
37#include <linux/in.h>
38#include <asm/types.h>
39#include <linux/lockd/bind.h>
40#include <acpi/acpi_drivers.h>
41#include <linux/nfsd/nfsfh.h>
42#include <linux/sunrpc/auth.h>
43#include <linux/sunrpc/cache.h>
44#include <linux/sunrpc/svc.h>
45#include <linux/sunrpc/xdr.h>
46#include <linux/sunrpc/timer.h>
47#include <video/vga.h>
48#include <linux/errno.h>
49#include <linux/string.h>
50#include <linux/mm.h>
51#include <linux/slab.h>
52#include <linux/lockd/lockd.h>
53#include <linux/lockd/nlm.h>
54#include <linux/nfsd/export.h>
55#include <asm/uaccess.h>
56#include "includeTest.h"
57
58MODULE_AUTHOR("David Cruz <cruzd@us.ibm.com>");
59MODULE_DESCRIPTION(TEST_DRIVER_NAME);
60MODULE_LICENSE("GPL");
61
62static int test_ioctl(struct inode *, struct file *, unsigned int,
63		      unsigned long);
64static int test_open(struct inode *, struct file *);
65static int test_close(struct inode *, struct file *);
66static void test_acpi(void);
67static void test_vga(void);
68static void test_sunrpc_auth(void);
69static void test_nfsfh(void);
70static void test_lockd(void);
71static void test_sunrpc_cache(void);
72static void test_sunrpc_svc(void);
73static void test_sunrpc_timer(void);
74
75static int Major = 0;
76
77static struct block_device_operations bdops = {
78open:	test_open,
79release:test_close,
80ioctl:	test_ioctl,
81};
82
83static char genhd_flags = 0;
84static struct gendisk *gd_ptr;
85static struct pm_dev *ltp_pm_dev = NULL;
86
87static int test_open(struct inode *ino, struct file *f)
88{
89	printk("device open\n");
90	return 0;
91}
92
93static int test_close(struct inode *ino, struct file *f)
94{
95	printk("device closed\n");
96	return 0;
97}
98
99static int test_ioctl(struct inode *ino, struct file *f, unsigned int cmd,
100		      unsigned long l)
101{
102
103	int rc = 0;		//return code
104	int arg;
105
106	printk("Entered the ioctl call.\n");
107
108	if (copy_from_user(&arg, (void *)l, sizeof(int))) {
109		//bad address
110		return (-EFAULT);
111	}
112
113	switch (cmd) {
114
115	case OPTION1:
116		option1();
117		break;
118	default:
119		printk("Mismatching ioctl command\n");
120		break;
121	}
122
123	//0 by default
124	return rc;
125}
126
127static void option1(void)
128{
129	printk("Module option 1 chosen\n");
130}
131
132static int ltp_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data)
133{
134	return 0;
135}
136
137static int test_init_module(void)
138{
139
140	int rc;
141
142	printk("starting module\n");
143
144	ltp_pm_dev = pm_register(PM_UNKNOWN_DEV, 0, ltp_pm_callback);
145	rc = register_blkdev(INCLUDEMAJOR, DEVICE_NAME);
146
147	printk("BLK INC - result =%d major %d\n", rc, INCLUDEMAJOR);
148
149	if (rc < 0) {
150		printk("Failed to register device.\n");
151		return rc;
152	}
153
154	gd_ptr = kmalloc(sizeof(struct gendisk *), GFP_KERNEL);
155	if (!gd_ptr) {
156		printk(KERN_ALERT "ERROR getting memory !!!\n");
157		return 0;
158	}
159
160	printk("major = %d\n", Major);
161	gd_ptr = alloc_disk(1);
162	printk(KERN_ALERT "gd_ptr after alloc = %p \n", gd_ptr);
163	gd_ptr->major = INCLUDEMAJOR;
164	gd_ptr->first_minor = 0;
165	gd_ptr->fops = &bdops;
166//      gd_ptr->minor_shift= MINOR_SHIFT_BITS;
167	gd_ptr->driverfs_dev = NULL;
168	gd_ptr->capacity = MAX_NUM_DISKS;
169//      gd_ptr->disk_de = NULL;
170	gd_ptr->flags = genhd_flags;
171
172	sprintf(gd_ptr->disk_name, DEVICE_NAME);
173	add_disk(gd_ptr);
174
175	printk("major = %d\n", Major);
176
177	test_acpi();
178	test_vga();
179	test_lockd();
180	test_sunrpc_auth();
181	test_nfsfh();
182	test_sunrpc_cache();
183	test_sunrpc_svc();
184	test_sunrpc_timer();
185	printk("finished module\n");
186
187	return 0;
188}
189
190static void test_exit_module(void)
191{
192
193	int rc;
194
195	pm_unregister(ltp_pm_dev);
196	put_disk(gd_ptr);
197	del_gendisk(gd_ptr);
198
199	rc = unregister_blkdev(INCLUDEMAJOR, DEVICE_NAME);
200
201	if (rc < 0) {
202		printk("unregister failed %d\n", rc);
203	} else {
204		printk("unregister success\n");
205	}
206}
207
208static void test_acpi(void)
209{
210	u32 flag;
211
212	for (flag = 0; flag <= 4; flag++)
213		acpi_set_debug(flag);
214
215	printk("finished acpi test\n");
216}
217
218static void test_sunrpc_auth(void)
219{
220	struct rpc_cred cred;
221
222	atomic_set(&(cred.cr_count), 0);
223	get_rpccred(&cred);
224	printk("finished auth test\n");
225}
226
227static void test_vga(void)
228{
229
230	unsigned short vgaS = 0;
231	int i = 0;
232	vga_r((caddr_t) i, vgaS);
233	printk("finished vga test\n");
234}
235
236static void test_nfsfh(void)
237{
238	dev_t dev = 0;
239	u32 unfs = 0, u32ptr[2];
240	ino_t ino = 0;
241	struct svc_fh A1;
242	int i = 20;
243
244	u32_to_dev_t((__u32) unfs);
245	ino_t_to_u32(ino);
246	u32_to_ino_t((__u32) unfs);
247	mk_fsid_v0(u32ptr, dev, ino);
248	mk_fsid_v1(u32ptr, unfs);
249	SVCFH_fmt(&A1);
250	fh_init(&A1, i);
251	fh_lock(&A1);
252	fh_unlock(&A1);
253	printk("finished nfsfh test\n");
254}
255
256static void test_lockd(void)
257{
258
259	struct nlm_file file;
260	struct sockaddr_in sin1, sin2;
261	struct file_lock fl1, fl2;
262
263	nlm_compare_locks(&fl1, &fl2);
264	nlm_cmp_addr(&sin1, &sin2);
265	nlmsvc_file_inode(&file);
266	printk("finished lockd test\n");
267}
268
269static void test_sunrpc_cache(void)
270{
271	struct cache_head head;
272	struct cache_detail detail;
273
274	cache_get(&head);
275	cache_put(&head, &detail);
276	printk("finished cache test\n");
277}
278
279static void test_sunrpc_svc(void)
280{
281	u32 val;
282	struct svc_rqst rqstp;
283	char name[50];
284	struct iovec iov;
285	int bits = 0, bits2 = 0;
286	rqstp.rq_resused = 1;
287
288	svc_getu32(&iov);
289//      svc_putu32(&iov, val);
290
291	xdr_argsize_check(&rqstp, &val);
292	xdr_ressize_check(&rqstp, &val);
293	svc_take_page(&rqstp);
294	svc_pushback_allpages(&rqstp);
295	svc_pushback_unused_pages(&rqstp);
296	svc_free_allpages(&rqstp);
297	hash_str(name, bits);
298	hash_mem(name, bits, bits2);
299	printk("finished svc test\n");
300
301}
302
303static void test_sunrpc_timer()
304{
305	struct rpc_rtt rt;
306
307	rpc_inc_timeo(&rt);
308	rpc_clear_timeo(&rt);
309	rpc_ntimeo(&rt);
310	printk("finished timer test\n");
311}
312
313module_init(test_init_module)
314    module_exit(test_exit_module)
315