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