gfxterm_menu.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2013 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* All tests need to include test.h for GRUB testing framework. */
  19. #include <grub/test.h>
  20. #include <grub/dl.h>
  21. #include <grub/video.h>
  22. #include <grub/video_fb.h>
  23. #include <grub/command.h>
  24. #include <grub/font.h>
  25. #include <grub/procfs.h>
  26. #include <grub/env.h>
  27. #include <grub/normal.h>
  28. #include <grub/time.h>
  29. GRUB_MOD_LICENSE ("GPLv3+");
  30. static const char testfile[] =
  31. "menuentry \"test\" {\n"
  32. "\ttrue\n"
  33. "}\n"
  34. "menuentry \"s̛ ơ t o̒ s̒ u o̕̚ 8.04 m̂ñåh̊z̆x̣ a̡ b̢g̢ u᷎ô᷎ ô᷎ O̷ a̖̣ ȃ̐\" --class ubuntu --class linux --class os {\n"
  35. "\ttrue\n"
  36. "}\n"
  37. "menuentry \" הַרמלל(טוֹבָ) לֶךְ\" --class opensuse --class linux --class os {\n"
  38. "\ttrue\n"
  39. "}\n"
  40. "menuentry \"الرملل جِداً لِكَ\" --class gentoo --class linux --class os {\n"
  41. "\ttrue\n"
  42. "}\n"
  43. "menuentry \"ὑπόγυͅον\" --class kubuntu --class linux --class os {\n"
  44. "\ttrue\n"
  45. "}\n"
  46. "menuentry \"سَّ نِّ نَّ نٌّ نّْ\" --class linuxmint --class linux --class os {\n"
  47. "\ttrue\n"
  48. "}\n"
  49. /* Chinese & UTF-8 test from Carbon Jiao. */
  50. "menuentry \"从硬盘的第一主分区启动\" --class \"windows xp\" --class windows --class os {\n"
  51. "\ttrue\n"
  52. "}\n"
  53. "timeout=3\n";
  54. static char *
  55. get_test_cfg (grub_size_t *sz)
  56. {
  57. *sz = grub_strlen (testfile);
  58. return grub_strdup (testfile);
  59. }
  60. struct grub_procfs_entry test_cfg =
  61. {
  62. .name = "test.cfg",
  63. .get_contents = get_test_cfg
  64. };
  65. struct
  66. {
  67. const char *name;
  68. const char *var;
  69. const char *val;
  70. } tests[] =
  71. {
  72. { "gfxterm_menu", NULL, NULL },
  73. { "gfxmenu", "theme", "starfield/theme.txt" },
  74. { "gfxterm_ar", "lang", "en@arabic" },
  75. { "gfxterm_cyr", "lang", "en@cyrillic" },
  76. { "gfxterm_heb", "lang", "en@hebrew" },
  77. { "gfxterm_gre", "lang", "en@greek" },
  78. { "gfxterm_ru", "lang", "ru" },
  79. { "gfxterm_fr", "lang", "fr" },
  80. { "gfxterm_quot", "lang", "en@quot" },
  81. { "gfxterm_piglatin", "lang", "en@piglatin" },
  82. { "gfxterm_ch", "lang", "de_CH" },
  83. { "gfxterm_red", "menu_color_normal", "red/blue" },
  84. { "gfxterm_high", "menu_color_highlight", "blue/red" },
  85. };
  86. #define FONT_NAME "Unknown Regular 16"
  87. /* Functional test main method. */
  88. static void
  89. gfxterm_menu (void)
  90. {
  91. unsigned i, j;
  92. grub_font_t font;
  93. grub_dl_load ("png");
  94. grub_dl_load ("gettext");
  95. grub_dl_load ("gfxterm");
  96. grub_errno = GRUB_ERR_NONE;
  97. grub_dl_load ("gfxmenu");
  98. font = grub_font_get (FONT_NAME);
  99. if (font && grub_strcmp (font->name, FONT_NAME) != 0)
  100. font = 0;
  101. if (!font)
  102. font = grub_font_load ("unicode");
  103. if (!font)
  104. {
  105. grub_test_assert (0, "unicode font not found: %s", grub_errmsg);
  106. return;
  107. }
  108. grub_procfs_register ("test.cfg", &test_cfg);
  109. for (j = 0; j < ARRAY_SIZE (tests); j++)
  110. for (i = 0; i < GRUB_TEST_VIDEO_SMALL_N_MODES; i++)
  111. {
  112. grub_uint64_t start;
  113. #if defined (GRUB_MACHINE_MIPS_QEMU_MIPS) || defined (GRUB_MACHINE_IEEE1275)
  114. if (grub_test_video_modes[i].width > 1024)
  115. continue;
  116. if (grub_strcmp (tests[j].name, "gfxmenu") == 0
  117. && grub_test_video_modes[i].width > 800)
  118. continue;
  119. #endif
  120. start = grub_get_time_ms ();
  121. grub_video_capture_start (&grub_test_video_modes[i],
  122. grub_video_fbstd_colors,
  123. grub_test_video_modes[i].number_of_colors);
  124. if (grub_errno)
  125. {
  126. grub_test_assert (0, "can't start capture: %d: %s",
  127. grub_errno, grub_errmsg);
  128. return;
  129. }
  130. grub_terminal_input_fake_sequence ((int []) { -1, -1, -1, GRUB_TERM_KEY_DOWN, -1, 'e',
  131. -1, GRUB_TERM_KEY_RIGHT, -1, 'x', -1, GRUB_TERM_ESC, -1, GRUB_TERM_ESC }, 14);
  132. grub_video_checksum (tests[j].name);
  133. if (grub_test_use_gfxterm ())
  134. return;
  135. grub_env_context_open ();
  136. if (tests[j].var)
  137. grub_env_set (tests[j].var, tests[j].val);
  138. grub_normal_execute ("(proc)/test.cfg", 1, 0);
  139. grub_env_context_close ();
  140. grub_test_use_gfxterm_end ();
  141. grub_terminal_input_fake_sequence_end ();
  142. grub_video_checksum_end ();
  143. grub_video_capture_end ();
  144. if (tests[j].var)
  145. grub_env_unset (tests[j].var);
  146. grub_printf ("%s %dx%dx%s done %lld ms\n", tests[j].name,
  147. grub_test_video_modes[i].width,
  148. grub_test_video_modes[i].height,
  149. grub_video_checksum_get_modename (), (long long) (grub_get_time_ms () - start));
  150. }
  151. grub_procfs_unregister (&test_cfg);
  152. }
  153. /* Register example_test method as a functional test. */
  154. GRUB_FUNCTIONAL_TEST (gfxterm_menu, gfxterm_menu);