31004e6
From 7a17fdeafeca824d9dec7c2a57e8f958d58b45eb Mon Sep 17 00:00:00 2001
31004e6
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
31004e6
Date: Tue, 7 May 2013 12:28:59 +0200
f74b50e
Subject: [PATCH 438/482] 	* grub-core/tests/setjmp_test.c: New test.
31004e6
31004e6
---
31004e6
 ChangeLog                             |  4 ++
31004e6
 grub-core/Makefile.core.def           |  5 +++
31004e6
 grub-core/tests/lib/functional_test.c |  1 +
31004e6
 grub-core/tests/setjmp_test.c         | 74 +++++++++++++++++++++++++++++++++++
31004e6
 4 files changed, 84 insertions(+)
31004e6
 create mode 100644 grub-core/tests/setjmp_test.c
31004e6
31004e6
diff --git a/ChangeLog b/ChangeLog
31004e6
index cbd5d97..aeb61cd 100644
31004e6
--- a/ChangeLog
31004e6
+++ b/ChangeLog
31004e6
@@ -1,5 +1,9 @@
31004e6
 2013-05-07  Vladimir Serbinenko  <phcoder@gmail.com>
31004e6
 
31004e6
+	* grub-core/tests/setjmp_test.c: New test.
31004e6
+
31004e6
+2013-05-07  Vladimir Serbinenko  <phcoder@gmail.com>
31004e6
+
31004e6
 	New variables 'net_default_*' to determine MAC/IP of default interface.
31004e6
 
31004e6
 2013-05-07  Vladimir Serbinenko  <phcoder@gmail.com>
31004e6
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
31004e6
index 56a1ec3..7dc106e 100644
31004e6
--- a/grub-core/Makefile.core.def
31004e6
+++ b/grub-core/Makefile.core.def
31004e6
@@ -1743,6 +1743,11 @@ module = {
31004e6
 };
31004e6
 
31004e6
 module = {
31004e6
+  name = setjmp_test;
31004e6
+  common = tests/setjmp_test.c;
31004e6
+};
31004e6
+
31004e6
+module = {
31004e6
   name = videotest_checksum;
31004e6
   common = tests/videotest_checksum.c;
31004e6
 };
31004e6
diff --git a/grub-core/tests/lib/functional_test.c b/grub-core/tests/lib/functional_test.c
31004e6
index 957354e..8f66fe3 100644
31004e6
--- a/grub-core/tests/lib/functional_test.c
31004e6
+++ b/grub-core/tests/lib/functional_test.c
31004e6
@@ -56,6 +56,7 @@ grub_functional_all_tests (grub_extcmd_context_t ctxt __attribute__ ((unused)),
31004e6
   grub_dl_load ("exfctest");
31004e6
   grub_dl_load ("videotest_checksum");
31004e6
   grub_dl_load ("gfxterm_menu");
31004e6
+  grub_dl_load ("setjmp_test");
31004e6
 
31004e6
   FOR_LIST_ELEMENTS (test, grub_test_list)
31004e6
     ok = !grub_test_run (test) && ok;
31004e6
diff --git a/grub-core/tests/setjmp_test.c b/grub-core/tests/setjmp_test.c
31004e6
new file mode 100644
31004e6
index 0000000..29aab25
31004e6
--- /dev/null
31004e6
+++ b/grub-core/tests/setjmp_test.c
31004e6
@@ -0,0 +1,74 @@
31004e6
+/*
31004e6
+ *  GRUB  --  GRand Unified Bootloader
31004e6
+ *  Copyright (C) 2013 Free Software Foundation, Inc.
31004e6
+ *
31004e6
+ *  GRUB is free software: you can redistribute it and/or modify
31004e6
+ *  it under the terms of the GNU General Public License as published by
31004e6
+ *  the Free Software Foundation, either version 3 of the License, or
31004e6
+ *  (at your option) any later version.
31004e6
+ *
31004e6
+ *  GRUB is distributed in the hope that it will be useful,
31004e6
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
31004e6
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31004e6
+ *  GNU General Public License for more details.
31004e6
+ *
31004e6
+ *  You should have received a copy of the GNU General Public License
31004e6
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
31004e6
+ */
31004e6
+
31004e6
+#include <grub/test.h>
31004e6
+#include <grub/dl.h>
31004e6
+#include <grub/setjmp.h>
31004e6
+
31004e6
+GRUB_MOD_LICENSE ("GPLv3+");
31004e6
+
31004e6
+static grub_jmp_buf jmp_point;
31004e6
+static int expected, ctr;
31004e6
+
31004e6
+static void
31004e6
+jmp0 (void)
31004e6
+{
31004e6
+  grub_longjmp (jmp_point, 0);
31004e6
+}
31004e6
+
31004e6
+static void
31004e6
+jmp1 (void)
31004e6
+{
31004e6
+  grub_longjmp (jmp_point, 1);
31004e6
+}
31004e6
+
31004e6
+static void
31004e6
+jmp2 (void)
31004e6
+{
31004e6
+  grub_longjmp (jmp_point, 2);
31004e6
+}
31004e6
+
31004e6
+static void
31004e6
+setjmp_test (void)
31004e6
+{
31004e6
+  int val;
31004e6
+
31004e6
+  expected = 0;
31004e6
+  val = grub_setjmp (jmp_point);
31004e6
+
31004e6
+  grub_test_assert (val == expected, "setjmp returned %d instead of %d",
31004e6
+		    val, expected);
31004e6
+  switch (ctr++)
31004e6
+    {
31004e6
+    case 0:
31004e6
+      expected = 1;
31004e6
+      jmp0 ();
31004e6
+    case 1:
31004e6
+      expected = 1;
31004e6
+      jmp1 ();
31004e6
+    case 2:
31004e6
+      expected = 2;
31004e6
+      jmp2 ();
31004e6
+    case 3:
31004e6
+      return;
31004e6
+    }
31004e6
+  grub_test_assert (0, "setjmp didn't return enough times");
31004e6
+}
31004e6
+
31004e6
+/* Register example_test method as a functional test.  */
31004e6
+GRUB_FUNCTIONAL_TEST (setjmp_test, setjmp_test);
31004e6
-- 
31004e6
1.8.2.1
31004e6