コード例 #1
0
def test_fork_and_wait():
    test_compilable('parallel-print.c', 'fork and wait compiled')
    test_mipster_execution('parallel-print.c',
                   lambda code, out: is_permutation_of(out, [0, 1, 2, 3, 4, 5, 6, 7]),
                   'fork creates a child process, where the parent can wait for the child process with MIPSTER')
    test_hypster_execution('parallel-print.c',
                   lambda code, out: is_permutation_of(out, [0, 1, 2, 3, 4, 5, 6, 7]),
                   'fork creates a child process, where the parent can wait for the child process with HYPSTER')
コード例 #2
0
def test_multidimensional_array():
    test_compilable('multidimensional.c',
                    'multidimensional array declarations do compile')
    test_mipster_execution('multidimensional.c', 42,
                           'multidimensional arrays assignments are implemented with the right semantics')
    test_compilable('access-order.c',
                    'access to start-address of multidimensional is possible')
    test_mipster_execution('access-order.c', 0,
                           'access to multidimensional arrays is implemented in row-major order')
コード例 #3
0
def test_struct_declaration():
    test_compilable('declaration.c',
                    'empty struct declarations compiled')
    test_compilable('definition.c',
                    'struct definition with global and local scope compiled')
    test_compilable('member-declaration.c',
                    'struct declaration with trivial members compiled')
    test_compilable('nested-declaration.c',
                    'struct declaration with struct members compiled')
コード例 #4
0
def test_array():
    test_compilable('global-declaration.c',
                    'array declaration do compile')
    test_compilable('assignment.c',
                    'assignments on arrays do compile')
    test_compilable('invalid-assignment.c',
                    'invalid assignments to an array do not compile', should_succeed=False)
    test_compilable('call-by-reference.c',
                    'arrays in the function signature do compile')
    test_mipster_execution('assignment.c', 42,
                           'arrays assignments are implemented with the right semantics')
    test_mipster_execution('call-by-reference.c', 42,
                           'array assignments in functions are implemented with the right semantics')
コード例 #5
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: +,-')
コード例 #6
0
def test_struct_execution():
    test_compilable('initialization.c',
                    'empty struct with initialization compiled')
    test_compilable('member-initialization.c',
                    'initialization of trivial struct members compiled')
    test_mipster_execution('member-initialization.c', 42,
                           'read and write operations of trivial struct member works when executed with MIPSTER')
    test_compilable('nested-initialization.c',
                    'struct initialization with struct members compiled')
    test_mipster_execution('nested-initialization.c', 42,
                           'read and write operations of nested struct member works when executed with MIPSTER')
    test_compilable('as-parameter.c',
                    'struct as function parameter compiled')
    test_mipster_execution('as-parameter.c', 42,
                           'read and write operations of structs as parameter work when executed with MIPSTER')
コード例 #7
0
def test_for_loop():
    test_compilable('missing-assignment.c',
                    'for loop with missing assignment do not compile', should_succeed=False)
    test_compilable('single-statement.c',
                    'for loop with one statement do compile')
    test_compilable('multiple-statements.c',
                    'for loop with multiple statements do compile')
    test_compilable('nested.c',
                    'nested for loops do compile')
    test_mipster_execution('single-statement.c', 42,
                           'for loop with one statement are implement with the right semantics')
    test_mipster_execution('multiple-statements.c', 42,
                           'for loop with multiple statements are implemented with the right semantics')
    test_mipster_execution('nested.c', 42,
                           'nested for loops are implemented with the right semantics')
コード例 #8
0
def test_bitwise_shift_compilation():
    for direction in ['right', 'left']:

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

        test_compilable(literal_file,
                        'bitwise-' + direction + '-shift operator with literals does compile')
        test_compilable(variable_file,
                        'bitwise-' + direction + '-shift operator with variables does compile')
        test_compilable(invalid_file,
                        'bitwise-' + direction + '-shift operator with invalid syntax does not compile', should_succeed=False)
コード例 #9
0
def test_hex_literal():
    test_compilable('all-digit-characters.c',
                    'hex integer literal with all characters compiled')
    test_mipster_execution('all-digit-characters.c', 42,
                           'hex integer literal with all characters has the right value')
    test_compilable('max-value.c',
                    'maximum hex integer literal compiled')
    test_mipster_execution('max-value.c', 42,
                           'maximum hex integer literal has the right value')
    test_compilable('min-value.c',
                    'minimum hex integer literal compiled')
    test_mipster_execution('min-value.c', 42,
                           'minimum hex integer literal has the right value')
コード例 #10
0
def test_fork_wait_exit():
    test_compilable('sum-exit-code.c', 'fork and wait compiled')
    test_mipster_execution('sum-exit-code.c', 28,
                           'exit code is returned as status parameter from wait with MIPSTER')
    test_hypster_execution('sum-exit-code.c', 28,
                           'exit code is returned as status parameter from wait with HYPSTER')