gcc/unittests/ChangeLog: * unittests-main.c: New file. --- gcc/unittests/unittests-main.c | 108 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 gcc/unittests/unittests-main.c
diff --git a/gcc/unittests/unittests-main.c b/gcc/unittests/unittests-main.c new file mode 100644 index 0000000..635a4f3 --- /dev/null +++ b/gcc/unittests/unittests-main.c @@ -0,0 +1,108 @@ +/* "main" and other top-level hooks for unittesting GCC. + Copyright (C) 2015 Free Software Foundation, Inc. + +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/>. */ + +#include <gtest/gtest.h> + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "opts.h" +#include "signop.h" +#include "hash-set.h" +#include "fixed-value.h" +#include "alias.h" +#include "flags.h" +#include "symtab.h" +#include "tree-core.h" +#include "stor-layout.h" +#include "tree.h" +#include "stringpool.h" +#include "stor-layout.h" +#include "rtl.h" +#include "predict.h" +#include "vec.h" +#include "hashtab.h" +#include "hash-set.h" +#include "machmode.h" +#include "hard-reg-set.h" +#include "input.h" +#include "function.h" +#include "dominance.h" +#include "cfg.h" +#include "cfganal.h" +#include "basic-block.h" +#include "tree-ssa-alias.h" +#include "internal-fn.h" +#include "gimple-fold.h" +#include "gimple-expr.h" +#include "toplev.h" + +namespace { + +class gcc_environment : public ::testing::Environment +{ + public: + gcc_environment () + : m_toplev (true, /* use_TV_TOTAL */ + false /* init_signals */) + { + } + + /* Implementation of base class' vfunc. */ + void SetUp() + { + /* Hack: run toplev::main once, to force initialization. */ + auto_vec <const char *> args; + args.safe_push ("unittesting"); + args.safe_push ("-quiet"); + + /* Hack: give it fake src/dst files, otherwise e.g. asm_out_file + becomes stdout, and we have an eventual crash. */ + args.safe_push ("-o"); + args.safe_push ("/tmp/fake.s"); + args.safe_push ("/tmp/fake.c"); + + m_toplev.main (args.length (), + const_cast <char **> (args.address ())); + + /* We've now run toplev once; everything should now be initialized + enough to allow use to run unit tests of the various subsystems. */ + } + + /* Implementation of base class' vfunc. */ + void TearDown() + { + m_toplev.finalize (); + } + + private: + toplev m_toplev; +}; + +} // anon namespace + +int main (int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + + ::testing::AddGlobalTestEnvironment(new gcc_environment); + + return RUN_ALL_TESTS(); +} -- 1.8.5.3