testsuite: add depmod test for modules.alias

Check if modules.alias is correctly generated from modules.order if we
have compressed modules.
diff --git a/Makefile.am b/Makefile.am
index 56f00c2..e4c1a83 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -176,7 +176,9 @@
 
 TESTSUITE = testsuite/test-init testsuite/test-testsuite testsuite/test-loaded \
 	    testsuite/test-modinfo testsuite/test-alias testsuite/test-new-module \
-	    testsuite/test-modprobe testsuite/test-blacklist testsuite/test-dependencies
+	    testsuite/test-modprobe testsuite/test-blacklist \
+	    testsuite/test-dependencies testsuite/test-depmod
+
 check_PROGRAMS = $(TESTSUITE)
 TESTS = $(TESTSUITE)
 
@@ -198,6 +200,8 @@
 testsuite_test_blacklist_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
 testsuite_test_dependencies_LDADD = $(TESTSUITE_LDADD)
 testsuite_test_dependencies_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
+testsuite_test_depmod_LDADD = $(TESTSUITE_LDADD)
+testsuite_test_depmod_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
 
 testsuite-distclean:
 	$(RM) -r $(ROOTFS)
diff --git a/testsuite/.gitignore b/testsuite/.gitignore
index 61c79e1..9706d3c 100644
--- a/testsuite/.gitignore
+++ b/testsuite/.gitignore
@@ -5,6 +5,7 @@
 /test-alias
 /test-blacklist
 /test-dependencies
+/test-depmod
 /test-init
 /test-loaded
 /test-modinfo
diff --git a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/correct-modules.alias b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/correct-modules.alias
new file mode 100644
index 0000000..5675329
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/correct-modules.alias
@@ -0,0 +1,37 @@
+# Aliases extracted from modules themselves.
+alias pci:v0000103Cd00003230sv0000103Csd0000323Dbc*sc*i* cciss
+alias pci:v0000103Cd00003230sv0000103Csd00003237bc*sc*i* cciss
+alias pci:v0000103Cd00003238sv0000103Csd00003215bc*sc*i* cciss
+alias pci:v0000103Cd00003238sv0000103Csd00003214bc*sc*i* cciss
+alias pci:v0000103Cd00003238sv0000103Csd00003213bc*sc*i* cciss
+alias pci:v0000103Cd00003238sv0000103Csd00003212bc*sc*i* cciss
+alias pci:v0000103Cd00003238sv0000103Csd00003211bc*sc*i* cciss
+alias pci:v0000103Cd00003230sv0000103Csd00003235bc*sc*i* cciss
+alias pci:v0000103Cd00003230sv0000103Csd00003234bc*sc*i* cciss
+alias pci:v0000103Cd00003230sv0000103Csd00003223bc*sc*i* cciss
+alias pci:v0000103Cd00003220sv0000103Csd00003225bc*sc*i* cciss
+alias pci:v00000E11d00000046sv00000E11sd0000409Dbc*sc*i* cciss
+alias pci:v00000E11d00000046sv00000E11sd0000409Cbc*sc*i* cciss
+alias pci:v00000E11d00000046sv00000E11sd0000409Bbc*sc*i* cciss
+alias pci:v00000E11d00000046sv00000E11sd0000409Abc*sc*i* cciss
+alias pci:v00000E11d00000046sv00000E11sd00004091bc*sc*i* cciss
+alias pci:v00000E11d0000B178sv00000E11sd00004083bc*sc*i* cciss
+alias pci:v00000E11d0000B178sv00000E11sd00004082bc*sc*i* cciss
+alias pci:v00000E11d0000B178sv00000E11sd00004080bc*sc*i* cciss
+alias pci:v00000E11d0000B060sv00000E11sd00004070bc*sc*i* cciss
+alias pci:v0000103Cd*sv*sd*bc01sc04i* hpsa
+alias pci:v0000103Cd0000323Bsv0000103Csd00003356bc*sc*i* hpsa
+alias pci:v0000103Cd0000323Bsv0000103Csd00003355bc*sc*i* hpsa
+alias pci:v0000103Cd0000323Bsv0000103Csd00003354bc*sc*i* hpsa
+alias pci:v0000103Cd0000323Bsv0000103Csd00003353bc*sc*i* hpsa
+alias pci:v0000103Cd0000323Bsv0000103Csd00003352bc*sc*i* hpsa
+alias pci:v0000103Cd0000323Bsv0000103Csd00003351bc*sc*i* hpsa
+alias pci:v0000103Cd0000323Bsv0000103Csd00003350bc*sc*i* hpsa
+alias pci:v0000103Cd0000323Asv0000103Csd00003233bc*sc*i* hpsa
+alias pci:v0000103Cd0000323Asv0000103Csd0000324Bbc*sc*i* hpsa
+alias pci:v0000103Cd0000323Asv0000103Csd0000324Abc*sc*i* hpsa
+alias pci:v0000103Cd0000323Asv0000103Csd00003249bc*sc*i* hpsa
+alias pci:v0000103Cd0000323Asv0000103Csd00003247bc*sc*i* hpsa
+alias pci:v0000103Cd0000323Asv0000103Csd00003245bc*sc*i* hpsa
+alias pci:v0000103Cd0000323Asv0000103Csd00003243bc*sc*i* hpsa
+alias pci:v0000103Cd0000323Asv0000103Csd00003241bc*sc*i* hpsa
diff --git a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/block/cciss.ko.gz b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/block/cciss.ko.gz
new file mode 100644
index 0000000..0684dc1
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/block/cciss.ko.gz
Binary files differ
diff --git a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/scsi/hpsa.ko.gz b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/scsi/hpsa.ko.gz
new file mode 100644
index 0000000..403d6fb
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/scsi/hpsa.ko.gz
Binary files differ
diff --git a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/scsi/scsi_mod.ko.gz b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/scsi/scsi_mod.ko.gz
new file mode 100644
index 0000000..2306bb1
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/scsi/scsi_mod.ko.gz
Binary files differ
diff --git a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/modules.builtin b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/modules.builtin
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/modules.builtin
diff --git a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/modules.order b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/modules.order
new file mode 100644
index 0000000..4b64309
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/modules.order
@@ -0,0 +1,7 @@
+#336
+kernel/drivers/block/cciss.ko
+#2094
+kernel/drivers/scsi/scsi_mod.ko
+#2137
+kernel/drivers/scsi/hpsa.ko
+
diff --git a/testsuite/test-depmod.c b/testsuite/test-depmod.c
new file mode 100644
index 0000000..4317327
--- /dev/null
+++ b/testsuite/test-depmod.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2012  ProFUSION embedded systems
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <errno.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <string.h>
+
+#include "testsuite.h"
+
+#define MODULES_ORDER_UNAME "3.5.4-1-ARCH"
+#define MODULES_ORDER_ROOTFS TESTSUITE_ROOTFS "test-depmod/modules-order-compressed"
+#define MODULES_ORDER_LIB_MODULES MODULES_ORDER_ROOTFS "/lib/modules/" MODULES_ORDER_UNAME
+static __noreturn int depmod_modules_order_for_compressed(const struct test *t)
+{
+	const char *progname = ABS_TOP_BUILDDIR "/tools/depmod";
+	const char *const args[] = {
+		progname,
+		NULL,
+	};
+
+	test_spawn_prog(progname, args);
+	exit(EXIT_FAILURE);
+}
+static DEFINE_TEST(depmod_modules_order_for_compressed,
+	.description = "check if depmod let aliases in right order when using compressed modules",
+	.config = {
+		[TC_UNAME_R] = MODULES_ORDER_UNAME,
+		[TC_ROOTFS] = MODULES_ORDER_ROOTFS,
+	},
+	.output = {
+		.files = (const struct keyval[]) {
+			{ MODULES_ORDER_LIB_MODULES "/correct-modules.alias",
+			  MODULES_ORDER_LIB_MODULES "/modules.alias" },
+			{ }
+		},
+	});
+
+
+static const struct test *tests[] = {
+	&sdepmod_modules_order_for_compressed,
+	NULL,
+};
+
+TESTSUITE_MAIN(tests);