[Lldb-commits] [lldb] r190815 - Add test suite support for TestLoadUnload.py for Linux.

Matt Kopec Matt.Kopec at intel.com
Mon Sep 16 15:34:36 PDT 2013


Author: mkopec
Date: Mon Sep 16 17:34:36 2013
New Revision: 190815

URL: http://llvm.org/viewvc/llvm-project?rev=190815&view=rev
Log:
Add test suite support for TestLoadUnload.py for Linux.

Modified:
    lldb/trunk/test/functionalities/load_unload/Makefile
    lldb/trunk/test/functionalities/load_unload/TestLoadUnload.py
    lldb/trunk/test/functionalities/load_unload/main.c

Modified: lldb/trunk/test/functionalities/load_unload/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/load_unload/Makefile?rev=190815&r1=190814&r2=190815&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/load_unload/Makefile (original)
+++ lldb/trunk/test/functionalities/load_unload/Makefile Mon Sep 16 17:34:36 2013
@@ -1,51 +1,77 @@
-all: a.out liba.dylib libb.dylib libc.dylib libd.dylib
-
 CC ?= clang
 ifeq "$(ARCH)" ""
 	ARCH = x86_64
 endif
-CFLAGS ?=-arch $(ARCH) -g -O0
+
+ifeq "$(OS)" ""
+	OS = $(shell uname -s)
+endif
+
+CFLAGS ?= -g -O0
 CWD := $(shell pwd)
 
-all: a.out hidden/libd.dylib
+ifeq "$(OS)" "Darwin"
+	CFLAGS += -arch $(ARCH)
+	DS := dsymutil
+	LD_FLAGS := -dynamiclib
+	LIB_A := liba.dylib
+	LIB_B := libb.dylib
+	LIB_C := libc.dylib
+	LIB_D := libd.dylib
+	EXEC_PATH := "@executable_path"
+	EXEC_PATH_A := -install_name $(EXEC_PATH)/$(LIB_A)
+	EXEC_PATH_B := -install_name $(EXEC_PATH)/$(LIB_B)
+	EXEC_PATH_C := -install_name $(EXEC_PATH)/$(LIB_C)
+	EXEC_PATH_D := -install_name $(CWD)/$(LIB_D)
+else
+	CFLAGS += -fPIC
+	LD_FLAGS := -shared
+	LIB_DL := -ldl
+	LIB_A := liba.so
+	LIB_B := libb.so
+	LIB_C := libc.so
+	LIB_D := libd.so
+endif
+
+all: a.out $(LIB_A) $(LIB_B) $(LIB_C) $(LIB_D) hidden/$(LIB_D)
 
-a.out: main.o libd.dylib
-	$(CC) $(CFLAGS) -o a.out main.o -L. -ld
+a.out: main.o $(LIB_D)
+	$(CC) $(CFLAGS) -o a.out main.o -L. -ld $(LIB_DL)
 
 main.o: main.c
 	$(CC) $(CFLAGS) -c main.c
 
-hidden/libd.dylib: b.o
-	$(CC) $(CFLAGS) -dynamiclib -o hidden/libd.dylib d.o
-	dsymutil -o hidden/libd.dylib.dSYM hidden/libd.dylib
-
-liba.dylib: a.o libb.dylib
-	$(CC) $(CFLAGS) -dynamiclib -install_name "@executable_path/liba.dylib" -o liba.dylib a.o -L. -lb
-	dsymutil liba.dylib
+hidden/$(LIB_D): b.o
+	$(CC) $(CFLAGS) $(LD_FLAGS) -o hidden/$(LIB_D) d.o
+	if [ "$(OS)" = "Darwin" ]; then dsymutil -o hidden/$(LIB_D).dSYM hidden/$(LIB_D); fi
+
+$(LIB_A): a.o $(LIB_B)
+	$(CC) $(CFLAGS) $(LD_FLAGS) $(EXEC_PATH_A) -o $(LIB_A) a.o -L. -lb
+	if [ "$(OS)" = "Darwin" ]; then dsymutil $(LIB_A); fi
 
 a.o: a.c
 	$(CC) $(CFLAGS) -c a.c
 
-libb.dylib: b.o
-	$(CC) $(CFLAGS) -dynamiclib -install_name "@executable_path/libb.dylib" -o libb.dylib b.o
-	dsymutil libb.dylib
+$(LIB_B): b.o
+	$(CC) $(CFLAGS) $(LD_FLAGS) $(EXEC_PATH_B) -o $(LIB_B) b.o
+	if [ "$(OS)" = "Darwin" ]; then dsymutil $(LIB_B); fi
 
 b.o: b.c
 	$(CC) $(CFLAGS) -c b.c
 
-libc.dylib: c.o
-	$(CC) $(CFLAGS) -dynamiclib -install_name "@executable_path/libc.dylib" -o libc.dylib c.o
-	dsymutil libc.dylib
+$(LIB_C): c.o
+	$(CC) $(CFLAGS) $(LD_FLAGS) $(EXEC_PATH_C) -o $(LIB_C) c.o
+	if [ "$(OS)" = "Darwin" ]; then dsymutil $(LIB_C); fi
 
 c.o: c.c
 	$(CC) $(CFLAGS) -c c.c
 
-libd.dylib: d.o
-	$(CC) $(CFLAGS) -dynamiclib -install_name "$(CWD)/libd.dylib" -o libd.dylib d.o
-	dsymutil libd.dylib
+$(LIB_D): d.o
+	$(CC) $(CFLAGS) $(LD_FLAGS) $(EXEC_PATH_D) -o $(LIB_D) d.o
+	if [ "$(OS)" = "Darwin" ]; then dsymutil $(LIB_D); fi
 
 d.o: d.c
 	$(CC) $(CFLAGS) -c d.c
 
 clean:
-	rm -rf *.o *~ *.dylib a.out *.dSYM hidden/*
+	rm -rf *.o *~ *.dylib *.so a.out *.dSYM hidden/*

Modified: lldb/trunk/test/functionalities/load_unload/TestLoadUnload.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/load_unload/TestLoadUnload.py?rev=190815&r1=190814&r2=190815&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/load_unload/TestLoadUnload.py (original)
+++ lldb/trunk/test/functionalities/load_unload/TestLoadUnload.py Mon Sep 16 17:34:36 2013
@@ -24,9 +24,13 @@ class LoadUnloadTestCase(TestBase):
                                 '// Set break point at this line for test_lldb_process_load_and_unload_commands().')
         self.line_d_function = line_number('d.c',
                                            '// Find this line number within d_dunction().')
+        if not sys.platform.startswith("darwin"):
+            if "LD_LIBRARY_PATH" in os.environ:
+                self.runCmd("settings set target.env-vars " + self.dylibPath + "=" + os.environ["LD_LIBRARY_PATH"] + ":" + os.getcwd())
+            else:
+                self.runCmd("settings set target.env-vars " + self.dylibPath + "=" + os.getcwd())
 
     @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
-    @skipIfLinux # llvm.org/pr14424 - missing linux Makefiles/testcase support
     @not_remote_testsuite_ready
     def test_modules_search_paths(self):
         """Test target modules list after loading a different copy of the library libd.dylib, and verifies that it works with 'target modules search-paths add'."""
@@ -36,6 +40,8 @@ class LoadUnloadTestCase(TestBase):
 
         if sys.platform.startswith("darwin"):
             dylibName = 'libd.dylib'
+        else:
+            dylibName = 'libd.so'
 
         # The directory with the dynamic library we did not link to.
         new_dir = os.path.join(os.getcwd(), "hidden")
@@ -65,7 +71,7 @@ class LoadUnloadTestCase(TestBase):
 
         # Obliterate traces of libd from the old location.
         os.remove(old_dylib)
-        # Inform dyld of the new path, too.
+        # Inform (DY)LD_LIBRARY_PATH of the new path, too.
         env_cmd_string = "settings set target.env-vars " + self.dylibPath + "=" + new_dir
         if self.TraceOn():
             print "Set environment to: ", env_cmd_string
@@ -81,10 +87,9 @@ class LoadUnloadTestCase(TestBase):
             substrs = [new_dylib])
 
     @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
-    @skipIfLinux # llvm.org/pr14424 - missing linux Makefiles/testcase support
     @not_remote_testsuite_ready
     def test_dyld_library_path(self):
-        """Test DYLD_LIBRARY_PATH after moving libd.dylib, which defines d_function, somewhere else."""
+        """Test (DY)LD_LIBRARY_PATH after moving libd.dylib, which defines d_function, somewhere else."""
 
         # Invoke the default build rule.
         self.buildDefault()
@@ -95,6 +100,8 @@ class LoadUnloadTestCase(TestBase):
         if sys.platform.startswith("darwin"):
             dylibName = 'libd.dylib'
             dsymName = 'libd.dylib.dSYM'
+        else:
+            dylibName = 'libd.so'
 
         # The directory to relocate the dynamic library and its debugging info.
         special_dir = "hidden"
@@ -102,15 +109,16 @@ class LoadUnloadTestCase(TestBase):
 
         old_dylib = os.path.join(os.getcwd(), dylibName)
         new_dylib = os.path.join(new_dir, dylibName)
-        old_dSYM = os.path.join(os.getcwd(), dsymName)
-        new_dSYM = os.path.join(new_dir, dsymName)
 
         #system(["ls", "-lR", "."])
 
-        # Try running with the DYLD_LIBRARY_PATH environment variable set, make sure
+        # Try running with the (DY)LD_LIBRARY_PATH environment variable set, make sure
         # we pick up the hidden dylib.
 
         env_cmd_string = "settings set target.env-vars " + self.dylibPath + "=" + new_dir
+        if not sys.platform.startswith("darwin"):
+            env_cmd_string += ":" + os.getcwd()
+
         if self.TraceOn():
             print "Set environment to: ", env_cmd_string
         self.runCmd(env_cmd_string)
@@ -121,7 +129,7 @@ class LoadUnloadTestCase(TestBase):
 
         lldbutil.run_break_set_by_file_and_line (self, "d.c", self.line_d_function, num_expected_locations=1, loc_exact=True)
 
-        # For now we don't track DYLD_LIBRARY_PATH, so the old library will be in
+        # For now we don't track (DY)LD_LIBRARY_PATH, so the old library will be in
         # the modules list.
         self.expect("target modules list",
             substrs = [os.path.basename(old_dylib)],
@@ -138,7 +146,6 @@ class LoadUnloadTestCase(TestBase):
 
     @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
     @not_remote_testsuite_ready
-    @skipIfLinux # llvm.org/pr14424 - missing linux Makefiles/testcase support
     def test_lldb_process_load_and_unload_commands(self):
         """Test that lldb process load/unload command work correctly."""
 
@@ -160,9 +167,14 @@ class LoadUnloadTestCase(TestBase):
                     error=True, matching=False,
             patterns = ["1 match found .* %s" % self.mydir])
 
+        if sys.platform.startswith("darwin"):
+            dylibName = 'liba.dylib'
+        else:
+            dylibName = 'liba.so'
+
         # Use lldb 'process load' to load the dylib.
-        self.expect("process load liba.dylib", "liba.dylib loaded correctly",
-            patterns = ['Loading "liba.dylib".*ok',
+        self.expect("process load %s" % dylibName, "%s loaded correctly" % dylibName,
+            patterns = ['Loading "%s".*ok' % dylibName,
                         'Image [0-9]+ loaded'])
 
         # Search for and match the "Image ([0-9]+) loaded" pattern.
@@ -180,14 +192,13 @@ class LoadUnloadTestCase(TestBase):
             patterns = ["1 match found .*%s" % self.mydir])
 
         # Use lldb 'process unload' to unload the dylib.
-        self.expect("process unload %s" % index, "liba.dylib unloaded correctly",
+        self.expect("process unload %s" % index, "%s unloaded correctly" % dylibName,
             patterns = ["Unloading .* with index %s.*ok" % index])
 
         self.runCmd("process continue")
 
     @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
     @not_remote_testsuite_ready
-    @skipIfLinux # llvm.org/pr14424 - missing linux Makefiles/testcase support
     def test_load_unload(self):
         """Test breakpoint by name works correctly with dlopen'ing."""
 
@@ -229,7 +240,6 @@ class LoadUnloadTestCase(TestBase):
 
     @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
     @not_remote_testsuite_ready
-    @skipIfLinux # llvm.org/pr14424 - missing linux Makefiles/testcase support
     def test_step_over_load (self):
         """Test stepping over code that loads a shared library works correctly."""
 

Modified: lldb/trunk/test/functionalities/load_unload/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/load_unload/main.c?rev=190815&r1=190814&r2=190815&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/load_unload/main.c (original)
+++ lldb/trunk/test/functionalities/load_unload/main.c Mon Sep 16 17:34:36 2013
@@ -17,8 +17,13 @@
 int
 main (int argc, char const *argv[])
 {
+#if defined (__APPLE__)
     const char *a_name = "@executable_path/liba.dylib";
     const char *c_name = "@executable_path/libc.dylib";
+#else
+    const char *a_name = "liba.so";
+    const char *c_name = "libc.so";
+#endif
     void *a_dylib_handle = NULL;
     void *c_dylib_handle = NULL;
     int (*a_function) (void);





More information about the lldb-commits mailing list