示例#1
0
def test_bitwise_and_or_not():
    for instruction in [AND_INSTRUCTION, OR_INSTRUCTION, NOT_INSTRUCTION]:
        operation = instruction[0]

        literal_file = operation + '-with-literals.c'
        variable_file = operation + '-with-variables.c'
        invalid_file = 'invalid-' + operation + '.c'

        test_compilable(literal_file,
                        operation + ' operator with literals does compile')
        test_compilable(variable_file,
                        operation + ' operator with variables does compile')
        test_compilable(invalid_file,
                        operation + ' operator with invalid syntax does not compile', should_succeed=False)
        test_mipster_execution(literal_file, 42,
                               operation + ' operator calculates the right result for literals when executed with MIPSTER')
        test_mipster_execution(variable_file, 42,
                               operation + ' operator calculates the right result for variables when executed with MIPSTER')
        test_riscv_instruction(instruction, literal_file)
        test_riscv_instruction(instruction, variable_file)

    test_mipster_execution('precedence.c', 42,
                           'bitwise and, or & not ' + ' operators respect the precedence of the C operators: &,|,~')
    test_mipster_execution('precedence2.c', 42,
                           'bitwise and, or & not ' + ' operators respect the precedence of the C operators: +,-')
示例#2
0
def test_treiber_stack():
    test_riscv_instruction(LR_INSTRUCTION, 'load-reserved.c')
    test_riscv_instruction(SC_INSTRUCTION, 'store-conditional.c')
    test_execution('./selfie -c treiber-stack.c <assignment>stack-push.c -m 128',
                   'all pushed elements are actually in the treiber-stack',
                   success_criteria=lambda code, out: is_permutation_of(out, [0, 1, 2, 3, 4, 5, 6, 7]))
    test_execution('./selfie -c treiber-stack.c <assignment>stack-pop.c -m 128',
                   'all treiber-stack elements can be popped ',
                   success_criteria=lambda code, out: is_permutation_of(out, [0, 1, 2, 3, 4, 5, 6, 7]))
示例#3
0
def test_bitwise_shift_execution():
    for direction, instruction in [('right', SRL_INSTRUCTION), ('left', SLL_INSTRUCTION)]:

        literal_file = instruction[0] + '-with-literals.c'
        variable_file = instruction[0] + '-with-variables.c'

        test_riscv_instruction(instruction, literal_file)
        test_riscv_instruction(instruction, variable_file)
        test_mipster_execution(literal_file, 42,
                               'bitwise-' + direction + '-shift operator calculates the right result for literals when executed with MIPSTER')
        test_mipster_execution(variable_file, 42,
                               'bitwise-' + direction + '-shift operator calculates the right result for variables when executed with MIPSTER')

    test_mipster_execution('precedence.c', 42,
                           'bitwise shift operators respect the precedence of the C operators: <<, >>')