def check_bitwise_and_or_not() -> List[Check]: def check_instruction(instruction) -> List[Check]: operation = instruction[0] literal_file = operation + '-with-literals.c' variable_file = operation + '-with-variables.c' invalid_file = 'invalid-' + operation + '.c' return check_compilable(literal_file, operation + ' operator with literals does compile') + \ check_compilable(variable_file, operation + ' operator with variables does compile') + \ check_compilable(invalid_file, operation + ' operator with invalid syntax does not compile', should_succeed=False) + \ check_mipster_execution(literal_file, 42, operation + ' operator calculates the right result for literals when executed with MIPSTER') + \ check_mipster_execution(variable_file, 42, operation + ' operator calculates the right result for variables when executed with MIPSTER') + \ check_riscv_instruction(instruction, literal_file) + \ check_riscv_instruction(instruction, variable_file) return list(flatmap(check_instruction, [AND_INSTRUCTION, OR_INSTRUCTION, NOT_INSTRUCTION])) + \ check_mipster_execution('precedence.c', 42, 'bitwise and, or & not ' + ' operators respect the precedence of the C operators: &,|,~') + \ check_mipster_execution('precedence2.c', 42, 'bitwise and, or & not ' + ' operators respect the precedence of the C operators: +,-')
def check_assignment(assignment: Assignment, baseline: List[Assignment]) -> Tuple[int, List[str]]: def check(a: Assignment): return list(map(execute_with_output, a.create_checks())) def change_result_to_mandatory(r: CheckResult): return CheckResult(r.result, r.msg, r.output, r.warning, r.should_succeed, r.command, True) if not assignment in baseline: baseline_results = list(flatmap(lambda a: map(change_result_to_mandatory, check(a)), baseline)) else: baseline_results = [ ] set_assignment_name(assignment.category) print_message('executing test \'{}\''.format(assignment.name)) results = baseline_results + check(assignment) set_assignment_name('') (grade_value, reasons) = grade(results) for reason in reasons: print_warning(reason) print_grade(grade_value)
def check_bitwise_shift_compilation() -> List[Check]: def check_direction(direction: str) -> List[Check]: literal_file = direction + '-shift-with-literals.c' variable_file = direction + '-shift-with-variables.c' invalid_file = 'invalid-' + direction + '-shift.c' return check_compilable(literal_file, 'bitwise-' + direction + '-shift operator with literals does compile') + \ check_compilable(variable_file, 'bitwise-' + direction + '-shift operator with variables does compile') + \ check_compilable(invalid_file, 'bitwise-' + direction + '-shift operator with invalid syntax does not compile', should_succeed=False) return list(flatmap(check_direction, ['right', 'left']))
def check_bitwise_shift_execution() -> List[Check]: def check_instruction(direction: str, instruction: Tuple[str, Any]) -> List[Check]: literal_file = instruction[0] + '-with-literals.c' variable_file = instruction[0] + '-with-variables.c' return check_riscv_instruction(instruction, literal_file) + \ check_riscv_instruction(instruction, variable_file) + \ check_mipster_execution(literal_file, 42, 'bitwise-' + direction + '-shift operator calculates the right result for literals when executed with MIPSTER') + \ check_mipster_execution(variable_file, 42, 'bitwise-' + direction + '-shift operator calculates the right result for variables when executed with MIPSTER') instructions = [('right', SRL_INSTRUCTION), ('left', SLL_INSTRUCTION)] return list(flatmap(lambda i: check_instruction(i[0], i[1]), instructions)) + \ check_mipster_execution('precedence.c', 42, 'bitwise shift operators respect the precedence of the C operators: <<, >>')