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

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