test-container: ability to specify exec path

Message ID xn7e33u0nv.fsf@greed.delorie.com
State Superseded
Headers

Commit Message

DJ Delorie Dec. 11, 2019, 1:11 a.m. UTC
  Carlos asked for something like this for $ORIGIN testing...
  

Comments

Florian Weimer Dec. 11, 2019, 11:50 a.m. UTC | #1
* DJ Delorie:

> Carlos asked for something like this for $ORIGIN testing...
>
> diff --git a/nss/tst-nss-test3.root/tst-nss-test3.script b/nss/tst-nss-test3.root/tst-nss-test3.script
> index a10beb1e6c..03ba5c5276 100644
> --- a/nss/tst-nss-test3.root/tst-nss-test3.script
> +++ b/nss/tst-nss-test3.root/tst-nss-test3.script
> @@ -1,2 +1,3 @@
>  cp $B/nss/libnss_test1.so $L/libnss_test1.so.2
>  cp $B/nss/libnss_test2.so $L/libnss_test2.so.2
> +exec /usr/bin/foo
> diff --git a/support/test-container.c b/support/test-container.c
> index 5d08979df3..d4ecfe8a98 100644
> --- a/support/test-container.c
> +++ b/support/test-container.c
> @@ -95,6 +95,7 @@ int verbose = 0;
>           mv FILE FILE
>  	 cp FILE FILE
>  	 rm FILE
> +	 exec PATH
>  	 FILE must start with $B/, $S/, $I/, $L/, or /
>  	  (expands to build dir, source dir, install dir, library dir
>  	   (in container), or container's root)
> @@ -104,6 +105,7 @@ int verbose = 0;
>           - 'mv': A minimal move files command.
>           - 'cp': A minimal copy files command.
>           - 'rm': A minimal remove files command.
> +	 - 'exec': change where test is run from (may end in /)

So it's the path to the executable in the container, and the test
program is copied there?

I think you should make this more explicit, because the comment above
sounds like as this changes the current directory for the test.

Thanks,
Florian
  

Patch

diff --git a/nss/tst-nss-test3.root/tst-nss-test3.script b/nss/tst-nss-test3.root/tst-nss-test3.script
index a10beb1e6c..03ba5c5276 100644
--- a/nss/tst-nss-test3.root/tst-nss-test3.script
+++ b/nss/tst-nss-test3.root/tst-nss-test3.script
@@ -1,2 +1,3 @@ 
 cp $B/nss/libnss_test1.so $L/libnss_test1.so.2
 cp $B/nss/libnss_test2.so $L/libnss_test2.so.2
+exec /usr/bin/foo
diff --git a/support/test-container.c b/support/test-container.c
index 5d08979df3..d4ecfe8a98 100644
--- a/support/test-container.c
+++ b/support/test-container.c
@@ -95,6 +95,7 @@  int verbose = 0;
          mv FILE FILE
 	 cp FILE FILE
 	 rm FILE
+	 exec PATH
 	 FILE must start with $B/, $S/, $I/, $L/, or /
 	  (expands to build dir, source dir, install dir, library dir
 	   (in container), or container's root)
@@ -104,6 +105,7 @@  int verbose = 0;
          - 'mv': A minimal move files command.
          - 'cp': A minimal copy files command.
          - 'rm': A minimal remove files command.
+	 - 'exec': change where test is run from (may end in /)
    * mytest.root/postclean.req causes fresh rsync (with delete) after
      test if present
 
@@ -868,7 +870,9 @@  main (int argc, char **argv)
 		  the_words[i] = concat (new_root_path,
 					 support_libdir_prefix,
 					 the_words[i] + 2, NULL);
-		else if (the_words[i][0] == '/')
+		/* "exec" uses inside-root paths.  */
+		else if (strcmp (the_words[0], "exec") != 0
+			 && the_words[i][0] == '/')
 		  the_words[i] = concat (new_root_path,
 					 the_words[i], NULL);
 	      }
@@ -912,6 +916,33 @@  main (int argc, char **argv)
 	      {
 		maybe_xunlink (the_words[1]);
 	      }
+	    else if (nt == 2 && strcmp (the_words[0], "exec") == 0)
+	      {
+		char *new_exec_path = the_words[1];
+		char *test_basename = new_child_proc[0];
+
+		/* Find the base name of the test.  */
+		if (strrchr (test_basename, '/') != NULL)
+		  test_basename = strrchr (test_basename, '/') + 1;
+
+		/* If the new exec path ends with a slash, that's the
+		 * directory, and use the old test base name.  */
+		if (new_exec_path [strlen(new_exec_path) - 1] == '/')
+		    new_exec_path = concat (new_exec_path,
+					    test_basename,
+					    NULL);
+
+
+		/* new_child_proc is in the build tree, so has the
+		   same path inside the chroot as outside.  The new
+		   exec path is, by definition, relative to the
+		   chroot.  */
+		copy_one_file (new_child_proc[0],  concat (new_root_path,
+							   new_exec_path,
+							   NULL));
+
+		new_child_proc[0] = strdup (new_exec_path);
+	      }
 	    else if (nt == 1 && strcmp (the_words[0], "su") == 0)
 	      {
 		be_su = 1;