<commit_before># This is a test suite for Kconfiglib. It runs selftests on Kconfigs provided
# by us and tests compatibility with the C Kconfig implementation by comparing
# the output of Kconfiglib with the output of the scripts/kconfig/*conf
# utilities for different targets and defconfigs. It should be run from the
# top-level kernel directory with
#
#  $ python Kconfiglib/testsuite.py
#
# Some additional options can be turned on by passing arguments. With no argument,
# they default to off.
#
#  - speedy:
#    Run scripts/kconfig/conf directly when comparing outputs instead of using
#    'make' targets. Makes things a lot faster, but could break if Kconfig
#    files start depending on additional environment variables besides ARCH and
#    SRCARCH. (These would be set in the Makefiles in that case.) Safe as of
#    Linux 3.7.0-rc8.
#
#  - obsessive:
#    By default, only valid arch/defconfig pairs will be tested. With this
#    enabled, every arch will be tested with every defconfig, which increases
#    the test time by an order of magnitude. Occasionally finds (usually very
#    obscure) bugs, and I make sure everything passes with it.
#
#  - log:
#    Log timestamped failures of the defconfig test to test_defconfig_fails in
#    the root. Especially handy in obsessive mode.
#
# For example, to run in speedy mode with logging, run
#
#  $ python Kconfiglib/testsuite.py speedy log
#
# (PyPy also works, and runs the defconfig tests roughly 20% faster on my
# machine. Some of the other tests get an even greater speed-up.)
#
# The tests have been roughly arranged in order of time needed.
#
# All tests should pass. Report regressions to <EMAIL>

import kconfiglib
import os
import re
import subprocess
import sys
import textwrap
import time

speedy_mode = False
obsessive_mode = False
log_mode = False

# Assign this to avoid warnings from Kconfiglib. Nothing in the kernel's
# Kconfig files seems to actually look at the value as of 3.7.0-rc8. This is
# only relevant for the test suite, as this will get set by the kernel Makefile
# when using (i)scriptconfig.
os.environ["KERNELVERSION"] = "3.7.0"

# Prevent accidental loading of configuration files by removing
# KCONFIG_ALLCONFIG from the environment
os.environ.pop("KCONFIG_ALLCONFIG", None)

# Number of arch/defconfig pairs tested so far
nconfigs = 0

def run_tests():
    global speedy_mode, obsessive_mode, log_mode
    for s in sys.argv[1:]:
        if s == "speedy":
            speedy_mode = True
            print "Speedy mode enabled"
        elif s == "obsessive":
            obsessive_mode = True
            print "Obsessive mode enabled"
        elif s == "log":
            log_mode = True
            print "Log mode enabled"
        else:
            print "Unrecognized option '{0}'".format(s)
            return

    run_selftests()
    run_compatibility_tests()

def run_selftests():
    """Runs tests on specific configurations provided by us."""

    #
    # Helper functions
    #

    # Verifies that a symbol has a particular value
    def verify_value(sym_name, val):
        sym = c[sym_name]
        sym_val = sym.get_value()
        verify(sym_val == val,
               "{0} should have the value {1} but has the value {2}"
               .format(sym_name, val, sym_val))

    # Assigns a user value to the symbol and verifies the new value
    def assign_and_verify_new_value(sym_name, val, new_val):
        sym = c[sym_name]
        sym_old_val = sym.get_value()
        sym.set_user_value(val)
        sym_new_val = sym.get_value()
        verify(sym_new_val == new_val,
               "{0} should have the new value {1} after being assigned the "
               "user value {2}. Instead, the value was {3}. The old user "
               "value was {4}."
               .format(sym_name, new_val, val, sym_new_val, sym_old_val))

    # Assigns a user value to the symbol and verifies the new user value
    def assign_and_verify_new_user_value(sym_name, val, new_val):
        sym = c[sym_name]
        sym_old_val = sym.get_user_value()
        sym.set_user_value(val)
        sym_new_val = sym.get_user_value()
        verify(sym_new_val == new_val,
               "{0} should have the user value {1} after being assigned {2}. "
               "Instead, the new user value was {3}. The old user value was {4}.".
               format(sym_name, new_val, val, sym_new_val, sym_old_val))

    print "Running selftests...\n"

    print "Testing tristate comparisons..."

    def verify_truth_table(comp_fn, *bools):
        bools_list = list(bools)
        for (x, y) in (("n", "n"), ("n", "m"), ("n", "y"),
                       ("m", "n"), ("m", "m"), ("m", "y"),
                       ("y", "n"), ("y", "m"), ("y", "y")):
            expected = bools_list.pop(0)
            verify(comp_fn(x, y) == expected,
                   "Expected {0} on ('{1}', '{2}') to be {3}".
                   format(comp_fn, x, y, expected))

    verify_truth_table(kconfiglib.tri_less,<commit_msg>Add some quotes for the sake of readability.<commit_after># This is a test suite for Kconfiglib. It runs selftests on Kconfigs provided
# by us and tests compatibility with the C Kconfig implementation by comparing
# the output of Kconfiglib with the output of the scripts/kconfig/*conf
# utilities for different targets and defconfigs. It should be run from the
# top-level kernel directory with
#
#  $ python Kconfiglib/testsuite.py
#
# Some additional options can be turned on by passing arguments. With no argument,
# they default to off.
#
#  - speedy:
#    Run scripts/kconfig/conf directly when comparing outputs instead of using
#    'make' targets. Makes things a lot faster, but could break if Kconfig
#    files start depending on additional environment variables besides ARCH and
#    SRCARCH. (These would be set in the Makefiles in that case.) Safe as of
#    Linux 3.7.0-rc8.
#
#  - obsessive:
#    By default, only valid arch/defconfig pairs will be tested. With this
#    enabled, every arch will be tested with every defconfig, which increases
#    the test time by an order of magnitude. Occasionally finds (usually very
#    obscure) bugs, and I make sure everything passes with it.
#
#  - log:
#    Log timestamped failures of the defconfig test to test_defconfig_fails in
#    the root. Especially handy in obsessive mode.
#
# For example, to run in speedy mode with logging, run
#
#  $ python Kconfiglib/testsuite.py speedy log
#
# (PyPy also works, and runs the defconfig tests roughly 20% faster on my
# machine. Some of the other tests get an even greater speed-up.)
#
# The tests have been roughly arranged in order of time needed.
#
# All tests should pass. Report regressions to <EMAIL>

import kconfiglib
import os
import re
import subprocess
import sys
import textwrap
import time

speedy_mode = False
obsessive_mode = False
log_mode = False

# Assign this to avoid warnings from Kconfiglib. Nothing in the kernel's
# Kconfig files seems to actually look at the value as of 3.7.0-rc8. This is
# only relevant for the test suite, as this will get set by the kernel Makefile
# when using (i)scriptconfig.
os.environ["KERNELVERSION"] = "3.7.0"

# Prevent accidental loading of configuration files by removing
# KCONFIG_ALLCONFIG from the environment
os.environ.pop("KCONFIG_ALLCONFIG", None)

# Number of arch/defconfig pairs tested so far
nconfigs = 0

def run_tests():
    global speedy_mode, obsessive_mode, log_mode
    for s in sys.argv[1:]:
        if s == "speedy":
            speedy_mode = True
            print "Speedy mode enabled"
        elif s == "obsessive":
            obsessive_mode = True
            print "Obsessive mode enabled"
        elif s == "log":
            log_mode = True
            print "Log mode enabled"
        else:
            print "Unrecognized option '{0}'".format(s)
            return

    run_selftests()
    run_compatibility_tests()

def run_selftests():
    """Runs tests on specific configurations provided by us."""

    #
    # Helper functions
    #

    # Verifies that a symbol has a particular value
    def verify_value(sym_name, val):
        sym = c[sym_name]
        sym_val = sym.get_value()
        verify(sym_val == val,
               "{0} should have the value '{1}' but has the value '{2}'"
               .format(sym_name, val, sym_val))

    # Assigns a user value to the symbol and verifies the new value
    def assign_and_verify_new_value(sym_name, val, new_val):
        sym = c[sym_name]
        sym_old_val = sym.get_value()
        sym.set_user_value(val)
        sym_new_val = sym.get_value()
        verify(sym_new_val == new_val,
               "{0} should have the new value '{1}' after being assigned the "
               "user value '{2}'. Instead, the value was '{3}'. The old user "
               "value was '{4}'."
               .format(sym_name, new_val, val, sym_new_val, sym_old_val))

    # Assigns a user value to the symbol and verifies the new user value
    def assign_and_verify_new_user_value(sym_name, val, new_val):
        sym = c[sym_name]
        sym_old_val = sym.get_user_value()
        sym.set_user_value(val)
        sym_new_val = sym.get_user_value()
        verify(sym_new_val == new_val,
               "{0} should have the user value '{1}' after being assigned "
               "'{2}'. Instead, the new user value was '{3}'. The old user "
               "value was '{4}'."
               .format(sym_name, new_val, val, sym_new_val, sym_old_val))

    print "Running selftests...\n"

    print "Testing tristate comparisons..."

    def verify_truth_table(comp_fn, *bools):
        bools_list = list(bools)
        for (x, y) in (("n", "n"), ("n", "m"), ("n", "y"),
                       ("m", "n"), ("m", "m"), ("m", "y"),
                       ("y", "n"), ("y", "m"), ("y", "y")):
            expected = bools_list.pop(0)
            verify(comp_fn(x, y) == expected,
                   "Expected {0} on ('{1}', '{2}') to be {3}".
                   format(comp_fn, x, y, expected))

    verify_truth_table(kconfiglib.tri_less,
{'fraction_non_alphanumeric': 0.09500645289387472, 'fraction_numerical': 0.0067507197458552565, 'mean_word_length': 2.694169416941694, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3250416', 'n_tokens_mistral': 3045, 'n_tokens_neox': 2985, 'n_words': 1160}