CLI: implement LSan feature support 96/153996/7
authorAlexander Aksenov <a.aksenov@samsung.com>
Wed, 4 Oct 2017 16:30:35 +0000 (19:30 +0300)
committerAlexander Aksenov <a.aksenov@samsung.com>
Tue, 10 Oct 2017 19:58:49 +0000 (22:58 +0300)
Change-Id: I9c767ee098a90f9ce13ec189852d29516ae3d043
Signed-off-by: Alexander Aksenov <a.aksenov@samsung.com>
src/cli/example/example_conf.py
src/cli/swap_cli/features/lsan.py [new file with mode: 0644]
src/cli/swap_cli/features_handler.py
src/cli/swap_cli/protocol/v4_2.py

index 2a86498..27d006d 100644 (file)
@@ -14,6 +14,7 @@ probe_features = [
      'network',
      'thread',
      'opengl',
+     'lsan'
 ]
 
 app = {
diff --git a/src/cli/swap_cli/features/lsan.py b/src/cli/swap_cli/features/lsan.py
new file mode 100644 (file)
index 0000000..4e6835a
--- /dev/null
@@ -0,0 +1,54 @@
+import struct
+import feature
+from .. import handler
+from .. import client_lib
+
+
+class LSanFeature(feature.Feature):
+
+    __CONFIG_LSAN = 'lsan'
+    __PROTOCOL_LSAN = {'MEMORY_ALLOC_ALWAYS_PROBING', 'LSAN'}
+    __MSG_LSAN_STR = 'MSG_LSAN'
+    __LSAN_MSG_ERR = 0x0
+    __LSAN_MSG_STATUS = 0x1
+    __LSAN_MSG_REPORT = 0x2
+    __LSAN_INIT_DONE = 0x4
+    __STATUS_FMT = 'I'
+    __HEAD_FMT = 'III1c'
+
+    def __init__(self, handler, intr, outdir):
+        self.__handler = handler
+        self.__intr = intr
+        self.__outdir = outdir
+        self.__handler.register_cb(self.__MSG_LSAN_STR, self.__lsan_handler)
+
+    def __get_filepath(self, data):
+        size = struct.calcsize(self.__HEAD_FMT)
+        first_loop = True
+        cnt = size
+        c = ''
+        path = ''
+        while first_loop or c != '\0':
+            # This prevents adding to path null-termination
+            path += c
+            first_loop = False
+            c = data[cnt]
+            cnt += 1
+        return path
+
+    def __pull_lsan_report(self, path):
+        self.__intr.pull(path, self.__outdir)
+
+    def __lsan_handler(self, data):
+        parsed = struct.unpack_from(self.__STATUS_FMT, data)
+
+        if parsed[0] == self.__LSAN_MSG_REPORT:
+            path = self.__get_filepath(data)
+            self.__pull_lsan_report(path)
+
+    @classmethod
+    def resolve_features(cls, features_list):
+        if cls.__CONFIG_LSAN in features_list:
+            return cls.__PROTOCOL_LSAN
+        else:
+            return None
index 5ec73be..5ce9af0 100644 (file)
@@ -1,10 +1,11 @@
 from .features import feature
 from .features import common
+from .features import lsan
 
 
 class FeaturesHandler(object):
 
-    __features_list = [common.CommonFeature]
+    __features_list = [common.CommonFeature, lsan.LSanFeature]
 
 
     def __init__(self, handler=None, intr=None, outdir=None):
index 44add7a..525b1d7 100644 (file)
@@ -1,12 +1,20 @@
 from __future__ import absolute_import
 import copy
 from . import v4_1
+from . import format_descriptor
 
 
 def proto_data():
     # raise ValueError('Not implemented')
     data = copy.deepcopy(v4_1.proto_data())
 
+    # TODO make it better way
+    feature_dict = data[format_descriptor.ProtoData.FEATURES]
+    feature_dict['LSAN'] = 0x4000000000000
+
+    data_msgs = data[format_descriptor.ProtoData.DATA_MESSAGES]
+    data_msgs['MSG_LSAN'] = 0x0022
+
     return data