Skip to content

Commit 24b22ed

Browse files
author
Bar Soloveychik
committed
added test that check archive names
1 parent c1d0e30 commit 24b22ed

File tree

6 files changed

+80
-19
lines changed

6 files changed

+80
-19
lines changed
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1-
C_SOURCES := main.c
1+
C_SOURCES := main.c a.c b.c c.c
2+
EXE := # Define a.out explicitly
3+
MAKE_DSYM := NO
4+
5+
all: a.out
6+
7+
a.out: main.o libfoo.a
8+
$(LD) $(LDFLAGS) $^ -o $@
9+
10+
libfoo.a: a.o b.o
11+
$(AR) $(ARFLAGS) $@ $^
212

313
include Makefile.rules

lldb/test/API/python_api/sbmodule/TestSBModule.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,40 @@ def tearDown(self):
1818
if self.background_pid:
1919
os.kill(self.background_pid, signal.SIGKILL)
2020

21-
def test_getname(self):
22-
"""Test the SBModule::GetName() method"""
21+
@skipIfRemote
22+
def test_GetObjectName(self):
23+
"""Test the SBModule::GetObjectName() method"""
2324
self.build()
24-
target, _, _, _ = lldbutil.run_to_source_breakpoint(
25-
self, "// break here", lldb.SBFileSpec("main.c")
26-
)
25+
exe = self.getBuildArtifact("a.out")
26+
libfoo_path = self.getBuildArtifact("libfoo.a")
27+
target_exe = self.dbg.CreateTarget(exe)
28+
self.assertTrue(target_exe.IsValid(), "Target for a.out is valid")
29+
30+
# Test that the executable module has no object name (usually the first module in the target)
31+
exe_module = target_exe.GetModuleAtIndex(0)
32+
self.assertTrue(exe_module.IsValid(), "Executable module is valid")
33+
self.assertIsNone(exe_module.GetObjectName(), "a.out should have no object name")
34+
35+
# check archive member names
36+
module_specs = lldb.SBModuleSpecList.GetModuleSpecifications(libfoo_path)
37+
self.assertGreater(module_specs.GetSize(), 0, "Archive should have at least one module spec")
38+
target = self.dbg.CreateTarget(None)
39+
self.assertTrue(target.IsValid(), "Target is valid")
40+
found = set()
41+
expected = {"a.o", "b.o"}
42+
for i in range(module_specs.GetSize()):
43+
spec = module_specs.GetSpecAtIndex(i)
44+
obj_name = spec.GetObjectName()
45+
self.assertIsInstance(obj_name, str)
46+
self.assertIn(obj_name, expected, f"Unexpected object name: {obj_name}")
47+
#create a module from the arhive using the sepc
48+
module = target.AddModule(spec)
49+
self.assertTrue(module.IsValid(), "Module is valid")
50+
self.assertTrue(module.IsValid(), f"Module for {obj_name} is valid")
51+
self.assertEqual(module.GetObjectName(), obj_name, f"Object name for {obj_name} matches")
52+
found.add(obj_name)
53+
self.assertEqual(found, expected, "Did not find all expected archive members")
2754

28-
self.assertGreater(target.GetNumModules(), 0)
29-
for i in range(target.GetNumModules()):
30-
module = target.GetModuleAtIndex(i)
31-
file_spec = module.GetFileSpec()
32-
name = module.GetName()
33-
if file_spec.IsValid() and file_spec.exists:
34-
#If file is valid and file exist, expect GetName() to be None
35-
self.assertIsNone(name, f"Expected None for module with valid file {file_spec.GetFilename()}, got {name!r}")
36-
else:
37-
#If no valid file, expect GetName() to be a non - empty string
38-
self.assertIsInstance(name, str)
39-
self.assertTrue(name, "Expected a non-empty name for module without a valid file")
40-
4155
@skipUnlessDarwin
4256
@skipIfRemote
4357
def test_module_is_file_backed(self):

lldb/test/API/python_api/sbmodule/a.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
int __a_global = 1;
2+
3+
int a(int arg) {
4+
int result = arg + __a_global;
5+
return result; // Set file and line breakpoint inside a().
6+
}
7+
8+
int aa(int arg1) {
9+
int result1 = arg1 - __a_global;
10+
return result1;
11+
}

lldb/test/API/python_api/sbmodule/b.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
static int __b_global = 2;
2+
char __extra[4096]; // Make sure sizeof b.o differs from a.o and c.o
3+
4+
int b(int arg) {
5+
int result = arg + __b_global;
6+
return result;
7+
}
8+
9+
int bb(int arg1) {
10+
int result2 = arg1 - __b_global;
11+
return result2;
12+
}

lldb/test/API/python_api/sbmodule/c.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
static int __c_global = 3;
2+
char __extra[4096]; // Make sure sizeof b.o differs from a.o and c.o
3+
char __extra2[4096]; // Make sure sizeof b.o differs from a.o and c.o
4+
int c(int arg) {
5+
int result = arg + __c_global;
6+
return result;
7+
}
8+
9+
int cc(int arg1) {
10+
int result3 = arg1 - __c_global;
11+
return result3;
12+
}

lldb/test/API/python_api/sbmodule/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
extern int a(int);
2+
extern int b(int);
13
int main() {
24
while (1) // break here
35
;

0 commit comments

Comments
 (0)