[REFACTOR] divide kprobe tests module 65/74065/2
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 9 Jun 2016 12:50:26 +0000 (15:50 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Fri, 10 Jun 2016 18:10:40 +0000 (21:10 +0300)
Change-Id: I34dabc4072e385a1a504fe2dbb3a55ceb29a1c37
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
tests/kprobe_tests/Kbuild
tests/kprobe_tests/kp_module.c [new file with mode: 0644]
tests/kprobe_tests/kp_module.h [new file with mode: 0644]
tests/kprobe_tests/kp_tests.c [moved from tests/kprobe_tests/kp_tests_module.c with 85% similarity]

index 7ffd593..f60b2c1 100644 (file)
@@ -1,4 +1,6 @@
 EXTRA_CFLAGS := $(extra_cflags)
 
 obj-m := swap_kp_tests.o
-swap_kp_tests-y := kp_tests_module.o
+swap_kp_tests-y := \
+       kp_module.o \
+       kp_tests.o
diff --git a/tests/kprobe_tests/kp_module.c b/tests/kprobe_tests/kp_module.c
new file mode 100644 (file)
index 0000000..171bc30
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2016
+ *
+ * 2016         Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/uaccess.h>
+#include <linux/kallsyms.h>
+#include "kp_module.h"
+
+
+static asmlinkage long (*olog_sys_write)(unsigned int, const char __user *, size_t);
+
+static long write_to_stdout(const char *buf, size_t len)
+{
+       long ret;
+
+       mm_segment_t fs = get_fs();
+       set_fs(get_ds());
+       ret = olog_sys_write(1, buf, len);
+       set_fs(fs);
+
+       return ret;
+}
+
+static int olog_init(void)
+{
+       olog_sys_write = (void *)kallsyms_lookup_name("sys_write");
+       if (olog_sys_write == NULL) {
+               pr_err("ERR: not found 'sys_write' symbol\n");
+               return -ESRCH;
+       }
+
+       return 0;
+}
+
+void olog(const char *fmt, ...)
+{
+       char buf[256];
+       va_list args;
+
+       va_start(args, fmt);
+       vsnprintf(buf, sizeof(buf), fmt, args);
+       va_end(args);
+
+       printk("%s", buf);
+       write_to_stdout(buf, strlen(buf));
+}
+
+
+
+
+static void print_mod_info(void)
+{
+       struct module *mod = THIS_MODULE;
+
+       printk("### MOD_INFO:\n");
+       printk("    core: %p..%p\n", mod->module_init, mod->module_init + mod->init_text_size);
+       printk("    init: %p..%p\n", mod->module_core, mod->module_core + mod->core_text_size);
+       printk("\n");
+}
+
+
+/* TODO: move declare to header */
+int kp_tests_run(void);
+
+static int __init tests_init(void)
+{
+       int ret;
+
+       ret = olog_init();
+       if (ret)
+               return ret;
+
+       print_mod_info();
+
+       olog("### Begin tests ###\n");
+       kp_tests_run();
+       olog("### End tests ###\n");
+
+       return -1;
+}
+
+static void __exit tests_exit(void)
+{
+}
+
+module_init(tests_init);
+module_exit(tests_exit);
+
+MODULE_LICENSE("GPL");
diff --git a/tests/kprobe_tests/kp_module.h b/tests/kprobe_tests/kp_module.h
new file mode 100644 (file)
index 0000000..e3f0b2b
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2016
+ *
+ * 2016         Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+
+#ifndef _KP_MODULE_H
+#define _KP_MODULE_H
+
+
+void olog(const char *fmt, ...);
+
+
+#endif /* _KP_MODULE_H */
similarity index 85%
rename from tests/kprobe_tests/kp_tests_module.c
rename to tests/kprobe_tests/kp_tests.c
index 816d92e..6386f50 100644 (file)
 
 
 #include <linux/slab.h>
-#include <linux/string.h>
 #include <linux/delay.h>
 #include <linux/module.h>
 #include <linux/kthread.h>
-#include <ksyms/ksyms.h>
 #include <kprobe/swap_kprobes.h>
-#include <master/swap_initializer.h>
+#include "kp_module.h"
 
 
 static struct task_struct *cur_task;
 
 
-
-/*
- ******************************************************************************
- *                                    log                                     *
- ******************************************************************************
- */
-static long write_to_stdout(const char *buf, size_t len)
-{
-       static asmlinkage long (*sys_write)(unsigned int, const char __user *, size_t) = NULL;
-       long ret = -ESRCH;
-
-       if (sys_write == NULL)
-               sys_write = (void *)swap_ksyms("sys_write");
-
-       if (sys_write) {
-               mm_segment_t fs = get_fs();
-               set_fs(get_ds());
-               ret = sys_write(1, buf, len);
-               set_fs(fs);
-       }
-
-       return ret;
-}
-
-static void olog(const char *fmt, ...)
-{
-       char buf[256];
-       va_list args;
-
-       va_start(args, fmt);
-       vsnprintf(buf, sizeof(buf), fmt, args);
-       va_end(args);
-
-       printk("%s", buf);
-       write_to_stdout(buf, strlen(buf));
-}
-
-
-
-
 static struct kprobe *kp_create(char *name,
                                int (*pre_h)(struct kprobe *, struct pt_regs *))
 {
@@ -447,24 +405,10 @@ static void test_sync_unreg_and_multiple_handlers2(void)
        post_test_sync_unreg_and_mh(2, 2);
 }
 
-
-static void print_mod_info(void)
-{
-       struct module *mod = THIS_MODULE;
-
-       printk("### MOD_INFO:\n");
-       printk("    core: %p..%p\n", mod->module_init, mod->module_init + mod->init_text_size);
-       printk("    init: %p..%p\n", mod->module_core, mod->module_core + mod->core_text_size);
-       printk("\n");
-}
-
-static int test_init(void)
+int kp_tests_run(void)
 {
        cur_task = current;
 
-       print_mod_info();
-
-       olog("### Begin tests ###\n");
        test_recursion();
        test_recursion_and_multiple_handlers();
        test_recursion_and_multiple_handlers2();
@@ -473,16 +417,6 @@ static int test_init(void)
        test_sync_unreg();
        test_sync_unreg_and_multiple_handlers();
        test_sync_unreg_and_multiple_handlers2();
-       olog("### End tests ###\n");
-
-       return -1;
-}
 
-static void test_exit(void)
-{
+       return 0;
 }
-
-
-SWAP_LIGHT_INIT_MODULE(NULL, test_init, test_exit, NULL, NULL);
-
-MODULE_LICENSE("GPL");