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

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