Blame SOURCES/0038-Add-a-bunch-of-tests-for-various-default-kernel-titl.patch

56d25d
From 78b6384b47585fc7d8f4020920ad72100623ce3b Mon Sep 17 00:00:00 2001
56d25d
From: Peter Jones <pjones@redhat.com>
56d25d
Date: Thu, 2 Jul 2015 12:34:30 -0400
56d25d
Subject: [PATCH 38/41] Add a bunch of tests for various
56d25d
 --default-{kernel,title,index}.
56d25d
56d25d
... and fix some failures where we see them.
56d25d
56d25d
Related: rhbz#1184014
56d25d
56d25d
(though I can't actually replicate his failure.)
56d25d
56d25d
Signed-off-by: Peter Jones <pjones@redhat.com>
56d25d
---
56d25d
 grubby.c                        | 50 ++++++++++++++++++++++++-----------------
56d25d
 test.sh                         | 10 +++++++++
56d25d
 test/results/defaultkernel/g.1  |  1 +
56d25d
 test/results/defaultkernel/l1.1 |  1 +
56d25d
 test/results/defaultkernel/z.1  |  1 +
56d25d
 test/results/defaulttitle/z.1   |  1 +
56d25d
 6 files changed, 44 insertions(+), 20 deletions(-)
56d25d
 create mode 100644 test/results/defaultkernel/g.1
56d25d
 create mode 100644 test/results/defaultkernel/l1.1
56d25d
 create mode 100644 test/results/defaultkernel/z.1
56d25d
 create mode 100644 test/results/defaulttitle/z.1
56d25d
56d25d
diff --git a/grubby.c b/grubby.c
56d25d
index a2b0d55..ecd0e9b 100644
56d25d
--- a/grubby.c
56d25d
+++ b/grubby.c
56d25d
@@ -423,7 +423,7 @@ char *grub2ExtractTitle(struct singleLine * line) {
56d25d
 
56d25d
     /* bail out if line does not start with menuentry */
56d25d
     if (strcmp(line->elements[0].item, "menuentry"))
56d25d
-      return NULL;
56d25d
+	return NULL;
56d25d
 
56d25d
     i = 1;
56d25d
     current = line->elements[i].item;
56d25d
@@ -432,10 +432,12 @@ char *grub2ExtractTitle(struct singleLine * line) {
56d25d
     /* if second word is quoted, strip the quotes and return single word */
56d25d
     if (isquote(*current) && isquote(current[current_len - 1])) {
56d25d
 	char *tmp;
56d25d
-	
56d25d
-	tmp = strdup(current);
56d25d
-	*(tmp + current_len - 1) = '\0';
56d25d
-	return ++tmp;
56d25d
+
56d25d
+	tmp = strdup(current+1);
56d25d
+	if (!tmp)
56d25d
+	    return NULL;
56d25d
+	tmp[strlen(tmp)-1] = '\0';
56d25d
+	return tmp;
56d25d
     }
56d25d
 
56d25d
     /* if no quotes, return second word verbatim */
56d25d
@@ -448,11 +450,11 @@ char *grub2ExtractTitle(struct singleLine * line) {
56d25d
     char * result;
56d25d
     /* need to ensure that ' does not match " as we search */
56d25d
     char quote_char = *current;
56d25d
-    
56d25d
+
56d25d
     resultMaxSize = sizeOfSingleLine(line);
56d25d
     result = malloc(resultMaxSize);
56d25d
     snprintf(result, resultMaxSize, "%s", ++current);
56d25d
-    
56d25d
+
56d25d
     i++;
56d25d
     for (; i < line->numElements; ++i) {
56d25d
 	current = line->elements[i].item;
56d25d
@@ -4596,27 +4598,35 @@ int main(int argc, const char ** argv) {
56d25d
 	struct singleLine * line;
56d25d
 	struct singleEntry * entry;
56d25d
 
56d25d
-	if (config->defaultImage == -1) return 0;
56d25d
+	if (config->defaultImage == -1)
56d25d
+	    return 0;
56d25d
 	if (config->defaultImage == DEFAULT_SAVED_GRUB2 &&
56d25d
 		cfi->defaultIsSaved)
56d25d
 	    config->defaultImage = 0;
56d25d
 	entry = findEntryByIndex(config, config->defaultImage);
56d25d
-	if (!entry) return 0;
56d25d
+	if (!entry)
56d25d
+		return 0;
56d25d
 
56d25d
 	if (!configureGrub2) {
56d25d
-	  line = getLineByType(LT_TITLE, entry->lines);
56d25d
-	  if (!line) return 0;
56d25d
-	  printf("%s\n", line->elements[1].item);
56d25d
-
56d25d
+	    char *title;
56d25d
+	    line = getLineByType(LT_TITLE, entry->lines);
56d25d
+	    if (!line)
56d25d
+		return 0;
56d25d
+	    title = extractTitle(config, line);
56d25d
+	    if (!title)
56d25d
+		return 0;
56d25d
+	    printf("%s\n", title);
56d25d
+	    free(title);
56d25d
 	} else {
56d25d
-	  char * title;
56d25d
+	    char * title;
56d25d
 
56d25d
-	  dbgPrintf("This is GRUB2, default title is embeded in menuentry\n");
56d25d
-	  line = getLineByType(LT_MENUENTRY, entry->lines);
56d25d
-	  if (!line) return 0;
56d25d
-	  title = grub2ExtractTitle(line);
56d25d
-	  if (title)
56d25d
-	    printf("%s\n", title);
56d25d
+	    dbgPrintf("This is GRUB2, default title is embeded in menuentry\n");
56d25d
+	    line = getLineByType(LT_MENUENTRY, entry->lines);
56d25d
+	    if (!line)
56d25d
+		return 0;
56d25d
+	    title = grub2ExtractTitle(line);
56d25d
+	    if (title)
56d25d
+		printf("%s\n", title);
56d25d
 	}
56d25d
 	return 0;
56d25d
 
56d25d
diff --git a/test.sh b/test.sh
56d25d
index 30115d1..efd9e84 100755
56d25d
--- a/test.sh
56d25d
+++ b/test.sh
56d25d
@@ -298,6 +298,9 @@ grubDisplayTest grub.9 defaulttitle/g.9 --default-title
56d25d
 grubDisplayTest grub.10 defaulttitle/g.10 --default-title
56d25d
 grubDisplayTest grub.11 defaulttitle/g.11 --default-title
56d25d
 
56d25d
+testing="GRUB display default kernel"
56d25d
+grubDisplayTest grub.1 defaultkernel/g.1 --default-kernel
56d25d
+
56d25d
 testing="LILO default directive"
56d25d
 liloTest lilo.1 default/l1.1 --set-default=/boot/vmlinuz-2.4.18-4
56d25d
 liloTest lilo.1 default/l1.2 --remove-kernel=/boot/vmlinuz-2.4.18-4smp
56d25d
@@ -305,10 +308,17 @@ liloTest lilo.1 default/l1.3 --add-kernel /boot/kernel --title label \
56d25d
     --copy-default
56d25d
 liloTest lilo.1 default/l1.4 --add-kernel /boot/kernel --title label \
56d25d
     --copy-default --make-default
56d25d
+liloDisplayTest lilo.1 defaultkernel/l1.1 --default-kernel
56d25d
 
56d25d
 testing="Z/IPL default directive"
56d25d
 ziplTest zipl.1 default/z1.1 --add-kernel /boot/new-kernel --title test
56d25d
 ziplTest zipl.1 default/z1.2 --add-kernel /boot/new-kernel --title test --make-default
56d25d
+testing="Z/IPL display default index"
56d25d
+ziplDisplayTest zipl.1 defaultindex/0 --default-index
56d25d
+testing="Z/IPL display default title"
56d25d
+ziplDisplayTest zipl.1 defaulttitle/z.1 --default-title
56d25d
+testing="Z/IPL display default kernel"
56d25d
+ziplDisplayTest zipl.1 defaultkernel/z.1 --default-kernel
56d25d
 
56d25d
 testing="GRUB fallback directive"
56d25d
 grubTest grub.5 fallback/g5.1 --remove-kernel=/boot/vmlinuz-2.4.7-ac3 \
56d25d
diff --git a/test/results/defaultkernel/g.1 b/test/results/defaultkernel/g.1
56d25d
new file mode 100644
56d25d
index 0000000..2c3ac11
56d25d
--- /dev/null
56d25d
+++ b/test/results/defaultkernel/g.1
56d25d
@@ -0,0 +1 @@
56d25d
+/boot/vmlinuz-2.4.7-2
56d25d
diff --git a/test/results/defaultkernel/l1.1 b/test/results/defaultkernel/l1.1
56d25d
new file mode 100644
56d25d
index 0000000..fd22b1b
56d25d
--- /dev/null
56d25d
+++ b/test/results/defaultkernel/l1.1
56d25d
@@ -0,0 +1 @@
56d25d
+/boot/vmlinuz-2.4.18-4smp
56d25d
diff --git a/test/results/defaultkernel/z.1 b/test/results/defaultkernel/z.1
56d25d
new file mode 100644
56d25d
index 0000000..2c62e98
56d25d
--- /dev/null
56d25d
+++ b/test/results/defaultkernel/z.1
56d25d
@@ -0,0 +1 @@
56d25d
+/boot/vmlinuz-2.4.9-37
56d25d
diff --git a/test/results/defaulttitle/z.1 b/test/results/defaulttitle/z.1
56d25d
new file mode 100644
56d25d
index 0000000..a08e1f3
56d25d
--- /dev/null
56d25d
+++ b/test/results/defaulttitle/z.1
56d25d
@@ -0,0 +1 @@
56d25d
+linux
56d25d
-- 
56d25d
2.4.3
56d25d