Skip to content

Commit f7f9822

Browse files
Klaus Heinrich Kiwijk-ozlabs
Klaus Heinrich Kiwi
authored andcommitted
discover/grub2: Add the '-e' test support
Grub2 allows a special-case of file test using the '-e' operator, where the path can be empty, and the device existance is tested. E.g.: if [ -e (md/md-boot) ]; then Add the support for testing this condition, as well as some tests for this scenario (also fix an existing testcase where this was wrongly passing). This fixes the following RH CoreOS bug: https://bugzilla.redhat.com/show_bug.cgi?id=1915540 Signed-off-by: Klaus Heinrich Kiwi <[email protected]> Signed-off-by: Jeremy Kerr <[email protected]>
1 parent fb64728 commit f7f9822

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

discover/grub2/builtins.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ static bool builtin_test_op_file(struct grub2_script *script, char op,
245245
return false;
246246

247247
switch (op) {
248+
case 'e':
249+
/* -e: for grub, a special case is testing for the device
250+
* presence itself (e.g. allows null file). */
251+
result = true;
252+
break;
248253
case 's':
249254
/* -s: return true if file exists and has non-zero size */
250255
result = !path ? false : statbuf.st_size > 0;
@@ -336,7 +341,7 @@ static bool builtin_test_op(struct grub2_script *script,
336341
return strlen(a1) != 0;
337342
}
338343

339-
if (!strcmp(op, "-s") || !strcmp(op, "-f")) {
344+
if (!strcmp(op, "-s") || !strcmp(op, "-f") || !(strcmp(op, "-e"))) {
340345
*consumed = 2;
341346
return builtin_test_op_file(script, op[1], a1);
342347
}

test/parser/test-grub2-test-file-ops.c

+27
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,28 @@ if [ ! -d / -a $status = success ]
5555
then status=fail_d_5
5656
fi
5757

58+
if [ -e /file_that_does_not_exist -a $status = success ]
59+
then status=fail_e_1
60+
fi
61+
if [ ! -e /dir -a $status = success ]
62+
then status=fail_e_2
63+
fi
64+
if [ ! -e /empty_file -a $status = success ]
65+
then status=fail_e_3
66+
fi
67+
if [ -e "" -a $status = success ]
68+
then status=fail_e_4
69+
fi
70+
if [ ! -e / -a $status = success ]
71+
then status=fail_e_5
72+
fi
73+
if [ ! -e (00000000-0000-0000-0000-000000000001) -a $status = success ]
74+
then status=fail_e_6
75+
fi
76+
if [ -e (00000000-0000-0000-0000-000000000002) -a $status = success ]
77+
then status=fail_e_7
78+
fi
79+
5880
menuentry $status {
5981
linux /vmlinux
6082
}
@@ -64,9 +86,14 @@ void run_test(struct parser_test *test)
6486
{
6587
struct discover_boot_option *opt;
6688
struct discover_context *ctx;
89+
struct discover_device *dev;
6790

6891
ctx = test->ctx;
6992

93+
/* set local uuid */
94+
dev = test->ctx->device;
95+
dev->uuid = "00000000-0000-0000-0000-000000000001";
96+
7097
test_read_conf_embedded(test, "/grub2/grub.cfg");
7198
test_add_dir(test, ctx->device, "/");
7299
test_add_file_data(test, ctx->device, "/empty_file", "", 0);

test/parser/test-grub2-ubuntu-13_04-x86.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ void run_test(struct parser_test *test)
1919
check_unresolved_resource(opt->boot_image);
2020
check_unresolved_resource(opt->initrd);
2121
check_name(opt, "Kubuntu GNU/Linux");
22-
check_args(opt, "root=UUID=29beca39-9181-4780-bbb2-ab5d4be59aaf ro quiet splash ");
22+
check_args(opt, "root=UUID=29beca39-9181-4780-bbb2-ab5d4be59aaf ro quiet splash vt.handoff=7");
2323

2424
opt = get_boot_option(ctx, 1);
2525
check_unresolved_resource(opt->boot_image);
2626
check_unresolved_resource(opt->initrd);
2727
check_name(opt, "Kubuntu GNU/Linux, with Linux 3.8.0-19-generic");
28-
check_args(opt, "root=UUID=29beca39-9181-4780-bbb2-ab5d4be59aaf ro quiet splash ");
28+
check_args(opt, "root=UUID=29beca39-9181-4780-bbb2-ab5d4be59aaf ro quiet splash vt.handoff=7");
2929

3030
opt = get_boot_option(ctx, 2);
3131
check_name(opt, "Kubuntu GNU/Linux, with Linux 3.8.0-19-generic (recovery mode)");

0 commit comments

Comments
 (0)