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

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