torvalds/linux

View on GitHub
tools/testing/selftests/tc-testing/tdc.py

Summary

Maintainability
F
6 days
Test Coverage

File tdc.py has 855 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0

"""
tdc.py - Linux tc (Traffic Control) unit test driver
Severity: Major
Found in tools/testing/selftests/tc-testing/tdc.py - About 2 days to fix

    Function set_operation_mode has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

    def set_operation_mode(pm, parser, args, remaining):
        """
        Load the test case data and process remaining arguments to determine
        what the script should do for this run, and call the appropriate
        function.
    Severity: Minor
    Found in tools/testing/selftests/tc-testing/tdc.py - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function run_one_test has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

    def run_one_test(pm, args, index, tidx):
        global NAMES
        ns = NAMES['NS']
        dev0 = NAMES['DEV0']
        dev1 = NAMES['DEV1']
    Severity: Minor
    Found in tools/testing/selftests/tc-testing/tdc.py - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_test_cases has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_test_cases(args):
        """
        If a test case file is specified, retrieve tests from that file.
        Otherwise, glob for all json files in subdirectories and load from
        each one.
    Severity: Minor
    Found in tools/testing/selftests/tc-testing/tdc.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function generate_case_ids has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    def generate_case_ids(alltests):
        """
        If a test case has a blank ID field, generate a random hex ID for it
        and then write the test cases back to disk.
        """
    Severity: Minor
    Found in tools/testing/selftests/tc-testing/tdc.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function test_runner has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    def test_runner(pm, args, filtered_tests):
        """
        Driver function for the unit tests.
    
        Prints information about the tests being run, executes the setup and
    Severity: Minor
    Found in tools/testing/selftests/tc-testing/tdc.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function find_in_json_dict has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def find_in_json_dict(res, outputJSONVal, matchJSONVal):
        for matchJSONKey, matchJSONVal in matchJSONVal.items():
            if type(outputJSONVal) == dict:
                if matchJSONKey not in outputJSONVal:
                    failmsg = 'Key not found in json output: {}: {}\nMatching against output: {}'
    Severity: Minor
    Found in tools/testing/selftests/tc-testing/tdc.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function load_required_plugins has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def load_required_plugins(self, reqs, parser, args, remaining):
            '''
            Get all required plugins from the list of test cases and load any plugin
            that is not already enabled.
            '''
    Severity: Minor
    Found in tools/testing/selftests/tc-testing/tdc.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function filter_tests_by_category has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def filter_tests_by_category(args, testlist):
        '''
        Remove tests from testlist that are not in a named category.
        '''
        answer = list()
    Severity: Minor
    Found in tools/testing/selftests/tc-testing/tdc.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function run_one_test has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def run_one_test(pm, args, index, tidx):
        global NAMES
        ns = NAMES['NS']
        dev0 = NAMES['DEV0']
        dev1 = NAMES['DEV1']
    Severity: Minor
    Found in tools/testing/selftests/tc-testing/tdc.py - About 1 hr to fix

      Function get_required_plugins has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_required_plugins(self, testlist):
              '''
              Get all required plugins from the list of test cases and return
              all unique items.
              '''
      Severity: Minor
      Found in tools/testing/selftests/tc-testing/tdc.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function prepare_env has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def prepare_env(caseinfo, args, pm, stage, prefix, cmdlist, output = None):
          """
          Execute the setup/teardown commands for a test case.
          Optionally terminate test execution if the command fails.
          """
      Severity: Minor
      Found in tools/testing/selftests/tc-testing/tdc.py - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function prepare_env has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def prepare_env(caseinfo, args, pm, stage, prefix, cmdlist, output = None):
      Severity: Major
      Found in tools/testing/selftests/tc-testing/tdc.py - About 50 mins to fix

        Function mp_bins has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        def mp_bins(alltests):
            serial = []
            parallel = []
        
            for test in alltests:
        Severity: Minor
        Found in tools/testing/selftests/tc-testing/tdc.py - About 45 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function verify_by_json has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def verify_by_json(procout, res, tidx, args, pm):
        Severity: Minor
        Found in tools/testing/selftests/tc-testing/tdc.py - About 35 mins to fix

          Function exec_cmd has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def exec_cmd(caseinfo, args, pm, stage, command):
          Severity: Minor
          Found in tools/testing/selftests/tc-testing/tdc.py - About 35 mins to fix

            Function __init__ has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def __init__(self, argparser):
                    super().__init__()
                    self.plugins = set()
                    self.plugin_instances = []
                    self.failed_plugins = {}
            Severity: Minor
            Found in tools/testing/selftests/tc-testing/tdc.py - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function exec_cmd has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            def exec_cmd(caseinfo, args, pm, stage, command):
                """
                Perform any required modifications on an executable command, then run
                it in a subprocess and return the results.
                """
            Severity: Minor
            Found in tools/testing/selftests/tc-testing/tdc.py - About 25 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            There are no issues that match your filters.

            Category
            Status