New test: cmdline and cat.

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-05-08 11:49:25 +02:00
parent 16f7c8f6d3
commit 0e7b2e3217
8 changed files with 180 additions and 26 deletions

View file

@ -1,3 +1,7 @@
2013-05-08 Vladimir Serbinenko <phcoder@gmail.com>
New test: cmdline and cat.
2013-05-08 Vladimir Serbinenko <phcoder@gmail.com> 2013-05-08 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/commands/cat.c: Show UTF-8 characters. * grub-core/commands/cat.c: Show UTF-8 characters.

View file

@ -1762,6 +1762,11 @@ module = {
common = tests/gfxterm_menu.c; common = tests/gfxterm_menu.c;
}; };
module = {
name = cmdline_cat_test;
common = tests/cmdline_cat_test.c;
};
module = { module = {
name = bitmap; name = bitmap;
common = video/bitmap.c; common = video/bitmap.c;

View file

@ -1,3 +1,9 @@
{ "cmdline_cat", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0x7dbff368, 0x7dbff368, 0x5a5bdc8d, 0x5a5bdc8d, 0x79753177, 0x79753177, 0xd01ede5b, 0xd01ede5b, 0x13708a73, 0x13708a73, 0x90186de3, 0x90186de3, 0xe63d02a2, 0xe63d02a2, 0x2c9dc262, 0x2c9dc262, 0x3eebd7b, 0x3eebd7b, 0xe8f3a5d8, 0xe8f3a5d8, 0xd38ecfe3, 0xd38ecfe3, 0x51878485, 0x51878485, 0xcbdb6d67, 0xcbdb6d67, 0xca25582, 0xca25582, 0x5bea0484, 0x5bea0484, 0x9ec5f71d, 0x9ec5f71d, 0x3f0bd7bc, 0x3f0bd7bc, 0xdbb0a5d2, 0xdbb0a5d2, 0xea710e2f, 0xea710e2f, 0xd14933fe, 0xd14933fe, 0x4906b783, 0xad94ffeb, 0xf31c9259, 0xf31c9259, }, 45 },
{ "cmdline_cat", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0xfeea303f, 0xfeea303f, 0x9a6d5200, 0x9a6d5200, 0x784f6e43, 0x784f6e43, 0xc3973f40, 0xc3973f40, 0x954a7cb1, 0x954a7cb1, 0x8b7c607f, 0x8b7c607f, 0x290bf4b3, 0x290bf4b3, 0x5d67148d, 0x5d67148d, 0x37008df4, 0x37008df4, 0xce9d51c7, 0xce9d51c7, 0xe29b4663, 0xe29b4663, 0xefb7cd59, 0xefb7cd59, 0xe12cc621, 0xe12cc621, 0xd6d4461f, 0xd6d4461f, 0x4d4490ef, 0x4d4490ef, 0x6ce4a360, 0x6ce4a360, 0x812e6359, 0x812e6359, 0xe2f82bc9, 0xe2f82bc9, 0x9621917d, 0x9621917d, 0xbbe37c69, 0xbbe37c69, 0x719d9b99, 0xe95c1cc3, 0xe0476ad0, 0xe0476ad0, }, 45 },
{ "cmdline_cat", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0x50b82239, 0x50b82239, 0x82c36c12, 0x82c36c12, 0x6311208d, 0x6311208d, 0x816bd4b3, 0x816bd4b3, 0xc9281fd0, 0xc9281fd0, 0x75767bac, 0x75767bac, 0x52edeac, 0x52edeac, 0xfdb551f7, 0xfdb551f7, 0xba21cd3, 0xba21cd3, 0xf2b3468a, 0xf2b3468a, 0xd5560323, 0xd5560323, 0x12c650f6, 0x12c650f6, 0x3d6c5861, 0x3d6c5861, 0x50062423, 0x50062423, 0x2ce22983, 0x2ce22983, 0x4996bc4d, 0x4996bc4d, 0x50450525, 0x50450525, 0xe1c94312, 0xe1c94312, 0x21224aac, 0x21224aac, 0x94cbe214, 0x94cbe214, 0x4578c664, 0xcb360887, 0x5a749f1d, 0x5a749f1d, }, 45 },
{ "cmdline_cat", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0xbb687653, 0xbb687653, 0xa81427a7, 0xa81427a7, 0x71d7f3b, 0x71d7f3b, 0x25fea6ca, 0x25fea6ca, 0x17c19d74, 0x17c19d74, 0x4779bf48, 0x4779bf48, 0xe424e759, 0xe424e759, 0xb57fb5ae, 0xb57fb5ae, 0xd877002b, 0xd877002b, 0xdd8d7442, 0xdd8d7442, 0xe2536fde, 0xe2536fde, 0x1ebba341, 0x1ebba341, 0xef042176, 0xef042176, 0x6137f228, 0x6137f228, 0xf04a8558, 0xf04a8558, 0xff72172d, 0xff72172d, 0x5f26278f, 0x5f26278f, 0x3ed777c, 0x3ed777c, 0xb1d686e, 0xb1d686e, 0x5cead249, 0x5cead249, 0x271487f6, 0x3b9ece9a, 0xccc3db5e, 0xccc3db5e, }, 45 },
{ "cmdline_cat", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0xd594219a, 0xd594219a, 0x254fa44c, 0x254fa44c, 0x30177d61, 0x30177d61, 0x1a576e20, 0x1a576e20, 0xe439395f, 0xe439395f, 0xb289a26f, 0xb289a26f, 0xc9eaceca, 0xc9eaceca, 0x9e76037b, 0x9e76037b, 0xfa098eb4, 0xfa098eb4, 0x5881d993, 0x5881d993, 0x3a4ac117, 0x3a4ac117, 0x203e9716, 0x203e9716, 0x67aed713, 0x67aed713, 0xb740eccb, 0xb740eccb, 0xd50247da, 0xd50247da, 0xe0c382bf, 0xe0c382bf, 0x95d81f9d, 0x95d81f9d, 0x1051b5ac, 0x1051b5ac, 0x71f00e30, 0x71f00e30, 0xe35fe082, 0xe35fe082, 0xeda25a7a, 0xc4543b1e, 0x4725b91c, 0x4725b91c, }, 45 },
{ "cmdline_cat", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xd803b53b, 0xd803b53b, 0x70b7ae8b, 0x70b7ae8b, 0xa20d9a15, 0xa20d9a15, 0x6113d33b, 0x6113d33b, 0xfd38d301, 0xfd38d301, 0x8b04db4, 0x8b04db4, 0xdae859df, 0xdae859df, 0x80cf138b, 0x80cf138b, 0xdfa6ef9, 0xdfa6ef9, 0x856adaf0, 0x856adaf0, 0x7023cc2d, 0x7023cc2d, 0xad7e7d54, 0xad7e7d54, 0xde8eff49, 0xde8eff49, 0x34355cc3, 0x34355cc3, 0x25adccda, 0x25adccda, 0x6d6c350d, 0x6d6c350d, 0x1c49b499, 0x1c49b499, 0x8188f1b4, 0x8188f1b4, 0x5556dc0c, 0x5556dc0c, 0xbd9ef1f5, 0xbd9ef1f5, 0x5176575b, 0xd3e2f7f1, 0xccda996c, 0xccda996c, }, 45 },
{ "gfxterm_menu", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xa14ad466, 0x69520db1, 0xa14ad466, 0xe82e990f, 0x59c36f00, 0x59c36f00, 0xcba09304, 0xcba09304, 0xcba09304, 0x97b293e6, 0x97b293e6, 0x97b293e6, 0xd2fea778, 0xd2fea778, 0xd2fea778, 0x59c36f00, 0xe82e990f, 0xe82e990f, 0x59c36f00, }, 20 }, { "gfxterm_menu", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xa14ad466, 0x69520db1, 0xa14ad466, 0xe82e990f, 0x59c36f00, 0x59c36f00, 0xcba09304, 0xcba09304, 0xcba09304, 0x97b293e6, 0x97b293e6, 0x97b293e6, 0xd2fea778, 0xd2fea778, 0xd2fea778, 0x59c36f00, 0xe82e990f, 0xe82e990f, 0x59c36f00, }, 20 },
{ "gfxterm_menu", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0xa3faf149, 0xb4654ad0, 0xa3faf149, 0xff6942c6, 0xaa4593fe, 0xaa4593fe, 0xfda7eac8, 0xfda7eac8, 0xfda7eac8, 0x272045f3, 0x272045f3, 0x272045f3, 0x1b2c55ba, 0x1b2c55ba, 0x1b2c55ba, 0xaa4593fe, 0xff6942c6, 0xff6942c6, 0xaa4593fe, }, 20 }, { "gfxterm_menu", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0xa3faf149, 0xb4654ad0, 0xa3faf149, 0xff6942c6, 0xaa4593fe, 0xaa4593fe, 0xfda7eac8, 0xfda7eac8, 0xfda7eac8, 0x272045f3, 0x272045f3, 0x272045f3, 0x1b2c55ba, 0x1b2c55ba, 0x1b2c55ba, 0xaa4593fe, 0xff6942c6, 0xff6942c6, 0xaa4593fe, }, 20 },
{ "gfxterm_menu", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0xd5e4100a, 0x39522e26, 0xd5e4100a, 0x2e0276, 0xc9cbf769, 0xc9cbf769, 0x270340e6, 0x270340e6, 0x270340e6, 0x13ea67c8, 0x13ea67c8, 0x13ea67c8, 0x318e0f43, 0x318e0f43, 0x318e0f43, 0xc9cbf769, 0x2e0276, 0x2e0276, 0xc9cbf769, }, 20 }, { "gfxterm_menu", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0xd5e4100a, 0x39522e26, 0xd5e4100a, 0x2e0276, 0xc9cbf769, 0xc9cbf769, 0x270340e6, 0x270340e6, 0x270340e6, 0x13ea67c8, 0x13ea67c8, 0x13ea67c8, 0x318e0f43, 0x318e0f43, 0x318e0f43, 0xc9cbf769, 0x2e0276, 0x2e0276, 0xc9cbf769, }, 20 },

View file

@ -0,0 +1,117 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
/* All tests need to include test.h for GRUB testing framework. */
#include <grub/test.h>
#include <grub/dl.h>
#include <grub/video.h>
#include <grub/video_fb.h>
#include <grub/command.h>
#include <grub/font.h>
#include <grub/procfs.h>
#include <grub/env.h>
#include <grub/normal.h>
#include <grub/time.h>
GRUB_MOD_LICENSE ("GPLv3+");
static const char testfile[] =
/* Chinese & UTF-8 test from Carbon Jiao. */
"从硬盘的第一主分区启动\n"
"The quick brown fox jumped over the lazy dog.\n"
/* Characters used:
Code point Description UTF-8 encoding
----------- ------------------------------ --------------
U+263A unfilled smiley face E2 98 BA
U+00A1 inverted exclamation point C2 A1
U+00A3 British pound currency symbol C2 A3
U+03C4 Greek tau CF 84
U+00E4 lowercase letter a with umlaut C3 A4
U+2124 set 'Z' symbol (integers) E2 84 A4
U+2286 subset symbol E2 8A 86
U+211D set 'R' symbol (real numbers) E2 84 9D */
"Unicode test: happy\xE2\x98\xBA \xC2\xA3 5.00"
" \xC2\xA1\xCF\x84\xC3\xA4u! "
" \xE2\x84\xA4\xE2\x8A\x86\xE2\x84\x9D\n"
/* Test handling of bad (non-UTF8) sequences*/
"\x99Hello\xc2Hello\xc1\x81Hello\n";
;
static char *
get_test_txt (void)
{
return grub_strdup (testfile);
}
struct grub_procfs_entry test_txt =
{
.name = "test.txt",
.get_contents = get_test_txt
};
/* Functional test main method. */
static void
cmdline_cat_test (void)
{
unsigned i;
grub_dl_load ("gfxterm");
if (grub_font_load ("unicode") == 0)
{
grub_test_assert (0, "unicode font not found: %s", grub_errmsg);
return;
}
grub_procfs_register ("test.txt", &test_txt);
for (i = 0; i < GRUB_TEST_VIDEO_SMALL_N_MODES; i++)
{
grub_video_capture_start (&grub_test_video_modes[i],
grub_video_fbstd_colors,
grub_test_video_modes[i].number_of_colors);
grub_terminal_input_fake_sequence ((int [])
{ 'c', 'a', 't', ' ',
'(', 'p', 'r', 'o', 'c', ')',
'/', 't', 'e', 's', 't', '.',
't', 'x', 't', '\n',
GRUB_TERM_NO_KEY,
GRUB_TERM_NO_KEY, '\e'},
23);
grub_video_checksum ("cmdline_cat");
if (grub_test_use_gfxterm ())
return;
grub_cmdline_run (1);
grub_test_use_gfxterm_end ();
grub_terminal_input_fake_sequence_end ();
grub_video_checksum_end ();
grub_video_capture_end ();
}
grub_procfs_unregister (&test_txt);
}
/* Register example_test method as a functional test. */
GRUB_FUNCTIONAL_TEST (cmdline_cat_test, cmdline_cat_test);

View file

@ -111,9 +111,6 @@ gfxterm_menu (void)
for (j = 0; j < ARRAY_SIZE (tests); j++) for (j = 0; j < ARRAY_SIZE (tests); j++)
for (i = 0; i < GRUB_TEST_VIDEO_SMALL_N_MODES; i++) for (i = 0; i < GRUB_TEST_VIDEO_SMALL_N_MODES; i++)
{ {
struct grub_term_output *saved_outputs;
struct grub_term_output *saved_gfxnext;
struct grub_term_output *gfxterm;
grub_uint64_t start = grub_get_time_ms (); grub_uint64_t start = grub_get_time_ms ();
grub_video_capture_start (&grub_test_video_modes[i], grub_video_capture_start (&grub_test_video_modes[i],
@ -124,26 +121,8 @@ gfxterm_menu (void)
grub_video_checksum (tests[j].name); grub_video_checksum (tests[j].name);
saved_outputs = grub_term_outputs; if (grub_test_use_gfxterm ())
return;
FOR_ACTIVE_TERM_OUTPUTS (gfxterm)
if (grub_strcmp (gfxterm->name, "gfxterm") == 0)
break;
if (!gfxterm)
FOR_DISABLED_TERM_OUTPUTS (gfxterm)
if (grub_strcmp (gfxterm->name, "gfxterm") == 0)
break;
if (!gfxterm)
{
grub_test_assert (0, "terminal `%s' isn't found", "gfxterm");
return;
}
saved_gfxnext = gfxterm->next;
grub_term_outputs = gfxterm;
gfxterm->next = 0;
gfxterm->init (gfxterm);
grub_env_context_open (); grub_env_context_open ();
if (tests[j].var) if (tests[j].var)
@ -151,9 +130,7 @@ gfxterm_menu (void)
grub_normal_execute ("(proc)/test.cfg", 1, 0); grub_normal_execute ("(proc)/test.cfg", 1, 0);
grub_env_context_close (); grub_env_context_close ();
gfxterm->fini (gfxterm); grub_test_use_gfxterm_end ();
gfxterm->next = saved_gfxnext;
grub_term_outputs = saved_outputs;
grub_terminal_input_fake_sequence_end (); grub_terminal_input_fake_sequence_end ();
grub_video_checksum_end (); grub_video_checksum_end ();

View file

@ -57,6 +57,7 @@ grub_functional_all_tests (grub_extcmd_context_t ctxt __attribute__ ((unused)),
grub_dl_load ("videotest_checksum"); grub_dl_load ("videotest_checksum");
grub_dl_load ("gfxterm_menu"); grub_dl_load ("gfxterm_menu");
grub_dl_load ("setjmp_test"); grub_dl_load ("setjmp_test");
grub_dl_load ("cmdline_cat_test");
FOR_LIST_ELEMENTS (test, grub_test_list) FOR_LIST_ELEMENTS (test, grub_test_list)
ok = !grub_test_run (test) && ok; ok = !grub_test_run (test) && ok;

View file

@ -22,6 +22,7 @@
#include <grub/video.h> #include <grub/video.h>
#include <grub/lib/crc.h> #include <grub/lib/crc.h>
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/term.h>
GRUB_MOD_LICENSE ("GPLv3+"); GRUB_MOD_LICENSE ("GPLv3+");
@ -759,3 +760,42 @@ grub_video_checksum_end (void)
ctr = 0; ctr = 0;
grub_video_capture_refresh_cb = 0; grub_video_capture_refresh_cb = 0;
} }
static struct grub_term_output *saved_outputs;
static struct grub_term_output *saved_gfxnext;
static struct grub_term_output *gfxterm;
int
grub_test_use_gfxterm (void)
{
saved_outputs = grub_term_outputs;
FOR_ACTIVE_TERM_OUTPUTS (gfxterm)
if (grub_strcmp (gfxterm->name, "gfxterm") == 0)
break;
if (!gfxterm)
FOR_DISABLED_TERM_OUTPUTS (gfxterm)
if (grub_strcmp (gfxterm->name, "gfxterm") == 0)
break;
if (!gfxterm)
{
grub_test_assert (0, "terminal `%s' isn't found", "gfxterm");
return 1;
}
saved_gfxnext = gfxterm->next;
grub_term_outputs = gfxterm;
gfxterm->next = 0;
gfxterm->init (gfxterm);
return 0;
}
void
grub_test_use_gfxterm_end (void)
{
gfxterm->fini (gfxterm);
gfxterm->next = saved_gfxnext;
grub_term_outputs = saved_outputs;
}

View file

@ -114,6 +114,10 @@ grub_video_checksum_get_modename (void);
extern struct grub_video_mode_info grub_test_video_modes[GRUB_TEST_VIDEO_ALL_N_MODES]; extern struct grub_video_mode_info grub_test_video_modes[GRUB_TEST_VIDEO_ALL_N_MODES];
int
grub_test_use_gfxterm (void);
void grub_test_use_gfxterm_end (void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif