Home | History | Annotate | Line # | Download | only in gcc
selftest.h revision 1.1.1.3
      1      1.1  mrg /* A self-testing framework, for use by -fself-test.
      2  1.1.1.3  mrg    Copyright (C) 2015-2019 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.1.3  mrg 			  const char *desc_val1, const char *desc_val2,
     71  1.1.1.3  mrg 			  const char *val1, const char *val2);
     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.1.3  mrg /* Implementation detail of ASSERT_STR_STARTSWITH.  */
     82  1.1.1.3  mrg 
     83  1.1.1.3  mrg extern void assert_str_startswith (const location &loc,
     84  1.1.1.3  mrg 				   const char *desc_str,
     85  1.1.1.3  mrg 				   const char *desc_prefix,
     86  1.1.1.3  mrg 				   const char *val_str,
     87  1.1.1.3  mrg 				   const char *val_prefix);
     88  1.1.1.3  mrg 
     89  1.1.1.3  mrg 
     90      1.1  mrg /* A named temporary file for use in selftests.
     91      1.1  mrg    Usable for writing out files, and as the base class for
     92      1.1  mrg    temp_source_file.
     93      1.1  mrg    The file is unlinked in the destructor.  */
     94      1.1  mrg 
     95      1.1  mrg class named_temp_file
     96      1.1  mrg {
     97      1.1  mrg  public:
     98      1.1  mrg   named_temp_file (const char *suffix);
     99      1.1  mrg   ~named_temp_file ();
    100      1.1  mrg   const char *get_filename () const { return m_filename; }
    101      1.1  mrg 
    102      1.1  mrg  private:
    103      1.1  mrg   char *m_filename;
    104      1.1  mrg };
    105      1.1  mrg 
    106      1.1  mrg /* A class for writing out a temporary sourcefile for use in selftests
    107      1.1  mrg    of input handling.  */
    108      1.1  mrg 
    109      1.1  mrg class temp_source_file : public named_temp_file
    110      1.1  mrg {
    111      1.1  mrg  public:
    112      1.1  mrg   temp_source_file (const location &loc, const char *suffix,
    113      1.1  mrg 		    const char *content);
    114      1.1  mrg };
    115      1.1  mrg 
    116  1.1.1.3  mrg /* RAII-style class for avoiding introducing locale-specific differences
    117  1.1.1.3  mrg    in strings containing localized quote marks, by temporarily overriding
    118  1.1.1.3  mrg    the "open_quote" and "close_quote" globals to something hardcoded.
    119  1.1.1.3  mrg 
    120  1.1.1.3  mrg    Specifically, the C locale's values are used:
    121  1.1.1.3  mrg    - open_quote becomes "`"
    122  1.1.1.3  mrg    - close_quote becomes "'"
    123  1.1.1.3  mrg    for the lifetime of the object.  */
    124  1.1.1.3  mrg 
    125  1.1.1.3  mrg class auto_fix_quotes
    126  1.1.1.3  mrg {
    127  1.1.1.3  mrg  public:
    128  1.1.1.3  mrg   auto_fix_quotes ();
    129  1.1.1.3  mrg   ~auto_fix_quotes ();
    130  1.1.1.3  mrg 
    131  1.1.1.3  mrg  private:
    132  1.1.1.3  mrg   const char *m_saved_open_quote;
    133  1.1.1.3  mrg   const char *m_saved_close_quote;
    134  1.1.1.3  mrg };
    135  1.1.1.3  mrg 
    136      1.1  mrg /* Various selftests involving location-handling require constructing a
    137      1.1  mrg    line table and one or more line maps within it.
    138      1.1  mrg 
    139      1.1  mrg    For maximum test coverage we want to run these tests with a variety
    140      1.1  mrg    of situations:
    141      1.1  mrg    - line_table->default_range_bits: some frontends use a non-zero value
    142      1.1  mrg    and others use zero
    143      1.1  mrg    - the fallback modes within line-map.c: there are various threshold
    144  1.1.1.3  mrg    values for location_t beyond line-map.c changes
    145      1.1  mrg    behavior (disabling of the range-packing optimization, disabling
    146      1.1  mrg    of column-tracking).  We can exercise these by starting the line_table
    147      1.1  mrg    at interesting values at or near these thresholds.
    148      1.1  mrg 
    149      1.1  mrg    The following struct describes a particular case within our test
    150      1.1  mrg    matrix.  */
    151      1.1  mrg 
    152      1.1  mrg struct line_table_case;
    153      1.1  mrg 
    154      1.1  mrg /* A class for overriding the global "line_table" within a selftest,
    155      1.1  mrg    restoring its value afterwards.  At most one instance of this
    156      1.1  mrg    class can exist at once, due to the need to keep the old value
    157      1.1  mrg    of line_table as a GC root.  */
    158      1.1  mrg 
    159      1.1  mrg class line_table_test
    160      1.1  mrg {
    161      1.1  mrg  public:
    162      1.1  mrg   /* Default constructor.  Override "line_table", using sane defaults
    163      1.1  mrg      for the temporary line_table.  */
    164      1.1  mrg   line_table_test ();
    165      1.1  mrg 
    166      1.1  mrg   /* Constructor.  Override "line_table", using the case described by C.  */
    167      1.1  mrg   line_table_test (const line_table_case &c);
    168      1.1  mrg 
    169      1.1  mrg   /* Destructor.  Restore the saved line_table.  */
    170      1.1  mrg   ~line_table_test ();
    171      1.1  mrg };
    172      1.1  mrg 
    173      1.1  mrg /* Run TESTCASE multiple times, once for each case in our test matrix.  */
    174      1.1  mrg 
    175      1.1  mrg extern void
    176      1.1  mrg for_each_line_table_case (void (*testcase) (const line_table_case &));
    177      1.1  mrg 
    178      1.1  mrg /* Read the contents of PATH into memory, returning a 0-terminated buffer
    179      1.1  mrg    that must be freed by the caller.
    180      1.1  mrg    Fail (and abort) if there are any problems, with LOC as the reported
    181      1.1  mrg    location of the failure.  */
    182      1.1  mrg 
    183      1.1  mrg extern char *read_file (const location &loc, const char *path);
    184      1.1  mrg 
    185      1.1  mrg /* A helper function for writing tests that interact with the
    186      1.1  mrg    garbage collector.  */
    187      1.1  mrg 
    188      1.1  mrg extern void forcibly_ggc_collect ();
    189      1.1  mrg 
    190      1.1  mrg /* Convert a path relative to SRCDIR/gcc/testsuite/selftests
    191      1.1  mrg    to a real path (either absolute, or relative to pwd).
    192      1.1  mrg    The result should be freed by the caller.  */
    193      1.1  mrg 
    194      1.1  mrg extern char *locate_file (const char *path);
    195      1.1  mrg 
    196      1.1  mrg /* The path of SRCDIR/testsuite/selftests.  */
    197      1.1  mrg 
    198      1.1  mrg extern const char *path_to_selftest_files;
    199      1.1  mrg 
    200  1.1.1.2  mrg /* selftest::test_runner is an implementation detail of selftest::run_tests,
    201  1.1.1.2  mrg    exposed here to allow plugins to run their own suites of tests.  */
    202  1.1.1.2  mrg 
    203  1.1.1.2  mrg class test_runner
    204  1.1.1.2  mrg {
    205  1.1.1.2  mrg  public:
    206  1.1.1.2  mrg   test_runner (const char *name);
    207  1.1.1.2  mrg   ~test_runner ();
    208  1.1.1.2  mrg 
    209  1.1.1.2  mrg  private:
    210  1.1.1.2  mrg   const char *m_name;
    211  1.1.1.2  mrg   long m_start_time;
    212  1.1.1.2  mrg };
    213  1.1.1.2  mrg 
    214      1.1  mrg /* Declarations for specific families of tests (by source file), in
    215      1.1  mrg    alphabetical order.  */
    216  1.1.1.2  mrg extern void attribute_c_tests ();
    217      1.1  mrg extern void bitmap_c_tests ();
    218  1.1.1.3  mrg extern void cgraph_c_tests ();
    219  1.1.1.3  mrg extern void convert_c_tests ();
    220      1.1  mrg extern void diagnostic_c_tests ();
    221      1.1  mrg extern void diagnostic_show_locus_c_tests ();
    222  1.1.1.3  mrg extern void dumpfile_c_tests ();
    223      1.1  mrg extern void edit_context_c_tests ();
    224      1.1  mrg extern void et_forest_c_tests ();
    225      1.1  mrg extern void fibonacci_heap_c_tests ();
    226  1.1.1.3  mrg extern void fold_const_c_tests ();
    227      1.1  mrg extern void function_tests_c_tests ();
    228      1.1  mrg extern void ggc_tests_c_tests ();
    229  1.1.1.3  mrg extern void gimple_c_tests ();
    230      1.1  mrg extern void hash_map_tests_c_tests ();
    231      1.1  mrg extern void hash_set_tests_c_tests ();
    232      1.1  mrg extern void input_c_tests ();
    233  1.1.1.3  mrg extern void json_cc_tests ();
    234  1.1.1.3  mrg extern void opt_problem_cc_tests ();
    235  1.1.1.3  mrg extern void optinfo_emit_json_cc_tests ();
    236  1.1.1.3  mrg extern void predict_c_tests ();
    237      1.1  mrg extern void pretty_print_c_tests ();
    238      1.1  mrg extern void read_rtl_function_c_tests ();
    239      1.1  mrg extern void rtl_tests_c_tests ();
    240  1.1.1.3  mrg extern void sbitmap_c_tests ();
    241      1.1  mrg extern void selftest_c_tests ();
    242  1.1.1.3  mrg extern void simplify_rtx_c_tests ();
    243      1.1  mrg extern void spellcheck_c_tests ();
    244      1.1  mrg extern void spellcheck_tree_c_tests ();
    245      1.1  mrg extern void sreal_c_tests ();
    246      1.1  mrg extern void store_merging_c_tests ();
    247      1.1  mrg extern void tree_c_tests ();
    248      1.1  mrg extern void tree_cfg_c_tests ();
    249  1.1.1.3  mrg extern void typed_splay_tree_c_tests ();
    250  1.1.1.2  mrg extern void unique_ptr_tests_cc_tests ();
    251      1.1  mrg extern void vec_c_tests ();
    252  1.1.1.2  mrg extern void vec_perm_indices_c_tests ();
    253  1.1.1.3  mrg extern void wide_int_cc_tests ();
    254  1.1.1.3  mrg extern void opt_proposer_c_tests ();
    255      1.1  mrg 
    256      1.1  mrg extern int num_passes;
    257      1.1  mrg 
    258      1.1  mrg } /* end of namespace selftest.  */
    259      1.1  mrg 
    260      1.1  mrg /* Macros for writing tests.  */
    261      1.1  mrg 
    262      1.1  mrg /* Evaluate EXPR and coerce to bool, calling
    263      1.1  mrg    ::selftest::pass if it is true,
    264      1.1  mrg    ::selftest::fail if it false.  */
    265      1.1  mrg 
    266      1.1  mrg #define ASSERT_TRUE(EXPR)				\
    267      1.1  mrg   ASSERT_TRUE_AT (SELFTEST_LOCATION, (EXPR))
    268      1.1  mrg 
    269      1.1  mrg /* Like ASSERT_TRUE, but treat LOC as the effective location of the
    270      1.1  mrg    selftest.  */
    271      1.1  mrg 
    272      1.1  mrg #define ASSERT_TRUE_AT(LOC, EXPR)			\
    273      1.1  mrg   SELFTEST_BEGIN_STMT					\
    274  1.1.1.2  mrg   const char *desc_ = "ASSERT_TRUE (" #EXPR ")";	\
    275  1.1.1.2  mrg   bool actual_ = (EXPR);				\
    276  1.1.1.2  mrg   if (actual_)						\
    277  1.1.1.2  mrg     ::selftest::pass ((LOC), desc_);			\
    278      1.1  mrg   else							\
    279  1.1.1.2  mrg     ::selftest::fail ((LOC), desc_);			\
    280      1.1  mrg   SELFTEST_END_STMT
    281      1.1  mrg 
    282      1.1  mrg /* Evaluate EXPR and coerce to bool, calling
    283      1.1  mrg    ::selftest::pass if it is false,
    284      1.1  mrg    ::selftest::fail if it true.  */
    285      1.1  mrg 
    286      1.1  mrg #define ASSERT_FALSE(EXPR)					\
    287      1.1  mrg   ASSERT_FALSE_AT (SELFTEST_LOCATION, (EXPR))
    288      1.1  mrg 
    289      1.1  mrg /* Like ASSERT_FALSE, but treat LOC as the effective location of the
    290      1.1  mrg    selftest.  */
    291      1.1  mrg 
    292      1.1  mrg #define ASSERT_FALSE_AT(LOC, EXPR)				\
    293      1.1  mrg   SELFTEST_BEGIN_STMT						\
    294  1.1.1.2  mrg   const char *desc_ = "ASSERT_FALSE (" #EXPR ")";		\
    295  1.1.1.2  mrg   bool actual_ = (EXPR);					\
    296  1.1.1.2  mrg   if (actual_)							\
    297  1.1.1.2  mrg     ::selftest::fail ((LOC), desc_);				\
    298  1.1.1.2  mrg   else								\
    299  1.1.1.2  mrg     ::selftest::pass ((LOC), desc_);				\
    300      1.1  mrg   SELFTEST_END_STMT
    301      1.1  mrg 
    302  1.1.1.3  mrg /* Evaluate VAL1 and VAL2 and compare them with ==, calling
    303      1.1  mrg    ::selftest::pass if they are equal,
    304      1.1  mrg    ::selftest::fail if they are non-equal.  */
    305      1.1  mrg 
    306  1.1.1.3  mrg #define ASSERT_EQ(VAL1, VAL2) \
    307  1.1.1.3  mrg   ASSERT_EQ_AT ((SELFTEST_LOCATION), (VAL1), (VAL2))
    308      1.1  mrg 
    309      1.1  mrg /* Like ASSERT_EQ, but treat LOC as the effective location of the
    310      1.1  mrg    selftest.  */
    311      1.1  mrg 
    312  1.1.1.3  mrg #define ASSERT_EQ_AT(LOC, VAL1, VAL2)		       \
    313      1.1  mrg   SELFTEST_BEGIN_STMT					       \
    314  1.1.1.3  mrg   const char *desc_ = "ASSERT_EQ (" #VAL1 ", " #VAL2 ")"; \
    315  1.1.1.3  mrg   if ((VAL1) == (VAL2))				       \
    316  1.1.1.2  mrg     ::selftest::pass ((LOC), desc_);			       \
    317      1.1  mrg   else							       \
    318  1.1.1.2  mrg     ::selftest::fail ((LOC), desc_);			       \
    319  1.1.1.2  mrg   SELFTEST_END_STMT
    320  1.1.1.2  mrg 
    321  1.1.1.3  mrg /* Evaluate VAL1 and VAL2 and compare them with known_eq, calling
    322  1.1.1.2  mrg    ::selftest::pass if they are always equal,
    323  1.1.1.2  mrg    ::selftest::fail if they might be non-equal.  */
    324  1.1.1.2  mrg 
    325  1.1.1.3  mrg #define ASSERT_KNOWN_EQ(VAL1, VAL2) \
    326  1.1.1.3  mrg   ASSERT_KNOWN_EQ_AT ((SELFTEST_LOCATION), (VAL1), (VAL2))
    327  1.1.1.2  mrg 
    328  1.1.1.2  mrg /* Like ASSERT_KNOWN_EQ, but treat LOC as the effective location of the
    329  1.1.1.2  mrg    selftest.  */
    330  1.1.1.2  mrg 
    331  1.1.1.3  mrg #define ASSERT_KNOWN_EQ_AT(LOC, VAL1, VAL2)			\
    332  1.1.1.2  mrg   SELFTEST_BEGIN_STMT							\
    333  1.1.1.3  mrg   const char *desc = "ASSERT_KNOWN_EQ (" #VAL1 ", " #VAL2 ")";	\
    334  1.1.1.3  mrg   if (known_eq (VAL1, VAL2))					\
    335  1.1.1.2  mrg     ::selftest::pass ((LOC), desc);					\
    336  1.1.1.2  mrg   else									\
    337  1.1.1.2  mrg     ::selftest::fail ((LOC), desc);					\
    338      1.1  mrg   SELFTEST_END_STMT
    339      1.1  mrg 
    340  1.1.1.3  mrg /* Evaluate VAL1 and VAL2 and compare them with !=, calling
    341      1.1  mrg    ::selftest::pass if they are non-equal,
    342      1.1  mrg    ::selftest::fail if they are equal.  */
    343      1.1  mrg 
    344  1.1.1.3  mrg #define ASSERT_NE(VAL1, VAL2)			       \
    345      1.1  mrg   SELFTEST_BEGIN_STMT					       \
    346  1.1.1.3  mrg   const char *desc_ = "ASSERT_NE (" #VAL1 ", " #VAL2 ")"; \
    347  1.1.1.3  mrg   if ((VAL1) != (VAL2))				       \
    348  1.1.1.2  mrg     ::selftest::pass (SELFTEST_LOCATION, desc_);	       \
    349  1.1.1.2  mrg   else							       \
    350  1.1.1.2  mrg     ::selftest::fail (SELFTEST_LOCATION, desc_);	       \
    351  1.1.1.2  mrg   SELFTEST_END_STMT
    352  1.1.1.2  mrg 
    353  1.1.1.3  mrg /* Evaluate VAL1 and VAL2 and compare them with maybe_ne, calling
    354  1.1.1.2  mrg    ::selftest::pass if they might be non-equal,
    355  1.1.1.2  mrg    ::selftest::fail if they are known to be equal.  */
    356  1.1.1.2  mrg 
    357  1.1.1.3  mrg #define ASSERT_MAYBE_NE(VAL1, VAL2) \
    358  1.1.1.3  mrg   ASSERT_MAYBE_NE_AT ((SELFTEST_LOCATION), (VAL1), (VAL2))
    359  1.1.1.2  mrg 
    360  1.1.1.2  mrg /* Like ASSERT_MAYBE_NE, but treat LOC as the effective location of the
    361  1.1.1.2  mrg    selftest.  */
    362  1.1.1.2  mrg 
    363  1.1.1.3  mrg #define ASSERT_MAYBE_NE_AT(LOC, VAL1, VAL2)			\
    364  1.1.1.2  mrg   SELFTEST_BEGIN_STMT							\
    365  1.1.1.3  mrg   const char *desc = "ASSERT_MAYBE_NE (" #VAL1 ", " #VAL2 ")";	\
    366  1.1.1.3  mrg   if (maybe_ne (VAL1, VAL2))					\
    367  1.1.1.2  mrg     ::selftest::pass ((LOC), desc);					\
    368  1.1.1.2  mrg   else									\
    369  1.1.1.2  mrg     ::selftest::fail ((LOC), desc);					\
    370  1.1.1.2  mrg   SELFTEST_END_STMT
    371  1.1.1.2  mrg 
    372  1.1.1.2  mrg /* Evaluate LHS and RHS and compare them with >, calling
    373  1.1.1.2  mrg    ::selftest::pass if LHS > RHS,
    374  1.1.1.2  mrg    ::selftest::fail otherwise.  */
    375  1.1.1.2  mrg 
    376  1.1.1.2  mrg #define ASSERT_GT(LHS, RHS)				\
    377  1.1.1.2  mrg   ASSERT_GT_AT ((SELFTEST_LOCATION), (LHS), (RHS))
    378  1.1.1.2  mrg 
    379  1.1.1.2  mrg /* Like ASSERT_GT, but treat LOC as the effective location of the
    380  1.1.1.2  mrg    selftest.  */
    381  1.1.1.2  mrg 
    382  1.1.1.2  mrg #define ASSERT_GT_AT(LOC, LHS, RHS)		       \
    383  1.1.1.2  mrg   SELFTEST_BEGIN_STMT					       \
    384  1.1.1.2  mrg   const char *desc_ = "ASSERT_GT (" #LHS ", " #RHS ")";	       \
    385  1.1.1.2  mrg   if ((LHS) > (RHS))					       \
    386  1.1.1.2  mrg     ::selftest::pass ((LOC), desc_);			       \
    387      1.1  mrg   else							       \
    388  1.1.1.2  mrg     ::selftest::fail ((LOC), desc_);			       \
    389  1.1.1.2  mrg   SELFTEST_END_STMT
    390  1.1.1.2  mrg 
    391  1.1.1.2  mrg /* Evaluate LHS and RHS and compare them with <, calling
    392  1.1.1.2  mrg    ::selftest::pass if LHS < RHS,
    393  1.1.1.2  mrg    ::selftest::fail otherwise.  */
    394  1.1.1.2  mrg 
    395  1.1.1.2  mrg #define ASSERT_LT(LHS, RHS)				\
    396  1.1.1.2  mrg   ASSERT_LT_AT ((SELFTEST_LOCATION), (LHS), (RHS))
    397  1.1.1.2  mrg 
    398  1.1.1.2  mrg /* Like ASSERT_LT, but treat LOC as the effective location of the
    399  1.1.1.2  mrg    selftest.  */
    400  1.1.1.2  mrg 
    401  1.1.1.2  mrg #define ASSERT_LT_AT(LOC, LHS, RHS)		       \
    402  1.1.1.2  mrg   SELFTEST_BEGIN_STMT					       \
    403  1.1.1.2  mrg   const char *desc_ = "ASSERT_LT (" #LHS ", " #RHS ")";	       \
    404  1.1.1.2  mrg   if ((LHS) < (RHS))					       \
    405  1.1.1.2  mrg     ::selftest::pass ((LOC), desc_);			       \
    406  1.1.1.2  mrg   else							       \
    407  1.1.1.2  mrg     ::selftest::fail ((LOC), desc_);			       \
    408      1.1  mrg   SELFTEST_END_STMT
    409      1.1  mrg 
    410  1.1.1.3  mrg /* Evaluate VAL1 and VAL2 and compare them with strcmp, calling
    411  1.1.1.3  mrg    ::selftest::pass if they are equal (and both are non-NULL),
    412  1.1.1.3  mrg    ::selftest::fail if they are non-equal, or are both NULL.  */
    413      1.1  mrg 
    414  1.1.1.3  mrg #define ASSERT_STREQ(VAL1, VAL2)				    \
    415      1.1  mrg   SELFTEST_BEGIN_STMT						    \
    416  1.1.1.3  mrg   ::selftest::assert_streq (SELFTEST_LOCATION, #VAL1, #VAL2, \
    417  1.1.1.3  mrg 			    (VAL1), (VAL2));		    \
    418      1.1  mrg   SELFTEST_END_STMT
    419      1.1  mrg 
    420      1.1  mrg /* Like ASSERT_STREQ, but treat LOC as the effective location of the
    421      1.1  mrg    selftest.  */
    422      1.1  mrg 
    423  1.1.1.3  mrg #define ASSERT_STREQ_AT(LOC, VAL1, VAL2)			    \
    424      1.1  mrg   SELFTEST_BEGIN_STMT						    \
    425  1.1.1.3  mrg   ::selftest::assert_streq ((LOC), #VAL1, #VAL2,		    \
    426  1.1.1.3  mrg 			    (VAL1), (VAL2));		    \
    427      1.1  mrg   SELFTEST_END_STMT
    428      1.1  mrg 
    429      1.1  mrg /* Evaluate HAYSTACK and NEEDLE and use strstr to determine if NEEDLE
    430      1.1  mrg    is within HAYSTACK.
    431      1.1  mrg    ::selftest::pass if NEEDLE is found.
    432      1.1  mrg    ::selftest::fail if it is not found.  */
    433      1.1  mrg 
    434      1.1  mrg #define ASSERT_STR_CONTAINS(HAYSTACK, NEEDLE)				\
    435      1.1  mrg   SELFTEST_BEGIN_STMT							\
    436      1.1  mrg   ::selftest::assert_str_contains (SELFTEST_LOCATION, #HAYSTACK, #NEEDLE, \
    437      1.1  mrg 				   (HAYSTACK), (NEEDLE));		\
    438      1.1  mrg   SELFTEST_END_STMT
    439      1.1  mrg 
    440  1.1.1.3  mrg /* Like ASSERT_STR_CONTAINS, but treat LOC as the effective location of the
    441  1.1.1.3  mrg    selftest.  */
    442  1.1.1.3  mrg 
    443  1.1.1.3  mrg #define ASSERT_STR_CONTAINS_AT(LOC, HAYSTACK, NEEDLE)			\
    444  1.1.1.3  mrg   SELFTEST_BEGIN_STMT							\
    445  1.1.1.3  mrg   ::selftest::assert_str_contains (LOC, #HAYSTACK, #NEEDLE,		\
    446  1.1.1.3  mrg 				   (HAYSTACK), (NEEDLE));		\
    447  1.1.1.3  mrg   SELFTEST_END_STMT
    448  1.1.1.3  mrg 
    449  1.1.1.3  mrg /* Evaluate STR and PREFIX and determine if STR starts with PREFIX.
    450  1.1.1.3  mrg      ::selftest::pass if STR does start with PREFIX.
    451  1.1.1.3  mrg      ::selftest::fail if does not, or either is NULL.  */
    452  1.1.1.3  mrg 
    453  1.1.1.3  mrg #define ASSERT_STR_STARTSWITH(STR, PREFIX)				    \
    454  1.1.1.3  mrg   SELFTEST_BEGIN_STMT							    \
    455  1.1.1.3  mrg   ::selftest::assert_str_startswith (SELFTEST_LOCATION, #STR, #PREFIX,	    \
    456  1.1.1.3  mrg 				     (STR), (PREFIX));			    \
    457  1.1.1.3  mrg   SELFTEST_END_STMT
    458  1.1.1.3  mrg 
    459      1.1  mrg /* Evaluate PRED1 (VAL1), calling ::selftest::pass if it is true,
    460      1.1  mrg    ::selftest::fail if it is false.  */
    461      1.1  mrg 
    462  1.1.1.2  mrg #define ASSERT_PRED1(PRED1, VAL1)				\
    463  1.1.1.2  mrg   SELFTEST_BEGIN_STMT						\
    464  1.1.1.2  mrg   const char *desc_ = "ASSERT_PRED1 (" #PRED1 ", " #VAL1 ")";	\
    465  1.1.1.2  mrg   bool actual_ = (PRED1) (VAL1);				\
    466  1.1.1.2  mrg   if (actual_)							\
    467  1.1.1.2  mrg     ::selftest::pass (SELFTEST_LOCATION, desc_);		\
    468  1.1.1.2  mrg   else								\
    469  1.1.1.2  mrg     ::selftest::fail (SELFTEST_LOCATION, desc_);		\
    470      1.1  mrg   SELFTEST_END_STMT
    471      1.1  mrg 
    472      1.1  mrg #define SELFTEST_BEGIN_STMT do {
    473      1.1  mrg #define SELFTEST_END_STMT   } while (0)
    474      1.1  mrg 
    475      1.1  mrg #endif /* #if CHECKING_P */
    476      1.1  mrg 
    477      1.1  mrg #endif /* GCC_SELFTEST_H */
    478