From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 01E852BDE for ; Thu, 4 Aug 2016 07:39:01 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP; 03 Aug 2016 22:39:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,469,1464678000"; d="scan'208";a="859450614" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga003.jf.intel.com with ESMTP; 03 Aug 2016 22:38:48 -0700 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id u745chWi003955; Thu, 4 Aug 2016 13:38:43 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id u745cfnH012769; Thu, 4 Aug 2016 13:38:43 +0800 Received: (from yliu84x@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id u745cf1B012765; Thu, 4 Aug 2016 13:38:41 +0800 From: Marvin Liu To: dts@dpdk.org Cc: Marvin Liu Date: Thu, 4 Aug 2016 13:38:21 +0800 Message-Id: <1470289102-12677-9-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1470289102-12677-1-git-send-email-yong.liu@intel.com> References: <1470289102-12677-1-git-send-email-yong.liu@intel.com> Subject: [dts] [PATCH 8/9] framework utils: move shared function from dts module 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: Thu, 04 Aug 2016 05:39:02 -0000 Some functions need shared with all modules in dts, remove them from dts module to utils module. This will help on the decouple of each module. Signed-off-by: Marvin Liu diff --git a/framework/utils.py b/framework/utils.py index 48bba0e..edfeeca 100644 --- a/framework/utils.py +++ b/framework/utils.py @@ -31,6 +31,10 @@ import json # json format import re +import os +import inspect + +DTS_ENV_PAT = r"DTS_*" def RED(text): @@ -99,6 +103,7 @@ def remove_old_rsa_key(crb, ip): (ip.strip(), rsa_key_path) crb.send_expect(remove_rsa_key_cmd, "# ") + def human_read_number(num): if num > 1000000: num /= 1000000 @@ -108,3 +113,28 @@ def human_read_number(num): return str(num) + "K" else: return str(num) + + +def get_subclasses(module, clazz): + """ + Get module attribute name and attribute. + """ + for subclazz_name, subclazz in inspect.getmembers(module): + if hasattr(subclazz, '__bases__') and clazz in subclazz.__bases__: + yield (subclazz_name, subclazz) + + +def copy_instance_attr(from_inst, to_inst): + for key in from_inst.__dict__.keys(): + to_inst.__dict__[key] = from_inst.__dict__[key] + + +def create_mask(indexes): + """ + Convert index to hex mask. + """ + val = 0 + for index in indexes: + val |= 1 << int(index) + + return hex(val).rstrip("L") -- 1.9.3