test suite reviews and discussions
 help / color / mirror / Atom feed
From: Marvin Liu <yong.liu@intel.com>
To: dts@dpdk.org
Cc: Marvin Liu <yong.liu@intel.com>
Subject: [dts] [PATCH v1 1/2] framework/utils: add function to retrieve object from backtrace
Date: Thu, 25 Jan 2018 14:48:12 -0500	[thread overview]
Message-ID: <1516909693-68447-1-git-send-email-yong.liu@intel.com> (raw)

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

             reply	other threads:[~2018-01-26  2:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-25 19:48 Marvin Liu [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1516909693-68447-1-git-send-email-yong.liu@intel.com \
    --to=yong.liu@intel.com \
    --cc=dts@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).