2016-06-06 19:11:30 +02:00
|
|
|
/* A self-testing framework, for use by -fself-test.
|
2017-01-01 13:07:43 +01:00
|
|
|
Copyright (C) 2015-2017 Free Software Foundation, Inc.
|
2016-06-06 19:11:30 +02:00
|
|
|
|
|
|
|
This file is part of GCC.
|
|
|
|
|
|
|
|
GCC is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free
|
|
|
|
Software Foundation; either version 3, or (at your option) any later
|
|
|
|
version.
|
|
|
|
|
|
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GCC; see the file COPYING3. If not see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#ifndef GCC_SELFTEST_H
|
|
|
|
#define GCC_SELFTEST_H
|
|
|
|
|
|
|
|
/* The selftest code should entirely disappear in a production
|
|
|
|
configuration, hence we guard all of it with #if CHECKING_P. */
|
|
|
|
|
|
|
|
#if CHECKING_P
|
|
|
|
|
|
|
|
namespace selftest {
|
|
|
|
|
2016-06-13 23:04:07 +02:00
|
|
|
/* A struct describing the source-location of a selftest, to make it
|
|
|
|
easier to track down failing tests. */
|
|
|
|
|
|
|
|
struct location
|
|
|
|
{
|
|
|
|
location (const char *file, int line, const char *function)
|
|
|
|
: m_file (file), m_line (line), m_function (function) {}
|
|
|
|
|
|
|
|
const char *m_file;
|
|
|
|
int m_line;
|
|
|
|
const char *m_function;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* A macro for use in selftests and by the ASSERT_ macros below,
|
|
|
|
constructing a selftest::location for the current source location. */
|
|
|
|
|
|
|
|
#define SELFTEST_LOCATION \
|
|
|
|
(::selftest::location (__FILE__, __LINE__, __FUNCTION__))
|
|
|
|
|
2016-06-06 19:11:30 +02:00
|
|
|
/* The entrypoint for running all tests. */
|
|
|
|
|
|
|
|
extern void run_tests ();
|
|
|
|
|
|
|
|
/* Record the successful outcome of some aspect of the test. */
|
|
|
|
|
2016-06-13 23:04:07 +02:00
|
|
|
extern void pass (const location &loc, const char *msg);
|
2016-06-06 19:11:30 +02:00
|
|
|
|
|
|
|
/* Report the failed outcome of some aspect of the test and abort. */
|
|
|
|
|
2016-08-29 19:23:14 +02:00
|
|
|
extern void fail (const location &loc, const char *msg)
|
|
|
|
ATTRIBUTE_NORETURN;
|
2016-06-06 19:11:30 +02:00
|
|
|
|
2016-06-13 22:58:08 +02:00
|
|
|
/* As "fail", but using printf-style formatted output. */
|
|
|
|
|
2016-06-13 23:04:07 +02:00
|
|
|
extern void fail_formatted (const location &loc, const char *fmt, ...)
|
2016-08-29 19:23:14 +02:00
|
|
|
ATTRIBUTE_PRINTF_2 ATTRIBUTE_NORETURN;
|
2016-06-13 22:58:08 +02:00
|
|
|
|
|
|
|
/* Implementation detail of ASSERT_STREQ. */
|
|
|
|
|
2016-06-13 23:04:07 +02:00
|
|
|
extern void assert_streq (const location &loc,
|
2016-06-13 22:58:08 +02:00
|
|
|
const char *desc_expected, const char *desc_actual,
|
|
|
|
const char *val_expected, const char *val_actual);
|
|
|
|
|
2016-08-23 18:51:57 +02:00
|
|
|
/* Implementation detail of ASSERT_STR_CONTAINS. */
|
|
|
|
|
|
|
|
extern void assert_str_contains (const location &loc,
|
|
|
|
const char *desc_haystack,
|
|
|
|
const char *desc_needle,
|
|
|
|
const char *val_haystack,
|
|
|
|
const char *val_needle);
|
|
|
|
|
2016-08-31 02:07:38 +02:00
|
|
|
/* A named temporary file for use in selftests.
|
|
|
|
Usable for writing out files, and as the base class for
|
|
|
|
temp_source_file.
|
|
|
|
The file is unlinked in the destructor. */
|
2016-08-16 20:02:43 +02:00
|
|
|
|
2016-08-31 02:07:38 +02:00
|
|
|
class named_temp_file
|
2016-08-16 20:02:43 +02:00
|
|
|
{
|
|
|
|
public:
|
2016-08-31 02:07:38 +02:00
|
|
|
named_temp_file (const char *suffix);
|
|
|
|
~named_temp_file ();
|
2016-08-16 20:02:43 +02:00
|
|
|
const char *get_filename () const { return m_filename; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
char *m_filename;
|
|
|
|
};
|
|
|
|
|
2016-08-31 02:07:38 +02:00
|
|
|
/* A class for writing out a temporary sourcefile for use in selftests
|
|
|
|
of input handling. */
|
|
|
|
|
|
|
|
class temp_source_file : public named_temp_file
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
temp_source_file (const location &loc, const char *suffix,
|
|
|
|
const char *content);
|
|
|
|
};
|
|
|
|
|
2016-08-18 18:22:10 +02:00
|
|
|
/* Various selftests involving location-handling require constructing a
|
|
|
|
line table and one or more line maps within it.
|
|
|
|
|
|
|
|
For maximum test coverage we want to run these tests with a variety
|
|
|
|
of situations:
|
|
|
|
- line_table->default_range_bits: some frontends use a non-zero value
|
|
|
|
and others use zero
|
|
|
|
- the fallback modes within line-map.c: there are various threshold
|
|
|
|
values for source_location/location_t beyond line-map.c changes
|
|
|
|
behavior (disabling of the range-packing optimization, disabling
|
|
|
|
of column-tracking). We can exercise these by starting the line_table
|
|
|
|
at interesting values at or near these thresholds.
|
|
|
|
|
|
|
|
The following struct describes a particular case within our test
|
|
|
|
matrix. */
|
|
|
|
|
|
|
|
struct line_table_case;
|
|
|
|
|
|
|
|
/* A class for overriding the global "line_table" within a selftest,
|
|
|
|
restoring its value afterwards. At most one instance of this
|
|
|
|
class can exist at once, due to the need to keep the old value
|
|
|
|
of line_table as a GC root. */
|
|
|
|
|
|
|
|
class line_table_test
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/* Default constructor. Override "line_table", using sane defaults
|
|
|
|
for the temporary line_table. */
|
|
|
|
line_table_test ();
|
|
|
|
|
|
|
|
/* Constructor. Override "line_table", using the case described by C. */
|
|
|
|
line_table_test (const line_table_case &c);
|
|
|
|
|
|
|
|
/* Destructor. Restore the saved line_table. */
|
|
|
|
~line_table_test ();
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Run TESTCASE multiple times, once for each case in our test matrix. */
|
|
|
|
|
|
|
|
extern void
|
|
|
|
for_each_line_table_case (void (*testcase) (const line_table_case &));
|
|
|
|
|
2016-10-12 16:55:47 +02:00
|
|
|
/* Read the contents of PATH into memory, returning a 0-terminated buffer
|
|
|
|
that must be freed by the caller.
|
|
|
|
Fail (and abort) if there are any problems, with LOC as the reported
|
|
|
|
location of the failure. */
|
|
|
|
|
|
|
|
extern char *read_file (const location &loc, const char *path);
|
|
|
|
|
2016-10-25 18:46:54 +02:00
|
|
|
/* A helper function for writing tests that interact with the
|
|
|
|
garbage collector. */
|
|
|
|
|
|
|
|
extern void forcibly_ggc_collect ();
|
|
|
|
|
2016-12-15 02:47:48 +01:00
|
|
|
/* Convert a path relative to SRCDIR/gcc/testsuite/selftests
|
|
|
|
to a real path (either absolute, or relative to pwd).
|
|
|
|
The result should be freed by the caller. */
|
|
|
|
|
|
|
|
extern char *locate_file (const char *path);
|
|
|
|
|
|
|
|
/* The path of SRCDIR/testsuite/selftests. */
|
|
|
|
|
|
|
|
extern const char *path_to_selftest_files;
|
|
|
|
|
2016-06-06 19:11:30 +02:00
|
|
|
/* Declarations for specific families of tests (by source file), in
|
|
|
|
alphabetical order. */
|
|
|
|
extern void bitmap_c_tests ();
|
2016-06-22 16:42:30 +02:00
|
|
|
extern void diagnostic_c_tests ();
|
2016-06-06 19:11:30 +02:00
|
|
|
extern void diagnostic_show_locus_c_tests ();
|
2016-09-02 20:00:57 +02:00
|
|
|
extern void edit_context_c_tests ();
|
2016-06-06 19:11:30 +02:00
|
|
|
extern void et_forest_c_tests ();
|
|
|
|
extern void fold_const_c_tests ();
|
2016-07-20 09:01:48 +02:00
|
|
|
extern void fibonacci_heap_c_tests ();
|
2016-06-06 19:11:30 +02:00
|
|
|
extern void function_tests_c_tests ();
|
|
|
|
extern void gimple_c_tests ();
|
2016-06-10 15:41:03 +02:00
|
|
|
extern void ggc_tests_c_tests ();
|
2016-06-06 19:11:30 +02:00
|
|
|
extern void hash_map_tests_c_tests ();
|
|
|
|
extern void hash_set_tests_c_tests ();
|
|
|
|
extern void input_c_tests ();
|
2016-06-08 17:53:56 +02:00
|
|
|
extern void pretty_print_c_tests ();
|
Introduce RTL function reader
This is the combination of these patches:
- [8a/9] Introduce class function_reader (v8)
- Add ASSERT_RTX_PTR_EQ
- [8b/9] Add target-independent selftests of RTL function reader (v2)
- [8c/9] Add aarch64-specific selftests for RTL function reader (v2)
- [8d/9] Add x86_64-specific selftests for RTL function reader (v2)
gcc/ChangeLog:
* Makefile.in (OBJS): Add read-md.o, read-rtl.o,
read-rtl-function.o, and selftest-rtl.o.
* config/aarch64/aarch64.c: Include selftest.h and
selftest-rtl.h.
(selftest::aarch64_test_loading_full_dump): New function.
(selftest::aarch64_run_selftests): New function.
(TARGET_RUN_TARGET_SELFTESTS): Wire it up to
selftest::aarch64_run_selftests.
* config/i386/i386.c
(selftest::ix86_test_loading_dump_fragment_1): New function.
(selftest::ix86_test_loading_call_insn): New function.
(selftest::ix86_test_loading_full_dump): New function.
(selftest::ix86_test_loading_unspec): New function.
(selftest::ix86_run_selftests): Call the new functions.
* emit-rtl.c (maybe_set_max_label_num): New function.
* emit-rtl.h (maybe_set_max_label_num): New decl.
* function.c (instantiate_decls): Guard call to
instantiate_decls_1 with if (DECL_INITIAL (fndecl)).
* function-tests.c (selftest::verify_three_block_rtl_cfg): Remove
"static".
* gensupport.c (gen_reader::gen_reader): Pass "false"
for new "compact" param of rtx_reader.
* print-rtl.c (rtx_writer::print_rtx_operand): Print "(nil)"
rather than an empty string for NULL strings.
* read-md.c: Potentially include config.h rather than bconfig.h.
Wrap include of errors.h with #ifdef GENERATOR_FILE.
(have_error): New global, copied from errors.c.
(md_reader::read_name): Rename to...
(md_reader::read_name_1): ...this, adding "out_loc" param,
and converting "missing name or number" to returning false, rather
than failing.
(md_reader::read_name): Reimplement in terms of read_name_1.
(md_reader::read_name_or_nil): New function.
(md_reader::read_string): Handle "(nil)" by returning NULL.
(md_reader::md_reader): Add new param "compact".
(md_reader::read_md_files): Wrap with #ifdef GENERATOR_FILE.
(md_reader::read_file): New method.
* read-md.h (md_reader::md_reader): Add new param "compact".
(md_reader::read_file): New method.
(md_reader::is_compact): New accessor.
(md_reader::read_name): Convert return type from void to
file_location.
(md_reader::read_name_or_nil): New decl.
(md_reader::read_name_1): New decl.
(md_reader::m_compact): New field.
(noop_reader::noop_reader): Pass "false" for new "compact" param
of rtx_reader.
(rtx_reader::rtx_reader): Add new "compact" param.
(rtx_reader::read_rtx_operand): Make virtual and convert return
type from void to rtx.
(rtx_reader::read_until): New decl.
(rtx_reader::handle_any_trailing_information): New virtual
function.
(rtx_reader::postprocess): New virtual function.
(rtx_reader::finalize_string): New virtual function.
(rtx_reader::m_in_call_function_usage): New field.
(rtx_reader::m_reuse_rtx_by_id): New field.
* read-rtl-function.c: New file.
* selftest-rtl.c (selftest::assert_rtx_ptr_eq_at): New function.
* selftest-rtl.h (ASSERT_RTX_PTR_EQ): New macro.
(selftest::verify_three_block_rtl_cfg): New decl.
* read-rtl-function.h: New file.
* read-rtl.c: Potentially include config.h rather than bconfig.h.
For host, include function.h, memmodel.h, and emit-rtl.h.
(one_time_initialization): New function.
(struct compact_insn_name): New struct.
(compact_insn_names): New array.
(find_code): Handle insn codes in compact dumps.
(apply_subst_iterator): Wrap with #ifdef GENERATOR_FILE.
(bind_subst_iter_and_attr): Likewise.
(add_condition_to_string): Likewise.
(add_condition_to_rtx): Likewise.
(apply_attribute_uses): Likewise.
(add_current_iterators): Likewise.
(apply_iterators): Likewise.
(initialize_iterators): Guard usage of apply_subst_iterator with
#ifdef GENERATOR_FILE.
(read_conditions): Wrap with #ifdef GENERATOR_FILE.
(md_reader::read_mapping): Likewise.
(add_define_attr_for_define_subst): Likewise.
(add_define_subst_attr): Likewise.
(read_subst_mapping): Likewise.
(check_code_iterator): Likewise.
(rtx_reader::read_rtx): Likewise. Move one-time initialization
logic to...
(one_time_initialization): New function.
(rtx_reader::read_until): New method.
(read_flags): New function.
(parse_reg_note_name): New function.
(rtx_reader::read_rtx_code): Initialize "iterator" to NULL.
Handle reuse_rtx ids.
Wrap iterator lookup within #ifdef GENERATOR_FILE.
Add parsing support for RTL dumps, mirroring the special-cases in
print_rtx, by calling read_flags, reading REG_NOTE names, INSN_UID
values, and calling handle_any_trailing_information.
(rtx_reader::read_rtx_operand): Convert return type from void
to rtx, returning return_rtx. Handle case 'e'. Call
finalize_string on XSTR and XTMPL fields.
(rtx_reader::read_nested_rtx): Handle dumps in which trailing
"(nil)" values were omitted. Call the postprocess vfunc on the
return_rtx.
(rtx_reader::rtx_reader): Add new "compact" param and pass to base
class ctor. Initialize m_in_call_function_usage. Call
one_time_initialization.
* rtl-tests.c (selftest::test_uncond_jump): Call
set_new_first_and_last_insn.
* rtl.h (read_rtx): Wrap decl with #ifdef GENERATOR_FILE.
* selftest-rtl.c: New file.
* selftest-rtl.h (class selftest::rtl_dump_test): New class.
(selftest::get_insn_by_uid): New decl.
* selftest-run-tests.c (selftest::run_tests): Call
read_rtl_function_c_tests.
* selftest.h (selftest::read_rtl_function_c_tests): New decl.
* tree-dfa.c (ssa_default_def): Return NULL_TREE for rtl function
dumps.
gcc/testsuite/ChangeLog:
* selftests/asr_div1.rtl: New file.
* selftests/aarch64: New subdirectory.
* selftests/aarch64/times-two.rtl: New file.
* selftests/bb-index.rtl: New file.
* selftests/cfg-test.rtl: New file.
* selftests/const-int.rtl: New file.
* selftests/example-labels.rtl: New file.
* selftests/insn-with-mode.rtl: New file.
* selftests/jump-to-label-ref.rtl: New file.
* selftests/jump-to-return.rtl: New file.
* selftests/jump-to-simple-return.rtl: New file.
* selftests/mem.rtl: New file.
* selftests/note-insn-deleted.rtl: New file.
* selftests/note_insn_basic_block.rtl: New file.
* selftests/simple-cse.rtl: New file.
* selftests/symbol-ref.rtl: New file.
* selftests/x86_64: New subdirectory.
* selftests/x86_64/call-insn.rtl: New file.
* selftests/x86_64/copy-hard-reg-into-frame.rtl: New file.
* selftests/x86_64/times-two.rtl: New file.
* selftests/x86_64/unspec.rtl: New file.
From-SVN: r244110
2017-01-05 20:32:09 +01:00
|
|
|
extern void read_rtl_function_c_tests ();
|
2016-06-06 19:11:30 +02:00
|
|
|
extern void rtl_tests_c_tests ();
|
2016-08-12 01:36:46 +02:00
|
|
|
extern void selftest_c_tests ();
|
2016-06-06 19:11:30 +02:00
|
|
|
extern void spellcheck_c_tests ();
|
2016-06-15 02:12:16 +02:00
|
|
|
extern void spellcheck_tree_c_tests ();
|
2016-07-20 09:00:50 +02:00
|
|
|
extern void sreal_c_tests ();
|
2016-11-08 17:04:20 +01:00
|
|
|
extern void store_merging_c_tests ();
|
2016-09-02 17:22:21 +02:00
|
|
|
extern void typed_splay_tree_c_tests ();
|
2016-06-06 19:11:30 +02:00
|
|
|
extern void tree_c_tests ();
|
|
|
|
extern void tree_cfg_c_tests ();
|
|
|
|
extern void vec_c_tests ();
|
|
|
|
extern void wide_int_cc_tests ();
|
|
|
|
|
|
|
|
extern int num_passes;
|
|
|
|
|
|
|
|
} /* end of namespace selftest. */
|
|
|
|
|
|
|
|
/* Macros for writing tests. */
|
|
|
|
|
|
|
|
/* Evaluate EXPR and coerce to bool, calling
|
|
|
|
::selftest::pass if it is true,
|
|
|
|
::selftest::fail if it false. */
|
|
|
|
|
|
|
|
#define ASSERT_TRUE(EXPR) \
|
2016-08-04 23:12:52 +02:00
|
|
|
ASSERT_TRUE_AT (SELFTEST_LOCATION, (EXPR))
|
|
|
|
|
|
|
|
/* Like ASSERT_TRUE, but treat LOC as the effective location of the
|
|
|
|
selftest. */
|
|
|
|
|
|
|
|
#define ASSERT_TRUE_AT(LOC, EXPR) \
|
2016-06-06 19:11:30 +02:00
|
|
|
SELFTEST_BEGIN_STMT \
|
|
|
|
const char *desc = "ASSERT_TRUE (" #EXPR ")"; \
|
|
|
|
bool actual = (EXPR); \
|
|
|
|
if (actual) \
|
2016-08-04 23:12:52 +02:00
|
|
|
::selftest::pass ((LOC), desc); \
|
2016-06-06 19:11:30 +02:00
|
|
|
else \
|
2016-08-04 23:12:52 +02:00
|
|
|
::selftest::fail ((LOC), desc); \
|
2016-06-06 19:11:30 +02:00
|
|
|
SELFTEST_END_STMT
|
|
|
|
|
|
|
|
/* Evaluate EXPR and coerce to bool, calling
|
|
|
|
::selftest::pass if it is false,
|
|
|
|
::selftest::fail if it true. */
|
|
|
|
|
|
|
|
#define ASSERT_FALSE(EXPR) \
|
2016-08-04 23:12:52 +02:00
|
|
|
ASSERT_FALSE_AT (SELFTEST_LOCATION, (EXPR))
|
|
|
|
|
|
|
|
/* Like ASSERT_FALSE, but treat LOC as the effective location of the
|
|
|
|
selftest. */
|
|
|
|
|
|
|
|
#define ASSERT_FALSE_AT(LOC, EXPR) \
|
2016-06-06 19:11:30 +02:00
|
|
|
SELFTEST_BEGIN_STMT \
|
2016-08-04 23:12:52 +02:00
|
|
|
const char *desc = "ASSERT_FALSE (" #EXPR ")"; \
|
|
|
|
bool actual = (EXPR); \
|
|
|
|
if (actual) \
|
|
|
|
::selftest::fail ((LOC), desc); \
|
|
|
|
else \
|
|
|
|
::selftest::pass ((LOC), desc); \
|
2016-06-06 19:11:30 +02:00
|
|
|
SELFTEST_END_STMT
|
|
|
|
|
|
|
|
/* Evaluate EXPECTED and ACTUAL and compare them with ==, calling
|
|
|
|
::selftest::pass if they are equal,
|
|
|
|
::selftest::fail if they are non-equal. */
|
|
|
|
|
2016-07-11 18:02:20 +02:00
|
|
|
#define ASSERT_EQ(EXPECTED, ACTUAL) \
|
|
|
|
ASSERT_EQ_AT ((SELFTEST_LOCATION), (EXPECTED), (ACTUAL))
|
|
|
|
|
|
|
|
/* Like ASSERT_EQ, but treat LOC as the effective location of the
|
|
|
|
selftest. */
|
|
|
|
|
|
|
|
#define ASSERT_EQ_AT(LOC, EXPECTED, ACTUAL) \
|
2016-06-06 19:11:30 +02:00
|
|
|
SELFTEST_BEGIN_STMT \
|
|
|
|
const char *desc = "ASSERT_EQ (" #EXPECTED ", " #ACTUAL ")"; \
|
|
|
|
if ((EXPECTED) == (ACTUAL)) \
|
2016-07-11 18:02:20 +02:00
|
|
|
::selftest::pass ((LOC), desc); \
|
2016-06-06 19:11:30 +02:00
|
|
|
else \
|
2016-07-11 18:02:20 +02:00
|
|
|
::selftest::fail ((LOC), desc); \
|
2016-06-06 19:11:30 +02:00
|
|
|
SELFTEST_END_STMT
|
|
|
|
|
|
|
|
/* Evaluate EXPECTED and ACTUAL and compare them with !=, calling
|
|
|
|
::selftest::pass if they are non-equal,
|
|
|
|
::selftest::fail if they are equal. */
|
|
|
|
|
|
|
|
#define ASSERT_NE(EXPECTED, ACTUAL) \
|
|
|
|
SELFTEST_BEGIN_STMT \
|
|
|
|
const char *desc = "ASSERT_NE (" #EXPECTED ", " #ACTUAL ")"; \
|
|
|
|
if ((EXPECTED) != (ACTUAL)) \
|
2016-06-13 23:04:07 +02:00
|
|
|
::selftest::pass (SELFTEST_LOCATION, desc); \
|
2016-06-06 19:11:30 +02:00
|
|
|
else \
|
2016-06-13 23:04:07 +02:00
|
|
|
::selftest::fail (SELFTEST_LOCATION, desc); \
|
2016-06-06 19:11:30 +02:00
|
|
|
SELFTEST_END_STMT
|
|
|
|
|
|
|
|
/* Evaluate EXPECTED and ACTUAL and compare them with strcmp, calling
|
|
|
|
::selftest::pass if they are equal,
|
|
|
|
::selftest::fail if they are non-equal. */
|
|
|
|
|
2016-06-13 22:58:08 +02:00
|
|
|
#define ASSERT_STREQ(EXPECTED, ACTUAL) \
|
|
|
|
SELFTEST_BEGIN_STMT \
|
2016-06-13 23:04:07 +02:00
|
|
|
::selftest::assert_streq (SELFTEST_LOCATION, #EXPECTED, #ACTUAL, \
|
|
|
|
(EXPECTED), (ACTUAL)); \
|
|
|
|
SELFTEST_END_STMT
|
|
|
|
|
2016-08-04 23:12:52 +02:00
|
|
|
/* Like ASSERT_STREQ, but treat LOC as the effective location of the
|
2016-06-13 23:04:07 +02:00
|
|
|
selftest. */
|
|
|
|
|
|
|
|
#define ASSERT_STREQ_AT(LOC, EXPECTED, ACTUAL) \
|
|
|
|
SELFTEST_BEGIN_STMT \
|
|
|
|
::selftest::assert_streq ((LOC), #EXPECTED, #ACTUAL, \
|
2016-06-13 22:58:08 +02:00
|
|
|
(EXPECTED), (ACTUAL)); \
|
2016-06-06 19:11:30 +02:00
|
|
|
SELFTEST_END_STMT
|
|
|
|
|
2016-08-23 18:51:57 +02:00
|
|
|
/* Evaluate HAYSTACK and NEEDLE and use strstr to determine if NEEDLE
|
|
|
|
is within HAYSTACK.
|
|
|
|
::selftest::pass if NEEDLE is found.
|
|
|
|
::selftest::fail if it is not found. */
|
|
|
|
|
|
|
|
#define ASSERT_STR_CONTAINS(HAYSTACK, NEEDLE) \
|
|
|
|
SELFTEST_BEGIN_STMT \
|
|
|
|
::selftest::assert_str_contains (SELFTEST_LOCATION, #HAYSTACK, #NEEDLE, \
|
|
|
|
(HAYSTACK), (NEEDLE)); \
|
|
|
|
SELFTEST_END_STMT
|
|
|
|
|
2016-06-06 19:11:30 +02:00
|
|
|
/* Evaluate PRED1 (VAL1), calling ::selftest::pass if it is true,
|
|
|
|
::selftest::fail if it is false. */
|
|
|
|
|
|
|
|
#define ASSERT_PRED1(PRED1, VAL1) \
|
|
|
|
SELFTEST_BEGIN_STMT \
|
|
|
|
const char *desc = "ASSERT_PRED1 (" #PRED1 ", " #VAL1 ")"; \
|
|
|
|
bool actual = (PRED1) (VAL1); \
|
|
|
|
if (actual) \
|
2016-06-13 23:04:07 +02:00
|
|
|
::selftest::pass (SELFTEST_LOCATION, desc); \
|
2016-06-06 19:11:30 +02:00
|
|
|
else \
|
2016-06-13 23:04:07 +02:00
|
|
|
::selftest::fail (SELFTEST_LOCATION, desc); \
|
2016-06-06 19:11:30 +02:00
|
|
|
SELFTEST_END_STMT
|
|
|
|
|
|
|
|
#define SELFTEST_BEGIN_STMT do {
|
|
|
|
#define SELFTEST_END_STMT } while (0)
|
|
|
|
|
|
|
|
#endif /* #if CHECKING_P */
|
|
|
|
|
|
|
|
#endif /* GCC_SELFTEST_H */
|