From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 856ED1B1BE for ; Fri, 26 Jan 2018 03:55:08 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jan 2018 18:55:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,414,1511856000"; d="scan'208";a="29585195" Received: from dpdk-test38.sh.intel.com ([10.67.119.87]) by orsmga002.jf.intel.com with ESMTP; 25 Jan 2018 18:55:06 -0800 From: Marvin Liu To: dts@dpdk.org Cc: Marvin Liu Date: Thu, 25 Jan 2018 14:48:12 -0500 Message-Id: <1516909693-68447-1-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.9.3 Subject: [dts] [PATCH v1 1/2] framework/utils: add function to retrieve object from backtrace X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Jan 2018 02:55:08 -0000 Sometimes can't find required variable for overall arch. Add one function can retrieve those variables from callback frame. Signed-off-by: Marvin Liu 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