def make_c_test(environment, filename): setup_c_environment(environment, filename) environment.executable = environment.builddir + "/" + environment.filename + ".exe" ensure_dir(os.path.dirname(environment.executable)) test = Test(environment, filename) compile = test.add_step("compile", step_compile_c) compile.add_check(check_cparser_problems) compile.add_check(check_no_errors) compile.add_check(check_firm_problems) compile.add_check(check_retcode_zero) compile.add_check(check_memcheck_output) asmchecks = parse_embedded_commands(environment, environment.filename) if asmchecks: environment.asmfile = environment.builddir + "/" + environment.filename + ".s" ensure_dir(os.path.dirname(environment.asmfile)) asm = test.add_step("asm", step_compile_c_asm) asm.add_checks(asmchecks) if environment.memcheck: return test # no execute necessary execute = test.add_step("execute", step_execute) execute.add_check(check_retcode_zero) execute.add_check(create_check_reference_output(environment)) return test
def make_lit_test(environment, filename): # Extract run lines from test runlines = [] for line in open(filename, "r"): match = runmatch.search(line) if not match: break cmd = match.group(1) # Fill in placeholders like %(cc)s cmd = cmd.format(cc=environment.cc, input=filename) # hack cmd = cmd.replace("FileCheck", "scripts/FileCheck") cmd = cmd.replace("not", "scripts/not") # TODO: handle further replacements runlines.append(cmd) if len(runlines) == 0: raise Exception("Coulnd't find any RUN: lines at beginning of %s" % filename) environment.filename = filename test = Test(environment, filename) i = 0 for cmd in runlines: runstep = test.add_step("run%d" % i, create_run_step(cmd)) i += 1 runstep.add_check(check_retcode_zero) return test
def make_cmd_should_work(environment, filename): read_cmds(environment, filename) test = Test(environment, filename) runcompiler = test.add_step("cmd_should_work", step_runcommand) runcompiler.add_check(check_retcode_zero) return test
def make_preprocessor_should_fail(environment, filename): setup_preprocess_environment(environment, filename) test = Test(environment, filename) preprocess = test.add_step("preprocess", step_preprocess) preprocess.add_check(create_check_errors_reference(environment)) return test
def make_cmd_should_warn(environment, filename): read_cmds(environment, filename) test = Test(environment, filename) runcompiler = test.add_step("cmd_should_warn", step_runcommand) runcompiler.add_check(check_retcode_zero) runcompiler.add_check(check_no_errors) runcompiler.add_check(create_check_warnings_reference(environment)) return test
def make_preprocessor_should_warn(environment, filename): setup_preprocess_environment(environment, filename) test = Test(environment, filename) preprocess = test.add_step("preprocess", step_preprocess) preprocess.add_check(check_no_errors) preprocess.add_check(check_retcode_zero) preprocess.add_check(create_check_warnings_reference(environment)) return test
def make_c_should_fail(environment, filename, cflags=""): setup_c_environment(environment, filename) environment.cflags += cflags parse_embedded_commands_no_check(environment) test = Test(environment, filename) compile = test.add_step("compile", step_compile_c_syntax_only) compile.add_check(create_check_errors_reference(environment)) test.steps.append(compile) return test
def make_fluffy_should_fail(environment, filename): environment.filename = filename environment.executable = environment.builddir + "/" + environment.filename + ".exe" ensure_dir(os.path.dirname(environment.executable)) test = Test(environment, filename) compile = test.add_step("compile", step_compile_fluffy) compile.add_check(check_missing_errors) return test
def make_c_should_warn(environment, filename, cflags=" -Wall -W"): setup_c_environment(environment, filename) environment.cflags += cflags parse_embedded_commands_no_check(environment) test = Test(environment, filename) compile = test.add_step("compile", step_compile_c_syntax_only) compile.add_check(check_retcode_zero) compile.add_check(check_no_errors) compile.add_check(create_check_warnings_reference(environment)) return test
def make_fluffy_test(environment, filename): environment.filename = filename environment.executable = environment.builddir + "/" + environment.filename + ".exe" ensure_dir(os.path.dirname(environment.executable)) test = Test(environment, filename) compile = test.add_step("compile", step_compile_fluffy) compile.add_check(check_no_errors) compile.add_check(check_firm_problems) compile.add_check(check_retcode_zero) execute = test.add_step("execute", step_execute) execute.add_check(check_retcode_zero) execute.add_check(create_check_reference_output(environment)) return test
def make_perftest(environment, filename, size, check_perf): setup_c_environment(environment, filename) environment.executable = environment.builddir + "/" + environment.filename + ".exe" ensure_dir(os.path.dirname(environment.executable)) if size != 0: environment.executionargs = " %s" % size test = Test(environment, filename) compile = test.add_step("compile", step_compile_c) compile.add_check(check_cparser_problems) compile.add_check(check_no_errors) compile.add_check(check_firm_problems) compile.add_check(check_retcode_zero) execute = test.add_step("execute", step_execute) execute.add_check(check_retcode_zero) execute.add_check(check_perf) return test
from test.test import Test test = Test() # 测试性能 test.test() # 绘制图片 test.paint()
import multiprocessing from multiprocessing import Process from types import TracebackType from typing import * from test.config_editor_test import ConfigEditorTest from test.fail_test import FailTest from test.hapi_sources_test import HapiSourcesTest from test.molecule_info_test import MoleculeInfoTest from test.test import Test from test.throw_test import ThrowTest tests: List[Test] = [ Test(), FailTest(), ThrowTest(), HapiSourcesTest(), MoleculeInfoTest(), ConfigEditorTest() ] def run_tests(): result_fmt = '{:36s} {:36s}' name_fmt = '{:36s} ' print('{}{}'.format(name_fmt, name_fmt).format('Test Name', 'Test Result')) q = multiprocessing.Queue() for test in tests: print(name_fmt.format(test.name())) p = Process(target=test.run, args=(q, ))