<commit_before>#!/usr/bin/env python
from __future__ import print_function

# Repeats an interestingness test a given number of times.
# If "RANGENUM" is present, it is replaced in turn with each number in the range.
#
# Use for:
#
# 1. Intermittent testcases.
#
#    Repeating the test can make the bug occur often enough for Lithium to make progress.
#
#     lithium.py range 1 20 crashes --timeout=3 ./js-dbg-32-mozilla-central-linux -m -n intermittent.js
#
# 2. Unstable testcases.
#
#    Varying a number in the test (using RANGENUM) may allow other parts of the testcase to be
#    removed (Lithium), or may allow different versions of the shell to crash (autoBisect).
#
#    In the testcase:
#      schedulegc(n);
#
#    On the command line:
#      lithium.py range 1 50 crashes --timeout=3 ./js-dbg-32-mozilla-central-linux -e "n=RANGENUM;" 740654.js

import os
import sys
from optparse import OptionParser

import ximport
path0 = os.path.dirname(os.path.abspath(__file__))
path1 = os.path.abspath(os.path.join(path0, os.pardir, 'util'))
sys.path.append(path1)


def parseOptions(arguments):
    parser = OptionParser()
    parser.disable_interspersed_args()
    _options, args = parser.parse_args(arguments)

    return int(args[0]), int(args[1]), args[2:]  # args[0] is minLoopNum, args[1] maxLoopNum


def interesting(cliArgs, tempPrefix):
    (rangeMin, rangeMax, arguments) = parseOptions(cliArgs)
    conditionScript = ximport.importRelativeOrAbsolute(arguments[0])
    conditionArgs = arguments[1:]

    if hasattr(conditionScript, "init"):
        conditionScript.init(conditionArgs)

    assert (rangeMax - rangeMin) >= 0
    for i in xrange(rangeMin, rangeMax + 1):
        # This doesn't do anything if RANGENUM is not found.
        replacedConditionArgs = [s.replace('RANGENUM', str(i)) for s in conditionArgs]
        print('Range number %d:' % i, end=' ')
        if conditionScript.interesting(replacedConditionArgs, tempPrefix):
            return True

    return False
<commit_msg>Switch to use range instead of xrange since we are moving off Python 2 eventually, as suggested by :truber.<commit_after>#!/usr/bin/env python
from __future__ import print_function

# Repeats an interestingness test a given number of times.
# If "RANGENUM" is present, it is replaced in turn with each number in the range.
#
# Use for:
#
# 1. Intermittent testcases.
#
#    Repeating the test can make the bug occur often enough for Lithium to make progress.
#
#     lithium.py range 1 20 crashes --timeout=3 ./js-dbg-32-mozilla-central-linux -m -n intermittent.js
#
# 2. Unstable testcases.
#
#    Varying a number in the test (using RANGENUM) may allow other parts of the testcase to be
#    removed (Lithium), or may allow different versions of the shell to crash (autoBisect).
#
#    In the testcase:
#      schedulegc(n);
#
#    On the command line:
#      lithium.py range 1 50 crashes --timeout=3 ./js-dbg-32-mozilla-central-linux -e "n=RANGENUM;" 740654.js

import os
import sys
from optparse import OptionParser

import ximport
path0 = os.path.dirname(os.path.abspath(__file__))
path1 = os.path.abspath(os.path.join(path0, os.pardir, 'util'))
sys.path.append(path1)


def parseOptions(arguments):
    parser = OptionParser()
    parser.disable_interspersed_args()
    _options, args = parser.parse_args(arguments)

    return int(args[0]), int(args[1]), args[2:]  # args[0] is minLoopNum, args[1] maxLoopNum


def interesting(cliArgs, tempPrefix):
    (rangeMin, rangeMax, arguments) = parseOptions(cliArgs)
    conditionScript = ximport.importRelativeOrAbsolute(arguments[0])
    conditionArgs = arguments[1:]

    if hasattr(conditionScript, "init"):
        conditionScript.init(conditionArgs)

    assert (rangeMax - rangeMin) >= 0
    for i in range(rangeMin, rangeMax + 1):
        # This doesn't do anything if RANGENUM is not found.
        replacedConditionArgs = [s.replace('RANGENUM', str(i)) for s in conditionArgs]
        print('Range number %d:' % i, end=' ')
        if conditionScript.interesting(replacedConditionArgs, tempPrefix):
            return True

    return False

{'fraction_non_alphanumeric': 0.10489170114383062, 'fraction_numerical': 0.016305670479435385, 'mean_word_length': 3.713302752293578, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6166800', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1291, 'n_words': 414}