testsuite: check if rootfs dir is dirty before running
authorLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 24 May 2012 04:31:36 +0000 (01:31 -0300)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 5 Jun 2012 03:54:47 +0000 (00:54 -0300)
Keep around a stamp-rootfs file that is generated together with the
rootfs. testsuite checks each test directory if its mtime is greater
than stamp's mtime, deciding if rootfs should be re-generated.

Makefile.am
testsuite/.gitignore
testsuite/testsuite.c

index 4dba42b..223e319 100644 (file)
@@ -128,9 +128,16 @@ endif
 # ------------------------------------------------------------------------------
 
 ROOTFS = testsuite/rootfs
+ROOTFS_PRISTINE = $(top_srcdir)/testsuite/rootfs-pristine
+CREATE_ROOTFS = $(AM_V_GEN) ( $(RM) -rf $(ROOTFS) && \
+                               cp -r $(ROOTFS_PRISTINE) $(ROOTFS) && \
+                               touch testsuite/stamp-rootfs )
 
-$(ROOTFS): $(top_srcdir)/testsuite/rootfs-pristine
-       $(AM_V_GEN) cp -r $< $@
+rootfs:
+       $(CREATE_ROOTFS)
+
+$(ROOTFS): $(ROOTFS_PRISTINE)
+       $(CREATE_ROOTFS)
 
 TESTSUITE_OVERRIDE_LIBS = testsuite/uname.la testsuite/path.la \
                          testsuite/init_module.la \
@@ -152,7 +159,8 @@ testsuite_init_module_la_LIBADD = libkmod/libkmod-private.la
 TESTSUITE_CPPFLAGS = $(AM_CPPFLAGS) \
                     -DTESTSUITE_ROOTFS=\"$(abs_top_builddir)/$(ROOTFS)/\" \
                     -DABS_TOP_BUILDDIR=\"$(abs_top_builddir)\"
-TESTSUITE_LDADD = testsuite/libtestsuite.la libkmod/libkmod-private.la
+TESTSUITE_LDADD = testsuite/libtestsuite.la libkmod/libkmod-private.la \
+                 libkmod/libkmod-util.la
 
 check_LTLIBRARIES += testsuite/libtestsuite.la
 testsuite_libtestsuite_la_SOURCES = testsuite/testsuite.c \
@@ -167,7 +175,7 @@ TESTSUITE = testsuite/test-init testsuite/test-testsuite testsuite/test-loaded \
 check_PROGRAMS = $(TESTSUITE)
 TESTS = $(TESTSUITE)
 
-testsuite_test_testsuite_LDADD = testsuite/libtestsuite.la
+testsuite_test_testsuite_LDADD = testsuite/libtestsuite.la libkmod/libkmod-util.la
 testsuite_test_testsuite_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
 testsuite_test_init_LDADD = $(TESTSUITE_LDADD)
 testsuite_test_init_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
@@ -189,6 +197,7 @@ testsuite_test_dependencies_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
 testsuite-distclean:
        -find $(ROOTFS) -type d -exec chmod +w {} \;
        -$(RM) -rf $(ROOTFS)
+       -$(RM) testsuite/stamp-rootfs
 
 DISTCLEAN_LOCAL_HOOKS += testsuite-distclean
 EXTRA_DIST += testsuite/rootfs-pristine
index 8e6a6ac..61c79e1 100644 (file)
@@ -12,3 +12,4 @@
 /test-testsuite
 /test-modprobe
 /rootfs
+/stamp-rootfs
index 9efe8de..c00746d 100644 (file)
 #include <unistd.h>
 #include <sys/epoll.h>
 #include <sys/prctl.h>
+#include <sys/stat.h>
 #include <sys/wait.h>
 
+#include "libkmod-util.h"
 #include "testsuite.h"
 
 static const char *ANSI_HIGHLIGHT_GREEN_ON = "\x1B[1;32m";
@@ -218,6 +220,28 @@ static inline int test_run_child(const struct test *t, int fdout[2],
                }
        }
 
+       if (t->config[TC_ROOTFS] != NULL) {
+               const char *stamp = TESTSUITE_ROOTFS "../stamp-rootfs";
+               const char *rootfs = t->config[TC_ROOTFS];
+               struct stat rootfsst, stampst;
+
+               if (stat(stamp, &stampst) != 0) {
+                       ERR("could not stat %s\n - %m", stamp);
+                       exit(EXIT_FAILURE);
+               }
+
+               if (stat(rootfs, &rootfsst) != 0) {
+                       ERR("could not stat %s\n - %m", rootfs);
+                       exit(EXIT_FAILURE);
+               }
+
+               if (stat_mstamp(&rootfsst) > stat_mstamp(&stampst)) {
+                       ERR("rootfs %s is dirty, please run 'make rootfs' before runnning this test\n",
+                                                               rootfs);
+                       exit(EXIT_FAILURE);
+               }
+       }
+
        if (t->need_spawn)
                return test_spawn_test(t);
        else