Skip to content

Commit 58f6ac6

Browse files
Add unittests for new d2d modules
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
1 parent 09c0e55 commit 58f6ac6

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed
1004 Bytes
Binary file not shown.
303 KB
Binary file not shown.

scanpipe/tests/pipes/test_d2d.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,73 @@ def test_scanpipe_pipes_d2d_map_ruby(self):
15801580
).count(),
15811581
)
15821582

1583+
@skipIf(sys.platform == "darwin", "Test is failing on macOS")
1584+
def test_scanpipe_pipes_d2d_extract_binary_symbols_from_resources(self):
1585+
input_dir = self.project1.input_path
1586+
input_resources = [
1587+
self.data / "d2d-macho/to-ollama.zip",
1588+
self.data / "d2d-macho/from-ollama.zip",
1589+
]
1590+
copy_inputs(input_resources, input_dir)
1591+
self.from_files, self.to_files = d2d.get_inputs(self.project1)
1592+
inputs_with_codebase_path_destination = [
1593+
(self.from_files, self.project1.codebase_path / d2d.FROM),
1594+
(self.to_files, self.project1.codebase_path / d2d.TO),
1595+
]
1596+
for input_files, codebase_path in inputs_with_codebase_path_destination:
1597+
for input_file_path in input_files:
1598+
scancode.extract_archive(input_file_path, codebase_path)
1599+
1600+
scancode.extract_archives(
1601+
self.project1.codebase_path,
1602+
recurse=True,
1603+
)
1604+
pipes.collect_and_create_codebase_resources(self.project1)
1605+
buffer = io.StringIO()
1606+
1607+
binary_resource = self.project1.codebaseresources.get(
1608+
path="to/libggml-cpu-skylakex.so"
1609+
)
1610+
d2d.extract_binary_symbols_from_resources(
1611+
resources=[binary_resource],
1612+
binary_symbols_func=d2d.collect_and_parse_macho_symbols,
1613+
logger=buffer.write,
1614+
)
1615+
symbols = binary_resource.extra_data.get("macho_symbols")
1616+
self.assertNotEqual(symbols, [])
1617+
1618+
@skipIf(sys.platform == "darwin", "Test is failing on macOS")
1619+
def test_scanpipe_pipes_d2d_extract_binary_symbols(self):
1620+
input_dir = self.project1.input_path
1621+
input_resources = [
1622+
self.data / "d2d-macho/to-ollama.zip",
1623+
self.data / "d2d-macho/from-ollama.zip",
1624+
]
1625+
copy_inputs(input_resources, input_dir)
1626+
self.from_files, self.to_files = d2d.get_inputs(self.project1)
1627+
inputs_with_codebase_path_destination = [
1628+
(self.from_files, self.project1.codebase_path / d2d.FROM),
1629+
(self.to_files, self.project1.codebase_path / d2d.TO),
1630+
]
1631+
for input_files, codebase_path in inputs_with_codebase_path_destination:
1632+
for input_file_path in input_files:
1633+
scancode.extract_archive(input_file_path, codebase_path)
1634+
1635+
scancode.extract_archives(
1636+
self.project1.codebase_path,
1637+
recurse=True,
1638+
)
1639+
pipes.collect_and_create_codebase_resources(self.project1)
1640+
buffer = io.StringIO()
1641+
d2d.extract_binary_symbols(
1642+
project=self.project1, options=["Go"], logger=buffer.write
1643+
)
1644+
binary_resource = self.project1.codebaseresources.get(
1645+
path="to/libggml-cpu-skylakex.so"
1646+
)
1647+
symbols = binary_resource.extra_data.get("macho_symbols")
1648+
self.assertNotEqual(symbols, [])
1649+
15831650
@skipIf(sys.platform == "darwin", "Test is failing on macOS")
15841651
def test_scanpipe_pipes_d2d_map_rust_symbols(self):
15851652
input_dir = self.project1.input_path
@@ -1620,6 +1687,40 @@ def test_scanpipe_pipes_d2d_map_rust_symbols(self):
16201687
).count(),
16211688
)
16221689

1690+
@skipIf(sys.platform == "darwin", "Test is failing on macOS")
1691+
def test_scanpipe_pipes_d2d_map_go_symbols(self):
1692+
input_dir = self.project1.input_path
1693+
input_resources = [
1694+
self.data / "d2d-macho/to-ollama.zip",
1695+
self.data / "d2d-macho/from-ollama.zip",
1696+
]
1697+
copy_inputs(input_resources, input_dir)
1698+
self.from_files, self.to_files = d2d.get_inputs(self.project1)
1699+
inputs_with_codebase_path_destination = [
1700+
(self.from_files, self.project1.codebase_path / d2d.FROM),
1701+
(self.to_files, self.project1.codebase_path / d2d.TO),
1702+
]
1703+
for input_files, codebase_path in inputs_with_codebase_path_destination:
1704+
for input_file_path in input_files:
1705+
scancode.extract_archive(input_file_path, codebase_path)
1706+
1707+
scancode.extract_archives(
1708+
self.project1.codebase_path,
1709+
recurse=True,
1710+
)
1711+
pipes.collect_and_create_codebase_resources(self.project1)
1712+
buffer = io.StringIO()
1713+
d2d.extract_binary_symbols(
1714+
project=self.project1, options=["Go"], logger=buffer.write
1715+
)
1716+
d2d.map_go_binaries_with_symbols(project=self.project1, logger=buffer.write)
1717+
self.assertEqual(
1718+
1,
1719+
CodebaseRelation.objects.filter(
1720+
project=self.project1, map_type="macho_symbols"
1721+
).count(),
1722+
)
1723+
16231724
@skipIf(sys.platform == "darwin", "Test is failing on macOS")
16241725
def test_scanpipe_pipes_d2d_map_elf_symbols(self):
16251726
input_dir = self.project1.input_path

0 commit comments

Comments
 (0)