test suite reviews and discussions
 help / color / mirror / Atom feed
From: xinfengx <xinfengx.zhao@intel.com>
To: dts@dpdk.org
Cc: xinfengx <xinfengx.zhao@intel.com>
Subject: [dts] [PATCH V1 2/6] tests/cryptodev_common: improve cryptodev common methods
Date: Thu,  4 Jun 2020 08:54:41 +0800	[thread overview]
Message-ID: <20200604005445.110297-3-xinfengx.zhao@intel.com> (raw)
In-Reply-To: <20200604005445.110297-1-xinfengx.zhao@intel.com>

Signed-off-by: xinfengx <xinfengx.zhao@intel.com>
---
 tests/cryptodev_common.py | 117 ++++++++++++++++++++++++++------------
 1 file changed, 81 insertions(+), 36 deletions(-)

diff --git a/tests/cryptodev_common.py b/tests/cryptodev_common.py
index a20dd51..832b3bf 100644
--- a/tests/cryptodev_common.py
+++ b/tests/cryptodev_common.py
@@ -29,32 +29,37 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+from net_device import GetNicObj
+from config import SuiteConf
+
+conf = SuiteConf('cryptodev_sample')
+
 
 def build_dpdk_with_cryptodev(test_case):
     # Rebuild the dpdk with cryptodev pmds
     snow3g_lib_path = "/root/libsso_snow3g/snow3g/"
-    if "snow3g_lib_path" in test_case.get_suite_cfg():
-        snow3g_lib_path = test_case.get_suite_cfg()["snow3g_lib_path"]
+    if "snow3g_lib_path" in conf.suite_cfg:
+        snow3g_lib_path = conf.suite_cfg["snow3g_lib_path"]
 
     zuc_lib_path = "/root/libsso_zuc.1.0.1.1-8/zuc"
-    if "zuc_lib_path" in test_case.get_suite_cfg():
-        zuc_lib_path = test_case.get_suite_cfg()["zuc_lib_path"]
+    if "zuc_lib_path" in conf.suite_cfg:
+        zuc_lib_path = conf.suite_cfg["zuc_lib_path"]
 
     kasumi_lib_path = "/root/LibSSO_0_3_1/isg_cid-wireless_libs/ciphers/kasumi/"
-    if "kasumi_lib_path" in test_case.get_suite_cfg():
-        kasumi_lib_path = test_case.get_suite_cfg()["kasumi_lib_path"]
+    if "kasumi_lib_path" in conf.suite_cfg:
+        kasumi_lib_path = conf.suite_cfg["kasumi_lib_path"]
 
     fip_cflags_path = "'-I/opt/openssl-fips-2.0.16/include/'"
-    if "fip_cflags_path" in test_case.get_suite_cfg():
-        fip_cflags_path = test_case.get_suite_cfg()["fip_cflags_path"]
+    if "fip_cflags_path" in conf.suite_cfg:
+        fip_cflags_path = conf.suite_cfg["fip_cflags_path"]
 
     fip_ldflags_path = "'-L/opt/openssl-fips-2.0.16/'"
-    if "fip_ldflags_path" in test_case.get_suite_cfg():
-        fip_cflags_path = test_case.get_suite_cfg()["fip_ldflags_path"]
+    if "fip_ldflags_path" in conf.suite_cfg:
+        fip_cflags_path = conf.suite_cfg["fip_ldflags_path"]
 
     fip_library_path = "/opt/openssl-fips-2.0.16/"
-    if "fip_library_path" in test_case.get_suite_cfg():
-        fip_cflags_path = test_case.get_suite_cfg()["fip_library_path"]
+    if "fip_library_path" in conf.suite_cfg:
+        fip_cflags_path = conf.suite_cfg["fip_library_path"]
 
     test_case.dut.send_expect(
         "export LIBSSO_SNOW3G_PATH={}".format(snow3g_lib_path), "#")
@@ -91,30 +96,61 @@ def build_dpdk_with_cryptodev(test_case):
 
 
 def bind_qat_device(test_case, driver = "igb_uio"):
-    if not driver:
-        test_case.logger.error("Please configure the driver of qat device to bind")
     if driver == 'vfio-pci':
+        test_case.dut.send_expect('modprobe vfio', '#', 10)
         test_case.dut.send_expect('modprobe vfio-pci', '#', 10)
 
-    if "crypto_dev_id" in test_case.get_suite_cfg():
-        crypto_dev_id = test_case.get_suite_cfg()["crypto_dev_id"]
+    if "crypto_dev_id" in conf.suite_cfg:
+        dev_id = conf.suite_cfg["crypto_dev_id"]
+        test_case.logger.info("specified the qat hardware device id in cfg: {}".format(dev_id))
+        out = test_case.dut.send_expect("lspci -D -d:{}|awk '{{print $1}}'".format(dev_id), "# ", 10)
     else:
-        crypto_dev_id = "443"
-    test_case.logger.info("crypto device id: " + crypto_dev_id)
+        out = test_case.dut.send_expect("lspci -D | grep QuickAssist |awk '{{print $1}}'", "# ", 10)
 
-    # Bind QAT VF devices
-    out = test_case.dut.send_expect("lspci -d:{}|awk '{{print $1}}'".format(crypto_dev_id), "# ", 10)
-    crypto_list = out.replace("\r", "\n").replace("\n\n", "\n").split("\n")
-    test_case._crypto_pci = crypto_list[0]
-    test_case.dut.send_expect(
-        'echo "8086 {}" > /sys/bus/pci/drivers/{}/new_id'.format(crypto_dev_id, driver), "# ", 10)
-    for line in crypto_list:
-        cmd = "echo 0000:{} > /sys/bus/pci/devices/0000\:{}/driver/unbind".format(
-            line, line.replace(":", "\:"))
-        test_case.dut.send_expect(cmd, "# ", 10)
-        cmd = "echo 0000:{} > /sys/bus/pci/drivers/{}/bind".format(
-            line, driver)
-        test_case.dut.send_expect(cmd, "# ", 10)
+    pf_list = out.replace("\r", "\n").replace("\n\n", "\n").split("\n")
+
+    dev = {}
+    for line in pf_list:
+        addr_array = line.strip().split(':')
+        if len(addr_array) !=3:
+            continue
+        domain_id = addr_array[0]
+        bus_id = addr_array[1]
+        devfun_id = addr_array[2]
+        pf_port = GetNicObj(test_case.dut, domain_id, bus_id, devfun_id)
+
+        sriov_vfs_pci = pf_port.get_sriov_vfs_pci()
+        if not sriov_vfs_pci:
+            raise Exception("can not get vf pci")
+
+        dev[line.strip()] = sriov_vfs_pci
+
+        test_case.dut.bind_eventdev_port(driver, ' '.join(sriov_vfs_pci))
+
+    if not dev:
+        raise Exception("can not find qat device")
+
+    test_case.dev = dev
+
+
+def get_qat_devices(test_case, cpm_num=None, num=1):
+    if not cpm_num:
+        cpm_num = len(test_case.dev.keys())
+    n, dev_list = 0, []
+    if cpm_num > len(test_case.dev.keys()):
+        self.logger.warning("QAT card only {} cpm, but {} required".format(
+            len(test_case.dev), cpm_num))
+        return []
+    for i in range(num):
+        for cpm in list(test_case.dev.keys())[:cpm_num]:
+            if n >= num:
+                break
+            if i < len(test_case.dev[cpm]):
+                dev_list.append(test_case.dev[cpm][i])
+            else:
+                self.logger.warning("not enough vf in cpm: {}".format(cpm))
+            n += 1
+    return dev_list
 
 
 def clear_dpdk_config(test_case):
@@ -147,6 +183,15 @@ default_eal_opts = {
 
 
 def get_eal_opt_str(test_case, override_eal_opts={}, add_port=False):
+    cores = ','.join(test_case.dut.get_core_list("1S/3C/1T"))
+    if "l" in conf.suite_cfg:
+        cores = conf.suite_cfg["l"]
+    default_eal_opts.update({'l': cores})
+    if "socket-mem" in conf.suite_cfg:
+        default_eal_opts.update({"socket-mem": (conf.suite_cfg["socket-mem"])})
+    mem_channel = test_case.dut.get_memory_channels()
+    default_eal_opts.update({'n': mem_channel})
+
     return get_opt_str(test_case, default_eal_opts, override_eal_opts, add_port)
 
 
@@ -158,15 +203,15 @@ def get_opt_str(test_case, default_opts, override_opts={}, add_port=False):
         if key in test_case.get_case_cfg():
             opts[key] = test_case.get_case_cfg()[key]
 
+    # Update options with func input
+    opts.update(override_opts)
+
     pci_list = [port["pci"] for port in test_case.dut.ports_info]
     if 'w' in list(opts.keys()) and opts['w']:
         pci_list.append(opts['w'])
     if add_port and pci_list:
         opts['w'] = " -w ".join(pci_list)
 
-    # Update options with func input
-    opts.update(override_opts)
-
     # Generate option string
     opt_str = ""
     for key,value in list(opts.items()):
@@ -192,7 +237,7 @@ def is_test_skip(test_case):
 
 
 def is_build_skip(test_case):
-    if "build_skip" in test_case.get_suite_cfg() \
-       and test_case.get_suite_cfg()["build_skip"] == "Y":
+    if "build_skip" in conf.suite_cfg \
+       and conf.suite_cfg["build_skip"] == "Y":
         test_case.logger.info("Build Skip is YES")
         return True
-- 
2.17.1


  parent reply	other threads:[~2020-06-04  0:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-04  0:54 [dts] [PATCH V1 0/6] rework cryptodev test script and conf xinfengx
2020-06-04  0:54 ` [dts] [PATCH V1 1/6] conf: simplify conf settings for cryptodev test xinfengx
2020-06-04  0:54 ` xinfengx [this message]
2020-06-04  0:54 ` [dts] [PATCH V1 3/6] tests/crypto_perf_cryptodev_perf: rework crypto_perf test script xinfengx
2020-06-04  0:54 ` [dts] [PATCH V1 4/6] tests/l2fwd_cryptodev_func: rework l2fwd_crypto " xinfengx
2020-06-04  0:54 ` [dts] [PATCH V1 5/6] tests/ipsec_gw_cryptodev_func: rework cryptodev ipsec " xinfengx
2020-06-04  0:54 ` [dts] [PATCH V1 6/6] tests/unit_tests_cryptodev_func: rework cryptodev unit " xinfengx
2020-06-12  1:46   ` Wan, Zhe
2020-06-04  0:59 ` [dts] [PATCH V1 0/6] rework cryptodev test script and conf Zhao, XinfengX
2020-06-19  3:32 ` Tu, Lijuan

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=20200604005445.110297-3-xinfengx.zhao@intel.com \
    --to=xinfengx.zhao@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).