1d4c55
commit b4bbedb1e75737a80bcc3d53d6eef1fbe0b5f4d5
1d4c55
Author: H.J. Lu <hjl.tools@gmail.com>
1d4c55
Date:   Sat Nov 6 14:13:27 2021 -0700
1d4c55
1d4c55
    dso-ordering-test.py: Put all sources in one directory [BZ #28550]
1d4c55
    
1d4c55
    Put all sources for DSO sorting tests in the dso-sort-tests-src directory
1d4c55
    and compile test relocatable objects with
1d4c55
    
1d4c55
    $(objpfx)tst-dso-ordering1-dir/tst-dso-ordering1-a.os: $(objpfx)dso-sort-tests-src/tst-dso-ordering1-a.c
1d4c55
            $(compile.c) $(OUTPUT_OPTION)
1d4c55
    
1d4c55
    to avoid random $< values from $(before-compile) when compiling test
1d4c55
    relocatable objects with
1d4c55
    
1d4c55
    $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
1d4c55
    compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
1d4c55
    compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
1d4c55
    
1d4c55
    for 3 "make -j 28" parallel builds on a machine with 112 cores at the
1d4c55
    same time.
1d4c55
    
1d4c55
    This partially fixes BZ #28550.
1d4c55
    
1d4c55
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
1d4c55
1d4c55
diff --git a/scripts/dso-ordering-test.py b/scripts/dso-ordering-test.py
1d4c55
index 944ee740527d60fd..bde0406be9da14fc 100644
1d4c55
--- a/scripts/dso-ordering-test.py
1d4c55
+++ b/scripts/dso-ordering-test.py
1d4c55
@@ -526,9 +526,13 @@ def process_testcase(t):
1d4c55
     base_test_name = t.test_name
1d4c55
     test_subdir = base_test_name + "-dir"
1d4c55
     testpfx = objpfx + test_subdir + "/"
1d4c55
+    test_srcdir = "dso-sort-tests-src/"
1d4c55
+    testpfx_src = objpfx + test_srcdir
1d4c55
 
1d4c55
     if not os.path.exists(testpfx):
1d4c55
         os.mkdir(testpfx)
1d4c55
+    if not os.path.exists(testpfx_src):
1d4c55
+        os.mkdir(testpfx_src)
1d4c55
 
1d4c55
     def find_objs_not_depended_on(t):
1d4c55
         objs_not_depended_on = []
1d4c55
@@ -595,6 +599,11 @@ def process_testcase(t):
1d4c55
         # Print out needed Makefile fragments for use in glibc/elf/Makefile.
1d4c55
         module_names = ""
1d4c55
         for o in test_descr.objs:
1d4c55
+            rule = ("$(objpfx)" + test_subdir + "/" + test_name
1d4c55
+                    + "-" + o + ".os: $(objpfx)" + test_srcdir
1d4c55
+                    + test_name + "-" + o + ".c\n"
1d4c55
+                    "\t$(compile.c) $(OUTPUT_OPTION)\n")
1d4c55
+            makefile.write (rule)
1d4c55
             module_names += " " + test_subdir + "/" + test_name + "-" + o
1d4c55
         makefile.write("modules-names +=%s\n" % (module_names))
1d4c55
 
1d4c55
@@ -637,7 +646,7 @@ def process_testcase(t):
1d4c55
                         # object.  This only needs to be done at most once for
1d4c55
                         # an object name.
1d4c55
                         if not dep in fake_created:
1d4c55
-                            f = open(testpfx + test_name + "-" + dep
1d4c55
+                            f = open(testpfx_src + test_name + "-" + dep
1d4c55
                                      + ".FAKE.c", "w")
1d4c55
                             f.write(" \n")
1d4c55
                             f.close()
1d4c55
@@ -648,6 +657,12 @@ def process_testcase(t):
1d4c55
                                  % (test_name + "-" + dep + ".FAKE.so",
1d4c55
                                     ("$(objpfx)" + test_subdir + "/"
1d4c55
                                      + test_name + "-" + dep + ".so")))
1d4c55
+                            rule = ("$(objpfx)" + test_subdir + "/"
1d4c55
+                                    + test_name + "-" + dep + ".FAKE.os: "
1d4c55
+                                    "$(objpfx)" + test_srcdir
1d4c55
+                                    + test_name + "-" + dep + ".FAKE.c\n"
1d4c55
+                                    "\t$(compile.c) $(OUTPUT_OPTION)\n")
1d4c55
+                            makefile.write (rule)
1d4c55
                             makefile.write \
1d4c55
                                 ("modules-names += %s\n"
1d4c55
                                  % (test_subdir + "/"
1d4c55
@@ -687,6 +702,10 @@ def process_testcase(t):
1d4c55
                       + test_descr.soname_map['#'] + ".so")
1d4c55
             ldflags += (" -Wl,-soname=" + soname)
1d4c55
         makefile.write("LDFLAGS-%s = %s\n" % (test_name, ldflags))
1d4c55
+        rule = ("$(objpfx)" + test_subdir + "/" + test_name + ".o: "
1d4c55
+                "$(objpfx)" + test_srcdir + test_name + ".c\n"
1d4c55
+                "\t$(compile.c) $(OUTPUT_OPTION)\n")
1d4c55
+        makefile.write (rule)
1d4c55
 
1d4c55
         not_depended_objs = find_objs_not_depended_on(test_descr)
1d4c55
         if not_depended_objs:
1d4c55
@@ -745,7 +764,7 @@ def process_testcase(t):
1d4c55
                      "  something_failed=true\n"
1d4c55
                      "else\n"
1d4c55
                      "  diff -wu ${common_objpfx}elf/%s/%s%s.output \\\n"
1d4c55
-                     "           ${common_objpfx}elf/%s/%s%s.exp\n"
1d4c55
+                     "           ${common_objpfx}elf/%s%s%s.exp\n"
1d4c55
                      "  if [ $? -ne 0 ]; then\n"
1d4c55
                      "    echo '%sFAIL: %s%s expected output comparison'\n"
1d4c55
                      "    something_failed=true\n"
1d4c55
@@ -753,14 +772,14 @@ def process_testcase(t):
1d4c55
                      "fi\n"
1d4c55
                      % (("X" if xfail else ""), test_name, tunable_descr,
1d4c55
                         test_subdir, test_name, tunable_sfx,
1d4c55
-                        test_subdir, base_test_name, exp_tunable_sfx,
1d4c55
+                        test_srcdir, base_test_name, exp_tunable_sfx,
1d4c55
                         ("X" if xfail else ""), test_name, tunable_descr))
1d4c55
 
1d4c55
         # Generate C files according to dependency and calling relations from
1d4c55
         # description string.
1d4c55
         for obj in test_descr.objs:
1d4c55
             src_name = test_name + "-" + obj + ".c"
1d4c55
-            f = open(testpfx + src_name, "w")
1d4c55
+            f = open(testpfx_src + src_name, "w")
1d4c55
             if obj in test_descr.callrefs:
1d4c55
                 called_objs = test_descr.callrefs[obj]
1d4c55
                 for callee in called_objs:
1d4c55
@@ -804,7 +823,7 @@ def process_testcase(t):
1d4c55
             f.close()
1d4c55
 
1d4c55
         # Open C file for writing main program
1d4c55
-        f = open(testpfx + test_name + ".c", "w")
1d4c55
+        f = open(testpfx_src + test_name + ".c", "w")
1d4c55
 
1d4c55
         # if there are some operations in main(), it means we need -ldl
1d4c55
         f.write("#include <stdio.h>\n")
1d4c55
@@ -885,7 +904,7 @@ def process_testcase(t):
1d4c55
             for obj in test_descr.objs:
1d4c55
                 src_name = test_name + "-" + obj + ".c"
1d4c55
                 obj_name = test_name + "-" + obj + ".os"
1d4c55
-                run_cmd([build_gcc, "-c", "-fPIC", testpfx + src_name,
1d4c55
+                run_cmd([build_gcc, "-c", "-fPIC", testpfx_src + src_name,
1d4c55
                           "-o", testpfx + obj_name])
1d4c55
 
1d4c55
             obj_processed = {}
1d4c55
@@ -903,10 +922,12 @@ def process_testcase(t):
1d4c55
                             deps.append(dep + ".FAKE")
1d4c55
                             if not dep in fake_created:
1d4c55
                                 base_name = testpfx + test_name + "-" + dep
1d4c55
+                                src_base_name = (testpfx_src + test_name
1d4c55
+                                                 + "-" + dep)
1d4c55
                                 cmd = [build_gcc, "-Wl,--no-as-needed",
1d4c55
                                        ("-Wl,-soname=" + base_name + ".so"),
1d4c55
                                        "-shared", base_name + ".FAKE.c",
1d4c55
-                                       "-o", base_name + ".FAKE.so"]
1d4c55
+                                       "-o", src_base_name + ".FAKE.so"]
1d4c55
                                 run_cmd(cmd)
1d4c55
                                 fake_created[dep] = True
1d4c55
                 dso_deps = map(lambda d: testpfx + test_name + "-" + d + ".so",
1d4c55
@@ -932,7 +953,7 @@ def process_testcase(t):
1d4c55
             main_deps = map(lambda d: testpfx + test_name + "-" + d + ".so",
1d4c55
                             deps)
1d4c55
             cmd = [build_gcc, "-Wl,--no-as-needed", "-o", testpfx + test_name,
1d4c55
-                   testpfx + test_name + ".c", "-L%s" % (os.getcwd()),
1d4c55
+                   testpfx_src + test_name + ".c", "-L%s" % (os.getcwd()),
1d4c55
                    "-Wl,-rpath-link=%s" % (os.getcwd())]
1d4c55
             if '#' in test_descr.soname_map:
1d4c55
                 soname = ("-Wl,-soname=" + testpfx + test_name + "-"
1d4c55
@@ -987,14 +1008,14 @@ def process_testcase(t):
1d4c55
         sfx = ""
1d4c55
         if r[0] != "":
1d4c55
             sfx = "-" + r[0].replace("=","_")
1d4c55
-        f = open(testpfx + t.test_name + sfx + ".exp", "w")
1d4c55
+        f = open(testpfx_src + t.test_name + sfx + ".exp", "w")
1d4c55
         (output, xfail) = r[1]
1d4c55
         f.write('%s' % output)
1d4c55
         f.close()
1d4c55
 
1d4c55
     # Create header part of top-level testcase shell script, to wrap execution
1d4c55
     # and output comparison together.
1d4c55
-    t.sh = open(testpfx + t.test_name + ".sh", "w")
1d4c55
+    t.sh = open(testpfx_src + t.test_name + ".sh", "w")
1d4c55
     t.sh.write("#!/bin/sh\n")
1d4c55
     t.sh.write("# Test driver for %s, generated by "
1d4c55
                 "dso-ordering-test.py\n" % (t.test_name))
1d4c55
@@ -1022,12 +1043,12 @@ def process_testcase(t):
1d4c55
         sfx = ""
1d4c55
         if r[0] != "":
1d4c55
             sfx = "-" + r[0].replace("=","_")
1d4c55
-        expected_output_files += " $(objpfx)%s/%s%s.exp" % (test_subdir,
1d4c55
+        expected_output_files += " $(objpfx)%s%s%s.exp" % (test_srcdir,
1d4c55
                                                             t.test_name, sfx)
1d4c55
     makefile.write \
1d4c55
-    ("$(objpfx)%s.out: $(objpfx)%s/%s.sh%s "
1d4c55
+    ("$(objpfx)%s.out: $(objpfx)%s%s.sh%s "
1d4c55
      "$(common-objpfx)support/test-run-command\n"
1d4c55
-     % (t.test_name, test_subdir, t.test_name,
1d4c55
+     % (t.test_name, test_srcdir, t.test_name,
1d4c55
         expected_output_files))
1d4c55
     makefile.write("\t$(SHELL) $< $(common-objpfx) '$(test-wrapper-env)' "
1d4c55
                     "'$(run-program-env)' > $@; $(evaluate-test)\n")