From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B297CA0564; Tue, 24 Mar 2020 07:51:50 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9F0EA1C0C2; Tue, 24 Mar 2020 07:51:50 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 98D9A1C0C0 for ; Tue, 24 Mar 2020 07:51:48 +0100 (CET) IronPort-SDR: UOJGwVT59kK3Vk0QS4ZxH3i8UNKZL/F6jZ9n9RdrDB0ImgX3qKOr4pGM4UV1VzV6BEBHdVOrnU dVJffuum3JVQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2020 23:51:48 -0700 IronPort-SDR: dFbo8O7gTQl7ui6duSwWCrxDDKI7sI3Bc7qqELNu28XFBa//Kb5m1DbBiDEzwVAkFxhDM4Q3p5 OXCgYTn5uwHA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,299,1580803200"; d="scan'208";a="281587989" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by fmsmga002.fm.intel.com with ESMTP; 23 Mar 2020 23:51:48 -0700 Received: from FMSMSX109.amr.corp.intel.com (10.18.116.9) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 23 Mar 2020 23:51:48 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx109.amr.corp.intel.com (10.18.116.9) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 23 Mar 2020 23:51:47 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.43]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.137]) with mapi id 14.03.0439.000; Tue, 24 Mar 2020 14:51:45 +0800 From: "Tu, Lijuan" To: "Mo, YufengX" , "dts@dpdk.org" , "Yao, Lei A" CC: "Mo, YufengX" Thread-Topic: [dts] [PATCH V1 1/1] tests/power_pbf: python3 support and script optimize Thread-Index: AQHWALjIf0YbbIrf+UC6wPwWEVed2ahXT+ew Date: Tue, 24 Mar 2020 06:51:44 +0000 Message-ID: <8CE3E05A3F976642AAB0F4675D0AD20E0BBF0A53@SHSMSX101.ccr.corp.intel.com> References: <20200323021019.11350-1-yufengx.mo@intel.com> <20200323021019.11350-2-yufengx.mo@intel.com> In-Reply-To: <20200323021019.11350-2-yufengx.mo@intel.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dts] [PATCH V1 1/1] tests/power_pbf: python3 support and script optimize 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: , Errors-To: dts-bounces@dpdk.org Sender: "dts" Applied, thanks > -----Original Message----- > From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of yufengmx > Sent: Monday, March 23, 2020 10:10 AM > To: dts@dpdk.org; Yao, Lei A > Cc: Mo, YufengX > Subject: [dts] [PATCH V1 1/1] tests/power_pbf: python3 support and script > optimize >=20 >=20 > #. python3 support. > #. use ^C to take the place of killall. > #. unify session method name. > #. unify exception catch process. >=20 > Signed-off-by: yufengmx > --- > tests/TestSuite_power_pbf.py | 119 ++++++++++++++++++++++------------- > 1 file changed, 77 insertions(+), 42 deletions(-) >=20 > diff --git a/tests/TestSuite_power_pbf.py b/tests/TestSuite_power_pbf.py > index 3c281bc..0f312f5 100644 > --- a/tests/TestSuite_power_pbf.py > +++ b/tests/TestSuite_power_pbf.py > @@ -1,6 +1,6 @@ > # BSD LICENSE > # > -# Copyright(c) 2010-2019 Intel Corporation. All rights reserved. > +# Copyright(c) 2010-2020 Intel Corporation. All rights reserved. > # All rights reserved. > # > # Redistribution and use in source and binary forms, with or without @@ = - > 35,11 +35,13 @@ import random import json import re import shutil > +import traceback > from collections import Counter > from pprint import pformat >=20 > # import dts libs > from test_case import TestCase > +from exception import VerifyFailure > from utils import create_mask >=20 >=20 > @@ -61,7 +63,7 @@ class TestPowerPbf(TestCase): >=20 > @property > def output_path(self): > - suiteName =3D self.__class__.__name__[4:].lower() > + suiteName =3D self.suite_name > if self.logger.log_path.startswith(os.sep): > output_path =3D os.path.join(self.logger.log_path, suiteName= ) > else: > @@ -95,10 +97,8 @@ class TestPowerPbf(TestCase): > for item in cmds: > expected_items =3D item[1] > if expected_items and isinstance(expected_items, (list, tupl= e)): > - check_output =3D True > expected_str =3D expected_items[0] or '# ' > else: > - check_output =3D False > expected_str =3D expected_items or '# ' >=20 > try: > @@ -120,10 +120,10 @@ class TestPowerPbf(TestCase): > time.sleep(2) > return outputs >=20 > - def d_console(self, cmds): > + def d_con(self, cmds): > return self.execute_cmds(cmds, con_name=3D'dut') >=20 > - def d_a_console(self, cmds): > + def d_a_con(self, cmds): > return self.execute_cmds(cmds, con_name=3D'dut_alt') >=20 > def get_cores_mask(self, config=3D'all'): > @@ -140,13 +140,13 @@ class TestPowerPbf(TestCase): > self.verify("No such" not in out, "Compilation error") > binary_dir =3D os.path.join(self.target_dir, example_dir, 'build= ') > cmd =3D ["ls -F {0} | grep '*'".format(binary_dir), '# ', 5] > - exec_file =3D self.d_a_console(cmd) > + exec_file =3D self.d_a_con(cmd) > binary_file =3D os.path.join(binary_dir, exec_file[:-1]) > return binary_file >=20 > def create_powermonitor_folder(self): > cmd =3D 'mkdir -p {0}; chmod 777 {0}'.format('/tmp/powermonitor'= ) > - self.d_console(cmd) > + self.d_con(cmd) >=20 > def init_test_binary_file(self): > self.create_powermonitor_folder() @@ -155,43 +155,56 @@ class > TestPowerPbf(TestCase): > "CONFIG_RTE_LIBRTE_POWER_DEBUG=3Dn$/" > "CONFIG_RTE_LIBRTE_POWER_DEBUG=3Dy/" > "' {0}/config/common_base").format(self.target_dir) > - self.d_a_console(cmd) > + self.d_a_con(cmd) > self.dut.skip_setup =3D False > self.dut.build_install_dpdk(self.target) > # set up vm power management binary process setting > self.vm_power_mgr =3D self.prepare_binary('vm_power_manager') > # set up distributor binary process setting > self.distributor =3D self.prepare_binary('distributor') > + self.is_mgr_on =3D self.is_distributor_on =3D None >=20 > def start_vm_power_mgr(self): > + if self.is_mgr_on: > + return > bin_file =3D os.sep.join([self.target_dir, '']) > config =3D "1S/4C/1T" > - eal_option =3D '-c {0} -n {1} --file-prefix=3Dvmpower --no-pci'.= format( > + option =3D '-v -c {0} -n {1} --file-prefix=3Dvmpower > + --no-pci'.format( > self.get_cores_mask(config), > self.memory_channels) > prompt =3D 'vmpower>' > - cmd =3D [' '.join([self.vm_power_mgr, eal_option]), prompt, 30] > - output =3D self.d_console(cmd) > + cmd =3D [' '.join([self.vm_power_mgr, option]), prompt, 30] > + output =3D self.d_con(cmd) > + self.is_mgr_on =3D True > + > return output >=20 > def close_vm_power_mgr(self): > - output =3D self.d_console('quit') > + if not self.is_mgr_on: > + return > + output =3D self.d_con('quit') > + self.is_mgr_on =3D False > return output >=20 > def start_distributor(self, high_core_num=3D1): > + if self.is_distributor_on: > + return > cores_mask, high_freq_cores =3D self.get_high_freq_core_mask( > high_core_num) > - eal_option =3D ' -c {0} -n {1} -- -p 0x1'.format( > + option =3D '-v -c {0} -n {1} -- -p 0x1'.format( > cores_mask, self.memory_channels) > prompt =3D 'Distributor thread' > - cmd =3D [' '.join([self.distributor, eal_option]), prompt, 30] > - output =3D self.d_console(cmd) > + cmd =3D [' '.join([self.distributor, option]), prompt, 30] > + output =3D self.d_con(cmd) > + self.is_distributor_on =3D True > return high_freq_cores, output >=20 > def close_distributor(self): > - cmds =3D ['killall distributor_app', '# ', 10] > - output =3D self.d_a_console(cmds) > - return output > + if not self.is_distributor_on: > + return > + cmd =3D "^C" > + self.d_con(cmd) > + self.is_distributor_on =3D False >=20 > def __preset_single_core_json_cmd(self, core_index, unit, name): > command =3D { > @@ -205,7 +218,7 @@ class TestPowerPbf(TestCase): > json_file =3D os.sep.join([self.output_path, json_name]) > with open(json_file, 'w') as fp: > json.dump(command, fp, indent=3D4, separators=3D(',', ': '), > - encoding=3D"utf-8", sort_keys=3DTrue) > + sort_keys=3DTrue) > fp.write(os.linesep) > self.dut.session.copy_file_to(json_file, self.target_dir) > # save a backup json file to retrace test command @@ -230,30 +24= 3,30 > @@ class TestPowerPbf(TestCase): > for core_index in _cores: > cmds.append( > self.__preset_single_core_json_cmd(core_index, unit, nam= e)) > - self.d_a_console(';'.join(cmds)) > + self.d_a_con(';'.join(cmds)) >=20 > def get_core_cur_freq(self, core_index): > cpu_attr =3D r'/sys/devices/system/cpu/cpu{0}/cpufreq/scaling_cu= r_freq' > cmd =3D 'cat ' + cpu_attr.format(core_index) > - output =3D self.d_a_console(cmd) > + output =3D self.d_a_con(cmd) > return int(output) >=20 > def get_core_scaling_max_freq(self, core_index): > cpu_attr =3D r'/sys/devices/system/cpu/cpu{0}/cpufreq/scaling_ma= x_freq' > cmd =3D 'cat ' + cpu_attr.format(core_index) > - output =3D self.d_a_console(cmd) > + output =3D self.d_a_con(cmd) > return int(output) >=20 > def get_core_scaling_min_freq(self, core_index): > cpu_attr =3D r'/sys/devices/system/cpu/cpu{0}/cpufreq/scaling_mi= n_freq' > cmd =3D 'cat ' + cpu_attr.format(core_index) > - output =3D self.d_a_console(cmd) > + output =3D self.d_a_con(cmd) > return int(output) >=20 > def get_core_scaling_base_freq(self, core_index): > cpu_attr =3D r'/sys/devices/system/cpu/cpu{0}/cpufreq/base_frequ= ency' > cmd =3D 'cat ' + cpu_attr.format(core_index) > - output =3D self.d_a_console(cmd) > + output =3D self.d_a_con(cmd) > return int(output) >=20 > @property > @@ -261,15 +274,15 @@ class TestPowerPbf(TestCase): > # check if cpu support bpf feature > cpu_attr =3D r'/sys/devices/system/cpu/cpu0/cpufreq/base_frequen= cy' > cmd =3D "ls {0}".format(cpu_attr) > - self.d_a_console(cmd) > + self.d_a_con(cmd) > cmd =3D "echo $?" > - output =3D self.d_a_console(cmd) > + output =3D self.d_a_con(cmd) > ret =3D True if output =3D=3D "0" else False > return ret >=20 > def get_sys_power_driver(self): > drv_file =3D r"/sys/devices/system/cpu/cpu0/cpufreq/scaling_driv= er" > - output =3D self.d_a_console('cat ' + drv_file) > + output =3D self.d_a_con('cat ' + drv_file) > if not output: > msg =3D 'unknown power driver' > self.verify(False, msg) > @@ -295,7 +308,7 @@ class TestPowerPbf(TestCase): > cmds =3D [] > for cpu_id in sorted(cpu_info.keys()): > cmds.append('cat {0}'.format(freq(cpu_id, key_value))) > - output =3D self.d_a_console(';'.join(cmds)) > + output =3D self.d_a_con(';'.join(cmds)) > freqs =3D [int(item) for item in output.splitlines()] > for index, cpu_id in enumerate(sorted(cpu_info.keys())): > cpu_info[cpu_id][key_value] =3D freqs[index] @@ -334,9 += 347,9 @@ > class TestPowerPbf(TestCase): > def get_high_freq_core_mask(self, number=3D1, min_cores=3D5): > index_list =3D [] > # get high frequency core first > - cores_index =3D self.get_high_freq_cores_index(number) > + cores_index =3D self.get_high_freq_cores_index(number + 1) > [index_list.append(core_index) for core_index in cores_index] > - high_freq_cores =3D index_list[:] > + high_freq_cores =3D index_list[1:] > # get normal cores to make sure minimum cores are enough > cores_index =3D self.get_normal_cores_index() > for core_index in cores_index: > @@ -428,6 +441,7 @@ class TestPowerPbf(TestCase): > SCALE_MIN > Check the CPU frequency is changed accordingly in this list > ''' > + except_content =3D None > try: > self.start_vm_power_mgr() > # random select one high priority core to run testing @@ -44= 6,10 > +460,14 @@ class TestPowerPbf(TestCase): > # test cpu core frequency change with unit command > for test_item in test_items: > self.check_core_freq_for_unit(*test_item) > - self.close_vm_power_mgr() > except Exception as e: > + self.logger.error(traceback.format_exc()) > + except_content =3D e > + finally: > self.close_vm_power_mgr() > - raise Exception(e) > + > + if except_content: > + raise VerifyFailure(except_content) >=20 > def verify_high_priority_core_turbo_status(self): > ''' > @@ -460,6 +478,7 @@ class TestPowerPbf(TestCase): > ENABLE_TURBO > Check the CPU frequency is changed accordingly in this list > ''' > + except_content =3D None > try: > self.start_vm_power_mgr() > # random select one high priority core to run testing @@ -47= 3,15 > +492,20 @@ class TestPowerPbf(TestCase): > # test cpu core frequency change with unit command > for test_item in test_items: > self.check_core_freq_for_unit(*test_item) > - self.close_vm_power_mgr() > except Exception as e: > + self.logger.error(traceback.format_exc()) > + except_content =3D e > + finally: > self.close_vm_power_mgr() > - raise Exception(e) > + > + if except_content: > + raise VerifyFailure(except_content) >=20 > def verify_distributor_high_priority_core(self): > ''' > check distributor example use high priority core as distribute c= ore > ''' > + except_content =3D None > try: > high_freq_cores, output =3D self.start_distributor() > self.close_distributor() > @@ -490,19 +514,25 @@ class TestPowerPbf(TestCase): > self.verify(expected_str in output, > "'{}' not display".format(expected_str)) > except Exception as e: > + self.logger.error(traceback.format_exc()) > + except_content =3D e > + finally: > self.close_distributor() > - raise Exception(e) > + > + if except_content: > + raise VerifyFailure(except_content) >=20 > def verify_distributor_high_priority_core_txrx(self): > ''' > check distributor sample will use high priority core for > distribute core and rx/tx core > ''' > + except_content =3D None > try: > high_freq_cores, output =3D self.start_distributor(3) > self.close_distributor() > # check the high priority core are assigned as rx core in lo= g > - pat =3D 'Core (\\d+) doing packet RX.' > + pat =3D 'Core (\d+) doing packet RX.' > result =3D re.findall(pat, output, re.M) > if len(result) =3D=3D 1: > core_index =3D int(result[0]) @@ -512,7 +542,7 @@ class > TestPowerPbf(TestCase): > msg =3D "No high frequency core doing packet RX" > self.verify(core_index in high_freq_cores, msg) > # Check the high priority core are assigned as tx core in lo= g > - pat =3D 'Core (\\d+) doing packet TX.' > + pat =3D 'Core (\d+) doing packet TX.' > result =3D re.findall(pat, output, re.M) > if len(result) =3D=3D 1: > core_index =3D int(result[0]) @@ -523,7 +553,7 @@ class > TestPowerPbf(TestCase): > self.verify(core_index in high_freq_cores, msg) > # check the high priority core is assigned as distributor co= re in > # log > - pat =3D r'Core (\\d+) acting as distributor core.' > + pat =3D r'Core (\d+) acting as distributor core.' > result =3D re.findall(pat, output, re.M) > if len(result) =3D=3D 1: > core_index =3D int(result[0]) @@ -533,8 +563,13 @@ class > TestPowerPbf(TestCase): > msg =3D "No high frequency core acting as distributor core" > self.verify(core_index in high_freq_cores, msg) > except Exception as e: > + self.logger.error(traceback.format_exc()) > + except_content =3D e > + finally: > self.close_distributor() > - raise Exception(e) > + > + if except_content: > + raise VerifyFailure(except_content) >=20 > def verify_pbf_supported(self): > if self.is_support_pbf: > @@ -543,7 +578,7 @@ class TestPowerPbf(TestCase): > raise Exception(msg) >=20 > def verify_power_driver(self): > - expected_drv =3D 'acpi-cpufreq' > + expected_drv =3D 'intel_pstate' > power_drv =3D self.get_sys_power_driver() > msg =3D "power pbf should work with {} driver".format(expected_d= rv) > self.verify(power_drv =3D=3D expected_drv, msg) @@ -560,7 +595,7= @@ > class TestPowerPbf(TestCase): > self.dut_ports =3D self.dut.get_ports() > self.verify(len(self.dut_ports) >=3D 1, "Insufficient ports") > # get dut node cores information > - self.d_a_console('modprobe msr') > + self.d_a_con('modprobe msr') > self.dut.init_core_list_uncached_linux() > # check if cpu support bpf feature > self.verify_pbf_supported() > -- > 2.21.0