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