DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Juraj Linkeš" <juraj.linkes@pantheon.tech>
To: thomas@monjalon.net, david.marchand@redhat.com,
	Honnappa.Nagarahalli@arm.com, ohilyard@iol.unh.edu,
	lijuan.tu@intel.com
Cc: dev@dpdk.org, "Juraj Linkeš" <juraj.linkes@pantheon.tech>
Subject: [RFC PATCH v1 06/15] dts: merge DTS framework/checkCase.py to DPDK
Date: Wed,  6 Apr 2022 14:55:57 +0000	[thread overview]
Message-ID: <20220406145606.2913834-7-juraj.linkes@pantheon.tech> (raw)
In-Reply-To: <20220406145606.2913834-1-juraj.linkes@pantheon.tech>

---
 dts/framework/checkCase.py | 214 +++++++++++++++++++++++++++++++++++++
 1 file changed, 214 insertions(+)
 create mode 100644 dts/framework/checkCase.py

diff --git a/dts/framework/checkCase.py b/dts/framework/checkCase.py
new file mode 100644
index 0000000000..7b2c22b3c0
--- /dev/null
+++ b/dts/framework/checkCase.py
@@ -0,0 +1,214 @@
+import collections
+import json
+import os
+
+from .settings import (
+    CONFIG_ROOT_PATH,
+    HOST_DRIVER_SETTING,
+    get_nic_name,
+    load_global_setting,
+)
+from .utils import RED
+
+filter_json_file = os.path.join(CONFIG_ROOT_PATH, "test_case_checklist.json")
+support_json_file = os.path.join(CONFIG_ROOT_PATH, "test_case_supportlist.json")
+
+
+class CheckCase(object):
+    """
+    Class for check test case running criteria. All information will be loaded
+    from DTS_CFG_FOLDER/test_case_*list.json. Current two files are maintained. One is
+    for check whether test case should skip, another one is for check whether
+    current environment support test case execution.
+    """
+
+    def __init__(self):
+        self.dut = None
+        self.comments = ""
+
+        self.check_function_dict = {}
+        self.support_function_dict = {}
+        try:
+            self.check_function_dict = json.load(
+                open(filter_json_file), object_pairs_hook=collections.OrderedDict
+            )
+        except:
+            print(
+                RED(
+                    "Can't load check list for test cases, all case will be taken as supported"
+                )
+            )
+
+        try:
+            self.support_function_dict = json.load(
+                open(support_json_file), object_pairs_hook=collections.OrderedDict
+            )
+        except:
+            print(
+                RED(
+                    "Can't load support list for test cases, all case will be taken as supported"
+                )
+            )
+
+    def check_dut(self, dut):
+        """
+        Change DUT instance for environment check
+        """
+        self.dut = dut
+
+    def _check_os(self, os_type):
+        if "all" == os_type[0].lower():
+            return True
+        dut_os_type = self.dut.get_os_type()
+        if dut_os_type in os_type:
+            return True
+        else:
+            return False
+
+    def _check_nic(self, nic_type):
+        if "all" == nic_type[0].lower():
+            return True
+        dut_nic_type = get_nic_name(self.dut.ports_info[0]["type"])
+        if dut_nic_type in nic_type:
+            return True
+        else:
+            return False
+
+    def _check_target(self, target):
+        if "all" == target[0].lower():
+            return True
+        if self.dut.target in target:
+            return True
+        else:
+            return False
+
+    def _check_host_driver(self, drivers):
+        host_driver = load_global_setting(HOST_DRIVER_SETTING)
+        if "all" == drivers[0].lower():
+            return True
+        if host_driver in drivers:
+            return True
+        else:
+            return False
+
+    def case_skip(self, case_name):
+        """
+        Check whether test case and DUT match skip criteria
+        Return True if skip should skip
+        """
+        skip_flag = False
+        self.comments = ""
+
+        if self.dut is None:
+            print(RED("No Dut assigned before case skip check"))
+            return skip_flag
+
+        if case_name in list(self.check_function_dict.keys()):
+            case_checks = self.check_function_dict[case_name]
+            # each case may have several checks
+            for case_check in case_checks:
+                # init result for each check
+                skip_flag = False
+                for key in list(case_check.keys()):
+                    # some items like "Bug ID" and "Comments" do not need check
+                    try:
+                        if "Comments" == key:
+                            continue
+                        if "Bug ID" == key:
+                            continue
+                        check_function = getattr(self, "_check_%s" % key.lower())
+                    except:
+                        print(RED("can't check %s type" % key))
+
+                    # skip this check if any item not matched
+                    if check_function(case_check[key]):
+                        skip_flag = True
+                    else:
+                        skip_flag = False
+                        break
+
+                # if all items matched, this case should skip
+                if skip_flag:
+                    if "Comments" in list(case_check.keys()):
+                        self.comments = case_check["Comments"]
+                    return skip_flag
+
+        return skip_flag
+
+    def case_support(self, case_name):
+        """
+        Check whether test case and DUT match support criteria
+        Return False if test case not supported
+        """
+        support_flag = True
+        self.comments = ""
+
+        if self.dut is None:
+            print(RED("No Dut assigned before case support check"))
+            return support_flag
+
+        if case_name in list(self.support_function_dict.keys()):
+            # each case may have several supports
+            case_supports = self.support_function_dict[case_name]
+            for case_support in case_supports:
+                # init result for each check
+                support_flag = True
+                for key in list(case_support.keys()):
+                    # some items like "Bug ID" and "Comments" do not need check
+                    try:
+                        if "Comments" == key:
+                            continue
+                        if "Bug ID" == key:
+                            continue
+                        check_function = getattr(self, "_check_%s" % key.lower())
+                    except:
+                        print(RED("can't check %s type" % key))
+
+                    # skip this case if any item not matched
+                    if check_function(case_support[key]):
+                        support_flag = True
+                    else:
+                        support_flag = False
+                        break
+
+            if support_flag is False:
+                if "Comments" in list(case_support.keys()):
+                    self.comments = case_support["Comments"]
+                return support_flag
+
+        return support_flag
+
+
+class simple_dut(object):
+    def __init__(self, os="", target="", nic=""):
+        self.ports_info = [{}]
+        self.os = os
+        self.target = target
+        self.ports_info[0]["type"] = nic
+
+    def get_os_type(self):
+        return self.os
+
+
+if __name__ == "__main__":
+    dut = simple_dut(os="linux", target="x86_64-native-linuxapp-gcc", nic="177d:a034")
+    dut1 = simple_dut(
+        os="freebsd", target="x86_64-native-linuxapp-gcc", nic="8086:158b"
+    )
+
+    # create instance for check/support case list
+    case_inst = CheckCase()
+
+    # check dut
+    case_inst.check_dut(dut)
+    print(case_inst.case_skip("fdir_flexword_drop_ipv4"))
+    print(case_inst.comments)
+    print(case_inst.case_support("Vxlan_tunnel"))
+    print(case_inst.comments)
+
+    # check other dut
+    case_inst.check_dut(dut1)
+    print(case_inst.case_skip("fdir_flexword_drop_ipv4"))
+    print(case_inst.comments)
+    print(case_inst.case_support("Vxlan_tunnel"))
+    print(case_inst.comments)
-- 
2.20.1


  parent reply	other threads:[~2022-04-06 14:57 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-06 14:55 [RFC PATCH v1 00/15] merge DTS core files " Juraj Linkeš
2022-04-06 14:55 ` [RFC PATCH v1 01/15] dts: merge DTS dep/tclclient.tgz " Juraj Linkeš
2022-04-06 14:55 ` [RFC PATCH v1 02/15] dts: merge DTS dep/tgen.tgz " Juraj Linkeš
2022-04-06 14:55 ` [RFC PATCH v1 03/15] dts: merge DTS dts " Juraj Linkeš
2022-04-06 14:55 ` [RFC PATCH v1 04/15] dts: merge DTS framework/__init__.py " Juraj Linkeš
2022-04-06 14:55 ` [RFC PATCH v1 05/15] dts: merge DTS framework/asan_test.py " Juraj Linkeš
2022-04-06 14:55 ` Juraj Linkeš [this message]
2022-04-06 14:55 ` [RFC PATCH v1 07/15] dts: merge DTS framework/dts.py " Juraj Linkeš
2022-04-06 14:55 ` [RFC PATCH v1 08/15] dts: merge DTS framework/exception.py " Juraj Linkeš
2022-04-06 14:56 ` [RFC PATCH v1 09/15] dts: merge DTS framework/logger.py " Juraj Linkeš
2022-04-06 14:56 ` [RFC PATCH v1 10/15] dts: merge DTS framework/packet.py " Juraj Linkeš
2022-04-06 14:56 ` [RFC PATCH v1 11/15] dts: merge DTS framework/project_dpdk.py " Juraj Linkeš
2022-04-06 14:56 ` [RFC PATCH v1 12/15] dts: merge DTS framework/serializer.py " Juraj Linkeš
2022-04-06 14:56 ` [RFC PATCH v1 13/15] dts: merge DTS framework/utils.py " Juraj Linkeš
2022-04-06 14:56 ` [RFC PATCH v1 14/15] dts: merge DTS main.py " Juraj Linkeš
2022-04-06 14:56 ` [RFC PATCH v1 15/15] dts: merge DTS version.py " Juraj Linkeš
2022-04-07  5:04 ` [RFC PATCH v1 00/15] merge DTS core files " Jerin Jacob
2022-04-07  7:33   ` Thomas Monjalon
2022-04-11  7:41     ` Juraj Linkeš
2022-04-11 17:55       ` Honnappa Nagarahalli
2022-04-11 18:20         ` Owen Hilyard
2022-04-11 19:06   ` Honnappa Nagarahalli

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=20220406145606.2913834-7-juraj.linkes@pantheon.tech \
    --to=juraj.linkes@pantheon.tech \
    --cc=Honnappa.Nagarahalli@arm.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=lijuan.tu@intel.com \
    --cc=ohilyard@iol.unh.edu \
    --cc=thomas@monjalon.net \
    /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).