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