Esempio n. 1
0
def test_eq():
    T0 = make_test('T0', (rfm.RegressionTest, ), {})
    T1 = make_test('T1', (rfm.RegressionTest, ), {})
    T2 = make_test('T1', (rfm.RegressionTest, ), {})

    t0, t1, t2 = T0(), T1(), T2()
    assert t0 != t1
    assert hash(t0) != hash(t1)

    # T1 and T2 are different classes but have the same name, so the
    # corresponding tests should compare equal
    assert T1 is not T2
    assert t1 == t2
    assert hash(t1) == hash(t2)
Esempio n. 2
0
def repeat_tests(testcases, num_repeats):
    '''Returns new test cases parameterized over their repetition number'''

    tmp_registry = TestRegistry()
    unique_checks = set()
    for tc in testcases:
        check = tc.check
        if check.is_fixture() or check in unique_checks:
            continue

        unique_checks.add(check)
        cls = type(check)
        variant_info = cls.get_variant_info(
            check.variant_num, recurse=True
        )
        nc = make_test(
            f'{cls.__name__}', (cls,),
            {
                '$repeat_no': builtins.parameter(range(num_repeats))
            }
        )
        nc._rfm_custom_prefix = check.prefix
        for i in range(nc.num_variants):
            # Check if this variant should be instantiated
            vinfo = nc.get_variant_info(i, recurse=True)
            vinfo['params'].pop('$repeat_no')
            if vinfo == variant_info:
                tmp_registry.add(nc, variant_num=i)

    new_checks = tmp_registry.instantiate_all()
    return generate_testcases(new_checks)
Esempio n. 3
0
def test_make_test_without_builtins(local_exec_ctx):
    hello_cls = make_test(
        'HelloTest', (rfm.RunOnlyRegressionTest, ), {
            'valid_systems': ['*'],
            'valid_prog_environs': ['*'],
            'executable': 'echo',
            'sanity_patterns': sn.assert_true(1)
        })

    assert hello_cls.__name__ == 'HelloTest'
    _run(hello_cls(), *local_exec_ctx)
Esempio n. 4
0
def distribute_tests(testcases, node_map):
    '''Returns new testcases that will be parameterized to run in node of
    their partitions based on the nodemap
    '''
    tmp_registry = TestRegistry()

    # We don't want to register the same check for every environment
    # per partition
    check_part_combs = set()
    for tc in testcases:
        check, partition, _ = tc
        candidate_comb = (check.unique_name, partition.fullname)
        if check.is_fixture() or candidate_comb in check_part_combs:
            continue

        check_part_combs.add(candidate_comb)
        cls = type(check)
        variant_info = cls.get_variant_info(
            check.variant_num, recurse=True
        )
        nc = make_test(
            f'{cls.__name__}_{partition.fullname.replace(":", "_")}',
            (cls,),
            {
                'valid_systems': [partition.fullname],
                '$nid': builtins.parameter(
                    [[n] for n in node_map[partition.fullname]],
                    fmt=util.nodelist_abbrev
                )
            },
            methods=[
                builtins.run_before('run')(_rfm_pin_run_nodes),
                builtins.run_before('compile')(_rfm_pin_build_nodes),
                # We re-set the valid system in a hook to make sure that it
                # will not be overwriten by a parent post-init hook
                builtins.run_after('init')(
                    make_valid_systems_hook([partition.fullname])
                ),
            ]
        )

        # We have to set the prefix manually
        nc._rfm_custom_prefix = check.prefix
        for i in range(nc.num_variants):
            # Check if this variant should be instantiated
            vinfo = nc.get_variant_info(i, recurse=True)
            vinfo['params'].pop('$nid')
            if vinfo == variant_info:
                tmp_registry.add(nc, variant_num=i)

    new_checks = tmp_registry.instantiate_all()
    return generate_testcases(new_checks)
Esempio n. 5
0
def make_check(cls, *, alt_name=None, **vars):
    '''Create a new test from class `cls`.

    :arg cls: the class of the test.
    'arg alt_name: an alternative name to be given to the test class
    :arg vars: variables to set in the test upon creation
    '''

    if alt_name:
        cls = make_test(alt_name, (cls,), {})

    for k, v in vars.items():
        cls.setvar(k, v)

    return cls()
Esempio n. 6
0
def test_make_test_with_builtins(local_exec_ctx):
    class _X(rfm.RunOnlyRegressionTest):
        valid_systems = ['*']
        valid_prog_environs = ['*']
        executable = 'echo'
        message = variable(str)

        @run_before('run')
        def set_message(self):
            self.executable_opts = [self.message]

        @sanity_function
        def validate(self):
            return sn.assert_found(self.message, self.stdout)

    hello_cls = make_test('HelloTest', (_X, ), {})
    hello_cls.setvar('message', 'hello')
    assert hello_cls.__name__ == 'HelloTest'
    _run(hello_cls(), *local_exec_ctx)
Esempio n. 7
0
def test_make_test_with_builtins_inline(local_exec_ctx):
    def set_message(obj):
        obj.executable_opts = [obj.message]

    def validate(obj):
        return sn.assert_found(obj.message, obj.stdout)

    hello_cls = make_test('HelloTest', (rfm.RunOnlyRegressionTest, ), {
        'valid_systems': ['*'],
        'valid_prog_environs': ['*'],
        'executable': 'echo',
        'message': builtins.variable(str),
    },
                          methods=[
                              builtins.run_before('run')(set_message),
                              builtins.sanity_function(validate)
                          ])
    hello_cls.setvar('message', 'hello')
    assert hello_cls.__name__ == 'HelloTest'
    _run(hello_cls(), *local_exec_ctx)