aboutsummaryrefslogtreecommitdiff
path: root/gcc/selftest.h
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-08-18 16:22:10 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-08-18 16:22:10 +0000
commitf87e22c52128d9d9c9a72a81ae3922b46ce52e59 (patch)
tree88147dd9aecf18036124b1ad90c384efc1d40d24 /gcc/selftest.h
parent89c8878092d773cf3803a98e60d5632635199125 (diff)
downloadgcc-f87e22c52128d9d9c9a72a81ae3922b46ce52e59.zip
gcc-f87e22c52128d9d9c9a72a81ae3922b46ce52e59.tar.gz
gcc-f87e22c52128d9d9c9a72a81ae3922b46ce52e59.tar.bz2
selftest.h: add class line_table_test
input.c has a fixture class for running each selftest with a fresh line_table, and logic for looping over various interesting line_table test cases. This patch exposes the above in selftest.h so that such location-handling tests can be written in other files, renaming the class from temp_line_table to line_table_test. Also, the patch moves the stored line table ptr from being a member of the test class to being a global GC-root, to avoid it being collected if the GC runs during such a test. gcc/ChangeLog: * input.c (saved_line_table): New global. (class selftest::temp_line_table): Rename to line_table_test and move declaration to selftest.h, and drop field m_old_line_table. (selftest::temp_line_table::temp_line_table): Rename ctor to... (selftest::line_table_test::line_table_test): ...this. Add a default ctor. Store current value of line_table within saved_line_table. (selftest::temp_line_table::~temp_line_table): Rename dtor to... (selftest::line_table_test::~line_table_test): ...this, and restore line_table from the saved_line_table, rather than m_old_line_table. (selftest::test_accessing_ordinary_linemaps): Update for above renaming. (selftest::test_lexer): Likewise. (struct selftest::lexer_test): Likewise. (selftest::lexer_test::lexer_test): Likewise. (selftest::input_c_tests): Move the looping over test cases from here into... (selftest::for_each_line_table_case): New function. * input.h (saved_line_table): New decl. * selftest.h (struct selftest::line_table_case): New forward decl. (class selftest::line_table_test): New class, moved here from selftest::temp_line_table in input.c, and renamed. (selftest::for_each_line_table_case): New decl. From-SVN: r239580
Diffstat (limited to 'gcc/selftest.h')
-rw-r--r--gcc/selftest.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/gcc/selftest.h b/gcc/selftest.h
index 72de61f..58a40f6 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -85,6 +85,48 @@ class temp_source_file
char *m_filename;
};
+/* 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 &));
+
/* Declarations for specific families of tests (by source file), in
alphabetical order. */
extern void bitmap_c_tests ();