From ba7ed526860ebec73c16e3bc933c23fb1119313f Mon Sep 17 00:00:00 2001 From: Sam Xi Date: Mon, 9 Nov 2020 09:39:32 -0800 Subject: [PATCH] Use "pbtxt" extension for textprotos in code_generators. pbtxt, not pbtext, is the canonical extension. --- .../frontend/code_generator/user_callgraph.py | 4 ++-- ...ct.pbtext => branch_conditional_direct.pbtxt} | 0 ...rect_call.pbtext => branch_direct_call.pbtxt} | 0 ....pbtext => branch_implicit_fallthrough.pbtxt} | 0 ...nch_indirect.pbtext => branch_indirect.pbtxt} | 0 ...ct_call.pbtext => branch_indirect_call.pbtxt} | 0 ...xt => branch_indirect_call_multitarget.pbtxt} | 0 ...btext => conflictingfunction_codeblock.pbtxt} | 0 ...targets.pbtext => missingbranchtargets.pbtxt} | 0 ...ockbody.pbtext => missingcodeblockbody.pbtxt} | 0 .../{missingentry.pbtext => missingentry.pbtxt} | 0 ...ngsignature.pbtext => missingsignature.pbtxt} | 0 .../{onecallchain.pbtext => onecallchain.pbtxt} | 0 .../{onefunction.pbtext => onefunction.pbtxt} | 0 ...lvars.pbtext => onefunction_globalvars.pbtxt} | 0 ...ll_callchain.pbtext => small_callchain.pbtxt} | 0 frontend/tests/unit/test_callgraph.py | 14 +++++++------- frontend/tests/unit/test_source_generator.py | 16 ++++++++-------- 18 files changed, 17 insertions(+), 17 deletions(-) rename frontend/tests/resources/{branch_conditional_direct.pbtext => branch_conditional_direct.pbtxt} (100%) rename frontend/tests/resources/{branch_direct_call.pbtext => branch_direct_call.pbtxt} (100%) rename frontend/tests/resources/{branch_implicit_fallthrough.pbtext => branch_implicit_fallthrough.pbtxt} (100%) rename frontend/tests/resources/{branch_indirect.pbtext => branch_indirect.pbtxt} (100%) rename frontend/tests/resources/{branch_indirect_call.pbtext => branch_indirect_call.pbtxt} (100%) rename frontend/tests/resources/{branch_indirect_call_multitarget.pbtext => branch_indirect_call_multitarget.pbtxt} (100%) rename frontend/tests/resources/{conflictingfunction_codeblock.pbtext => conflictingfunction_codeblock.pbtxt} (100%) rename frontend/tests/resources/{missingbranchtargets.pbtext => missingbranchtargets.pbtxt} (100%) rename frontend/tests/resources/{missingcodeblockbody.pbtext => missingcodeblockbody.pbtxt} (100%) rename frontend/tests/resources/{missingentry.pbtext => missingentry.pbtxt} (100%) rename frontend/tests/resources/{missingsignature.pbtext => missingsignature.pbtxt} (100%) rename frontend/tests/resources/{onecallchain.pbtext => onecallchain.pbtxt} (100%) rename frontend/tests/resources/{onefunction.pbtext => onefunction.pbtxt} (100%) rename frontend/tests/resources/{onefunction_globalvars.pbtext => onefunction_globalvars.pbtxt} (100%) rename frontend/tests/resources/{small_callchain.pbtext => small_callchain.pbtxt} (100%) diff --git a/frontend/src/frontend/code_generator/user_callgraph.py b/frontend/src/frontend/code_generator/user_callgraph.py index 756a81b..172cdf0 100644 --- a/frontend/src/frontend/code_generator/user_callgraph.py +++ b/frontend/src/frontend/code_generator/user_callgraph.py @@ -59,11 +59,11 @@ def _load_cfg_from_file(path: str) -> cfg_pb2.CFG: with open(path, 'rb') as f: if path.endswith('pb'): cfg.ParseFromString(f.read()) - elif path.endswith('pbtext'): + elif path.endswith('pbtxt'): text_format.Parse(f.read(), cfg) else: raise RuntimeError( - 'Invalid protobuf suffix found, expected .pb or .pbtext') + 'Invalid protobuf suffix found, expected .pb or .pbtxt') return cfg def format_vars_definition(self) -> str: diff --git a/frontend/tests/resources/branch_conditional_direct.pbtext b/frontend/tests/resources/branch_conditional_direct.pbtxt similarity index 100% rename from frontend/tests/resources/branch_conditional_direct.pbtext rename to frontend/tests/resources/branch_conditional_direct.pbtxt diff --git a/frontend/tests/resources/branch_direct_call.pbtext b/frontend/tests/resources/branch_direct_call.pbtxt similarity index 100% rename from frontend/tests/resources/branch_direct_call.pbtext rename to frontend/tests/resources/branch_direct_call.pbtxt diff --git a/frontend/tests/resources/branch_implicit_fallthrough.pbtext b/frontend/tests/resources/branch_implicit_fallthrough.pbtxt similarity index 100% rename from frontend/tests/resources/branch_implicit_fallthrough.pbtext rename to frontend/tests/resources/branch_implicit_fallthrough.pbtxt diff --git a/frontend/tests/resources/branch_indirect.pbtext b/frontend/tests/resources/branch_indirect.pbtxt similarity index 100% rename from frontend/tests/resources/branch_indirect.pbtext rename to frontend/tests/resources/branch_indirect.pbtxt diff --git a/frontend/tests/resources/branch_indirect_call.pbtext b/frontend/tests/resources/branch_indirect_call.pbtxt similarity index 100% rename from frontend/tests/resources/branch_indirect_call.pbtext rename to frontend/tests/resources/branch_indirect_call.pbtxt diff --git a/frontend/tests/resources/branch_indirect_call_multitarget.pbtext b/frontend/tests/resources/branch_indirect_call_multitarget.pbtxt similarity index 100% rename from frontend/tests/resources/branch_indirect_call_multitarget.pbtext rename to frontend/tests/resources/branch_indirect_call_multitarget.pbtxt diff --git a/frontend/tests/resources/conflictingfunction_codeblock.pbtext b/frontend/tests/resources/conflictingfunction_codeblock.pbtxt similarity index 100% rename from frontend/tests/resources/conflictingfunction_codeblock.pbtext rename to frontend/tests/resources/conflictingfunction_codeblock.pbtxt diff --git a/frontend/tests/resources/missingbranchtargets.pbtext b/frontend/tests/resources/missingbranchtargets.pbtxt similarity index 100% rename from frontend/tests/resources/missingbranchtargets.pbtext rename to frontend/tests/resources/missingbranchtargets.pbtxt diff --git a/frontend/tests/resources/missingcodeblockbody.pbtext b/frontend/tests/resources/missingcodeblockbody.pbtxt similarity index 100% rename from frontend/tests/resources/missingcodeblockbody.pbtext rename to frontend/tests/resources/missingcodeblockbody.pbtxt diff --git a/frontend/tests/resources/missingentry.pbtext b/frontend/tests/resources/missingentry.pbtxt similarity index 100% rename from frontend/tests/resources/missingentry.pbtext rename to frontend/tests/resources/missingentry.pbtxt diff --git a/frontend/tests/resources/missingsignature.pbtext b/frontend/tests/resources/missingsignature.pbtxt similarity index 100% rename from frontend/tests/resources/missingsignature.pbtext rename to frontend/tests/resources/missingsignature.pbtxt diff --git a/frontend/tests/resources/onecallchain.pbtext b/frontend/tests/resources/onecallchain.pbtxt similarity index 100% rename from frontend/tests/resources/onecallchain.pbtext rename to frontend/tests/resources/onecallchain.pbtxt diff --git a/frontend/tests/resources/onefunction.pbtext b/frontend/tests/resources/onefunction.pbtxt similarity index 100% rename from frontend/tests/resources/onefunction.pbtext rename to frontend/tests/resources/onefunction.pbtxt diff --git a/frontend/tests/resources/onefunction_globalvars.pbtext b/frontend/tests/resources/onefunction_globalvars.pbtxt similarity index 100% rename from frontend/tests/resources/onefunction_globalvars.pbtext rename to frontend/tests/resources/onefunction_globalvars.pbtxt diff --git a/frontend/tests/resources/small_callchain.pbtext b/frontend/tests/resources/small_callchain.pbtxt similarity index 100% rename from frontend/tests/resources/small_callchain.pbtext rename to frontend/tests/resources/small_callchain.pbtxt diff --git a/frontend/tests/unit/test_callgraph.py b/frontend/tests/unit/test_callgraph.py index 6dfdb60..7b6bfc7 100644 --- a/frontend/tests/unit/test_callgraph.py +++ b/frontend/tests/unit/test_callgraph.py @@ -27,7 +27,7 @@ def test_callgraph_from_proto_file(resources): def test_get_formatted_headers_onecallchain(resources): - test_file = os.path.join(resources, 'onecallchain.pbtext') + test_file = os.path.join(resources, 'onecallchain.pbtxt') expected = ('void function_2();\n' 'void function_3();\n' 'void function_4();\n' @@ -39,7 +39,7 @@ def test_get_formatted_headers_onecallchain(resources): def test_load_onecallchain(resources): - test_file = os.path.join(resources, 'onecallchain.pbtext') + test_file = os.path.join(resources, 'onecallchain.pbtxt') cfg = user_callgraph.Callgraph.from_proto(test_file) assert isinstance(cfg, user_callgraph.Callgraph) assert len(cfg.functions) == 5 @@ -55,7 +55,7 @@ def test_load_binary_proto(resources): def test_load_onefunction(resources): - test_file = os.path.join(resources, 'onefunction.pbtext') + test_file = os.path.join(resources, 'onefunction.pbtxt') cfg = user_callgraph.Callgraph.from_proto(test_file) assert isinstance(cfg, user_callgraph.Callgraph) assert len(cfg.functions) == 1 @@ -63,7 +63,7 @@ def test_load_onefunction(resources): def test_print_function_onefunction(resources): - test_file = os.path.join(resources, 'onefunction.pbtext') + test_file = os.path.join(resources, 'onefunction.pbtxt') expected = ('void function_19() {\n' 'label1:;\n' 'int x = 1;\n' @@ -77,7 +77,7 @@ def test_print_function_onefunction(resources): def test_print_function_onecallchain(resources): - test_file = os.path.join(resources, 'onecallchain.pbtext') + test_file = os.path.join(resources, 'onecallchain.pbtxt') expected_2 = ('void function_2() {\n' 'label74:;\n' 'int x = 1;\n' @@ -100,7 +100,7 @@ def test_print_function_onecallchain(resources): def test_get_formatted_headers_onefunction(resources): - test_file = os.path.join(resources, 'onefunction.pbtext') + test_file = os.path.join(resources, 'onefunction.pbtxt') expected = 'void function_19();\n' cfg = user_callgraph.Callgraph.from_proto(test_file) output = cfg.format_headers() @@ -109,7 +109,7 @@ def test_get_formatted_headers_onefunction(resources): def test_indirect_branch_multitarget(resources): test_file = os.path.join(resources, - 'branch_indirect_call_multitarget.pbtext') + 'branch_indirect_call_multitarget.pbtxt') blocks.Branch.set_seed(0) expected = ( 'static int index_1034 = 0;\n' diff --git a/frontend/tests/unit/test_source_generator.py b/frontend/tests/unit/test_source_generator.py index 814c91b..6a2a64d 100644 --- a/frontend/tests/unit/test_source_generator.py +++ b/frontend/tests/unit/test_source_generator.py @@ -28,7 +28,7 @@ def resources(rootdir): @pytest.mark.parametrize( 'pbfile', - ['branch_indirect_call.pbtext', 'branch_indirect_call_multitarget.pbtext']) + ['branch_indirect_call.pbtxt', 'branch_indirect_call_multitarget.pbtxt']) def test_branch_indirect_call(resources, tmpdir, pbfile): test_file = os.path.join(resources, pbfile) cfg = user_callgraph.Callgraph.from_proto(test_file) @@ -45,7 +45,7 @@ def test_branch_indirect_call(resources, tmpdir, pbfile): def test_branch_direct_call(resources, tmpdir): - test_file = os.path.join(resources, 'branch_direct_call.pbtext') + test_file = os.path.join(resources, 'branch_direct_call.pbtxt') cfg = user_callgraph.Callgraph.from_proto(test_file) source_gen = source_generator.SourceGenerator(tmpdir, cfg) source_gen.write_files() @@ -60,7 +60,7 @@ def test_branch_direct_call(resources, tmpdir): def test_branch_indirect(resources, tmpdir): - test_file = os.path.join(resources, 'branch_indirect.pbtext') + test_file = os.path.join(resources, 'branch_indirect.pbtxt') cfg = user_callgraph.Callgraph.from_proto(test_file) source_gen = source_generator.SourceGenerator(tmpdir, cfg) source_gen.write_files() @@ -75,7 +75,7 @@ def test_branch_indirect(resources, tmpdir): def test_branch_conditional_direct(resources, tmpdir): - test_file = os.path.join(resources, 'branch_conditional_direct.pbtext') + test_file = os.path.join(resources, 'branch_conditional_direct.pbtxt') cfg = user_callgraph.Callgraph.from_proto(test_file) source_gen = source_generator.SourceGenerator(tmpdir, cfg) source_gen.write_files() @@ -86,7 +86,7 @@ def test_branch_conditional_direct(resources, tmpdir): def test_branch_implicit_fallthrough(resources, tmpdir): - test_file = os.path.join(resources, 'branch_implicit_fallthrough.pbtext') + test_file = os.path.join(resources, 'branch_implicit_fallthrough.pbtxt') cfg = user_callgraph.Callgraph.from_proto(test_file) source_gen = source_generator.SourceGenerator(tmpdir, cfg) source_gen.write_files() @@ -131,7 +131,7 @@ def check_for_asm(binary: str, symbol: str, asm: str) -> bool: def test_write_onefunction(resources, tmpdir): - test_file = os.path.join(resources, 'onefunction.pbtext') + test_file = os.path.join(resources, 'onefunction.pbtxt') expected_dir = os.path.join(resources, 'write_onefunction') cfg = user_callgraph.Callgraph.from_proto(test_file) source_gen = source_generator.SourceGenerator(tmpdir, cfg) @@ -142,7 +142,7 @@ def test_write_onefunction(resources, tmpdir): def test_write_onefunction_globalvars(resources, tmpdir): - test_file = os.path.join(resources, 'onefunction_globalvars.pbtext') + test_file = os.path.join(resources, 'onefunction_globalvars.pbtxt') expected_dir = os.path.join(resources, 'write_onefunction_globalvars') cfg = user_callgraph.Callgraph.from_proto(test_file) source_gen = source_generator.SourceGenerator(tmpdir, cfg) @@ -153,7 +153,7 @@ def test_write_onefunction_globalvars(resources, tmpdir): def test_write_onecallchain(resources, tmpdir): - test_file = os.path.join(resources, 'onecallchain.pbtext') + test_file = os.path.join(resources, 'onecallchain.pbtxt') expected_dir = os.path.join(resources, 'write_onecallchain') cfg = user_callgraph.Callgraph.from_proto(test_file) source_gen = source_generator.SourceGenerator(tmpdir, cfg)