test suite reviews and discussions
 help / color / mirror / Atom feed
* [dts] [PATCH v1 1/2] framework/utils: add function to retrieve object from backtrace
@ 2018-01-25 19:48 Marvin Liu
  2018-01-25 19:48 ` [dts] [PATCH v1 2/2] framework: add command history recording Marvin Liu
  2018-01-28 22:56 ` [dts] [PATCH v2 " Marvin Liu
  0 siblings, 2 replies; 3+ messages in thread
From: Marvin Liu @ 2018-01-25 19:48 UTC (permalink / raw)
  To: dts; +Cc: Marvin Liu

Sometimes can't find required variable for overall arch. Add one
function can retrieve those variables from callback frame.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/framework/utils.py b/framework/utils.py
index 762c927..a0dcf8f 100644
--- a/framework/utils.py
+++ b/framework/utils.py
@@ -233,3 +233,22 @@ def convert_ip2int(ip_str, ip_type):
         ip_val = (h << 64) | l
 
     return ip_val
+
+def get_backtrace_object(file_name, obj_name):
+    import inspect
+    frame = inspect.currentframe()
+    obj = None
+    found = False
+    while frame:
+        file_path = inspect.getsourcefile(frame)
+        call_file = file_path.split(os.sep)[-1]
+        if file_name == call_file:
+            found = True
+            break
+
+        frame = frame.f_back
+
+    if found:
+        obj = getattr(frame.f_locals['self'], obj_name, None)
+
+    return obj
-- 
1.9.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-01-29  6:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-25 19:48 [dts] [PATCH v1 1/2] framework/utils: add function to retrieve object from backtrace Marvin Liu
2018-01-25 19:48 ` [dts] [PATCH v1 2/2] framework: add command history recording Marvin Liu
2018-01-28 22:56 ` [dts] [PATCH v2 " Marvin Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).