From 4646deeaad961e90d7c3e5458197b99e4d16d305 Mon Sep 17 00:00:00 2001 From: xuyangfan Date: Thu, 29 Feb 2024 07:59:53 +0800 Subject: [PATCH 1/3] support unit test framework Change-Id: Id0306616f2575086cc76486d10b36a3ea1f5374a --- es2panda/aot/options.cpp | 6 +++++ es2panda/es2panda.h | 2 ++ es2panda/test/runner.py | 54 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 0a5a9c83a2..1ef3c589de 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -215,6 +215,8 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg opTypeDtsBuiltin("type-dts-builtin", false, "Enable builtin type extractor for .d.ts file"); // compiler + panda::PandArg opEnableAbcInput("enable-abc-input", false, "Support for abc files as input"); + panda::PandArg opDumpAsmProgram("dump-asm-program", false, "Dump pandasm program"); panda::PandArg opDumpAssembly("dump-assembly", false, "Dump pandasm"); panda::PandArg opDebugInfo("debug-info", false, "Compile with debug info"); panda::PandArg opDumpDebugInfo("dump-debug-info", false, "Dump debug info"); @@ -268,6 +270,8 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&opEnableTypeCheck); argparser_->Add(&opTypeExtractor); argparser_->Add(&opTypeDtsBuiltin); + argparser_->Add(&opEnableAbcInput); + argparser_->Add(&opDumpAsmProgram); argparser_->Add(&opDumpAssembly); argparser_->Add(&opDebugInfo); argparser_->Add(&opDumpDebugInfo); @@ -457,6 +461,8 @@ bool Options::Parse(int argc, const char **argv) } compilerOptions_.recordSource = opRecordSource.GetValue(); + compilerOptions_.enableAbcInput = opEnableAbcInput.GetValue(); + compilerOptions_.dumpAsmProgram = opDumpAsmProgram.GetValue(); compilerOptions_.dumpAsm = opDumpAssembly.GetValue(); compilerOptions_.dumpAst = opDumpAst.GetValue(); compilerOptions_.dumpTransformedAst = opDumpTransformedAst.GetValue(); diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index b8136bcb39..8f11cc5601 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -71,6 +71,8 @@ struct PatchFixOptions { }; struct CompilerOptions { + bool enableAbcInput {false}; + bool dumpAsmProgram {false}; bool isDebug {false}; bool dumpAst {false}; bool dumpTransformedAst {false}; diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index 71736725da..ee2ff13360 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -80,6 +80,9 @@ def get_args(): parser.add_argument( '--error', action='store_true', dest='error', default=False, help='capture stderr') + parser.add_argument( + '--abc-to-asm', '-abc2asm', action='store_true', dest='abc_to_asm', + default=False, help='run abc2asm tests') parser.add_argument( '--regression', '-r', action='store_true', dest='regression', default=False, help='run regression tests') @@ -560,6 +563,50 @@ class RegressionRunner(Runner): def test_path(self, src): return src +class AbcToAsmRunner(Runner): + def __init__(self, args): + Runner.__init__(self, args, "Abc to asm") + + def add_directory(self, directory, extension, flags, func=Test): + glob_expression = path.join( + self.test_root, directory, "*.%s" % (extension)) + files = glob(glob_expression) + files = fnmatch.filter(files, self.test_root + '**' + self.args.filter) + + self.tests += list(map(lambda f: AbcToAsmTest(f, flags), files)) + + def test_path(self, src): + return src + +class AbcToAsmTest(Test): + def run(self, runner): + output_abc_file = ("%s.abc" % (path.splitext(self.path)[0])).replace("/", "_") + gen_abc_cmd = runner.cmd_prefix + [runner.es2panda] + gen_abc_cmd.extend(["--dump-asm-program", "--output=" + output_abc_file]) + gen_abc_cmd.append(self.path) + self.log_cmd(gen_abc_cmd) + abc_to_asm_cmd = runner.cmd_prefix + [runner.es2panda] + abc_to_asm_cmd.extend(["--dump-asm-program", "--enable-abc-input"]) + abc_to_asm_cmd.extend(output_abc_file) + self.log_cmd.append(abc_to_asm_cmd) + process_gen_abc = subprocess.Popen( + gen_abc_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + gen_abc_out, gen_abc_err = process.communicate() + gen_abc_output = gen_abc_out.decode("utf-8", errors="ignore") + gen_abc_err.decode("utf-8", errors="ignore") + process_abc_to_asm = subprocess.Popen( + abc_to_asm_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + abc_to_asm_out, abc_to_asm_err = process.communicate() + abc_to_asm_output = abc_to_asm_out.decode("utf-8", errors="ignore") + abc_to_asm_err.decode("utf-8", errors="ignore") + try: + self.passed = gen_abc_output == abc_to_asm_output and process.returncode in [0, 1] + except: Exception: + self.passed = False + + if os.path.exists(output_abc_file) + os.remove(test_abc_path) + return self + + class Test262Runner(Runner): def __init__(self, args): @@ -1535,6 +1582,13 @@ def main(): runners.append(transformer_runner) + if args.abc_to_asm: + runner = AbcToAsmRunner(args) + runner.add_directory("abc2asm/js", "js" , ["--dump-asm-program"]) + runner.add_directory("abc2asm/ts", "ts", ["--dump-asm-program"]) + runner.add_directory("abc2asm/abc", "abc", ["--enable-abc-input", "--dump-asm-program"]) + runners.append(runner) + if args.test262: runners.append(Test262Runner(args)) -- Gitee From 800cd09a357391a301c3a40cf751a7711d62ecc4 Mon Sep 17 00:00:00 2001 From: xuyangfan Date: Thu, 29 Feb 2024 07:59:53 +0800 Subject: [PATCH 2/3] support unit test framework Signed-off-by:xuyangfan Change-Id: Id0306616f2575086cc76486d10b36a3ea1f5374a Change-Id: I425c2f5593f436a10e6d6bdf24fe735d2e304bcd --- es2panda/aot/options.cpp | 6 +++++ es2panda/es2panda.h | 2 ++ es2panda/test/runner.py | 54 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 0a5a9c83a2..1ef3c589de 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -215,6 +215,8 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg opTypeDtsBuiltin("type-dts-builtin", false, "Enable builtin type extractor for .d.ts file"); // compiler + panda::PandArg opEnableAbcInput("enable-abc-input", false, "Support for abc files as input"); + panda::PandArg opDumpAsmProgram("dump-asm-program", false, "Dump pandasm program"); panda::PandArg opDumpAssembly("dump-assembly", false, "Dump pandasm"); panda::PandArg opDebugInfo("debug-info", false, "Compile with debug info"); panda::PandArg opDumpDebugInfo("dump-debug-info", false, "Dump debug info"); @@ -268,6 +270,8 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&opEnableTypeCheck); argparser_->Add(&opTypeExtractor); argparser_->Add(&opTypeDtsBuiltin); + argparser_->Add(&opEnableAbcInput); + argparser_->Add(&opDumpAsmProgram); argparser_->Add(&opDumpAssembly); argparser_->Add(&opDebugInfo); argparser_->Add(&opDumpDebugInfo); @@ -457,6 +461,8 @@ bool Options::Parse(int argc, const char **argv) } compilerOptions_.recordSource = opRecordSource.GetValue(); + compilerOptions_.enableAbcInput = opEnableAbcInput.GetValue(); + compilerOptions_.dumpAsmProgram = opDumpAsmProgram.GetValue(); compilerOptions_.dumpAsm = opDumpAssembly.GetValue(); compilerOptions_.dumpAst = opDumpAst.GetValue(); compilerOptions_.dumpTransformedAst = opDumpTransformedAst.GetValue(); diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index b8136bcb39..8f11cc5601 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -71,6 +71,8 @@ struct PatchFixOptions { }; struct CompilerOptions { + bool enableAbcInput {false}; + bool dumpAsmProgram {false}; bool isDebug {false}; bool dumpAst {false}; bool dumpTransformedAst {false}; diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index 71736725da..ee2ff13360 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -80,6 +80,9 @@ def get_args(): parser.add_argument( '--error', action='store_true', dest='error', default=False, help='capture stderr') + parser.add_argument( + '--abc-to-asm', '-abc2asm', action='store_true', dest='abc_to_asm', + default=False, help='run abc2asm tests') parser.add_argument( '--regression', '-r', action='store_true', dest='regression', default=False, help='run regression tests') @@ -560,6 +563,50 @@ class RegressionRunner(Runner): def test_path(self, src): return src +class AbcToAsmRunner(Runner): + def __init__(self, args): + Runner.__init__(self, args, "Abc to asm") + + def add_directory(self, directory, extension, flags, func=Test): + glob_expression = path.join( + self.test_root, directory, "*.%s" % (extension)) + files = glob(glob_expression) + files = fnmatch.filter(files, self.test_root + '**' + self.args.filter) + + self.tests += list(map(lambda f: AbcToAsmTest(f, flags), files)) + + def test_path(self, src): + return src + +class AbcToAsmTest(Test): + def run(self, runner): + output_abc_file = ("%s.abc" % (path.splitext(self.path)[0])).replace("/", "_") + gen_abc_cmd = runner.cmd_prefix + [runner.es2panda] + gen_abc_cmd.extend(["--dump-asm-program", "--output=" + output_abc_file]) + gen_abc_cmd.append(self.path) + self.log_cmd(gen_abc_cmd) + abc_to_asm_cmd = runner.cmd_prefix + [runner.es2panda] + abc_to_asm_cmd.extend(["--dump-asm-program", "--enable-abc-input"]) + abc_to_asm_cmd.extend(output_abc_file) + self.log_cmd.append(abc_to_asm_cmd) + process_gen_abc = subprocess.Popen( + gen_abc_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + gen_abc_out, gen_abc_err = process.communicate() + gen_abc_output = gen_abc_out.decode("utf-8", errors="ignore") + gen_abc_err.decode("utf-8", errors="ignore") + process_abc_to_asm = subprocess.Popen( + abc_to_asm_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + abc_to_asm_out, abc_to_asm_err = process.communicate() + abc_to_asm_output = abc_to_asm_out.decode("utf-8", errors="ignore") + abc_to_asm_err.decode("utf-8", errors="ignore") + try: + self.passed = gen_abc_output == abc_to_asm_output and process.returncode in [0, 1] + except: Exception: + self.passed = False + + if os.path.exists(output_abc_file) + os.remove(test_abc_path) + return self + + class Test262Runner(Runner): def __init__(self, args): @@ -1535,6 +1582,13 @@ def main(): runners.append(transformer_runner) + if args.abc_to_asm: + runner = AbcToAsmRunner(args) + runner.add_directory("abc2asm/js", "js" , ["--dump-asm-program"]) + runner.add_directory("abc2asm/ts", "ts", ["--dump-asm-program"]) + runner.add_directory("abc2asm/abc", "abc", ["--enable-abc-input", "--dump-asm-program"]) + runners.append(runner) + if args.test262: runners.append(Test262Runner(args)) -- Gitee From 952fdb8b43b21139135b6cb1acf47d20d0f5de66 Mon Sep 17 00:00:00 2001 From: xuyangfan Date: Thu, 29 Feb 2024 09:27:59 +0800 Subject: [PATCH 3/3] support unit test framework Signed-off-by:xuyangfan Change-Id: I94a37c592387a55b8815e529c4902ce2637fafd7 --- es2panda/test/runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index ee2ff13360..26c1244dc4 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -599,7 +599,7 @@ class AbcToAsmTest(Test): abc_to_asm_output = abc_to_asm_out.decode("utf-8", errors="ignore") + abc_to_asm_err.decode("utf-8", errors="ignore") try: self.passed = gen_abc_output == abc_to_asm_output and process.returncode in [0, 1] - except: Exception: + except Exception: self.passed = False if os.path.exists(output_abc_file) -- Gitee