Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/src/frontend/code_generator/user_callgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions frontend/tests/unit/test_callgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -55,15 +55,15 @@ 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
assert cfg.entry_point == 2


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'
Expand All @@ -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'
Expand All @@ -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()
Expand All @@ -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'
Expand Down
16 changes: 8 additions & 8 deletions frontend/tests/unit/test_source_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down