[PATCH 5/9] add disable-debug runtime option

Gene Czarcinski gczarcinski at ec.rr.com
Mon Sep 15 12:50:48 UTC 2014


To facilitate having compile-time DEBUG enabled and still being
able to successfully run the tests, add a new --disable-debug
parameter to grubby so that, even if compile-time DEBUG is enabled,
the output will be suppressed.

This permits "make test" to be run.

Besides the changes to grubby, changing test.sh to use
"./grubby --disable-debug" instead of "./grubby", only
one test had to be slightly changed.
---
 grubby.c                | 38 +++++++++++++++++++++++++++-----------
 test.sh                 |  8 ++++----
 test/results/debug/g2.1 |  2 +-
 3 files changed, 32 insertions(+), 16 deletions(-)

diff --git a/grubby.c b/grubby.c
index 451d291..a4a9e65 100644
--- a/grubby.c
+++ b/grubby.c
@@ -43,13 +43,18 @@
 #endif
 
 #if DEBUG
-#define dbgPrintf(format, args...) fprintf(stderr, format , ## args)
+    #define dbgPrintf(format, args...) \
+	if (!disableDebug) {\
+	    fprintf(stderr, format , ## args); \
+	}
 #else
-#define dbgPrintf(format, args...)
+    #define dbgPrintf(format, args...)
 #endif
 
 int debug = 0;	/* Currently just for template debugging */
 
+int disableDebug = 0; /* at runtime, disable output from compile-time DEBUG */
+
 #define _(A) (A)
 
 #define MAX_EXTRA_INITRDS	  16	/* code segment checked by --bootloader-probe */
@@ -2762,15 +2767,19 @@ int grubGetBootFromDeviceMap(const char * device,
 int suseGrubConfGetBoot(const char * path, char ** bootPtr) {
     char * grubDevice;
 
-    if (suseGrubConfGetInstallDevice(path, &grubDevice))
+    if (suseGrubConfGetInstallDevice(path, &grubDevice)) {
 	dbgPrintf("error looking for grub installation device\n");
-    else
+    }
+    else {
 	dbgPrintf("grubby installation device: %s\n", grubDevice);
+    }
 
-    if (grubGetBootFromDeviceMap(grubDevice, bootPtr))
+    if (grubGetBootFromDeviceMap(grubDevice, bootPtr)) {
 	dbgPrintf("error looking for grub boot device\n");
-    else
+    }
+    else {
 	dbgPrintf("grubby boot device: %s\n", *bootPtr);
+    }
 
     free(grubDevice);
     return 0;
@@ -4369,9 +4378,11 @@ int addNewKernel(struct grubConfig * config, struct singleEntry * template,
                     newMBKernelArgs, NULL)) return 1;
 
 #if DEBUG
-    fprintf(stderr,"--end of addNewKernel()-----\n");
-    printEntry(new, stderr);
-    fprintf(stderr,"--end of addNewKernel()-----\n");
+    if (!disableDebug) {
+	fprintf(stderr,"--end of addNewKernel()-----\n");
+	printEntry(new, stderr);
+	fprintf(stderr,"--end of addNewKernel()-----\n");
+    }
 #endif
 
     return 0;
@@ -4471,6 +4482,8 @@ int main(int argc, const char ** argv) {
 	    _("display the title of the default kernel") },
 	{ "devtree", 0, POPT_ARG_STRING, &newDevTreePath, 0,
 	    _("device tree file for new stanza"), _("dtb-path") },
+	{ "disable-debug", 0, 0, &disableDebug, 0,
+	    _("at run-time, disable compile-time DEBUG output") },
 	{ "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,
 	    _("configure elilo bootloader") },
 	{ "efi", 0, POPT_ARG_NONE, &isEfi, 0,
@@ -4548,7 +4561,6 @@ int main(int argc, const char ** argv) {
 	strncat(saved_command_line, j == argc -1 ? "" : " ", 1);
     }
 
-    dbgPrintf("---> Begin grubby execution <------------------------------------\n");
     optCon = poptGetContext("grubby", argc, argv, options, 0);
     poptReadDefaultConfig(optCon, 1);
 
@@ -4581,6 +4593,8 @@ int main(int argc, const char ** argv) {
 	return 1;
     }
 
+    dbgPrintf("---> Begin grubby execution <------------------------------------\n");
+
     if ((configureLilo + configureGrub2 + configureGrub + configureELilo + 
 		configureYaboot + configureSilo + configureZipl +
 		configureExtLinux ) > 1) {
@@ -4898,7 +4912,9 @@ int main(int argc, const char ** argv) {
         return 1;
     }
 #if DEBUG
-    printEntries(config);
+    if (!disableDebug) {
+	printEntries(config);
+    }
 #endif
 
     if (!outputFile)
diff --git a/test.sh b/test.sh
index d98368b..d1e027b 100755
--- a/test.sh
+++ b/test.sh
@@ -62,7 +62,7 @@ oneTest() {
 
 
     echo "$testing ... $mode $cfg $correct"
-    runme=( ./grubby "$mode" --bad-image-okay $ENV_FILE -c "$cfg" -o - "$@" )
+    runme=( ./grubby --disable-debug "$mode" --bad-image-okay $ENV_FILE -c "$cfg" -o - "$@" )
     if "${runme[@]}" | cmp "$correct" > /dev/null; then
 	(( pass++ ))
 	if $opt_verbose; then
@@ -107,7 +107,7 @@ oneDisplayTest() {
     fi
 
     echo "$testing ... $mode $cfg $correct"
-    runme=( ./grubby "$mode" $BIO $ENV_FILE -c "$cfg" "$@" )
+    runme=( ./grubby --disable-debug "$mode" $BIO $ENV_FILE -c "$cfg" "$@" )
     if "${runme[@]}" 2>&1 | cmp "$correct" > /dev/null; then
 	(( pass++ ))
 	if $opt_verbose; then
@@ -211,7 +211,7 @@ for n in test/*.[0-9]*; do
     touch -t 200301010101.00 ${b}-test
     time=$(ls -l ${b}-test | awk '{ print $6 " " $7 " "$8}')
     perm=$(ls -l ${b}-test | awk '{print $1}')
-    ./grubby --${b} --add-kernel bar --title title -c ${b}-test 
+    ./grubby --disable-debug --${b} --add-kernel bar --title title -c ${b}-test
     if [[ $? != 0 ]]; then
 	echo "  FAIL (grubby returned non-zero)"
 	(( fail++ ))
@@ -239,7 +239,7 @@ for n in test/*.[0-9]*; do
 
     cp test/${b}.1 ${b}-test
     ln -s ./${b}-test mytest
-    ./grubby --${b} --add-kernel bar --title title -c mytest
+    ./grubby --disable-debug --${b} --add-kernel bar --title title -c mytest
     if [[ $? != 0 ]]; then
 	echo "  failed (grubby returned non-zero)"
 	(( fail++ ))
diff --git a/test/results/debug/g2.1 b/test/results/debug/g2.1
index f5187f5..c2c2fee 100644
--- a/test/results/debug/g2.1
+++ b/test/results/debug/g2.1
@@ -1,4 +1,4 @@
-DBG: command line: --grub2 --env=test/grub2-support_files/env_temp -c test/grub2.1 --boot-filesystem=/boot --default-kernel --debug
+DBG: command line: --disable-debug --grub2 --env=test/grub2-support_files/env_temp -c test/grub2.1 --boot-filesystem=/boot --default-kernel --debug
 DBG: Image entry failed: access to /boot/vmlinuz-2.6.38.8-32.fc15.x86_64 failed
 DBG: menuentry 'Linux, with Fedora 2.6.38.8-32.fc15.x86_64' --class gnu-linux --class gnu --class os { 
 DBG: 	load_video
-- 
1.9.3



More information about the anaconda-patches mailing list