[dts] [PATCH 3/4] read compile switch config and compile dpdk before test

xu,huilong huilongx.xu at intel.com
Sat Apr 1 09:42:31 CEST 2017


update list:
    1. read compile switch config file
    2. set run suite list on this test
    3. update compile switch or apple patch
    4. compile dpdk and back up dpdk
    5. furnish interface for change different dpdk compile switch compile result

Signed-off-by: xu,huilong <huilongx.xu at intel.com>
---
 framework/dts.py          |   2 +-
 framework/project_dpdk.py | 103 +++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 102 insertions(+), 3 deletions(-)

diff --git a/framework/dts.py b/framework/dts.py
index 369599d..54033fa 100644
--- a/framework/dts.py
+++ b/framework/dts.py
@@ -345,7 +345,7 @@ def dts_run_target(duts, tester, targets, test_suites):
     for target in targets:
         log_handler.info("\nTARGET " + target)
         result.target = target
-
+        duts[0].set_test_suites(test_suites)
         try:
             drivername = settings.load_global_setting(settings.HOST_DRIVER_SETTING)
             if drivername == "":
diff --git a/framework/project_dpdk.py b/framework/project_dpdk.py
index a0cb4c2..3e44e70 100644
--- a/framework/project_dpdk.py
+++ b/framework/project_dpdk.py
@@ -39,8 +39,8 @@ from crb import Crb
 from dut import Dut
 from tester import Tester
 from logger import getLogger
-from settings import IXIA, DRIVERS
-
+from settings import IXIA, DRIVERS, FOLDERS
+from config import CompileConf
 
 class DPDKdut(Dut):
 
@@ -52,6 +52,7 @@ class DPDKdut(Dut):
     def __init__(self, crb, serializer):
         super(DPDKdut, self).__init__(crb, serializer)
         self.testpmd = None
+        self.read_compiel_switch = True
 
     def set_target(self, target, bind_dev=True):
         """
@@ -87,6 +88,9 @@ class DPDKdut(Dut):
             self.bind_interfaces_linux(drivername)
         self.extra_nic_setup()
 
+    def set_test_suites(self, test_suites):
+        self.test_suites = test_suites
+
     def setup_modules(self, target):
         """
         Install DPDK required kernel module on DUT.
@@ -157,16 +161,111 @@ class DPDKdut(Dut):
             self.send_expect("sed -i -e 's/CONFIG_RTE_LIBRTE_FM10K_INC_VECTOR=.*$/"
                              + "CONFIG_RTE_LIBRTE_FM10K_INC_VECTOR=n/' config/common_base", "# ", 30)
 
+    def get_dpdk_compile_switch(self):
+        self.default_compile_switch = {}
+        for line in open(r'conf/common_base'):
+            try: 
+                key, value = line.strip('\n').split('=')
+            except ValueError:
+                continue
+            if value:
+                self.default_compile_switch[key] = value
+
     def set_package(self, pkg_name="", patch_list=[]):
         self.package = pkg_name
         self.patches = patch_list
 
+    def reset_switch(self, switch = 'default'):
+        if switch == 'default':
+            for key,value in self.default_compile_switch.items():
+                self.send_expect("sed -i -e 's/%s=.*$/%s=%s/' config/common_base" % (key, key, value), "# ")
+        else:
+            if switch[0] not in self.default_compile_switch:
+                print 'switch %s not find in dpdk compilw switch' % switch[0]
+                raise KeyError
+ 
+            self.send_expect("sed -i -e 's/%s=.*$/%s=%s/' config/common_base" % (switch[0], switch[0], switch[1]), "# ")
+
+    def copy_patch(self, patch_file):
+        try:
+            patch_file = FOLDERS["Depends"] + r'/%s' % patch_file
+        except:
+            self.logger.warning(str(FOLDERS))
+            patch_file = r'dep/%s' % patch_file
+            FOLDERS["Depends"] = 'dep'
+        patch_dst = "/tmp/"
+        # dpdk patch and build
+        self.session.copy_file_to(patch_file, patch_dst)
+
+    def hot_fixpatch(self, patchfile, on):
+        try:
+            if on:
+                self.send_expect("patch -p0 < /tmp/%s" % patchfile, "#")
+            else:
+                self.send_expect("patch -p0 -R < /tmp/%s" % patchfile, "#")
+        except Exception, e:
+            raise ValueError("patch_hotfix_dpdk failure: %s" % e)
+
     def build_install_dpdk(self, target, extra_options=''):
         """
         Build DPDK source code with specified target.
         """
+        if self.read_compiel_switch:
+            self.get_dpdk_compile_switch()
+            compile_config = CompileConf()
+            self.compile_switch = compile_config.load_compile_cfg()
+            self.read_compiel_switch = False
+        else:
+            self.compile_switch = {}
+        for key, value in self.compile_switch.items():
+            if set(value['suite_list']) & set(self.test_suites):
+                # whether run suite should re-compile dpdk
+                 try:
+                 # try apply dpdk patch
+                     for patch in value['patch_list']:
+                         self.copy_patch(patch)
+                         self.hot_fixpatch(patch, True) 
+                 except KeyError:
+                     print 'no patch need apply'
+                     # set compilw switch
+                 for config_name, config_value in value.items():
+                     if config_name not in ['suite_list', 'patch_list', 'compile_app']:
+                         self.reset_switch([config_name, config_value])
+
+                 build_install_dpdk = getattr(self, 'build_install_dpdk_%s' % self.get_os_type())
+                 build_install_dpdk(target, extra_options)
+                 try:
+                    # try compile examples
+                    #print 'value is', value
+                    for app in value['compile_app']: 
+                        self.build_dpdk_apps('./examples/%s' % app.split(':')[0])
+                        try:
+                            self.send_expect('cp -rf %s %s' % (app.split(':')[1], self.target + r'/' + app.split(':')[0] + '_' + key), "#")
+                        except IndexError:
+                            print 'not dst path, so not need copy examples'
+                 except KeyError:
+                    print 'no app should compile'
+                 # backup compile result
+                 self.send_expect('cp -rf %s %s' % (self.target, self.target + '_' + key), "#")
+                 try:
+                     for patch in value['patch_list']:
+                         self.hot_fixpatch(patch, False)
+                 except KeyError:
+                     print 'no patch should remove'
+                 self.reset_switch('default')
+
+        #compile default switch 
         build_install_dpdk = getattr(self, 'build_install_dpdk_%s' % self.get_os_type())
         build_install_dpdk(target, extra_options)
+        self.send_expect('mv %s %s' % (self.target, self.target + '_default' ), "#")
+        self.send_expect('ln -sf  %s %s' % (self.target + '_default', self.target), "#")
+
+    def reset_compile_target(self, dst_target='default'):
+        self.send_expect('rm -rf %s ' % self.target , "#") 
+        if dst_target == 'default':
+            self.send_expect('ln -sf  %s %s' % (self.target + '_default', self.target), "#")
+        else:
+            self.send_expect('ln -sf  %s %s' % (dst_target, self.target), "#")
 
     def build_install_dpdk_linux(self, target, extra_options):
         """
-- 
1.9.3



More information about the dts mailing list