446cf2
commit 033362cfd7e0e1dccd6c9a2642710d6e3a7e7007
446cf2
Author: Carlos O'Donell <carlos@redhat.com>
446cf2
Date:   Thu Jan 23 09:45:00 2020 -0500
446cf2
446cf2
    test-container: Support $(complocaledir) and mkdirp.
446cf2
    
446cf2
    Expand the support infrastructure:
446cf2
    - Create $(complocaledir) in the testroot.pristine to support localedef.
446cf2
    - Add the variable $complocaledir to script support.
446cf2
    - Add the script command 'mkdirp'.
446cf2
    
446cf2
    All localedef tests which run with default paths need to have the
446cf2
    $(complocaledir) created in testroot.pristine. The localedef binary
446cf2
    will not by itself create the default path, but it will write into
446cf2
    the path. By adding this we can simplify the localedef tests.
446cf2
    
446cf2
    The variable $complocaledir is the value of the configured
446cf2
    $(complocaledir) which is the location of the compiled locales that
446cf2
    will be searched by the runtime by default.
446cf2
    
446cf2
    The command mkdirp will be available in script setup and will
446cf2
    be equivalent to running `mkdir -p`.
446cf2
    
446cf2
    The variable and command can be used to write more complex tests.
446cf2
    
446cf2
    Reviewed-by: DJ Delorie <dj@redhat.com>
446cf2
446cf2
diff --git a/Makefile b/Makefile
446cf2
index ae44b9cdd29fb0e3..3748d6f7cfb6223b 100644
446cf2
--- a/Makefile
446cf2
+++ b/Makefile
446cf2
@@ -371,6 +371,9 @@ $(objpfx)testroot.pristine/install.stamp :
446cf2
 	# We need a working /bin/sh for some of the tests.
446cf2
 	test -d $(objpfx)testroot.pristine/bin || \
446cf2
 	  mkdir $(objpfx)testroot.pristine/bin
446cf2
+	# We need the compiled locale dir for localedef tests.
446cf2
+	test -d $(objpfx)testroot.pristine/$(complocaledir) || \
446cf2
+	  mkdir -p $(objpfx)testroot.pristine/$(complocaledir)
446cf2
 	cp $(objpfx)support/shell-container $(objpfx)testroot.pristine/bin/sh
446cf2
 	cp $(objpfx)support/echo-container $(objpfx)testroot.pristine/bin/echo
446cf2
 	cp $(objpfx)support/true-container $(objpfx)testroot.pristine/bin/true
446cf2
diff --git a/support/test-container.c b/support/test-container.c
446cf2
index 9eff8baeef0e9d8a..9fcc91e478038232 100644
446cf2
--- a/support/test-container.c
446cf2
+++ b/support/test-container.c
446cf2
@@ -72,6 +72,10 @@ int verbose = 0;
446cf2
 
446cf2
    * mkdir $buildroot/testroot.pristine/
446cf2
    * install into it
446cf2
+     * default glibc install
446cf2
+     * create /bin for /bin/sh
446cf2
+     * create $(complocaledir) so localedef tests work with default paths.
446cf2
+     * install /bin/sh, /bin/echo, and /bin/true.
446cf2
    * rsync to $buildroot/testroot.root/
446cf2
 
446cf2
    "Per-test" actions:
446cf2
@@ -97,9 +101,23 @@ int verbose = 0;
446cf2
 	 rm FILE
446cf2
 	 cwd PATH
446cf2
 	 exec FILE
446cf2
-	 FILE must start with $B/, $S/, $I/, $L/, or /
446cf2
-	  (expands to build dir, source dir, install dir, library dir
446cf2
-	   (in container), or container's root)
446cf2
+	 mkdirp MODE DIR
446cf2
+
446cf2
+       variables:
446cf2
+	 $B/ build dir, equivalent to $(common-objpfx)
446cf2
+	 $S/ source dir, equivalent to $(srcdir)
446cf2
+	 $I/ install dir, equivalent to $(prefix)
446cf2
+	 $L/ library dir (in container), equivalent to $(libdir)
446cf2
+	 $complocaledir/ compiled locale dir, equivalent to $(complocaledir)
446cf2
+	 / container's root
446cf2
+
446cf2
+	 If FILE begins with any of these variables then they will be
446cf2
+	 substituted for the described value.
446cf2
+
446cf2
+	 The goal is to expose as many of the runtime's configured paths
446cf2
+	 via variables so they can be used to setup the container environment
446cf2
+	 before execution reaches the test.
446cf2
+
446cf2
        details:
446cf2
          - '#': A comment.
446cf2
          - 'su': Enables running test as root in the container.
446cf2
@@ -108,6 +126,8 @@ int verbose = 0;
446cf2
          - 'rm': A minimal remove files command.
446cf2
 	 - 'cwd': set test working directory
446cf2
 	 - 'exec': change test binary location (may end in /)
446cf2
+	 - 'mkdirp': A minimal "mkdir -p FILE" command.
446cf2
+
446cf2
    * mytest.root/postclean.req causes fresh rsync (with delete) after
446cf2
      test if present
446cf2
 
446cf2
@@ -859,6 +879,7 @@ main (int argc, char **argv)
446cf2
 	    int nt = tokenize (the_line, the_words, 3);
446cf2
 	    int i;
446cf2
 
446cf2
+	    /* Expand variables.  */
446cf2
 	    for (i = 1; i < nt; ++i)
446cf2
 	      {
446cf2
 		if (memcmp (the_words[i], "$B/", 3) == 0)
446cf2
@@ -875,6 +896,10 @@ main (int argc, char **argv)
446cf2
 		  the_words[i] = concat (new_root_path,
446cf2
 					 support_libdir_prefix,
446cf2
 					 the_words[i] + 2, NULL);
446cf2
+		else if (memcmp (the_words[i], "$complocaledir/", 15) == 0)
446cf2
+		  the_words[i] = concat (new_root_path,
446cf2
+					 support_complocaledir_prefix,
446cf2
+					 the_words[i] + 14, NULL);
446cf2
 		/* "exec" and "cwd" use inside-root paths.  */
446cf2
 		else if (strcmp (the_words[0], "exec") != 0
446cf2
 			 && strcmp (the_words[0], "cwd") != 0
446cf2
@@ -892,6 +917,9 @@ main (int argc, char **argv)
446cf2
 		  the_words[2] = concat (the_words[2], the_words[1], NULL);
446cf2
 	      }
446cf2
 
446cf2
+	    /* Run the following commands in the_words[0] with NT number of
446cf2
+	       arguments (including the command).  */
446cf2
+
446cf2
 	    if (nt == 2 && strcmp (the_words[0], "so") == 0)
446cf2
 	      {
446cf2
 		the_words[2] = concat (new_root_path, support_libdir_prefix,
446cf2
@@ -961,6 +989,14 @@ main (int argc, char **argv)
446cf2
 	      {
446cf2
 		be_su = 1;
446cf2
 	      }
446cf2
+	    else if (nt == 3 && strcmp (the_words[0], "mkdirp") == 0)
446cf2
+	      {
446cf2
+		long int m;
446cf2
+		errno = 0;
446cf2
+		m = strtol (the_words[1], NULL, 0);
446cf2
+		TEST_COMPARE (errno, 0);
446cf2
+		xmkdirp (the_words[2], m);
446cf2
+	      }
446cf2
 	    else if (nt > 0 && the_words[0][0] != '#')
446cf2
 	      {
446cf2
 		fprintf (stderr, "\033[31minvalid [%s]\033[0m\n", the_words[0]);