2014-01-23 17:54:03

by Andrzej Kaczmarek

[permalink] [raw]
Subject: [RFC] Valgrind on Android

Hi,

This is patch I've been using for some time now to build BlueZ packages
in a way that bluetooth starts automatically via Valgrind, so no need
to hack this manually.

It's enabled automatically for userdebug and eng build which may be not
exactly what everybody wants, so other option could be to rely on some
fancy variable (VALGRIND_FOR_BLUEZ or sth) so those who want it enabled
may just define this in environment.



Andrzej Kaczmarek (1):
android: Add support for Valgrind in debug variants

android/Android.mk | 13 +++++++++++++
android/init.bluetooth.rc-debug | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+)
create mode 100644 android/init.bluetooth.rc-debug

--
1.8.5.2



2014-01-23 17:54:04

by Andrzej Kaczmarek

[permalink] [raw]
Subject: [RFC] android: Add support for Valgrind in debug variants

This patch automatically builds BlueZ in a way it can be easily run
with Valgrind which is available in AOSP tree.

For userdebug and eng variant, bluetoothd will have additional
dependency to necessary Valgrind modules and bluetoothd binary will not
be stripped. Special version of init.bluetooth.rc is also provided
which defines bluetoothd service to be run using Valgrind with proper
environment and it will be installed automatically as well.
---
android/Android.mk | 13 +++++++++++++
android/init.bluetooth.rc-debug | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+)
create mode 100644 android/init.bluetooth.rc-debug

diff --git a/android/Android.mk b/android/Android.mk
index c274295..55093d2 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -80,6 +80,15 @@ $(foreach file,$(lib_headers), $(shell ln -sf ../$(file) $(LOCAL_PATH)/bluez/lib
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := bluetoothd

+ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
+LOCAL_STRIP_MODULE := false
+LOCAL_REQUIRED_MODULES := valgrind \
+ memcheck-$(TARGET_ARCH)-linux \
+ vgpreload_core-$(TARGET_ARCH)-linux \
+ vgpreload_memcheck-$(TARGET_ARCH)-linux \
+ default.supp
+endif
+
include $(BUILD_EXECUTABLE)

#
@@ -294,7 +303,11 @@ include $(CLEAR_VARS)

LOCAL_MODULE := init.bluetooth.rc
LOCAL_MODULE_CLASS := ETC
+ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
+LOCAL_SRC_FILES := bluez/android/$(LOCAL_MODULE)-debug
+else
LOCAL_SRC_FILES := bluez/android/$(LOCAL_MODULE)
+endif
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)

diff --git a/android/init.bluetooth.rc-debug b/android/init.bluetooth.rc-debug
new file mode 100644
index 0000000..c6c382c
--- /dev/null
+++ b/android/init.bluetooth.rc-debug
@@ -0,0 +1,39 @@
+# required permissions
+on boot
+ chown bluetooth bluetooth /data/misc/bluetooth
+ chown bluetooth bluetooth /dev/uhid
+
+# services
+on property:bluetooth.start=daemon
+ setprop bluetooth.start none
+ start bluetoothd
+
+on property:bluetooth.stop=daemon
+ setprop bluetooth.stop none
+ stop bluetoothd
+
+on property:bluetooth.start=snoop
+ setprop bluetooth.start none
+ start bluetoothd-snoop
+
+on property:bluetooth.stop=snoop
+ setprop bluetooth.stop none
+ stop bluetoothd-snoop
+
+service bluetoothd /system/bin/logwrapper /system/bin/valgrind --leak-check=full /system/bin/bluetoothd
+ setenv G_SLICE always-malloc
+ setenv G_DEBUG gc-friendly
+ class main
+ # init does not yet support setting capabilities so run as root,
+ # bluetoothd drop uid to bluetooth with the right linux capabilities
+ group bluetooth
+ disabled
+ oneshot
+
+service bluetoothd-snoop /system/bin/logwrapper /system/bin/bluetoothd-snoop
+ class main
+ # init does not yet support setting capabilities so run as root,
+ # bluetoothd-snoop drops unneeded linux capabilities
+ group nobody
+ disabled
+ oneshot
--
1.8.5.2