Begin incorporating Python unit tests into build

We now build a separate APE binary for each test so they can run in
parallel. We've got 148 tests running fast and stable so far.
This commit is contained in:
Justine Tunney 2021-09-12 21:04:44 -07:00
parent 51904e2687
commit b5f743cdc3
121 changed files with 4995 additions and 4767 deletions

View file

@ -1269,41 +1269,68 @@ class ChainOfVisitors:
v.visit(object)
v.emit("", 0)
common_msg = "/* File automatically generated by %s. */\n\n"
def main(srcfile, dump_module=False):
argv0 = sys.argv[0]
components = argv0.split(os.sep)
argv0 = os.sep.join(components[-2:])
auto_gen_msg = common_msg % argv0
mod = asdl.parse(srcfile)
if dump_module:
print('Parsed Module:')
print(mod)
if not asdl.check(mod):
sys.exit(1)
if H_FILE:
with open(H_FILE, "w") as f:
f.write(auto_gen_msg)
f.write('#include "asdl.h"\n\n')
f.write("\
#ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_PYTHON_AST_H_\n\
#define COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_PYTHON_AST_H_\n\
#include \"third_party/python/Include/asdl.h\"\n\
#if !(__ASSEMBLER__ + __LINKER__ + 0)\n\
COSMOPOLITAN_C_START_\n\
/* clang-format off */\n\
/* File automatically generated by %s. */\n\
\n\
" % argv0)
c = ChainOfVisitors(TypeDefVisitor(f),
StructVisitor(f),
PrototypeVisitor(f),
)
c.visit(mod)
f.write("PyObject* PyAST_mod2obj(mod_ty t);\n")
f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n")
f.write("int PyAST_Check(PyObject* obj);\n")
f.write("\
PyObject* PyAST_mod2obj(mod_ty t);\n\
mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n\
int PyAST_Check(PyObject* obj);\n\
\n\
COSMOPOLITAN_C_END_\n\
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */\n\
#endif /* COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_PYTHON_AST_H_ */\n")
if C_FILE:
with open(C_FILE, "w") as f:
f.write(auto_gen_msg)
f.write('#include <stddef.h>\n')
f.write('\n')
f.write('#include "Python.h"\n')
f.write('#include "%s-ast.h"\n' % mod.name)
f.write('\n')
f.write("static PyTypeObject AST_type;\n")
f.write('\
#include "third_party/python/Include/%s-ast.h"\n\
#include "third_party/python/Include/abstract.h"\n\
#include "third_party/python/Include/boolobject.h"\n\
#include "third_party/python/Include/descrobject.h"\n\
#include "third_party/python/Include/dictobject.h"\n\
#include "third_party/python/Include/listobject.h"\n\
#include "third_party/python/Include/longobject.h"\n\
#include "third_party/python/Include/modsupport.h"\n\
#include "third_party/python/Include/object.h"\n\
#include "third_party/python/Include/objimpl.h"\n\
#include "third_party/python/Include/pyerrors.h"\n\
#include "third_party/python/Include/pythonrun.h"\n\
#include "third_party/python/Include/tupleobject.h"\n\
#include "third_party/python/Include/yoink.h"\n\
/* clang-format off */\n\
\n\
PYTHON_PROVIDE("_ast");\n\
\n\
/* File automatically generated by %s. */\n\
\n\
static PyTypeObject AST_type;\n\
' % (mod.name, argv0))
v = ChainOfVisitors(
PyTypesDeclareVisitor(f),
PyTypesVisitor(f),