2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2010 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#ifndef GRUB_TEST_HEADER
2N/A#define GRUB_TEST_HEADER
2N/A
2N/A#include <grub/dl.h>
2N/A#include <grub/list.h>
2N/A#include <grub/misc.h>
2N/A#include <grub/types.h>
2N/A#include <grub/symbol.h>
2N/A
2N/Astruct grub_test
2N/A{
2N/A /* The next test. */
2N/A struct grub_test *next;
2N/A
2N/A /* The test name. */
2N/A char *name;
2N/A
2N/A /* The test main function. */
2N/A void (*main) (void);
2N/A};
2N/Atypedef struct grub_test *grub_test_t;
2N/A
2N/Aextern grub_test_t grub_test_list;
2N/A
2N/Avoid grub_test_register (const char *name, void (*test) (void));
2N/Avoid grub_test_unregister (const char *name);
2N/A
2N/A/* Execute a test and print results. */
2N/Aint grub_test_run (grub_test_t test);
2N/A
2N/A/* Test `cond' for nonzero; log failure otherwise. */
2N/Avoid grub_test_nonzero (int cond, const char *file,
2N/A const char *func, grub_uint32_t line,
2N/A const char *fmt, ...)
2N/A __attribute__ ((format (printf, 5, 6)));
2N/A
2N/A/* Macro to fill in location details and an optional error message. */
2N/A#define grub_test_assert(cond, ...) \
2N/A grub_test_nonzero(cond, GRUB_FILE, __FUNCTION__, __LINE__, \
2N/A ## __VA_ARGS__, \
2N/A "assert failed: %s", #cond)
2N/A
2N/A/* Macro to define a unit test. */
2N/A#define GRUB_UNIT_TEST(name, funp) \
2N/A void grub_unit_test_init (void) \
2N/A { \
2N/A grub_test_register (name, funp); \
2N/A } \
2N/A \
2N/A void grub_unit_test_fini (void) \
2N/A { \
2N/A grub_test_unregister (name); \
2N/A }
2N/A
2N/A/* Macro to define a functional test. */
2N/A#define GRUB_FUNCTIONAL_TEST(name, funp) \
2N/A GRUB_MOD_INIT(name) \
2N/A { \
2N/A grub_test_register (#name, funp); \
2N/A } \
2N/A \
2N/A GRUB_MOD_FINI(name) \
2N/A { \
2N/A grub_test_unregister (#name); \
2N/A }
2N/A
2N/A#endif /* ! GRUB_TEST_HEADER */