#!/usr/bin/env sh set -e # Overwrite essential files in case students tampered up them cp -r essential/* ../handin/ cd ../handin # 如果需要编译的话,在这里加上编译的命令 ../autograde/grade.py
defrun_tests(): try: global scores for problem in config['problems']: executable = problem['exec'] args = problem['args'] process = subprocess.Popen([executable] + args) # We must wait with timeout, otherwise it won't respond to external exceptions. # https://stackoverflow.com/a/631605/13688160 if process.wait(timeout=23333333) == 0: score = problem['score'] print(problem['name'] + ' passed') else: score = 0 print(problem['name'] + ' failed') scores[problem['name']] = score except FunctionTimedOut: try: process.kill() except NameError: pass except Exception as e: # Code to handle any other exception print("An error occurred: {}".format(str(e)))
tester = StoppableThread(target=run_tests) tester.start() tester.join(timeout=config['timeout']) if tester.is_alive(): tester.stop(exception=FunctionTimedOut) tester.join() print(f"The whole google test timed out after {config['timeout']} seconds") print("Please make your code faster.")
out = '' for problem in config['problems']: iflen(out) != 0: out += ', ' if problem['name'] in scores: score = scores[problem['name']] else: score = 0 out += '"' + problem['name'] + '": ' + str(score) print('{"scores": {' + out + '}}')