From 7ba7fd5922a366b44cecf523992911b6e22f7420 Mon Sep 17 00:00:00 2001 From: TejasweeSulekh <75196163+TejasweeSulekh@users.noreply.github.com> Date: Sun, 27 Sep 2026 19:24:45 +0530 Subject: [PATCH] Introduced testcase for model with root_ops --- codegen/tools/test/test_gen_oplist.py | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/codegen/tools/test/test_gen_oplist.py b/codegen/tools/test/test_gen_oplist.py index 18689cd2505..1ec5aa6ecee 100644 --- a/codegen/tools/test/test_gen_oplist.py +++ b/codegen/tools/test/test_gen_oplist.py @@ -255,6 +255,42 @@ def test_get_kernel_metadata_from_ops_yaml(self) -> None: "default", ) + @patch("executorch.codegen.tools.gen_oplist._get_kernel_metadata_for_model") + @patch("executorch.codegen.tools.gen_oplist._get_operators") + @patch("executorch.codegen.tools.gen_oplist._dump_yaml") + def test_gen_op_list_with_model_and_root_ops( + self, + mock_dump_yaml, + mock_get_operators, + mock_get_kernel_metadata_for_model, + ) -> None: + mock_get_operators.return_value = ["aten::sub"] + mock_get_kernel_metadata_for_model.return_value = {"aten::sub": ["v1/6;"]} + + output_path = os.path.join(self.temp_dir.name, "output.yaml") + temp_file = tempfile.NamedTemporaryFile() + + args = [ + f"--output_path={output_path}", + "--root_ops=aten::add", + f"--model_file_path={temp_file.name}", + ] + + gen_oplist.main(args) + + # Verify that gen_oplist combined BOTH operators into the final output + mock_dump_yaml.assert_called_once_with( + ["aten::add", "aten::sub"], + Path(output_path), + temp_file.name, + { + "aten::add": ["default"], + "aten::sub": ["v1/6;"], + }, + False, + ) + temp_file.close() + def tearDown(self): self.temp_dir.cleanup()