const chai = require("chai"); const assert = chai.assert; const fs = require("fs"); var tmp = require("tmp-promise"); const path = require("path"); const util = require("util"); const exec = util.promisify(require("child_process").exec); const BuildZqField = require("./buildzqfield"); module.exports = testField; async function testField(prime, test) { tmp.setGracefulCleanup(); const dir = await tmp.dir({prefix: "circom_", unsafeCleanup: true }); const source = await BuildZqField(prime, "Fr"); // console.log(dir.path); await fs.promises.writeFile(path.join(dir.path, "fr.asm"), source.asm, "utf8"); await fs.promises.writeFile(path.join(dir.path, "fr.h"), source.h, "utf8"); await fs.promises.writeFile(path.join(dir.path, "fr.c"), source.c, "utf8"); await exec(`cp ${path.join(__dirname, "tester.cpp")} ${dir.path}`); await exec("nasm -fmacho64 --prefix _ " + ` ${path.join(dir.path, "fr.asm")}` ); await exec("g++" + ` ${path.join(dir.path, "tester.cpp")}` + ` ${path.join(dir.path, "fr.o")}` + ` ${path.join(dir.path, "fr.c")}` + ` -o ${path.join(dir.path, "tester")}` + " -lgmp" ); const inLines = []; for (let i=0; i${path.join(dir.path, "out.tst")}`); const res = await fs.promises.readFile(path.join(dir.path, "out.tst"), "utf8"); const resLines = res.split("\n"); for (let i=0; i