Debian Codegraph @

testsuite/systemtap.context/systemtap_test_module1.c

raw
1 /* -*- linux-c -*-
2 * Systemtap Test Module 1
3 * Copyright (C) 2007 Red Hat Inc.
4 *
5 * This file is part of systemtap, and is free software. You can
6 * redistribute it and/or modify it under the terms of the GNU General
7 * Public License (GPL); either version 2, or (at your option) any
8 * later version.
9 */
10
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/proc_fs.h>
15 #include <linux/compiler.h>
16 #include <linux/uaccess.h>
17
18 MODULE_LICENSE("GPL");
19
20 int my_init_module(void);
21 void my_cleanup_module(void);
22 module_init(my_init_module);
23 module_exit(my_cleanup_module);
24
25
26 /* The purpose of this module is to provide a bunch of functions that */
27 /* do nothing important, and then call them in different contexts. */
28 /* We use a /proc file to trigger function calls from user context. */
29 /* Then systemtap scripts set probes on the functions and run tests */
30 /* to see if the expected output is received. This is better than using */
31 /* the kernel because kernel internals frequently change. */
32
33 /* The source is modelled after LTP's crasher testcase */
34
35 /** These functions are in module 2 **/
36 /* They are there to prevent compiler optimization from */
37 /* optimizing away functions. */
38 int yyy_func1 (int);
39 int yyy_int (int,int,int);
40 unsigned yyy_uint (unsigned,unsigned,unsigned);
41 long yyy_long (long,long,long);
42 int64_t yyy_int64 (int64_t,int64_t,int64_t);
43 char yyy_char(char, char, char);
44 char *yyy_str(char *, char *, char *);
45
46 /************ Below are the functions to create this module ************/
47
48 static struct proc_dir_entry *stm_ctl = NULL;
49
50 static ssize_t stm_write_cmd (struct file *file, const char __user *buf,
51 size_t count, loff_t *ppos)
52 {
53 char type;
54
55 if (get_user(type, (char __user *)buf))
56 return -EFAULT;
57
58 switch (type) {
59 case '0':
60 yyy_func1(1234);
61 break;
62 case '1':
63 yyy_int(-1, 200, 300);
64 break;
65 case '2':
66 yyy_uint((unsigned)-1, 200, 300);
67 break;
68 case '3':
69 yyy_long(-1L, 200L, 300L);
70 break;
71 case '4':
72 yyy_int64(-1, 200, 300);
73 break;
74 case '5':
75 yyy_char('a', 'b', 'c');
76 break;
77 case '6':
78 yyy_str("Hello", "System", "Tap");
79 break;
80 default:
81 printk ("systemtap_test_module1: invalid command type %d\n", (int)type);
82 return -EINVAL;
83 }
84
85 return count;
86 }
87
88 static const struct proc_ops stm_pops_cmd = {
89 // .proc_owner = THIS_MODULE,
90 .proc_write = stm_write_cmd,
91 };
92
93 int my_init_module(void)
94 {
95 stm_ctl = proc_create_data ("stap_test_cmd", 0666, NULL, &stm_pops_cmd, NULL);
96 if (stm_ctl == NULL)
97 return -1;
98 return 0;
99 }
100
101 void my_cleanup_module(void)
102 {
103 if (stm_ctl)
104 remove_proc_entry ("stap_test_cmd", NULL);
105 }
106
107 MODULE_DESCRIPTION("systemtap backtrace test module1");
108 MODULE_LICENSE("GPL");