diff options
-rw-r--r-- | net/bluetooth/Kconfig | 13 | ||||
-rw-r--r-- | net/bluetooth/Makefile | 2 | ||||
-rw-r--r-- | net/bluetooth/af_bluetooth.c | 6 | ||||
-rw-r--r-- | net/bluetooth/selftest.c | 62 | ||||
-rw-r--r-- | net/bluetooth/selftest.h | 45 |
5 files changed, 128 insertions, 0 deletions
diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig index 29bcafc41adf..3296841531c9 100644 --- a/net/bluetooth/Kconfig +++ b/net/bluetooth/Kconfig | |||
@@ -64,4 +64,17 @@ config BT_6LOWPAN | |||
64 | help | 64 | help |
65 | IPv6 compression over Bluetooth Low Energy. | 65 | IPv6 compression over Bluetooth Low Energy. |
66 | 66 | ||
67 | config BT_SELFTEST | ||
68 | bool "Bluetooth self testing support" | ||
69 | depends on BT && DEBUG_KERNEL | ||
70 | help | ||
71 | Run self tests when initializing the Bluetooth subsystem. This | ||
72 | is a developer option and can cause significant delay when booting | ||
73 | the system. | ||
74 | |||
75 | When the Bluetooth subsystem is built as module, then the test | ||
76 | cases are run first thing at module load time. When the Bluetooth | ||
77 | subsystem is compiled into the kernel image, then the test cases | ||
78 | are run late in the initcall hierarchy. | ||
79 | |||
67 | source "drivers/bluetooth/Kconfig" | 80 | source "drivers/bluetooth/Kconfig" |
diff --git a/net/bluetooth/Makefile b/net/bluetooth/Makefile index 364cff1ad4b1..8e96e3072266 100644 --- a/net/bluetooth/Makefile +++ b/net/bluetooth/Makefile | |||
@@ -15,4 +15,6 @@ bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \ | |||
15 | hci_sock.o hci_sysfs.o l2cap_core.o l2cap_sock.o smp.o sco.o lib.o \ | 15 | hci_sock.o hci_sysfs.o l2cap_core.o l2cap_sock.o smp.o sco.o lib.o \ |
16 | a2mp.o amp.o ecc.o hci_request.o hci_debugfs.o | 16 | a2mp.o amp.o ecc.o hci_request.o hci_debugfs.o |
17 | 17 | ||
18 | bluetooth-$(CONFIG_BT_SELFTEST) += selftest.o | ||
19 | |||
18 | subdir-ccflags-y += -D__CHECK_ENDIAN__ | 20 | subdir-ccflags-y += -D__CHECK_ENDIAN__ |
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c index 012e3b03589d..ce22e0cfa923 100644 --- a/net/bluetooth/af_bluetooth.c +++ b/net/bluetooth/af_bluetooth.c | |||
@@ -31,6 +31,8 @@ | |||
31 | #include <net/bluetooth/bluetooth.h> | 31 | #include <net/bluetooth/bluetooth.h> |
32 | #include <linux/proc_fs.h> | 32 | #include <linux/proc_fs.h> |
33 | 33 | ||
34 | #include "selftest.h" | ||
35 | |||
34 | #define VERSION "2.20" | 36 | #define VERSION "2.20" |
35 | 37 | ||
36 | /* Bluetooth sockets */ | 38 | /* Bluetooth sockets */ |
@@ -716,6 +718,10 @@ static int __init bt_init(void) | |||
716 | 718 | ||
717 | BT_INFO("Core ver %s", VERSION); | 719 | BT_INFO("Core ver %s", VERSION); |
718 | 720 | ||
721 | err = bt_selftest(); | ||
722 | if (err < 0) | ||
723 | return err; | ||
724 | |||
719 | bt_debugfs = debugfs_create_dir("bluetooth", NULL); | 725 | bt_debugfs = debugfs_create_dir("bluetooth", NULL); |
720 | 726 | ||
721 | err = bt_sysfs_init(); | 727 | err = bt_sysfs_init(); |
diff --git a/net/bluetooth/selftest.c b/net/bluetooth/selftest.c new file mode 100644 index 000000000000..00cac4a5e229 --- /dev/null +++ b/net/bluetooth/selftest.c | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | BlueZ - Bluetooth protocol stack for Linux | ||
3 | |||
4 | Copyright (C) 2014 Intel Corporation | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License version 2 as | ||
8 | published by the Free Software Foundation; | ||
9 | |||
10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
11 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
12 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. | ||
13 | IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY | ||
14 | CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES | ||
15 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
16 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
17 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
18 | |||
19 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, | ||
20 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS | ||
21 | SOFTWARE IS DISCLAIMED. | ||
22 | */ | ||
23 | |||
24 | #include <net/bluetooth/bluetooth.h> | ||
25 | |||
26 | #include "selftest.h" | ||
27 | |||
28 | static int __init run_selftest(void) | ||
29 | { | ||
30 | BT_INFO("Starting self testing"); | ||
31 | |||
32 | BT_INFO("Finished self testing"); | ||
33 | |||
34 | return 0; | ||
35 | } | ||
36 | |||
37 | #if IS_MODULE(CONFIG_BT) | ||
38 | |||
39 | /* This is run when CONFIG_BT_SELFTEST=y and CONFIG_BT=m and is just a | ||
40 | * wrapper to allow running this at module init. | ||
41 | * | ||
42 | * If CONFIG_BT_SELFTEST=n, then this code is not compiled at all. | ||
43 | */ | ||
44 | int __init bt_selftest(void) | ||
45 | { | ||
46 | return run_selftest(); | ||
47 | } | ||
48 | |||
49 | #else | ||
50 | |||
51 | /* This is run when CONFIG_BT_SELFTEST=y and CONFIG_BT=y and is run | ||
52 | * via late_initcall() as last item in the initialization sequence. | ||
53 | * | ||
54 | * If CONFIG_BT_SELFTEST=n, then this code is not compiled at all. | ||
55 | */ | ||
56 | static int __init bt_selftest_init(void) | ||
57 | { | ||
58 | return run_selftest(); | ||
59 | } | ||
60 | late_initcall(bt_selftest_init); | ||
61 | |||
62 | #endif | ||
diff --git a/net/bluetooth/selftest.h b/net/bluetooth/selftest.h new file mode 100644 index 000000000000..2aa0a346a913 --- /dev/null +++ b/net/bluetooth/selftest.h | |||
@@ -0,0 +1,45 @@ | |||
1 | /* | ||
2 | BlueZ - Bluetooth protocol stack for Linux | ||
3 | Copyright (C) 2014 Intel Corporation | ||
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 version 2 as | ||
7 | published by the Free Software Foundation; | ||
8 | |||
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
10 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
11 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. | ||
12 | IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY | ||
13 | CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES | ||
14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | |||
18 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, | ||
19 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS | ||
20 | SOFTWARE IS DISCLAIMED. | ||
21 | */ | ||
22 | |||
23 | #if IS_ENABLED(CONFIG_BT_SELFTEST) && IS_MODULE(CONFIG_BT) | ||
24 | |||
25 | /* When CONFIG_BT_SELFTEST=y and the CONFIG_BT=m, then the self testing | ||
26 | * is run at module loading time. | ||
27 | */ | ||
28 | int bt_selftest(void); | ||
29 | |||
30 | #else | ||
31 | |||
32 | /* When CONFIG_BT_SELFTEST=y and CONFIG_BT=y, then the self testing | ||
33 | * is run via late_initcall() to make sure that subsys_initcall() of | ||
34 | * the Bluetooth subsystem and device_initcall() of the Crypto subsystem | ||
35 | * do not clash. | ||
36 | * | ||
37 | * When CONFIG_BT_SELFTEST=n, then this turns into an empty call that | ||
38 | * has no impact. | ||
39 | */ | ||
40 | static inline int bt_selftest(void) | ||
41 | { | ||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | #endif | ||