diff options
author | David Malcolm <dmalcolm@redhat.com> | 2016-06-06 17:11:30 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2016-06-06 17:11:30 +0000 |
commit | d9b950dd440fe2029a111cda56add2c9e91123b9 (patch) | |
tree | 63fc70ab85f16020285e16504429ce186042a4da /gcc/input.c | |
parent | dbc6221fe5aa38017bb5818aa28257360b15f3b6 (diff) | |
download | gcc-d9b950dd440fe2029a111cda56add2c9e91123b9.zip gcc-d9b950dd440fe2029a111cda56add2c9e91123b9.tar.gz gcc-d9b950dd440fe2029a111cda56add2c9e91123b9.tar.bz2 |
Selftest framework
gcc/ChangeLog:
* Makefile.in (OBJS): Add function-tests.o,
hash-map-tests.o, hash-set-tests.o, rtl-tests.o,
selftest-run-tests.o.
(OBJS-libcommon): Add selftest.o.
(OBJS-libcommon-target): Add selftest.o.
(all.internal): Add "selftest".
(all.cross): Likewise.
(selftest): New phony target.
(s-selftest): New target.
(selftest-gdb): New phony target.
(COLLECT2_OBJS): Add selftest.o.
* bitmap.c: Include "selftest.h".
(selftest::test_gc_alloc): New function.
(selftest::test_set_range): New function.
(selftest::test_clear_bit_in_middle): New function.
(selftest::test_copying): New function.
(selftest::test_bitmap_single_bit_set_p): New function.
(selftest::bitmap_c_tests): New function.
* common.opt (fself-test): New.
* diagnostic-show-locus.c: Include "selftest.h".
(make_range): New function.
(test_range_contains_point_for_single_point): New function.
(test_range_contains_point_for_single_line): New function.
(test_range_contains_point_for_multiple_lines): New function.
(assert_eq): New function.
(test_get_line_width_without_trailing_whitespace): New function.
(selftest::diagnostic_show_locus_c_tests): New function.
* et-forest.c: Include "selftest.h".
(selftest::test_single_node): New function.
(selftest::test_simple_tree): New function.
(selftest::test_disconnected_nodes): New function.
(selftest::et_forest_c_tests): New function.
* fold-const.c: Include "selftest.h".
(selftest::assert_binop_folds_to_const): New function.
(selftest::assert_binop_folds_to_nonlvalue): New function.
(selftest::test_arithmetic_folding): New function.
(selftest::fold_const_c_tests): New function.
* function-tests.c: New file.
* gimple.c: Include "selftest.h".
Include "gimple-pretty-print.h".
(selftest::verify_gimple_pp): New function.
(selftest::test_assign_single): New function.
(selftest::test_assign_binop): New function.
(selftest::test_nop_stmt): New function.
(selftest::test_return_stmt): New function.
(selftest::test_return_without_value): New function.
(selftest::gimple_c_tests): New function.
* hash-map-tests.c: New file.
* hash-set-tests.c: New file.
* input.c: Include "selftest.h".
(selftest::assert_loceq): New function.
(selftest::test_accessing_ordinary_linemaps): New function.
(selftest::test_unknown_location): New function.
(selftest::test_builtins): New function.
(selftest::test_reading_source_line): New function.
(selftest::input_c_tests): New function.
* rtl-tests.c: New file.
* selftest-run-tests.c: New file.
* selftest.c: New file.
* selftest.h: New file.
* spellcheck.c: Include "selftest.h".
(selftest::levenshtein_distance_unit_test_oneway): New function,
adapted from testsuite/gcc.dg/plugin/levenshtein_plugin.c.
(selftest::levenshtein_distance_unit_test): Likewise.
(selftest::spellcheck_c_tests): Likewise.
* toplev.c: Include selftest.h.
(toplev::run_self_tests): New.
(toplev::main): Handle -fself-test.
* toplev.h (toplev::run_self_tests): New.
* tree.c: Include "selftest.h".
(selftest::test_integer_constants): New function.
(selftest::test_identifiers): New function.
(selftest::test_labels): New function.
(selftest::tree_c_tests): New function.
* tree-cfg.c: Include "selftest.h".
(selftest::push_fndecl): New function.
(selftest::test_linear_chain): New function.
(selftest::test_diamond): New function.
(selftest::test_fully_connected): New function.
(selftest::tree_cfg_c_tests): New function.
* vec.c: Include "selftest.h".
(selftest::safe_push_range): New function.
(selftest::test_quick_push): New function.
(selftest::test_safe_push): New function.
(selftest::test_truncate): New function.
(selftest::test_safe_grow_cleared): New function.
(selftest::test_pop): New function.
(selftest::test_safe_insert): New function.
(selftest::test_ordered_remove): New function.
(selftest::test_unordered_remove): New function.
(selftest::test_block_remove): New function.
(selftest::reverse_cmp): New function.
(selftest::test_qsort): New function.
(selftest::vec_c_tests): New function.c.
* wide-int.cc: Include selftest.h and wide-int-print.h.
(selftest::from_int <wide_int>): New function.
(selftest::from_int <offset_int>): New function.
(selftest::from_int <widest_int>): New function.
(selftest::assert_deceq): New function.
(selftest::assert_hexeq): New function.
(selftest::test_printing <VALUE_TYPE>): New function template.
(selftest::test_ops <VALUE_TYPE>): New function template.
(selftest::test_comparisons <VALUE_TYPE>): New function template.
(selftest::run_all_wide_int_tests <VALUE_TYPE>): New function
template.
(selftest::wide_int_cc_tests): New function.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/levenshtein-test-1.c: Delete.
* gcc.dg/plugin/levenshtein_plugin.c: Delete.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Remove the
above.
From-SVN: r237144
Diffstat (limited to 'gcc/input.c')
-rw-r--r-- | gcc/input.c | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/gcc/input.c b/gcc/input.c index 61b1e44..0b340a8 100644 --- a/gcc/input.c +++ b/gcc/input.c @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3. If not see #include "coretypes.h" #include "intl.h" #include "diagnostic-core.h" +#include "selftest.h" /* This is a cache used by get_next_line to store the content of a file to be searched for file lines. */ @@ -1136,3 +1137,118 @@ dump_location_info (FILE *stream) dump_labelled_location_range (stream, "AD-HOC LOCATIONS", MAX_SOURCE_LOCATION + 1, UINT_MAX); } + +#if CHECKING_P + +namespace selftest { + +/* Selftests of location handling. */ + +/* Verify the result of LOCATION_FILE/LOCATION_LINE/LOCATION_COLUMN + on LOC. */ + +static void +assert_loceq (const char *exp_filename, int exp_linenum, int exp_colnum, + location_t loc) +{ + ASSERT_STREQ (exp_filename, LOCATION_FILE (loc)); + ASSERT_EQ (exp_linenum, LOCATION_LINE (loc)); + ASSERT_EQ (exp_colnum, LOCATION_COLUMN (loc)); +} + +/* Verify basic operation of ordinary linemaps. */ + +static void +test_accessing_ordinary_linemaps () +{ + /* Build a simple linemap describing some locations. */ + linemap_add (line_table, LC_ENTER, false, "foo.c", 0); + + linemap_line_start (line_table, 1, 100); + location_t loc_a = linemap_position_for_column (line_table, 1); + location_t loc_b = linemap_position_for_column (line_table, 23); + + linemap_line_start (line_table, 2, 100); + location_t loc_c = linemap_position_for_column (line_table, 1); + location_t loc_d = linemap_position_for_column (line_table, 17); + + /* Example of a very long line. */ + linemap_line_start (line_table, 3, 2000); + location_t loc_e = linemap_position_for_column (line_table, 700); + + linemap_add (line_table, LC_LEAVE, false, NULL, 0); + + /* Multiple files. */ + linemap_add (line_table, LC_ENTER, false, "bar.c", 0); + linemap_line_start (line_table, 1, 200); + location_t loc_f = linemap_position_for_column (line_table, 150); + linemap_add (line_table, LC_LEAVE, false, NULL, 0); + + /* Verify that we can recover the location info. */ + assert_loceq ("foo.c", 1, 1, loc_a); + assert_loceq ("foo.c", 1, 23, loc_b); + assert_loceq ("foo.c", 2, 1, loc_c); + assert_loceq ("foo.c", 2, 17, loc_d); + assert_loceq ("foo.c", 3, 700, loc_e); + assert_loceq ("bar.c", 1, 150, loc_f); + + ASSERT_FALSE (is_location_from_builtin_token (loc_a)); +} + +/* Verify various properties of UNKNOWN_LOCATION. */ + +static void +test_unknown_location () +{ + ASSERT_EQ (NULL, LOCATION_FILE (UNKNOWN_LOCATION)); + ASSERT_EQ (0, LOCATION_LINE (UNKNOWN_LOCATION)); + ASSERT_EQ (0, LOCATION_COLUMN (UNKNOWN_LOCATION)); +} + +/* Verify various properties of BUILTINS_LOCATION. */ + +static void +test_builtins () +{ + assert_loceq ("<built-in>", 0, 0, BUILTINS_LOCATION); + ASSERT_PRED1 (is_location_from_builtin_token, BUILTINS_LOCATION); +} + +/* Verify reading of input files (e.g. for caret-based diagnostics). */ + +static void +test_reading_source_line () +{ + /* We will read *this* source file, using __FILE__. + Here is some specific text to read and test for: + The quick brown fox jumps over the lazy dog. */ + const int linenum_after_test_message = __LINE__; + const int linenum = linenum_after_test_message - 1; + + int line_size; + const char *source_line = location_get_source_line (__FILE__, linenum, &line_size); + ASSERT_TRUE (source_line != NULL); + ASSERT_EQ (53, line_size); + if (!strncmp (" The quick brown fox jumps over the lazy dog. */", + source_line, line_size)) + ::selftest::pass (__FILE__, __LINE__, + "source_line matched expected value"); + else + ::selftest::fail (__FILE__, __LINE__, + "source_line did not match expected value"); +} + +/* Run all of the selftests within this file. */ + +void +input_c_tests () +{ + test_accessing_ordinary_linemaps (); + test_unknown_location (); + test_builtins (); + test_reading_source_line (); +} + +} // namespace selftest + +#endif /* CHECKING_P */ |