summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xkhab_test/Makefile28
-rwxr-xr-xkhab_test/fault_injection_khab_test_export.c78
-rwxr-xr-xkhab_test/fault_injection_khab_test_import.c84
-rwxr-xr-xkhab_test/fault_injection_khab_test_open.c64
-rwxr-xr-xkhab_test/fault_injection_khab_test_unexport.c86
-rwxr-xr-xkhab_test/fault_injection_khab_test_unimport.c92
-rwxr-xr-xkhab_test/khab_test_close.c75
-rwxr-xr-xkhab_test/khab_test_export.c155
-rwxr-xr-xkhab_test/khab_test_import.c131
-rwxr-xr-xkhab_test/khab_test_open.c69
-rwxr-xr-xkhab_test/khab_test_query.c86
-rwxr-xr-xkhab_test/khab_test_recv.c140
-rwxr-xr-xkhab_test/khab_test_send.c127
-rwxr-xr-xkhab_test/khab_test_unexport.c119
-rwxr-xr-xkhab_test/khab_test_unimport.c118
-rwxr-xr-xkhab_test/khab_unittest_kprobe.c177
16 files changed, 1629 insertions, 0 deletions
diff --git a/khab_test/Makefile b/khab_test/Makefile
new file mode 100755
index 0000000..b431cc9
--- /dev/null
+++ b/khab_test/Makefile
@@ -0,0 +1,28 @@
+obj-m := fault_injection_khab_test_export.o
+obj-m += fault_injection_khab_test_import.o
+obj-m += fault_injection_khab_test_open.o
+obj-m += fault_injection_khab_test_unexport.o
+obj-m += fault_injection_khab_test_unimport.o
+obj-m += khab_test_close.o
+obj-m += khab_test_export.o
+obj-m += khab_test_import.o
+obj-m += khab_test_open.o
+obj-m += khab_test_query.o
+obj-m += khab_test_recv.o
+obj-m += khab_test_send.o
+obj-m += khab_test_unexport.o
+obj-m += khab_test_unimport.o
+obj-m += khab_unittest_kprobe.o
+
+SRC := $(shell pwd)
+
+all:
+ $(MAKE) -C $(KERNEL_SRC) M=$(SRC)
+
+modules_install:
+ $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
+
+clean:
+ rm -f *.o *~ core .depend .*.cmd *.ko *.mod.c
+ rm -f Module.markers Module.symvers modules.order
+ rm -rf .tmp_versions Modules.symvers
diff --git a/khab_test/fault_injection_khab_test_export.c b/khab_test/fault_injection_khab_test_export.c
new file mode 100755
index 0000000..061aec4
--- /dev/null
+++ b/khab_test/fault_injection_khab_test_export.c
@@ -0,0 +1,78 @@
+/*
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 and
+* only version 2 as published by the Free Software Foundation.
+*
+* 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.
+*/
+
+#include <linux/habmm.h>
+#include <linux/module.h>
+#include <linux/ktf.h>
+
+KTF_INIT();
+
+TEST(hab_handler, Test_habmm_export)
+{
+ int32_t handle;
+ int32_t open_r;
+ int32_t export_r;
+ uint32_t export_id;
+ char size_page[4096] = "abcdefghigklmn";
+
+ open_r = habmm_socket_open(&handle, 601, 0, 0);
+ tlog(T_INFO, "fault injection Test_habmm_export begin: habmm_socket_open the return value open_r=%d handle=0x%x\n",open_r,handle);
+ EXPECT_INT_EQ(0, open_r);
+ if (open_r < 0)
+ {
+ goto err;
+ }
+
+ /*fault injection Test_habmm_export testing*/
+ tlog(T_INFO, "fault injection Test_habmm_export testing : size_bytes is 4096 and flag is 0\n");
+ export_r = habmm_export(handle, size_page, 4096, &export_id, 0);
+ tlog(T_INFO, "fault injection Test_habmm_export testing size_bytes is 4096 and flag is 0 the return value export_r=%d export_id=%d \n",export_r,export_id);
+ EXPECT_INT_EQ(0, export_r);
+ if (export_r < 0)
+ {
+ goto err1;
+ }
+
+ habmm_socket_close(handle);
+ return;
+err1:
+ terr("fault injection for Test_habmm_export_fault_injection failed\n");
+ return;
+err:
+ terr("Can't open the mmid socket\n");
+ return;
+}
+
+static void add_tests(void)
+{
+ ADD_TEST(Test_habmm_export);
+}
+
+static int __init hab_ut_init(void)
+{
+ int ret;
+ tlog(T_INFO, "fault injection khab test kernel module for hab initialising\n");
+ add_tests();
+ tlog(T_INFO, "fault injection khab test export initialized\n");
+ return ret;
+}
+
+static void __exit hab_ut_exit(void)
+{
+ tlog(T_INFO, "fault injection khab test export module unloaded\n");
+ KTF_CLEANUP();
+}
+
+module_init(hab_ut_init);
+module_exit(hab_ut_exit);
+MODULE_LICENSE("GPL v2");
diff --git a/khab_test/fault_injection_khab_test_import.c b/khab_test/fault_injection_khab_test_import.c
new file mode 100755
index 0000000..8bacfe5
--- /dev/null
+++ b/khab_test/fault_injection_khab_test_import.c
@@ -0,0 +1,84 @@
+/*
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 and
+* only version 2 as published by the Free Software Foundation.
+*
+* 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.
+*/
+
+#include <linux/habmm.h>
+#include <linux/module.h>
+#include <linux/ktf.h>
+
+KTF_INIT();
+
+TEST(hab_handler, Test_habmm_import)
+{
+ int32_t handle;
+ int32_t open_r;
+ int32_t recv_r;
+ int32_t import_r;
+ char export_id;
+ uint32_t size_export_id = 1;
+ char *size_page = NULL;
+
+ open_r = habmm_socket_open(&handle, 601, 0, 0);
+ tlog(T_INFO, "fault injection Test_habmm_import begin: habmm_socket_open the return value open_r=%d handle=0x%x\n", open_r, handle);
+ EXPECT_INT_EQ(0, open_r);
+ if (open_r < 0)
+ {
+ goto err;
+ }
+
+ recv_r = habmm_socket_recv(handle, &export_id, &size_export_id, 0, 0);
+ tlog(T_INFO, "fault injection Test_habmm_import : habmm_socket_recv the return value recv_r=%d export_id=%d\n", recv_r, export_id);
+ EXPECT_INT_EQ(0, recv_r);
+
+ /* fault injection Test_habmm_import testing */
+ tlog(T_INFO, "fault injection Test_habmm_import testing : size_bytes is 4096 and flag is 0x00000001\n");
+ import_r = habmm_import(handle, (void **)&size_page, 4096, export_id, 0x00000001);
+ tlog(T_INFO, "fault injection Test_habmm_import testing size_bytes is 4096 and flag is 0x00000001 the return value import_r=%d export_id=%d \n", import_r, export_id);
+ EXPECT_INT_EQ(0, import_r);
+ if (open_r < 0)
+ {
+ goto err1;
+ }
+
+ habmm_socket_close(handle);
+ return;
+err1:
+ terr("fault injection for Test_habmm_export_fault_injection failed\n");
+ return;
+err:
+ terr("Can't open the mmid socket\n");
+ return;
+}
+
+static void add_tests(void)
+{
+ ADD_TEST(Test_habmm_import);
+}
+
+static int __init hab_ut_init(void)
+{
+ int ret;
+ tlog(T_INFO, "fault injection khab test kernel module for hab initialising\n");
+ add_tests();
+ tlog(T_INFO, "fault injection khab test import initialized\n");
+ return ret;
+}
+
+static void __exit hab_ut_exit(void)
+{
+ tlog(T_INFO, "fault injection khab test import module unloaded\n");
+ KTF_CLEANUP();
+}
+
+module_init(hab_ut_init);
+module_exit(hab_ut_exit);
+MODULE_LICENSE("GPL v2"); \ No newline at end of file
diff --git a/khab_test/fault_injection_khab_test_open.c b/khab_test/fault_injection_khab_test_open.c
new file mode 100755
index 0000000..c00a209
--- /dev/null
+++ b/khab_test/fault_injection_khab_test_open.c
@@ -0,0 +1,64 @@
+/*
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 and
+* only version 2 as published by the Free Software Foundation.
+*
+* 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.
+*/
+
+#include <linux/habmm.h>
+#include <linux/module.h>
+#include <linux/ktf.h>
+
+KTF_INIT();
+
+TEST(hab_handler, Test_habmm_socket_open)
+{
+ int32_t handle;
+ int32_t open_r;
+
+ /* Test_habmm_socket_open testing */
+ tlog(T_INFO, "fault injection Test_habmm_socket_open testing begin: valid mmid is 601\n");
+ open_r = habmm_socket_open(&handle, 601, 0, 0);
+ tlog(T_INFO, "fault injection habmm_socket_open fault injection testing the return value open_r=%d handle=0x%x\n", open_r, handle);
+ EXPECT_INT_EQ(0, open_r);
+ if (open_r < 0)
+ {
+ goto err;
+ }
+
+ habmm_socket_close(handle);
+ return;
+err:
+ terr("fault injection for Test_habmm_socket_open failed\n");
+ return;
+}
+
+static void add_tests(void)
+{
+ ADD_TEST(Test_habmm_socket_open);
+}
+
+static int __init hab_ut_init(void)
+{
+ int ret;
+ tlog(T_INFO, "fault injection test kernel module for hab open initialising\n");
+ add_tests();
+ tlog(T_INFO, "fault injection khab test open initialized\n");
+ return ret;
+}
+
+static void __exit hab_ut_exit(void)
+{
+ tlog(T_INFO, "fault injection khab test open module unloaded\n");
+ KTF_CLEANUP();
+}
+
+module_init(hab_ut_init);
+module_exit(hab_ut_exit);
+MODULE_LICENSE("GPL v2"); \ No newline at end of file
diff --git a/khab_test/fault_injection_khab_test_unexport.c b/khab_test/fault_injection_khab_test_unexport.c
new file mode 100755
index 0000000..96554c6
--- /dev/null
+++ b/khab_test/fault_injection_khab_test_unexport.c
@@ -0,0 +1,86 @@
+/*
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 and
+* only version 2 as published by the Free Software Foundation.
+*
+* 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.
+*/
+
+#include <linux/habmm.h>
+#include <linux/module.h>
+#include <linux/ktf.h>
+
+KTF_INIT();
+
+TEST(hab_handler, Test_habmm_unexport)
+{
+ int32_t handle;
+ int32_t open_r;
+ int32_t export_r;
+ int32_t unexport_r;
+ uint32_t export_id;
+ char size_page[4096] = "abcdefghigklmn";
+
+ open_r = habmm_socket_open(&handle, 601, 0, 0);
+ tlog(T_INFO, "fault injection Test_habmm_unexport begin: habmm_socket_open the return value open_r=%d handle=0x%x\n", open_r, handle);
+ EXPECT_INT_EQ(0, open_r);
+ if (open_r < 0)
+ {
+ goto err;
+ }
+
+ tlog(T_INFO, "fault injection Test_habmm_unexport size_bytes is 4096 and flag is 0\n");
+ export_r = habmm_export(handle,size_page, 4096, &export_id, 0);
+ tlog(T_INFO, "fault injection Test_habmm_unexport size_bytes is 4096 and flag is 0 the return value export_r=%d export_id=%d \n", export_r, export_id);
+ EXPECT_INT_EQ(0, export_r);
+
+ /* fault injection Test_habmm_unexport testing */
+ tlog(T_INFO, "fault injection Test_habmm_unexport testing:\n");
+ unexport_r = habmm_unexport(handle, export_id, 0);
+ tlog(T_INFO, "fault injection Test_habmm_unexport testing flag is 0 the return value unexport_r=%d export_id=%d \n", unexport_r, export_id);
+ EXPECT_INT_EQ(0, unexport_r);
+ if (unexport_r < 0)
+ {
+ goto err1;
+ }
+
+ habmm_socket_close(handle);
+ return;
+err1:
+ terr("fault injection for Test_habmm_export_fault_injection failed\n");
+
+ return;
+err:
+ terr("Can't open the mmid socket\n");
+ return;
+}
+
+static void add_tests(void)
+{
+ ADD_TEST(Test_habmm_unexport);
+}
+
+
+static int __init hab_ut_init(void)
+{
+ int ret;
+ tlog(T_INFO, "fault injection khab test kernel module for hab initialising\n");
+ add_tests();
+ tlog(T_INFO, "fault injection khab test unexport initialized\n");
+ return ret;
+}
+
+static void __exit hab_ut_exit(void)
+{
+ tlog(T_INFO, "fault injection khab test unexport module unloaded\n");
+ KTF_CLEANUP();
+}
+
+module_init(hab_ut_init);
+module_exit(hab_ut_exit);
+MODULE_LICENSE("GPL v2"); \ No newline at end of file
diff --git a/khab_test/fault_injection_khab_test_unimport.c b/khab_test/fault_injection_khab_test_unimport.c
new file mode 100755
index 0000000..03f6048
--- /dev/null
+++ b/khab_test/fault_injection_khab_test_unimport.c
@@ -0,0 +1,92 @@
+/*
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 and
+* only version 2 as published by the Free Software Foundation.
+*
+* 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.
+*/
+
+#include <linux/habmm.h>
+#include <linux/module.h>
+#include <linux/ktf.h>
+
+KTF_INIT();
+
+TEST(hab_handler, Test_habmm_unimport)
+{
+ int32_t handle;
+ int32_t open_r;
+ int32_t recv_r;
+ int32_t import_r;
+ int32_t unimport_r;
+ char export_id;
+ uint32_t size_export_id = 1;
+ char *size_page = NULL;
+
+ open_r = habmm_socket_open(&handle, 601, 0, 0);
+ tlog(T_INFO, "fault injection Test_habmm_unimport begin: habmm_socket_open the return value open_r=%d handle=0x%x\n", open_r, handle);
+ EXPECT_INT_EQ(0, open_r);
+ if (open_r < 0)
+ {
+ goto err;
+ }
+
+ recv_r = habmm_socket_recv(handle, &export_id, &size_export_id, 0, 0);
+ tlog(T_INFO, "fault injection Test_habmm_unimport : habmm_socket_recv the return value recv_r=%d export_id=%d\n", recv_r, export_id);
+ EXPECT_INT_EQ(0, recv_r);
+
+ tlog(T_INFO, "fault injection Test_habmm_unimport :Test_habmm_import size_bytes is 4096 and flag is 0x00000001\n");
+ import_r = habmm_import(handle, (void **)&size_page, 4096, export_id, 0x00000001);
+ tlog(T_INFO, "fault injection Test_habmm_unimport: Test_habmm_import size_bytes is 4096 and flag is 0x00000001 the return value import_r=%d export_id=%d \n", import_r, export_id);
+ EXPECT_INT_EQ(0, import_r);
+
+ /* fault injection Test_habmm_unimport testing */
+ tlog(T_INFO, "fault injection Test_habmm_unimport testing:\n");
+ unimport_r = habmm_unimport(handle, export_id, (void *)size_page, 0);
+ tlog(T_INFO, "fault injection Test_habmm_unimport testing flag is 0 the return value unimport_r=%d export_id=%d \n", unimport_r, export_id);
+ EXPECT_INT_EQ(0, unimport_r);
+ if (open_r < 0)
+ {
+ goto err1;
+ }
+
+ habmm_socket_close(handle);
+ return;
+err1:
+ terr("fault injection for Test_habmm_export_fault_injection failed\n");
+
+ return;
+err:
+ terr("Can't open the mmid socket\n");
+ return;
+}
+
+
+static void add_tests(void)
+{
+ ADD_TEST(Test_habmm_unimport);
+}
+
+static int __init hab_ut_init(void)
+{
+ int ret;
+ tlog(T_INFO, "fault injection khab test kernel module for hab initialising\n");
+ add_tests();
+ tlog(T_INFO, "fault injection khab test unimport initialized\n");
+ return ret;
+}
+
+static void __exit hab_ut_exit(void)
+{
+ tlog(T_INFO, "fault injection khab test unimport module unloaded\n");
+ KTF_CLEANUP();
+}
+
+module_init(hab_ut_init);
+module_exit(hab_ut_exit);
+MODULE_LICENSE("GPL v2"); \ No newline at end of file
diff --git a/khab_test/khab_test_close.c b/khab_test/khab_test_close.c
new file mode 100755
index 0000000..1bbcce5
--- /dev/null
+++ b/khab_test/khab_test_close.c
@@ -0,0 +1,75 @@
+/*
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 and
+* only version 2 as published by the Free Software Foundation.
+*
+* 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.
+*/
+
+#include <linux/habmm.h>
+#include <linux/module.h>
+#include <linux/ktf.h>
+
+KTF_INIT();
+
+TEST(hab_handler, Test_habmm_socket_close)
+{
+ int32_t handle;
+ int32_t open_r;
+ int32_t close_r;
+
+ tlog(T_INFO, "Test_habmm_socket_close begin\n");
+ open_r = habmm_socket_open(&handle, 601, 0, 0);
+ tlog(T_INFO, "Test_habmm_socket_close the habmm_socket_open return value open_r=%d handle=%d\n", open_r, handle);
+ EXPECT_INT_EQ(0, open_r);
+ if (open_r < 0)
+ {
+ goto err;
+ }
+
+ /* Negative testing */
+ /* 1.input invalidate handle */
+ tlog(T_INFO, "1.Test_habmm_socket_close Negative testing :input invalid handle \n");
+ close_r = habmm_socket_close(112);
+ tlog(T_INFO, "1.Test_habmm_socket_close Negative testing the return value close_r=%d \n", close_r);
+ EXPECT_INT_LT(close_r, 0);
+
+ /* Positive testing */
+ tlog(T_INFO, "Test_habmm_socket_close Positive testing:\n");
+ close_r = habmm_socket_close(handle);
+ tlog(T_INFO, "Test_habmm_socket_close Positive testing the return value close_r=%d \n", close_r);
+ EXPECT_INT_EQ(0, close_r);
+ return;
+err:
+ terr("Can't open the mmid socket\n");
+ return;
+}
+
+static void add_tests(void)
+{
+ ADD_TEST(Test_habmm_socket_close);
+}
+
+static int __init hab_ut_init(void)
+{
+ int ret;
+ tlog(T_INFO, "Unit test kernel module for hab initialising\n");
+ add_tests();
+ tlog(T_INFO, "khab test close initialized\n");
+ return ret;
+}
+
+static void __exit hab_ut_exit(void)
+{
+ tlog(T_INFO, "khab test close module unloaded\n");
+ KTF_CLEANUP();
+}
+
+module_init(hab_ut_init);
+module_exit(hab_ut_exit);
+MODULE_LICENSE("GPL v2"); \ No newline at end of file
diff --git a/khab_test/khab_test_export.c b/khab_test/khab_test_export.c
new file mode 100755
index 0000000..4f3a0d8
--- /dev/null
+++ b/khab_test/khab_test_export.c
@@ -0,0 +1,155 @@
+/*
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 and
+* only version 2 as published by the Free Software Foundation.
+*
+* 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.
+*/
+
+#include <linux/habmm.h>
+#include <linux/module.h>
+#include <linux/ion_kernel.h>
+#include <linux/msm_ion.h>
+#include <linux/export.h>
+#include <linux/ktf.h>
+#include <linux/dma-mapping.h>
+#include <linux/dma-contiguous.h>
+#include <linux/dma-buf.h>
+
+KTF_INIT();
+
+void *invalid_address=(void *) 0x0000000008000000;
+
+TEST(hab_handler, Test_habmm_export)
+{
+ int32_t handle;
+ int32_t open_r;
+ int32_t export_r;
+ uint32_t export_id;
+ int32_t unexport_r;
+ uint32_t export_id2;
+ char *addr = NULL;
+ struct dma_buf *vhandle = NULL;
+ struct dma_buf *size_10 = NULL;
+ int32_t bufsz = 4096;
+ unsigned long err_ion_ptr = 0;
+
+ vhandle = ion_alloc(bufsz, ION_HEAP(ION_SYSTEM_HEAP_ID), 0);
+ if (IS_ERR_OR_NULL((void *)(vhandle))) {
+ if (IS_ERR((void *)(vhandle)))
+ err_ion_ptr = PTR_ERR((int *)(vhandle));
+ tlog(T_INFO, " ION alloc fail err ptr=%ld\n",
+ err_ion_ptr);
+ goto err;
+ }
+
+ size_10 = ion_alloc(10, ION_HEAP(ION_SYSTEM_HEAP_ID), 0);
+ if (IS_ERR_OR_NULL((void *)(size_10))) {
+ if (IS_ERR((void *)(size_10)))
+ err_ion_ptr = PTR_ERR((int *)(size_10));
+ tlog(T_INFO, " ION alloc fail err ptr=%ld\n",
+ err_ion_ptr);
+ goto err;
+ }
+
+ dma_buf_begin_cpu_access((struct dma_buf*)vhandle,
+ DMA_BIDIRECTIONAL);
+ addr = dma_buf_vmap((struct dma_buf*)vhandle);
+ tlog(T_INFO, "Test_habmm_export begin: habmm_socket_open the return value addr->size=%d \n", addr);
+
+ open_r = habmm_socket_open(&handle, 601, 0, 0);
+ tlog(T_INFO, "Test_habmm_export begin: habmm_socket_open the return value open_r=%d handle=0x%x\n", open_r, handle);
+ EXPECT_INT_EQ(0, open_r);
+ if (open_r < 0)
+ {
+ goto err;
+ }
+
+ /* Positive testing */
+ tlog(T_INFO, "Test_habmm_export Positive testing : size_bytes is 4096 and flag is 0x00020000\n");
+ export_r = habmm_export(handle, vhandle ,4096, &export_id, HABMM_EXPIMP_FLAGS_DMABUF);
+ export_id2 = export_id;
+ tlog(T_INFO, "Test_habmm_export Positive testing size_bytes is 4096 and flag is 0x00020000 the return value export_r=%d export_id=%d \n", export_r, export_id);
+ EXPECT_INT_EQ(0, export_r);
+
+ /* unexport the space */
+ unexport_r = habmm_unexport(handle, export_id2, 0x00000000);
+ tlog(T_INFO, "unexport the space flag is 0x00000000 the return value unexport_r=%d export_id2=%d \n", unexport_r, export_id2);
+ EXPECT_INT_EQ(0, unexport_r);
+
+ /* Negative testing */
+ /* 1.handle is error */
+ tlog(T_INFO, "1.habmm_export Negative testing : handle is error flag=0x00020000\n");
+ export_r = habmm_export(11, vhandle, 4096, &export_id, HABMM_EXPIMP_FLAGS_DMABUF);
+ tlog(T_INFO, "1.habmm_export Negative testing the return value export_r=%d flag=0x00020000\n", export_r);
+ EXPECT_INT_LT(export_r, 0);
+
+ /* 2.buff_to_share is null or invalid address */
+ tlog(T_INFO, "2.habmm_export Negative testing : buff_to_share is null flag=0x00020000\n");
+ export_r = habmm_export(handle, NULL, 4096, &export_id, HABMM_EXPIMP_FLAGS_DMABUF);
+ tlog(T_INFO, "2.habmm_export Negative testing the return value export_r=%d flag=0x00020000 \n", export_r);
+ EXPECT_INT_LT(export_r, 0);
+
+ //tlog(T_INFO, "3.habmm_export Negative testing : buff_to_share is invalid address flag=0x00000001\n");
+ //export_r = habmm_export(handle, invalid_address, 4096, &export_id, 0x00000001);
+ //tlog(T_INFO, "3.habmm_export Negative testing the return value export_r=%d flag=0x00000001 \n",export_r);
+ //EXPECT_INT_LT(export_r, 0);
+
+ //tlog(T_INFO, "3.habmm_export Negative testing : buff_to_share is invalid address flag=0x00010000\n");
+ //export_r = habmm_export(handle, invalid_address, 4096, &export_id, 0x00010000);
+ //tlog(T_INFO, "3.habmm_export Negative testing the return value export_r=%d flag=0x00010000 \n",export_r);
+ //EXPECT_INT_LT(export_r, 0);
+
+ /*3.export_id is null */
+ tlog(T_INFO, "3.habmm_export Negative testing : export_id is null flag=0x00020000\n");
+ export_r = habmm_export(handle, vhandle, 4096, NULL, HABMM_EXPIMP_FLAGS_DMABUF);
+ tlog(T_INFO, "3.habmm_export Negative testing the return value export_r=%d flag=0x00020000 \n", export_r);
+ EXPECT_INT_LT(export_r, 0);
+ /* 4.Size is not page aligned */
+ tlog(T_INFO, "4.habmm_export Negative testing : Size is not page aligned flag=0x00020000\n");
+ export_r = habmm_export(handle, size_10, 10, &export_id, HABMM_EXPIMP_FLAGS_DMABUF);
+ tlog(T_INFO, "4.habmm_export Negative testing the return value export_r=%d flag=0x00020000\n", export_r);
+ EXPECT_INT_LT(export_r, 0);
+
+ /* free the buf */
+ dma_buf_vunmap((struct dma_buf*)vhandle, addr);
+ dma_buf_end_cpu_access((struct dma_buf*)vhandle, DMA_BIDIRECTIONAL);
+ dma_buf_put(vhandle);
+ dma_buf_put(size_10);
+
+ habmm_socket_close(handle);
+ return;
+err:
+ terr("Can't open the mmid socket\n");
+ return;
+}
+
+
+static void add_tests(void)
+{
+ ADD_TEST(Test_habmm_export);
+}
+
+static int __init hab_ut_init(void)
+{
+ int ret;
+ tlog(T_INFO, "Unit test kernel module for hab initialising\n");
+ add_tests();
+ tlog(T_INFO, "khab test export initialized\n");
+ return ret;
+}
+
+static void __exit hab_ut_exit(void)
+{
+ tlog(T_INFO, "khab test export module unloaded\n");
+ KTF_CLEANUP();
+}
+
+module_init(hab_ut_init);
+module_exit(hab_ut_exit);
+MODULE_LICENSE("GPL v2"); \ No newline at end of file
diff --git a/khab_test/khab_test_import.c b/khab_test/khab_test_import.c
new file mode 100755
index 0000000..7954d9b
--- /dev/null
+++ b/khab_test/khab_test_import.c
@@ -0,0 +1,131 @@
+/*
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 and
+* only version 2 as published by the Free Software Foundation.
+*
+* 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.
+*/
+
+#include <linux/habmm.h>
+#include <linux/module.h>
+#include <linux/ktf.h>
+#include <linux/dma-mapping.h>
+#include <linux/dma-contiguous.h>
+#include <linux/dma-buf.h>
+
+KTF_INIT();
+
+
+TEST(hab_handler, Test_habmm_import)
+{
+ int32_t handle;
+ int32_t open_r;
+ int32_t recv_r;
+ int32_t import_r;
+ char export_id1;
+ char *addr = NULL;
+ uint32_t wrong_export_id = 1000;
+ uint32_t size_export_id = 1;
+ char *size_10 = NULL;
+ char *size_page = NULL;
+ int32_t unimport_r;
+
+ open_r = habmm_socket_open(&handle, 601, 0, 0);
+ tlog(T_INFO, "Test_habmm_import begin: habmm_socket_open the return value open_r=%d handle=0x%x\n", open_r, handle);
+ EXPECT_INT_EQ(0, open_r);
+ if (open_r < 0)
+ {
+ goto err;
+ }
+
+ recv_r = habmm_socket_recv(handle, &export_id1, &size_export_id, 0, 0);
+ tlog(T_INFO, "Test_habmm_import : habmm_socket_recv the return value recv_r=%d export_id1=%d\n", recv_r, export_id1);
+ EXPECT_INT_EQ(0, recv_r);
+
+ /* Positive testing */
+ tlog(T_INFO, "Test_habmm_import Positive testing : size_bytes is 4096 and flag is 0x00000000\n");
+ import_r = habmm_import(handle, (void **)&size_page, 4096, export_id1, 0x00000000);
+ tlog(T_INFO, "Test_habmm_import Positive testing size_bytes is 4096 and flag is 0x00000000 the return value import_r=%d export_id1=%d \n", import_r, export_id1);
+ EXPECT_INT_EQ(0, import_r);
+
+ addr = (char *)dma_buf_vmap((struct dma_buf*)size_page);
+ if (!addr)
+ {
+ tlog(T_INFO, "Test_habmm_import begin: the return value error!!! \n");
+ habmm_unimport(handle, export_id1, (void *)size_page, 0x00000000);
+ habmm_socket_close(handle);
+ return;
+ }
+
+ tlog(T_INFO, "Test_habmm_import begin: the return value *addr=%d \n", *addr);
+ *addr=3;
+ tlog(T_INFO, "Test_habmm_import begin: dma_buf_vmap the *addr=%d \n", *addr);
+
+ /* unimport the space */
+ unimport_r = habmm_unimport(handle, export_id1, (void *)size_page, 0x00000000);
+ tlog(T_INFO, "unimport the space the return value unimport_r=%d export_id1=%d flag=0x00000000\n", unimport_r, export_id1);
+ EXPECT_INT_EQ(0, unimport_r);
+
+ /* Negative testing */
+ /* 1.input invalid size_bytes */
+ tlog(T_INFO, "1.habmm_import Negative testing :input invalid size_bytes flag=0x00000000\n");
+ import_r = habmm_import(handle, (void **)&size_10, 10, export_id1, 0x00000000);
+ tlog(T_INFO, "1.habmm_import Negative testing the return value import_r=%d flag=0x00000000\n", import_r);
+ EXPECT_INT_LT(import_r, 0);
+
+ /* 2.input invalid export_id */
+ tlog(T_INFO, "2.habmm_import Negative testing :input invalid export_id flag=0x00000000\n");
+ import_r = habmm_import(handle, (void **)&size_page, 4096, wrong_export_id, 0x00000000);
+ tlog(T_INFO, "2.habmm_import Negative testing the return value import_r=%d flag=0x00000000\n", import_r);
+ EXPECT_INT_LT(import_r, 0);
+
+ /* 3.input invalid handle */
+ tlog(T_INFO, "3.habmm_import Negative testing :input invalid handle flag=0x00000000\n");
+ import_r = habmm_import(1, (void **)&size_page, 4096, export_id1, 0x00000000);
+ tlog(T_INFO, "3.habmm_import Negative testing the return value import_r=%d flag=0x00000000\n", import_r);
+ EXPECT_INT_LT(import_r, 0);
+
+ /* 4.buff_shared is null or invalid address */
+ tlog(T_INFO, "4.habmm_import Negative testing :buff_shared is null flag=0x00000000\n");
+ import_r = habmm_import(handle, NULL, 4096, export_id1, 0x00000000);
+ tlog(T_INFO, "4.habmm_import Negative testing the return value import_r=%d flag=0x00000000\n", import_r);
+ EXPECT_INT_LT(import_r, 0);
+
+ /* free the buf */
+ dma_buf_vunmap((struct dma_buf*)size_page, addr);
+
+ habmm_socket_close(handle);
+ return;
+err:
+ terr("Can't open the mmid socket\n");
+ return;
+}
+
+static void add_tests(void)
+{
+ ADD_TEST(Test_habmm_import);
+}
+
+static int __init hab_ut_init(void)
+{
+ int ret;
+ tlog(T_INFO, "Unit test kernel module for hab initialising\n");
+ add_tests();
+ tlog(T_INFO, "khab test import initialized\n");
+ return ret;
+}
+
+static void __exit hab_ut_exit(void)
+{
+ tlog(T_INFO, "khab test import module unloaded\n");
+ KTF_CLEANUP();
+}
+
+module_init(hab_ut_init);
+module_exit(hab_ut_exit);
+MODULE_LICENSE("GPL v2"); \ No newline at end of file
diff --git a/khab_test/khab_test_open.c b/khab_test/khab_test_open.c
new file mode 100755
index 0000000..f441486
--- /dev/null
+++ b/khab_test/khab_test_open.c
@@ -0,0 +1,69 @@
+/*
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 and
+* only version 2 as published by the Free Software Foundation.
+*
+* 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.
+*/
+
+#include <linux/habmm.h>
+#include <linux/module.h>
+#include <linux/ktf.h>
+
+KTF_INIT();
+
+TEST(hab_handler, Test_habmm_socket_open)
+{
+ int32_t handle;
+ int32_t open_r;
+
+ /* Positive testing */
+ tlog(T_INFO, "Test_habmm_socket_open Positive testing begin: valid mmid is 601\n");
+ open_r = habmm_socket_open(&handle, 601, 0, 0);
+ tlog(T_INFO, "habmm_socket_open Positive testing the return value open_r=%d handle=0x%x\n", open_r, handle);
+ EXPECT_INT_EQ(0, open_r);
+ habmm_socket_close(handle);
+
+ /* Negative testing */
+ /* 1.input invalid mmid */
+ tlog(T_INFO, "1.Test_habmm_socket_open Negative testing begin: invalid mmid is 603\n");
+ open_r = habmm_socket_open(&handle, 603, 0, 0);
+ tlog(T_INFO, "1.habmm_socket_open Negative testing the return value open_r=%d \n", open_r);
+ EXPECT_INT_LT(open_r, 0);
+
+ /* 2.input handle is null */
+ tlog(T_INFO, "2.Test_habmm_socket_open Negative testing begin: handle is null\n");
+ open_r = habmm_socket_open(NULL, 601, 0, 0);
+ tlog(T_INFO, "2.habmm_socket_open Negative testing the return value open_r=%d \n", open_r);
+ EXPECT_INT_LT(open_r, 0);
+ return;
+}
+
+static void add_tests(void)
+{
+ ADD_TEST(Test_habmm_socket_open);
+}
+
+static int __init hab_ut_init(void)
+{
+ int ret;
+ tlog(T_INFO, "Unit test kernel module for hab initialising\n");
+ add_tests();
+ tlog(T_INFO, "khab test open initialized\n");
+ return ret;
+}
+
+static void __exit hab_ut_exit(void)
+{
+ tlog(T_INFO, "khab test open module unloaded\n");
+ KTF_CLEANUP();
+}
+
+module_init(hab_ut_init);
+module_exit(hab_ut_exit);
+MODULE_LICENSE("GPL v2"); \ No newline at end of file
diff --git a/khab_test/khab_test_query.c b/khab_test/khab_test_query.c
new file mode 100755
index 0000000..549aa1c
--- /dev/null
+++ b/khab_test/khab_test_query.c
@@ -0,0 +1,86 @@
+/*
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 and
+* only version 2 as published by the Free Software Foundation.
+*
+* 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.
+*/
+
+#include <linux/habmm.h>
+#include <linux/module.h>
+#include <linux/ktf.h>
+
+KTF_INIT();
+
+TEST(hab_handler, Test_habmm_socket_query)
+{
+ int32_t handle;
+ int32_t open_r;
+ int32_t query_r;
+ struct hab_socket_info info;
+
+ tlog(T_INFO, "Test_habmm_socket_query begin\n");
+ open_r = habmm_socket_open(&handle, 601, 0, 0);
+ tlog(T_INFO, "Test_habmm_socket_query the habmm_socket_open return value open_r=%d handle=0x%x\n", open_r, handle);
+ EXPECT_INT_EQ(0, open_r);
+ if (open_r < 0)
+ {
+ goto err;
+ }
+
+ /* Positive testing */
+ tlog(T_INFO, "Test_habmm_socket_query Positive testing:\n");
+ query_r = habmm_socket_query(handle, &info, 0);
+ tlog(T_INFO, "Test_habmm_socket_query Positive testing the return value query_r=%d \n", query_r);
+ EXPECT_INT_EQ(0, query_r);
+ tlog(T_INFO,"Test_habmm_socket_query hab_socket_info : vmid local %d remote %d, vmname local %s remote %s\n",
+ info.vmid_local, info.vmid_remote, info.vmname_local, info.vmname_remote);
+
+ /* Negative testing */
+ /* 1.input invalidate handle */
+ tlog(T_INFO, "1.Test_habmm_socket_query Negative testing :input invalidate handle \n");
+ query_r = habmm_socket_query(1, &info, 0);
+ tlog(T_INFO, "1.Test_habmm_socket_query Negative testing the return value query_r=%d \n", query_r);
+ EXPECT_INT_LT(query_r, 0);
+
+ /* 2.input info is null */
+ tlog(T_INFO, "2.Test_habmm_socket_query Negative testing :input info is null \n");
+ query_r = habmm_socket_query(handle, NULL, 0);
+ tlog(T_INFO, "2.Test_habmm_socket_query Negative testing the return value query_r=%d \n", query_r);
+ EXPECT_INT_LT(query_r, 0);
+
+ habmm_socket_close(handle);
+ return;
+err:
+ terr("Can't open the mmid socket\n");
+ return;
+}
+
+static void add_tests(void)
+{
+ ADD_TEST(Test_habmm_socket_query);
+}
+
+static int __init hab_ut_init(void)
+{
+ int ret;
+ tlog(T_INFO, "Unit test kernel module for hab initialising\n");
+ add_tests();
+ tlog(T_INFO, "khab test query initialized\n");
+ return ret;
+}
+
+static void __exit hab_ut_exit(void)
+{
+ tlog(T_INFO, "khab test query module unloaded\n");
+ KTF_CLEANUP();
+}
+
+module_init(hab_ut_init);
+module_exit(hab_ut_exit);
+MODULE_LICENSE("GPL v2"); \ No newline at end of file
diff --git a/khab_test/khab_test_recv.c b/khab_test/khab_test_recv.c
new file mode 100755
index 0000000..dc8efa3
--- /dev/null
+++ b/khab_test/khab_test_recv.c
@@ -0,0 +1,140 @@
+/*
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 and
+* only version 2 as published by the Free Software Foundation.
+*
+* 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.
+*/
+
+#include <linux/habmm.h>
+#include <linux/module.h>
+#include <linux/ktf.h>
+
+KTF_INIT();
+
+TEST(hab_handler, Test_habmm_socket_recv)
+{
+ int32_t handle;
+ int32_t open_r;
+ int32_t recv_r;
+ char size_10[10] = "abcdefghi";
+ char size_5[5] = "abcd";
+ int32_t right_size = 10;
+ int32_t wrong_size = 5;
+
+ open_r = habmm_socket_open(&handle, 601, 0, 0);
+ tlog(T_INFO, "Test_habmm_socket_recv begin: habmm_socket_open the return value open_r=%d handle=0x%x\n", open_r, handle);
+ EXPECT_INT_EQ(0, open_r);
+ if (open_r < 0)
+ {
+ goto err;
+ }
+
+ /* Positive testing */
+ tlog(T_INFO, "Test_habmm_socket_recv Positive testing : size_bytes is 10 and flag is 0\n");
+ recv_r = habmm_socket_recv(handle, size_10, &right_size, UINT_MAX, 0);
+ tlog(T_INFO, "Test_habmm_socket_recv Positive testing size_bytes is 10 and flag is 0 the return value recv_r=%d right_size:%d\n", recv_r, right_size);
+ EXPECT_INT_EQ(0, recv_r);
+
+ recv_r = -1;
+ tlog(T_INFO, "Test_habmm_socket_recv Positive testing : size_bytes is 10 and flag is 1\n");
+
+ while(1){
+ recv_r = habmm_socket_recv(handle, &size_10, &right_size, UINT_MAX, HABMM_SOCKET_RECV_FLAGS_NON_BLOCKING);
+ if(recv_r == 0)
+ break;
+
+ }
+
+ tlog(T_INFO, "Test_habmm_socket_recv Positive testing size_bytes is 10 and flag is 1 the return value recv_r=%d \n", recv_r);
+ EXPECT_INT_EQ(0, recv_r);
+
+ /* Negative testing */
+ /* 1.Allocated bytes less than actual bytes */
+ tlog(T_INFO, "1.habmm_socket_recv Negative testing : Allocated bytes less than actual bytes flag is 0\n");
+ recv_r = habmm_socket_recv(handle, size_5, &wrong_size, UINT_MAX, 0);
+ tlog(T_INFO, "1.habmm_socket_recv Negative testing the return value recv_r=%d flag is 0\n", recv_r);
+ EXPECT_INT_LT(recv_r, 0);
+
+ recv_r = 2;
+ tlog(T_INFO, "1.habmm_socket_recv Negative testing : Allocated bytes less than actual bytes flag is 1\n");
+ while(1){
+ recv_r=habmm_socket_recv(handle,size_5,&wrong_size,UINT_MAX,HABMM_SOCKET_RECV_FLAGS_NON_BLOCKING);
+ if(recv_r < 0)
+ break;
+
+ }
+ tlog(T_INFO, "1.habmm_socket_recv Negative testing the return value recv_r=%d flag is 1\n", recv_r);
+ EXPECT_INT_LT(recv_r, 0);
+
+ /* 2.dst_buff is null */
+ tlog(T_INFO, "2.habmm_socket_recv Negative testing : dst_buff is null flag is 0\n");
+ recv_r = habmm_socket_recv(handle, NULL, &right_size, UINT_MAX, 0);
+ tlog(T_INFO, "2.habmm_socket_recv Negative testing the return value recv_r=%d flag is 0 \n", recv_r);
+ EXPECT_INT_LT(recv_r, 0);
+
+ recv_r=2;
+ tlog(T_INFO, "2.habmm_socket_recv Negative testing : dst_buff is null flag is 1\n");
+ recv_r = habmm_socket_recv(handle, NULL, &right_size, UINT_MAX, HABMM_SOCKET_RECV_FLAGS_NON_BLOCKING);
+ tlog(T_INFO, "2.habmm_socket_recv Negative testing the return value recv_r=%d flag is 1\n", recv_r);
+ EXPECT_INT_LT(recv_r, 0);
+
+ /* 3.input invalid handle */
+ tlog(T_INFO, "3.habmm_socket_recv Negative testing : input invalid handle flag is 0\n");
+ recv_r = habmm_socket_recv(1, size_10, &right_size, UINT_MAX, 0);
+ tlog(T_INFO, "3.habmm_socket_recv Negative testing the return value recv_r=%d flag is 0 \n", recv_r);
+ EXPECT_INT_LT(recv_r, 0);
+
+ tlog(T_INFO, "3.habmm_socket_recv Negative testing : input invalid handle flag is 1\n");
+ recv_r = habmm_socket_recv(1, size_10, &right_size, UINT_MAX, HABMM_SOCKET_RECV_FLAGS_NON_BLOCKING);
+ tlog(T_INFO, "3.habmm_socket_recv Negative testing the return value recv_r=%d flag is 1 \n", recv_r);
+ EXPECT_INT_LT(recv_r, 0);
+
+ /* 4.input size_bytes as NULL */
+ tlog(T_INFO, "3.habmm_socket_recv Negative testing : input size_bytes as NULL flag is 0\n");
+ recv_r = habmm_socket_recv(handle, size_10, NULL, UINT_MAX, 0);
+ tlog(T_INFO, "3.habmm_socket_recv Negative testing the return value recv_r=%d flag is 0 \n", recv_r);
+ EXPECT_INT_LT(recv_r, 0);
+
+ tlog(T_INFO, "3.habmm_socket_recv Negative testing : input size_bytes as NULL flag is 1\n");
+ recv_r = habmm_socket_recv(handle, size_10, NULL, UINT_MAX, HABMM_SOCKET_RECV_FLAGS_NON_BLOCKING);
+ tlog(T_INFO, "3.habmm_socket_recv Negative testing the return value recv_r=%d flag is 1 \n", recv_r);
+ EXPECT_INT_LT(recv_r, 0);
+
+ habmm_socket_close(handle);
+ return;
+err:
+ terr("Can't open the mmid socket\n");
+ return;
+}
+
+
+static void add_tests(void)
+{
+ ADD_TEST(Test_habmm_socket_recv);
+}
+
+
+static int __init hab_ut_init(void)
+{
+ int ret;
+ tlog(T_INFO, "Unit test kernel module for hab initialising\n");
+ add_tests();
+ tlog(T_INFO, "khab test recv initialized\n");
+ return ret;
+}
+
+static void __exit hab_ut_exit(void)
+{
+ tlog(T_INFO, "khab test recv module unloaded\n");
+ KTF_CLEANUP();
+}
+
+module_init(hab_ut_init);
+module_exit(hab_ut_exit);
+MODULE_LICENSE("GPL v2"); \ No newline at end of file
diff --git a/khab_test/khab_test_send.c b/khab_test/khab_test_send.c
new file mode 100755
index 0000000..faa95bd
--- /dev/null
+++ b/khab_test/khab_test_send.c
@@ -0,0 +1,127 @@
+/*
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 and
+* only version 2 as published by the Free Software Foundation.
+*
+* 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.
+*/
+
+#include <linux/habmm.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/ktf.h>
+
+KTF_INIT();
+
+TEST(hab_handler, Test_habmm_socket_send)
+{
+ int32_t handle;
+ int32_t open_r;
+ int32_t send_r;
+ char size_1= 'a';
+
+ open_r = habmm_socket_open(&handle, 601, 0, 0);
+ tlog(T_INFO, "Test_habmm_socket_send begin: habmm_socket_open the return value open_r=%d handle=0x%x\n", open_r, handle);
+ EXPECT_INT_EQ(0, open_r);
+ if (open_r < 0)
+ {
+ goto err;
+ }
+
+ /* #define HAB_HEADER_SIZE_MASK 0x0000FFFF the max size is 65535 */
+ char* buff_p = kmalloc(65535, GFP_KERNEL);
+ char* buff_n = kmalloc(65560, GFP_KERNEL);
+
+ /* Positive testing */
+ tlog(T_INFO, "Test_habmm_socket_send Positive testing : size_bytes is 1 and flag is 0\n");
+ send_r = habmm_socket_send(handle, &size_1, 1, 0);
+ tlog(T_INFO, "Test_habmm_socket_send Positive testing size_bytes is 1 and flag is 0 the return value send_r=%d \n", send_r);
+ EXPECT_INT_EQ(0, send_r);
+
+ tlog(T_INFO, "Test_habmm_socket_send Positive testing : size_bytes is 65535 and flag is 0\n");
+ send_r = habmm_socket_send(handle, buff_p, 65535, 0);
+ tlog(T_INFO, "Test_habmm_socket_send Positive testing size_bytes is 65535 and flag is 0 the return value send_r=%d \n", send_r);
+ EXPECT_INT_EQ(0, send_r);
+
+ tlog(T_INFO, "Test_habmm_socket_send Positive testing : size_bytes is 1 and flag is 1\n");
+ send_r = habmm_socket_send(handle, &size_1, 1, HABMM_SOCKET_SEND_FLAGS_NON_BLOCKING);
+ tlog(T_INFO, "Test_habmm_socket_send Positive testing size_bytes is 1 and flag is 1 the return value send_r=%d \n", send_r);
+ EXPECT_INT_EQ(0, send_r);
+
+ tlog(T_INFO, "Test_habmm_socket_send Positive testing : size_bytes is 65535 and flag is 1\n");
+ send_r = habmm_socket_send(handle, buff_p, 65535, HABMM_SOCKET_SEND_FLAGS_NON_BLOCKING);
+ tlog(T_INFO, "Test_habmm_socket_send Positive testing size_bytes is 65535 and flag is 1 the return value send_r=%d \n", send_r);
+ EXPECT_INT_EQ(0, send_r);
+
+ /* Negative testing */
+ /* 1.get invalid handle */
+ tlog(T_INFO, "1.Test_habmm_socket_send Negative testing begin: input invalid handle flag is 1\n");
+ send_r = habmm_socket_send(1, &size_1, 1, HABMM_SOCKET_SEND_FLAGS_NON_BLOCKING);
+ tlog(T_INFO, "1.Test_habmm_socket_send Negative testing the return value send_r=%d flag is 1\n", send_r);
+ EXPECT_INT_LT(send_r, 0);
+
+ tlog(T_INFO, "1.Test_habmm_socket_send Negative testing begin: input invalid handle flag is 0\n");
+ send_r = habmm_socket_send(1, &size_1, 1, 0);
+ tlog(T_INFO, "1.Test_habmm_socket_send Negative testing the return value send_r=%d flag is 0\n", send_r);
+ EXPECT_INT_LT(send_r, 0);
+
+ /* 2.input src_buff is null */
+ tlog(T_INFO, "2.Test_habmm_socket_send Negative testing : input src_buff is null flag is 1\n");
+ send_r = habmm_socket_send(handle, NULL, 1, HABMM_SOCKET_SEND_FLAGS_NON_BLOCKING);
+ tlog(T_INFO, "2.Test_habmm_socket_send Negative testing the return value send_r=%d flag is 1\n", send_r);
+ EXPECT_INT_LT(send_r, 0);
+
+ tlog(T_INFO, "2.Test_habmm_socket_send Negative testing : input src_buff is null flag is 0\n");
+ send_r = habmm_socket_send(handle, NULL, 1, 0);
+ tlog(T_INFO, "2.Test_habmm_socket_send Negative testing the return value send_r=%d flag is 0\n", send_r);
+ EXPECT_INT_LT(send_r, 0);
+ /* 3.input size is size_bytes is 65560 out of size bound */
+ tlog(T_INFO, "3.Test_habmm_socket_send Negative testing : input size_bytes is out of bound flag is 1\n");
+ send_r = habmm_socket_send(handle, buff_n, 65560, HABMM_SOCKET_SEND_FLAGS_NON_BLOCKING);
+ tlog(T_INFO, "3.Test_habmm_socket_send Negative testing the return value send_r=%d flag is 1\n", send_r);
+ EXPECT_INT_LT(send_r, 0);
+
+ tlog(T_INFO, "3.Test_habmm_socket_send Negative testing : input size_bytes is out of bound flag is 0\n");
+ send_r = habmm_socket_send(handle, buff_n, 65560, 0);
+ tlog(T_INFO, "3.Test_habmm_socket_send Negative testing the return value send_r=%d flag is 0\n", send_r);
+ EXPECT_INT_LT(send_r, 0);
+
+ habmm_socket_close(handle);
+ kfree(buff_p);
+ kfree(buff_n);
+ return;
+err:
+ terr("Can't open the mmid socket\n");
+ return;
+}
+
+
+
+static void add_tests(void)
+{
+ ADD_TEST(Test_habmm_socket_send);
+}
+
+static int __init hab_ut_init(void)
+{
+ int ret;
+ tlog(T_INFO, "Unit test kernel module for hab initialising\n");
+ add_tests();
+ tlog(T_INFO, "khab test send initialized\n");
+ return ret;
+}
+
+static void __exit hab_ut_exit(void)
+{
+ tlog(T_INFO, "khab test send module unloaded\n");
+ KTF_CLEANUP();
+}
+
+module_init(hab_ut_init);
+module_exit(hab_ut_exit);
+MODULE_LICENSE("GPL v2"); \ No newline at end of file
diff --git a/khab_test/khab_test_unexport.c b/khab_test/khab_test_unexport.c
new file mode 100755
index 0000000..eb84dd0
--- /dev/null
+++ b/khab_test/khab_test_unexport.c
@@ -0,0 +1,119 @@
+/*
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 and
+* only version 2 as published by the Free Software Foundation.
+*
+* 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.
+*/
+
+#include <linux/habmm.h>
+#include <linux/module.h>
+#include <linux/ktf.h>
+#include <linux/ion_kernel.h>
+#include <linux/msm_ion.h>
+#include <linux/dma-mapping.h>
+#include <linux/dma-contiguous.h>
+#include <linux/dma-buf.h>
+
+KTF_INIT();
+
+TEST(hab_handler, Test_habmm_unexport)
+{
+ int32_t handle;
+ int32_t open_r;
+ int32_t export_r;
+ int32_t unexport_r;
+ uint32_t export_id1;
+ char *addr = NULL;
+ struct dma_buf *vhandle = NULL;
+ int32_t bufsz = 4096;
+ unsigned long err_ion_ptr = 0;
+ uint32_t wrong_export_id = 1000;
+
+ vhandle = ion_alloc(bufsz, ION_HEAP(ION_SYSTEM_HEAP_ID), 0);
+ if (IS_ERR_OR_NULL((void *)(vhandle))) {
+ if (IS_ERR((void *)(vhandle)))
+ err_ion_ptr = PTR_ERR((int *)(vhandle));
+ tlog(T_INFO, " ION alloc fail err ptr=%ld\n",
+ err_ion_ptr);
+ goto err;
+ }
+
+ dma_buf_begin_cpu_access((struct dma_buf*)vhandle,
+ DMA_BIDIRECTIONAL);
+ addr = dma_buf_vmap((struct dma_buf*)vhandle);
+ tlog(T_INFO, "Test_habmm_export begin: habmm_socket_open the return value addr->size=%d \n", addr);
+
+ open_r = habmm_socket_open(&handle, 601, 0, 0);
+ tlog(T_INFO, "Test_habmm_unexport begin: habmm_socket_open the return value open_r=%d handle=0x%x\n", open_r, handle);
+ EXPECT_INT_EQ(0, open_r);
+ if (open_r < 0)
+ {
+ goto err;
+ }
+
+ tlog(T_INFO, "Test_habmm_unexport size_bytes is 4096 and flag is 0x00020000\n");
+ export_r = habmm_export(handle, vhandle, 4096, &export_id1, HABMM_EXPIMP_FLAGS_DMABUF);
+ tlog(T_INFO, "Test_habmm_unexport size_bytes is 4096 and flag is 0x00020000 the return value export_r=%d export_id=%d \n", export_r, export_id1);
+ EXPECT_INT_EQ(0, export_r);
+
+ /* Negative testing */
+ /* 1.input invalid export_id */
+ tlog(T_INFO, "1.Test_habmm_unexport Negative testing :input invalid export_id flag=0x00020000\n");
+ unexport_r = habmm_unexport(handle, wrong_export_id, 0);
+ tlog(T_INFO, "1.Test_habmm_unexport Negative testing the return value unexport_r=%d flag=0x00020000\n", unexport_r);
+ EXPECT_INT_LT(unexport_r, 0);
+
+ /* 2.input invalid handle */
+ tlog(T_INFO, "2.Test_habmm_unexport Negative testing :input invalid handle flag=0x00020000\n");
+ unexport_r = habmm_unexport(1, export_id1, 0);
+ tlog(T_INFO, "2.Test_habmm_unexport Negative testing the return value unexport_r=%d flag=0x00020000\n", unexport_r);
+ EXPECT_INT_LT(unexport_r, 0);
+
+ /*Positive testing*/
+ tlog(T_INFO, "Test_habmm_unexport Positive testing:\n");
+ unexport_r = habmm_unexport(handle, export_id1, 0);
+ tlog(T_INFO, "Test_habmm_unexport Positive testing flag is 0x00020000 the return value unexport_r=%d export_id1=%d \n", unexport_r, export_id1);
+ EXPECT_INT_EQ(0, unexport_r);
+
+ /*free the buf*/
+ dma_buf_vunmap((struct dma_buf*)vhandle, addr);
+ dma_buf_end_cpu_access((struct dma_buf*)vhandle, DMA_BIDIRECTIONAL);
+ dma_buf_put(vhandle);
+
+ habmm_socket_close(handle);
+ return;
+err:
+ terr("Can't open the mmid socket\n");
+ return;
+}
+
+static void add_tests(void)
+{
+ ADD_TEST(Test_habmm_unexport);
+}
+
+
+static int __init hab_ut_init(void)
+{
+ int ret;
+ tlog(T_INFO, "Unit test kernel module for hab initialising\n");
+ add_tests();
+ tlog(T_INFO, "khab test unexport initialized\n");
+ return ret;
+}
+
+static void __exit hab_ut_exit(void)
+{
+ tlog(T_INFO, "khab test unexport module unloaded\n");
+ KTF_CLEANUP();
+}
+
+module_init(hab_ut_init);
+module_exit(hab_ut_exit);
+MODULE_LICENSE("GPL v2"); \ No newline at end of file
diff --git a/khab_test/khab_test_unimport.c b/khab_test/khab_test_unimport.c
new file mode 100755
index 0000000..5042cec
--- /dev/null
+++ b/khab_test/khab_test_unimport.c
@@ -0,0 +1,118 @@
+/*
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 and
+* only version 2 as published by the Free Software Foundation.
+*
+* 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.
+*/
+
+#include <linux/habmm.h>
+#include <linux/module.h>
+#include <linux/ktf.h>
+
+KTF_INIT();
+
+void *invalid_address=(void *) 0x0000008008000000;
+
+TEST(hab_handler, Test_habmm_unimport)
+{
+ int32_t handle;
+ int32_t open_r;
+ int32_t recv_r;
+ int32_t import_r;
+ int32_t unimport_r;
+ char export_id1;
+ uint32_t wrong_export_id = 1000;
+ uint32_t size_export_id = 1;
+ char *size_page = NULL;
+
+ open_r = habmm_socket_open(&handle, 601, 0, 0);
+ tlog(T_INFO, "Test_habmm_unimport begin: habmm_socket_open the return value open_r=%d handle=0x%x\n", open_r, handle);
+ EXPECT_INT_EQ(0, open_r);
+ if (open_r < 0)
+ {
+ goto err;
+ }
+
+ recv_r = habmm_socket_recv(handle, &export_id1, &size_export_id, 0, 0);
+ tlog(T_INFO, "Test_habmm_unimport : habmm_socket_recv the return value recv_r=%d export_id1=%d\n", recv_r, export_id1);
+ EXPECT_INT_EQ(0, recv_r);
+
+ tlog(T_INFO, "Test_habmm_unimport :Test_habmm_import size_bytes is 4096 and flag is 0x00000000\n");
+ import_r = habmm_import(handle, (void **)&size_page, 4096, export_id1, 0x00000000);
+ tlog(T_INFO, "Test_habmm_unimport: Test_habmm_import size_bytes is 4096 and flag is 0x00000000 the return value import_r=%d export_id1=%d \n", import_r, export_id1);
+ EXPECT_INT_EQ(0, import_r);
+
+ /* Negative testing */
+ /* 1.input invalid export_id */
+ tlog(T_INFO, "1.Test_habmm_unimport Negative testing :input invalid export_id flag=0x00000000\n");
+ unimport_r = habmm_unimport(handle, wrong_export_id, (void *)size_page, 0x00000000);
+ tlog(T_INFO, "1.Test_habmm_unimport Negative testing the return value unimport_r=%d flag=0x00000000\n", unimport_r);
+ EXPECT_INT_LT(unimport_r, 0);
+
+ /* 2.input invalid handle */
+ tlog(T_INFO, "2.Test_habmm_unimport Negative testing :input invalid handle flag=0x00000000\n");
+ unimport_r = habmm_unimport(1, export_id1, (void *)size_page, 0x00000000);
+ tlog(T_INFO, "2.Test_habmm_unimport Negative testing the return value unimport_r=%d flag=0x00000000\n", unimport_r);
+ EXPECT_INT_LT(unimport_r, 0);
+
+ /* 3.input error buff_shared or invalid address */
+ tlog(T_INFO, "3.Test_habmm_unimport Negative testing :input invalid address flag=0x00000000\n");
+ unimport_r = habmm_unimport(handle, export_id1, invalid_address, 0x00000000);
+ tlog(T_INFO, "3.Test_habmm_unimport Negative testing the return value unimport_r=%d flag=0x00000000\n", unimport_r);
+ EXPECT_INT_LT(unimport_r, 0);
+
+ if(unimport_r == 0)
+ {
+ recv_r = habmm_socket_recv(handle, &export_id1, &size_export_id, 0, 0);
+ tlog(T_INFO, "Test_habmm_unimport : habmm_socket_recv the return value recv_r=%d export_id1=%d\n", recv_r, export_id1);
+ EXPECT_INT_EQ(0, recv_r);
+
+ tlog(T_INFO, "Test_habmm_unimport :Test_habmm_import size_bytes is 4096 and flag is 0x00000000\n");
+ import_r = habmm_import(handle, (void **)&size_page,4096, export_id1, 0x00000000);
+ tlog(T_INFO, "Test_habmm_unimport: Test_habmm_import size_bytes is 4096 and flag is 0x00000000 the return value import_r=%d export_id1=%d \n", import_r, export_id1);
+ EXPECT_INT_EQ(0, import_r);
+ }
+
+ /* Positive testing */
+ tlog(T_INFO, "Test_habmm_unimport Positive testing:\n");
+ unimport_r = habmm_unimport(handle, export_id1, (void *)size_page, 0x00000000);
+ tlog(T_INFO, "Test_habmm_unimport Positive testing the return value unimport_r=%d export_id1=%d flag=0x00000000\n", unimport_r, export_id1);
+ EXPECT_INT_EQ(0, unimport_r);
+
+ habmm_socket_close(handle);
+ return;
+err:
+ terr("Can't open the mmid socket\n");
+ return;
+}
+
+
+static void add_tests(void)
+{
+ ADD_TEST(Test_habmm_unimport);
+}
+
+static int __init hab_ut_init(void)
+{
+ int ret;
+ tlog(T_INFO, "Unit test kernel module for hab initialising\n");
+ add_tests();
+ tlog(T_INFO, "khab test unimport initialized\n");
+ return ret;
+}
+
+static void __exit hab_ut_exit(void)
+{
+ tlog(T_INFO, "khab test unimport module unloaded\n");
+ KTF_CLEANUP();
+}
+
+module_init(hab_ut_init);
+module_exit(hab_ut_exit);
+MODULE_LICENSE("GPL v2"); \ No newline at end of file
diff --git a/khab_test/khab_unittest_kprobe.c b/khab_test/khab_unittest_kprobe.c
new file mode 100755
index 0000000..d96957d
--- /dev/null
+++ b/khab_test/khab_unittest_kprobe.c
@@ -0,0 +1,177 @@
+/*
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 and
+* only version 2 as published by the Free Software Foundation.
+*
+* 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.
+*/
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/kprobes.h>
+#include <asm/ptrace.h>
+
+#define MAX_PROBES 6
+static char *symbol[MAX_PROBES];
+static int symbol_num;
+static int offset[MAX_PROBES];
+module_param_array(symbol, charp, &symbol_num, 0);
+module_param_array(offset, int, NULL, 0);
+
+struct probe_point {
+ char *api;
+ int offset;
+ int reg;
+ int value;
+};
+
+static const struct probe_point probe_lists[] = {
+ { "hab_vchan_open", 0x148, 0, 0 },
+ { "hab_mem_export", 0x38, 22, 0 },
+ { "hab_mem_import", 0x30, 22, 0 },
+ { "hab_mem_unimport", 0x30, 22,0 },
+ { "hab_mem_unexport", 0x30, 22, 0 },
+};
+/*
+ * insmod khab_unittest_kprobe.ko symbol=hab_vchan_open offset=0x148
+ * insmod khab_unittest_kprobe.ko symbol=hab_mem_export offset=0x38
+ * insmod khab_unittest_kprobe.ko symbol=hab_mem_import offset=0x30
+ * insmod khab_unittest_kprobe.ko symbol=hab_mem_unimport offset=0x30
+ * insmod khab_unittest_kprobe.ko symbol=hab_mem_unexport offset=0x30
+ */
+static int kp_index, kp2_index;
+static int kp_value, kp2_value;
+
+/* For each probe you need to allocate a kprobe structure */
+static struct kprobe kp;
+static struct kprobe kp2;
+
+static struct kprobe *kps[2] = {&kp, &kp2};
+
+/* kprobe pre_handler: called just before the probed instruction is executed */
+static int kp_pre_handler(struct kprobe *p, struct pt_regs *regs)
+{
+ printk(KERN_INFO "%s: p->addr=0x%pK, x[%d]=0x%lx\n", __func__,p->addr, kp_index, regs->user_regs.regs[kp_index]);
+ regs->user_regs.regs[kp_index] = kp_value;
+ /* A dump_stack() here will give a stack backtrace */
+ return 0;
+}
+
+static int kp2_pre_handler(struct kprobe *p, struct pt_regs *regs)
+{
+ printk(KERN_INFO "%s: p->addr=0x%pK, x[%d]=0x%lx\n", __func__,p->addr, kp2_index, regs->user_regs.regs[kp2_index]);
+ regs->user_regs.regs[kp2_index] = kp2_value;
+ /* A dump_stack() here will give a stack backtrace */
+ return 0;
+}
+
+/* kprobe post_handler: called after the probed instruction is executed */
+static void kp_post_handler(struct kprobe *p, struct pt_regs *regs,
+ unsigned long flags)
+{
+ printk(KERN_INFO "%s: p->addr=0x%pK, x[%d]=0x%lx, flags=%ld\n",__func__, p->addr, kp_index, regs->user_regs.regs[kp_index], flags);
+ regs->user_regs.regs[kp_index] = kp_value;
+ printk(KERN_INFO "%s: x[%d]=0x%lx", __func__, kp_index, regs->user_regs.regs[kp_index]);
+}
+
+static void kp2_post_handler(struct kprobe *p, struct pt_regs *regs,
+ unsigned long flags)
+{
+ printk(KERN_INFO "%s: p->addr=0x%pK, x[%d]=0x%lx, flags=%ld\n",__func__, p->addr, kp2_index, regs->user_regs.regs[kp2_index], flags);
+ regs->user_regs.regs[kp2_index] = kp2_value;
+ printk(KERN_INFO "%s: x[%d]=0x%lx", __func__, kp2_index, regs->user_regs.regs[kp2_index]);
+}
+
+/*
+ * fault_handler: this is called if an exception is generated for any
+ * instruction within the pre- or post-handler, or when Kprobes
+ * single-steps the probed instruction.
+ */
+static int kp_fault_handler(struct kprobe *p, struct pt_regs *regs, int trapnr)
+{
+ printk(KERN_INFO "fault_handler: p->addr = 0x%p, trap #%d\n",p->addr, trapnr);
+ /* Return 0 because we don't handle the fault. */
+ return 0;
+}
+
+static int __init kprobe_init(void)
+{
+ int i, j, ret, list_len;
+ kprobe_opcode_t *symbol_addr;
+
+ list_len = sizeof(probe_lists)/sizeof(struct probe_point);
+
+ printk(KERN_INFO "symbol numbers = %d, list number = %d\n", symbol_num, list_len);
+ for (i=0; i<symbol_num; i++) {
+ for (j=0; j<list_len; j++) {
+ if (!strcmp(symbol[i], probe_lists[j].api) && (offset[i] == probe_lists[j].offset)) {
+ if (i == 0) {
+ kp.symbol_name = probe_lists[j].api;
+ kp.offset = probe_lists[j].offset;
+ kp.pre_handler = kp_pre_handler;
+ kp.post_handler = kp_post_handler;
+ kp.fault_handler = kp_fault_handler;
+ kp_index = probe_lists[j].reg;
+ kp_value = probe_lists[j].value;
+ }
+ if (i == 1) {
+ kp2.symbol_name = probe_lists[j].api;
+ kp2.offset = probe_lists[j].offset;
+ kp2.pre_handler = kp2_pre_handler;
+ kp2.post_handler = kp2_post_handler;
+ kp2.fault_handler = kp_fault_handler;
+ kp2_index = probe_lists[j].reg;
+ kp2_value = probe_lists[j].value;
+ }
+ }
+ }
+ }
+
+ symbol_addr = (kprobe_opcode_t *)kallsyms_lookup_name(kp.symbol_name);
+ if (!symbol_addr) {
+ printk(KERN_INFO "Could not find address of %s\n", kp.symbol_name);
+ return -1;
+ }
+ printk(KERN_INFO "kp1.symbol_addr = 0x%lx\n", symbol_addr);
+
+ if (symbol_num == 1) {
+ ret = register_kprobe(&kp);
+ if (ret < 0) {
+ printk(KERN_INFO "register_kprobe failed, returned %d\n", ret);
+ return ret;
+ }
+ printk(KERN_INFO "Planted kprobe1: %s+%pK at %pK\n", kp.symbol_name, (kprobe_opcode_t *)kp.offset, (kprobe_opcode_t *)kp.addr);
+ }
+ else if (symbol_num == 2) {
+ ret = register_kprobes(kps, 2);
+ if (ret < 0) {
+ printk(KERN_INFO "register_kprobe failed, returned %d\n", ret);
+ return ret;
+ }
+ printk(KERN_INFO "Planted kprobe1: %s+%pK at %pK; kprobe2: %s+%pK at %pK\n", kp.symbol_name, (kprobe_opcode_t *)kp.offset,
+ (kprobe_opcode_t *)kp.addr, kp2.symbol_name, (kprobe_opcode_t *)kp2.offset, (kprobe_opcode_t *)kp2.addr);
+ }
+
+ return 0;
+}
+
+static void __exit kprobe_exit(void)
+{
+ if (symbol_num == 1) {
+ unregister_kprobe(&kp);
+ printk(KERN_INFO "kprobe at %pK unregistered\n", kp.addr);
+ }
+ else {
+ unregister_kprobes(kps, 2);
+ printk(KERN_INFO "kprobe1 at %pK and kprobe2 at %pK unregistered\n", kp.addr, kp2.addr);
+ }
+}
+
+module_init(kprobe_init);
+module_exit(kprobe_exit);
+MODULE_LICENSE("GPL v2"); \ No newline at end of file