Home | History | Annotate | Line # | Download | only in gcc
selftest.h revision 1.1.1.2
      1      1.1  mrg /* A self-testing framework, for use by -fself-test.
      2  1.1.1.2  mrg    Copyright (C) 2015-2018 Free Software Foundation, Inc.
      3      1.1  mrg 
      4      1.1  mrg This file is part of GCC.
      5      1.1  mrg 
      6      1.1  mrg GCC is free software; you can redistribute it and/or modify it under
      7      1.1  mrg the terms of the GNU General Public License as published by the Free
      8      1.1  mrg Software Foundation; either version 3, or (at your option) any later
      9      1.1  mrg version.
     10      1.1  mrg 
     11      1.1  mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
     12      1.1  mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13      1.1  mrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14      1.1  mrg for more details.
     15      1.1  mrg 
     16      1.1  mrg You should have received a copy of the GNU General Public License
     17      1.1  mrg along with GCC; see the file COPYING3.  If not see
     18      1.1  mrg <http://www.gnu.org/licenses/>.  */
     19      1.1  mrg 
     20      1.1  mrg #ifndef GCC_SELFTEST_H
     21      1.1  mrg #define GCC_SELFTEST_H
     22      1.1  mrg 
     23      1.1  mrg /* The selftest code should entirely disappear in a production
     24      1.1  mrg    configuration, hence we guard all of it with #if CHECKING_P.  */
     25      1.1  mrg 
     26      1.1  mrg #if CHECKING_P
     27      1.1  mrg 
     28      1.1  mrg namespace selftest {
     29      1.1  mrg 
     30      1.1  mrg /* A struct describing the source-location of a selftest, to make it
     31      1.1  mrg    easier to track down failing tests.  */
     32      1.1  mrg 
     33      1.1  mrg struct location
     34      1.1  mrg {
     35      1.1  mrg   location (const char *file, int line, const char *function)
     36      1.1  mrg     : m_file (file), m_line (line), m_function (function) {}
     37      1.1  mrg 
     38      1.1  mrg   const char *m_file;
     39      1.1  mrg   int m_line;
     40      1.1  mrg   const char *m_function;
     41      1.1  mrg };
     42      1.1  mrg 
     43      1.1  mrg /* A macro for use in selftests and by the ASSERT_ macros below,
     44      1.1  mrg    constructing a selftest::location for the current source location.  */
     45      1.1  mrg 
     46      1.1  mrg #define SELFTEST_LOCATION \
     47      1.1  mrg   (::selftest::location (__FILE__, __LINE__, __FUNCTION__))
     48      1.1  mrg 
     49      1.1  mrg /* The entrypoint for running all tests.  */
     50      1.1  mrg 
     51      1.1  mrg extern void run_tests ();
     52      1.1  mrg 
     53      1.1  mrg /* Record the successful outcome of some aspect of the test.  */
     54      1.1  mrg 
     55      1.1  mrg extern void pass (const location &loc, const char *msg);
     56      1.1  mrg 
     57      1.1  mrg /* Report the failed outcome of some aspect of the test and abort.  */
     58      1.1  mrg 
     59      1.1  mrg extern void fail (const location &loc, const char *msg)
     60      1.1  mrg   ATTRIBUTE_NORETURN;
     61      1.1  mrg 
     62      1.1  mrg /* As "fail", but using printf-style formatted output.  */
     63      1.1  mrg 
     64      1.1  mrg extern void fail_formatted (const location &loc, const char *fmt, ...)
     65      1.1  mrg   ATTRIBUTE_PRINTF_2 ATTRIBUTE_NORETURN;
     66      1.1  mrg 
     67      1.1  mrg /* Implementation detail of ASSERT_STREQ.  */
     68      1.1  mrg 
     69      1.1  mrg extern void assert_streq (const location &loc,
     70      1.1  mrg 			  const char *desc_expected, const char *desc_actual,
     71      1.1  mrg 			  const char *val_expected, const char *val_actual);
     72      1.1  mrg 
     73      1.1  mrg /* Implementation detail of ASSERT_STR_CONTAINS.  */
     74      1.1  mrg 
     75      1.1  mrg extern void assert_str_contains (const location &loc,
     76      1.1  mrg 				 const char *desc_haystack,
     77      1.1  mrg 				 const char *desc_needle,
     78      1.1  mrg 				 const char *val_haystack,
     79      1.1  mrg 				 const char *val_needle);
     80      1.1  mrg 
     81      1.1  mrg /* A named temporary file for use in selftests.
     82      1.1  mrg    Usable for writing out files, and as the base class for
     83      1.1  mrg    temp_source_file.
     84      1.1  mrg    The file is unlinked in the destructor.  */
     85      1.1  mrg 
     86      1.1  mrg class named_temp_file
     87      1.1  mrg {
     88      1.1  mrg  public:
     89      1.1  mrg   named_temp_file (const char *suffix);
     90      1.1  mrg   ~named_temp_file ();
     91      1.1  mrg   const char *get_filename () const { return m_filename; }
     92      1.1  mrg 
     93      1.1  mrg  private:
     94      1.1  mrg   char *m_filename;
     95      1.1  mrg };
     96      1.1  mrg 
     97      1.1  mrg /* A class for writing out a temporary sourcefile for use in selftests
     98      1.1  mrg    of input handling.  */
     99      1.1  mrg 
    100      1.1  mrg class temp_source_file : public named_temp_file
    101      1.1  mrg {
    102      1.1  mrg  public:
    103      1.1  mrg   temp_source_file (const location &loc, const char *suffix,
    104      1.1  mrg 		    const char *content);
    105      1.1  mrg };
    106      1.1  mrg 
    107      1.1  mrg /* Various selftests involving location-handling require constructing a
    108      1.1  mrg    line table and one or more line maps within it.
    109      1.1  mrg 
    110      1.1  mrg    For maximum test coverage we want to run these tests with a variety
    111      1.1  mrg    of situations:
    112      1.1  mrg    - line_table->default_range_bits: some frontends use a non-zero value
    113      1.1  mrg    and others use zero
    114      1.1  mrg    - the fallback modes within line-map.c: there are various threshold
    115      1.1  mrg    values for source_location/location_t beyond line-map.c changes
    116      1.1  mrg    behavior (disabling of the range-packing optimization, disabling
    117      1.1  mrg    of column-tracking).  We can exercise these by starting the line_table
    118      1.1  mrg    at interesting values at or near these thresholds.
    119      1.1  mrg 
    120      1.1  mrg    The following struct describes a particular case within our test
    121      1.1  mrg    matrix.  */
    122      1.1  mrg 
    123      1.1  mrg struct line_table_case;
    124      1.1  mrg 
    125      1.1  mrg /* A class for overriding the global "line_table" within a selftest,
    126      1.1  mrg    restoring its value afterwards.  At most one instance of this
    127      1.1  mrg    class can exist at once, due to the need to keep the old value
    128      1.1  mrg    of line_table as a GC root.  */
    129      1.1  mrg 
    130      1.1  mrg class line_table_test
    131      1.1  mrg {
    132      1.1  mrg  public:
    133      1.1  mrg   /* Default constructor.  Override "line_table", using sane defaults
    134      1.1  mrg      for the temporary line_table.  */
    135      1.1  mrg   line_table_test ();
    136      1.1  mrg 
    137      1.1  mrg   /* Constructor.  Override "line_table", using the case described by C.  */
    138      1.1  mrg   line_table_test (const line_table_case &c);
    139      1.1  mrg 
    140      1.1  mrg   /* Destructor.  Restore the saved line_table.  */
    141      1.1  mrg   ~line_table_test ();
    142      1.1  mrg };
    143      1.1  mrg 
    144      1.1  mrg /* Run TESTCASE multiple times, once for each case in our test matrix.  */
    145      1.1  mrg 
    146      1.1  mrg extern void
    147      1.1  mrg for_each_line_table_case (void (*testcase) (const line_table_case &));
    148      1.1  mrg 
    149      1.1  mrg /* Read the contents of PATH into memory, returning a 0-terminated buffer
    150      1.1  mrg    that must be freed by the caller.
    151      1.1  mrg    Fail (and abort) if there are any problems, with LOC as the reported
    152      1.1  mrg    location of the failure.  */
    153      1.1  mrg 
    154      1.1  mrg extern char *read_file (const location &loc, const char *path);
    155      1.1  mrg 
    156      1.1  mrg /* A helper function for writing tests that interact with the
    157      1.1  mrg    garbage collector.  */
    158      1.1  mrg 
    159      1.1  mrg extern void forcibly_ggc_collect ();
    160      1.1  mrg 
    161      1.1  mrg /* Convert a path relative to SRCDIR/gcc/testsuite/selftests
    162      1.1  mrg    to a real path (either absolute, or relative to pwd).
    163      1.1  mrg    The result should be freed by the caller.  */
    164      1.1  mrg 
    165      1.1  mrg extern char *locate_file (const char *path);
    166      1.1  mrg 
    167      1.1  mrg /* The path of SRCDIR/testsuite/selftests.  */
    168      1.1  mrg 
    169      1.1  mrg extern const char *path_to_selftest_files;
    170      1.1  mrg 
    171  1.1.1.2  mrg /* selftest::test_runner is an implementation detail of selftest::run_tests,
    172  1.1.1.2  mrg    exposed here to allow plugins to run their own suites of tests.  */
    173  1.1.1.2  mrg 
    174  1.1.1.2  mrg class test_runner
    175  1.1.1.2  mrg {
    176  1.1.1.2  mrg  public:
    177  1.1.1.2  mrg   test_runner (const char *name);
    178  1.1.1.2  mrg   ~test_runner ();
    179  1.1.1.2  mrg 
    180  1.1.1.2  mrg  private:
    181  1.1.1.2  mrg   const char *m_name;
    182  1.1.1.2  mrg   long m_start_time;
    183  1.1.1.2  mrg };
    184  1.1.1.2  mrg 
    185      1.1  mrg /* Declarations for specific families of tests (by source file), in
    186      1.1  mrg    alphabetical order.  */
    187  1.1.1.2  mrg extern void attribute_c_tests ();
    188      1.1  mrg extern void bitmap_c_tests ();
    189  1.1.1.2  mrg extern void sbitmap_c_tests ();
    190      1.1  mrg extern void diagnostic_c_tests ();
    191      1.1  mrg extern void diagnostic_show_locus_c_tests ();
    192      1.1  mrg extern void edit_context_c_tests ();
    193      1.1  mrg extern void et_forest_c_tests ();
    194      1.1  mrg extern void fold_const_c_tests ();
    195      1.1  mrg extern void fibonacci_heap_c_tests ();
    196      1.1  mrg extern void function_tests_c_tests ();
    197      1.1  mrg extern void gimple_c_tests ();
    198      1.1  mrg extern void ggc_tests_c_tests ();
    199      1.1  mrg extern void hash_map_tests_c_tests ();
    200      1.1  mrg extern void hash_set_tests_c_tests ();
    201      1.1  mrg extern void input_c_tests ();
    202      1.1  mrg extern void pretty_print_c_tests ();
    203      1.1  mrg extern void read_rtl_function_c_tests ();
    204      1.1  mrg extern void rtl_tests_c_tests ();
    205      1.1  mrg extern void selftest_c_tests ();
    206      1.1  mrg extern void spellcheck_c_tests ();
    207      1.1  mrg extern void spellcheck_tree_c_tests ();
    208      1.1  mrg extern void sreal_c_tests ();
    209      1.1  mrg extern void store_merging_c_tests ();
    210      1.1  mrg extern void typed_splay_tree_c_tests ();
    211      1.1  mrg extern void tree_c_tests ();
    212      1.1  mrg extern void tree_cfg_c_tests ();
    213  1.1.1.2  mrg extern void unique_ptr_tests_cc_tests ();
    214      1.1  mrg extern void vec_c_tests ();
    215      1.1  mrg extern void wide_int_cc_tests ();
    216  1.1.1.2  mrg extern void predict_c_tests ();
    217  1.1.1.2  mrg extern void simplify_rtx_c_tests ();
    218  1.1.1.2  mrg extern void vec_perm_indices_c_tests ();
    219      1.1  mrg 
    220      1.1  mrg extern int num_passes;
    221      1.1  mrg 
    222      1.1  mrg } /* end of namespace selftest.  */
    223      1.1  mrg 
    224      1.1  mrg /* Macros for writing tests.  */
    225      1.1  mrg 
    226      1.1  mrg /* Evaluate EXPR and coerce to bool, calling
    227      1.1  mrg    ::selftest::pass if it is true,
    228      1.1  mrg    ::selftest::fail if it false.  */
    229      1.1  mrg 
    230      1.1  mrg #define ASSERT_TRUE(EXPR)				\
    231      1.1  mrg   ASSERT_TRUE_AT (SELFTEST_LOCATION, (EXPR))
    232      1.1  mrg 
    233      1.1  mrg /* Like ASSERT_TRUE, but treat LOC as the effective location of the
    234      1.1  mrg    selftest.  */
    235      1.1  mrg 
    236      1.1  mrg #define ASSERT_TRUE_AT(LOC, EXPR)			\
    237      1.1  mrg   SELFTEST_BEGIN_STMT					\
    238  1.1.1.2  mrg   const char *desc_ = "ASSERT_TRUE (" #EXPR ")";	\
    239  1.1.1.2  mrg   bool actual_ = (EXPR);				\
    240  1.1.1.2  mrg   if (actual_)						\
    241  1.1.1.2  mrg     ::selftest::pass ((LOC), desc_);			\
    242      1.1  mrg   else							\
    243  1.1.1.2  mrg     ::selftest::fail ((LOC), desc_);			\
    244      1.1  mrg   SELFTEST_END_STMT
    245      1.1  mrg 
    246      1.1  mrg /* Evaluate EXPR and coerce to bool, calling
    247      1.1  mrg    ::selftest::pass if it is false,
    248      1.1  mrg    ::selftest::fail if it true.  */
    249      1.1  mrg 
    250      1.1  mrg #define ASSERT_FALSE(EXPR)					\
    251      1.1  mrg   ASSERT_FALSE_AT (SELFTEST_LOCATION, (EXPR))
    252      1.1  mrg 
    253      1.1  mrg /* Like ASSERT_FALSE, but treat LOC as the effective location of the
    254      1.1  mrg    selftest.  */
    255      1.1  mrg 
    256      1.1  mrg #define ASSERT_FALSE_AT(LOC, EXPR)				\
    257      1.1  mrg   SELFTEST_BEGIN_STMT						\
    258  1.1.1.2  mrg   const char *desc_ = "ASSERT_FALSE (" #EXPR ")";		\
    259  1.1.1.2  mrg   bool actual_ = (EXPR);					\
    260  1.1.1.2  mrg   if (actual_)							\
    261  1.1.1.2  mrg     ::selftest::fail ((LOC), desc_);				\
    262  1.1.1.2  mrg   else								\
    263  1.1.1.2  mrg     ::selftest::pass ((LOC), desc_);				\
    264      1.1  mrg   SELFTEST_END_STMT
    265      1.1  mrg 
    266      1.1  mrg /* Evaluate EXPECTED and ACTUAL and compare them with ==, calling
    267      1.1  mrg    ::selftest::pass if they are equal,
    268      1.1  mrg    ::selftest::fail if they are non-equal.  */
    269      1.1  mrg 
    270      1.1  mrg #define ASSERT_EQ(EXPECTED, ACTUAL) \
    271      1.1  mrg   ASSERT_EQ_AT ((SELFTEST_LOCATION), (EXPECTED), (ACTUAL))
    272      1.1  mrg 
    273      1.1  mrg /* Like ASSERT_EQ, but treat LOC as the effective location of the
    274      1.1  mrg    selftest.  */
    275      1.1  mrg 
    276      1.1  mrg #define ASSERT_EQ_AT(LOC, EXPECTED, ACTUAL)		       \
    277      1.1  mrg   SELFTEST_BEGIN_STMT					       \
    278  1.1.1.2  mrg   const char *desc_ = "ASSERT_EQ (" #EXPECTED ", " #ACTUAL ")"; \
    279      1.1  mrg   if ((EXPECTED) == (ACTUAL))				       \
    280  1.1.1.2  mrg     ::selftest::pass ((LOC), desc_);			       \
    281      1.1  mrg   else							       \
    282  1.1.1.2  mrg     ::selftest::fail ((LOC), desc_);			       \
    283  1.1.1.2  mrg   SELFTEST_END_STMT
    284  1.1.1.2  mrg 
    285  1.1.1.2  mrg /* Evaluate EXPECTED and ACTUAL and compare them with known_eq, calling
    286  1.1.1.2  mrg    ::selftest::pass if they are always equal,
    287  1.1.1.2  mrg    ::selftest::fail if they might be non-equal.  */
    288  1.1.1.2  mrg 
    289  1.1.1.2  mrg #define ASSERT_KNOWN_EQ(EXPECTED, ACTUAL) \
    290  1.1.1.2  mrg   ASSERT_KNOWN_EQ_AT ((SELFTEST_LOCATION), (EXPECTED), (ACTUAL))
    291  1.1.1.2  mrg 
    292  1.1.1.2  mrg /* Like ASSERT_KNOWN_EQ, but treat LOC as the effective location of the
    293  1.1.1.2  mrg    selftest.  */
    294  1.1.1.2  mrg 
    295  1.1.1.2  mrg #define ASSERT_KNOWN_EQ_AT(LOC, EXPECTED, ACTUAL)			\
    296  1.1.1.2  mrg   SELFTEST_BEGIN_STMT							\
    297  1.1.1.2  mrg   const char *desc = "ASSERT_KNOWN_EQ (" #EXPECTED ", " #ACTUAL ")";	\
    298  1.1.1.2  mrg   if (known_eq (EXPECTED, ACTUAL))					\
    299  1.1.1.2  mrg     ::selftest::pass ((LOC), desc);					\
    300  1.1.1.2  mrg   else									\
    301  1.1.1.2  mrg     ::selftest::fail ((LOC), desc);					\
    302      1.1  mrg   SELFTEST_END_STMT
    303      1.1  mrg 
    304      1.1  mrg /* Evaluate EXPECTED and ACTUAL and compare them with !=, calling
    305      1.1  mrg    ::selftest::pass if they are non-equal,
    306      1.1  mrg    ::selftest::fail if they are equal.  */
    307      1.1  mrg 
    308      1.1  mrg #define ASSERT_NE(EXPECTED, ACTUAL)			       \
    309      1.1  mrg   SELFTEST_BEGIN_STMT					       \
    310  1.1.1.2  mrg   const char *desc_ = "ASSERT_NE (" #EXPECTED ", " #ACTUAL ")"; \
    311      1.1  mrg   if ((EXPECTED) != (ACTUAL))				       \
    312  1.1.1.2  mrg     ::selftest::pass (SELFTEST_LOCATION, desc_);	       \
    313  1.1.1.2  mrg   else							       \
    314  1.1.1.2  mrg     ::selftest::fail (SELFTEST_LOCATION, desc_);	       \
    315  1.1.1.2  mrg   SELFTEST_END_STMT
    316  1.1.1.2  mrg 
    317  1.1.1.2  mrg /* Evaluate EXPECTED and ACTUAL and compare them with maybe_ne, calling
    318  1.1.1.2  mrg    ::selftest::pass if they might be non-equal,
    319  1.1.1.2  mrg    ::selftest::fail if they are known to be equal.  */
    320  1.1.1.2  mrg 
    321  1.1.1.2  mrg #define ASSERT_MAYBE_NE(EXPECTED, ACTUAL) \
    322  1.1.1.2  mrg   ASSERT_MAYBE_NE_AT ((SELFTEST_LOCATION), (EXPECTED), (ACTUAL))
    323  1.1.1.2  mrg 
    324  1.1.1.2  mrg /* Like ASSERT_MAYBE_NE, but treat LOC as the effective location of the
    325  1.1.1.2  mrg    selftest.  */
    326  1.1.1.2  mrg 
    327  1.1.1.2  mrg #define ASSERT_MAYBE_NE_AT(LOC, EXPECTED, ACTUAL)			\
    328  1.1.1.2  mrg   SELFTEST_BEGIN_STMT							\
    329  1.1.1.2  mrg   const char *desc = "ASSERT_MAYBE_NE (" #EXPECTED ", " #ACTUAL ")";	\
    330  1.1.1.2  mrg   if (maybe_ne (EXPECTED, ACTUAL))					\
    331  1.1.1.2  mrg     ::selftest::pass ((LOC), desc);					\
    332  1.1.1.2  mrg   else									\
    333  1.1.1.2  mrg     ::selftest::fail ((LOC), desc);					\
    334  1.1.1.2  mrg   SELFTEST_END_STMT
    335  1.1.1.2  mrg 
    336  1.1.1.2  mrg /* Evaluate LHS and RHS and compare them with >, calling
    337  1.1.1.2  mrg    ::selftest::pass if LHS > RHS,
    338  1.1.1.2  mrg    ::selftest::fail otherwise.  */
    339  1.1.1.2  mrg 
    340  1.1.1.2  mrg #define ASSERT_GT(LHS, RHS)				\
    341  1.1.1.2  mrg   ASSERT_GT_AT ((SELFTEST_LOCATION), (LHS), (RHS))
    342  1.1.1.2  mrg 
    343  1.1.1.2  mrg /* Like ASSERT_GT, but treat LOC as the effective location of the
    344  1.1.1.2  mrg    selftest.  */
    345  1.1.1.2  mrg 
    346  1.1.1.2  mrg #define ASSERT_GT_AT(LOC, LHS, RHS)		       \
    347  1.1.1.2  mrg   SELFTEST_BEGIN_STMT					       \
    348  1.1.1.2  mrg   const char *desc_ = "ASSERT_GT (" #LHS ", " #RHS ")";	       \
    349  1.1.1.2  mrg   if ((LHS) > (RHS))					       \
    350  1.1.1.2  mrg     ::selftest::pass ((LOC), desc_);			       \
    351      1.1  mrg   else							       \
    352  1.1.1.2  mrg     ::selftest::fail ((LOC), desc_);			       \
    353  1.1.1.2  mrg   SELFTEST_END_STMT
    354  1.1.1.2  mrg 
    355  1.1.1.2  mrg /* Evaluate LHS and RHS and compare them with <, calling
    356  1.1.1.2  mrg    ::selftest::pass if LHS < RHS,
    357  1.1.1.2  mrg    ::selftest::fail otherwise.  */
    358  1.1.1.2  mrg 
    359  1.1.1.2  mrg #define ASSERT_LT(LHS, RHS)				\
    360  1.1.1.2  mrg   ASSERT_LT_AT ((SELFTEST_LOCATION), (LHS), (RHS))
    361  1.1.1.2  mrg 
    362  1.1.1.2  mrg /* Like ASSERT_LT, but treat LOC as the effective location of the
    363  1.1.1.2  mrg    selftest.  */
    364  1.1.1.2  mrg 
    365  1.1.1.2  mrg #define ASSERT_LT_AT(LOC, LHS, RHS)		       \
    366  1.1.1.2  mrg   SELFTEST_BEGIN_STMT					       \
    367  1.1.1.2  mrg   const char *desc_ = "ASSERT_LT (" #LHS ", " #RHS ")";	       \
    368  1.1.1.2  mrg   if ((LHS) < (RHS))					       \
    369  1.1.1.2  mrg     ::selftest::pass ((LOC), desc_);			       \
    370  1.1.1.2  mrg   else							       \
    371  1.1.1.2  mrg     ::selftest::fail ((LOC), desc_);			       \
    372      1.1  mrg   SELFTEST_END_STMT
    373      1.1  mrg 
    374      1.1  mrg /* Evaluate EXPECTED and ACTUAL and compare them with strcmp, calling
    375      1.1  mrg    ::selftest::pass if they are equal,
    376      1.1  mrg    ::selftest::fail if they are non-equal.  */
    377      1.1  mrg 
    378      1.1  mrg #define ASSERT_STREQ(EXPECTED, ACTUAL)				    \
    379      1.1  mrg   SELFTEST_BEGIN_STMT						    \
    380      1.1  mrg   ::selftest::assert_streq (SELFTEST_LOCATION, #EXPECTED, #ACTUAL, \
    381      1.1  mrg 			    (EXPECTED), (ACTUAL));		    \
    382      1.1  mrg   SELFTEST_END_STMT
    383      1.1  mrg 
    384      1.1  mrg /* Like ASSERT_STREQ, but treat LOC as the effective location of the
    385      1.1  mrg    selftest.  */
    386      1.1  mrg 
    387      1.1  mrg #define ASSERT_STREQ_AT(LOC, EXPECTED, ACTUAL)			    \
    388      1.1  mrg   SELFTEST_BEGIN_STMT						    \
    389      1.1  mrg   ::selftest::assert_streq ((LOC), #EXPECTED, #ACTUAL,		    \
    390      1.1  mrg 			    (EXPECTED), (ACTUAL));		    \
    391      1.1  mrg   SELFTEST_END_STMT
    392      1.1  mrg 
    393      1.1  mrg /* Evaluate HAYSTACK and NEEDLE and use strstr to determine if NEEDLE
    394      1.1  mrg    is within HAYSTACK.
    395      1.1  mrg    ::selftest::pass if NEEDLE is found.
    396      1.1  mrg    ::selftest::fail if it is not found.  */
    397      1.1  mrg 
    398      1.1  mrg #define ASSERT_STR_CONTAINS(HAYSTACK, NEEDLE)				\
    399      1.1  mrg   SELFTEST_BEGIN_STMT							\
    400      1.1  mrg   ::selftest::assert_str_contains (SELFTEST_LOCATION, #HAYSTACK, #NEEDLE, \
    401      1.1  mrg 				   (HAYSTACK), (NEEDLE));		\
    402      1.1  mrg   SELFTEST_END_STMT
    403      1.1  mrg 
    404      1.1  mrg /* Evaluate PRED1 (VAL1), calling ::selftest::pass if it is true,
    405      1.1  mrg    ::selftest::fail if it is false.  */
    406      1.1  mrg 
    407  1.1.1.2  mrg #define ASSERT_PRED1(PRED1, VAL1)				\
    408  1.1.1.2  mrg   SELFTEST_BEGIN_STMT						\
    409  1.1.1.2  mrg   const char *desc_ = "ASSERT_PRED1 (" #PRED1 ", " #VAL1 ")";	\
    410  1.1.1.2  mrg   bool actual_ = (PRED1) (VAL1);				\
    411  1.1.1.2  mrg   if (actual_)							\
    412  1.1.1.2  mrg     ::selftest::pass (SELFTEST_LOCATION, desc_);		\
    413  1.1.1.2  mrg   else								\
    414  1.1.1.2  mrg     ::selftest::fail (SELFTEST_LOCATION, desc_);		\
    415      1.1  mrg   SELFTEST_END_STMT
    416      1.1  mrg 
    417      1.1  mrg #define SELFTEST_BEGIN_STMT do {
    418      1.1  mrg #define SELFTEST_END_STMT   } while (0)
    419      1.1  mrg 
    420      1.1  mrg #endif /* #if CHECKING_P */
    421      1.1  mrg 
    422      1.1  mrg #endif /* GCC_SELFTEST_H */
    423