avocado-framework/avocado

View on GitHub
avocado/utils/cpu.py

Summary

Maintainability
D
3 days
Test Coverage
F
59%

Standard pseudo-random generators are not suitable for security/cryptographic purposes.
Open

        governor = random.choice(avl_govs)
Severity: Info
Found in avocado/utils/cpu.py by bandit

File cpu.py has 541 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
Severity: Major
Found in avocado/utils/cpu.py - About 1 day to fix

    Function get_family has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_family():
        """Get family name of the cpu like Broadwell, Haswell, power8, power9."""
        family = None
        arch = get_arch()
        if arch == "x86_64" or arch == "i386":
    Severity: Minor
    Found in avocado/utils/cpu.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 set_idle_state has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    def set_idle_state(state_number="all", disable=True, setstate=None):
        """
        Set/Reset cpu idle states for all cpus.
    
        :param state_number: cpuidle state number, default: `all` all states
    Severity: Minor
    Found in avocado/utils/cpu.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 get_arch has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_arch():
        """Work out which CPU architecture we're running on."""
        cpu_table = [
            (b"^cpu.*(RS64|Broadband Engine)", "powerpc"),
            (rb"^cpu.*POWER\d+", "powerpc"),
    Severity: Minor
    Found in avocado/utils/cpu.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 get_x86_amd_zen has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_x86_amd_zen(family=None, model=None):
        """
        :param family: AMD family
        :type family: int
        :param model: AMD model
    Severity: Minor
    Found in avocado/utils/cpu.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 set_freq_governor has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def set_freq_governor(governor="random"):
        """
        To change the given cpu frequency governor.
    
        :param governor: frequency governor profile name whereas `random` is default
    Severity: Minor
    Found in avocado/utils/cpu.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 lscpu has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def lscpu():
        """
        Get Cores per socket, Physical sockets and Physical chips
        by executing 'lscpu' command.
    
    
    Severity: Minor
    Found in avocado/utils/cpu.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

    Avoid deeply nested control flow statements.
    Open

                        if line.startswith(b"CPU architecture"):
                            version = int(line.split(b":", 1)[1])
                            if version >= 8:
                                return "aarch64"
                            else:
    Severity: Major
    Found in avocado/utils/cpu.py - About 45 mins to fix

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

      def get_model():
          """
          Get model of cpu
          """
          arch = get_arch()
      Severity: Minor
      Found in avocado/utils/cpu.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 get_idle_state has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_idle_state():
          """
          Get current cpu idle values.
      
          :return: Dict of cpuidle states values for all cpus
      Severity: Minor
      Found in avocado/utils/cpu.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

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

      def get_vendor():
          """
          Get the current cpu vendor name.
      
          :return: a key of :data:`VENDORS_MAP` (e.g. 'intel') depending on the
      Severity: Minor
      Found in avocado/utils/cpu.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

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

      def numa_nodes_with_assigned_cpus():
          """
          Get NUMA nodes with associated CPU's on the system.
      
          :return: A dictionary,in which "NUMA node numbers" as key
      Severity: Minor
      Found in avocado/utils/cpu.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