Commit 754568a3 authored by Denis Samoylov's avatar Denis Samoylov Committed by facebook-github-bot-1

A common init function for binaries and a default main function for tests

Summary: Added initialization routines to test main function that can help with debugging tests

Reviewed By: markisaa, yfeldblum

Differential Revision: D2839759

fb-gh-sync-id: 71cad45f3747336c8c7f8706db139cd060e1442b
parent e2c9fd6c
......@@ -50,7 +50,10 @@ sudo apt-get install \
zlib1g-dev \
binutils-dev \
libjemalloc-dev \
libssl-dev
libssl-dev \
libunwind8-dev \
libelf-dev \
libdwarf-dev
```
Ubuntu 14.04 LTS
......@@ -163,3 +166,6 @@ Other Linux distributions
- double-conversion-devel
- openssl-devel
- libevent-devel
- libdwarf-dev
- libelf-dev
- libunwind8-dev
if HAVE_LINUX
SUBDIRS = . experimental init test
else
SUBDIRS = . test
endif
ACLOCAL_AMFLAGS = -I m4
......@@ -119,6 +123,13 @@ nobase_follyinclude_HEADERS = \
experimental/NestedCommandLineApp.h \
experimental/ProgramOptions.h \
experimental/ReadMostlySharedPtr.h \
experimental/symbolizer/Elf.h \
experimental/symbolizer/ElfCache.h \
experimental/symbolizer/Dwarf.h \
experimental/symbolizer/LineReader.h \
experimental/symbolizer/SignalHandler.h \
experimental/symbolizer/StackTrace.cpp \
experimental/symbolizer/Symbolizer.h \
experimental/Select64.h \
experimental/StringKeyedCommon.h \
experimental/StringKeyedUnorderedMap.h \
......@@ -184,6 +195,7 @@ nobase_follyinclude_HEADERS = \
IPAddressV6.h \
IPAddressException.h \
IndexedMemPool.h \
init/Init.h \
IntrusiveList.h \
io/Compression.h \
io/Cursor.h \
......
......@@ -468,6 +468,9 @@ AC_CHECK_HEADER([snappy.h], AC_CHECK_LIB([snappy], [main]))
AC_CHECK_HEADER([zlib.h], AC_CHECK_LIB([z], [main]))
AC_CHECK_HEADER([lzma.h], AC_CHECK_LIB([lzma], [main]))
AC_CHECK_HEADER([zstd.h], AC_CHECK_LIB([zstd], [main]))
AC_CHECK_HEADERS([libdwarf.h dwarf.h],, AC_MSG_ERROR([Please install libdwarf development package]))
AC_CHECK_HEADERS([libelf.h elf.h],, AC_MSG_ERROR([Please install libelf development package]))
AC_CHECK_HEADERS(libunwind.h, ac_cv_have_libunwind_h=1, ac_cv_have_libunwind_h=0)
# Include directory that contains "folly" so #include <folly/Foo.h> works
AM_CPPFLAGS='-I$(top_srcdir)/..'
......@@ -494,5 +497,8 @@ AM_CONDITIONAL([HAVE_EXTRANDOM_SFMT19937],
# Output
AC_CONFIG_FILES([Makefile
test/Makefile
test/function_benchmark/Makefile])
test/function_benchmark/Makefile
experimental/Makefile
experimental/symbolizer/Makefile
init/Makefile])
AC_OUTPUT
SUBDIRS = .
lib_LTLIBRARIES = libfollysymbolizer.la
libfollysymbolizer_la_SOURCES = \
Elf.cpp \
ElfCache.cpp \
Dwarf.cpp \
LineReader.cpp \
SignalHandler.cpp \
StackTrace.cpp \
Symbolizer.cpp
libfollysymbolizer_la_LIBADD = $(top_builddir)/libfolly.la
libfollysymbolizer_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LT_VERSION)
/*
* Copyright 2016 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/init/Init.h>
#include <folly/Singleton.h>
#include <folly/experimental/symbolizer/SignalHandler.h>
#include <glog/logging.h>
#include <gflags/gflags.h>
namespace folly {
void init(int* argc, char*** argv, bool removeFlags) {
// Install the handler now, to trap errors received during startup.
// The callbacks, if any, can be installed later
folly::symbolizer::installFatalSignalHandler();
google::ParseCommandLineFlags(argc, argv, removeFlags);
auto programName = argc && argv && *argc > 0 ? (*argv)[0] : "unknown";
google::InitGoogleLogging(programName);
// Don't use glog's DumpStackTraceAndExit; rely on our signal handler.
google::InstallFailureFunction(abort);
// Move from the registration phase to the "you can actually instantiate
// things now" phase.
folly::SingletonVault::singleton()->registrationComplete();
// Actually install the callbacks into the handler.
folly::symbolizer::installFatalSignalCallbacks();
}
} //!folly
/*
* Copyright 2016 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef INIT_LIGHT_BASE_H
#define INIT_LIGHT_BASE_H
/*
* Calls common init functions in the necessary order
* Among other things, this ensures that folly::Singletons are initialized
* correctly and installs signal handlers for a superior debugging experience.
* It also initializes gflags and glog.
*
* @param argc, argv arguments to your main
* @param removeFlags if true, will update argc,argv to remove recognized
* gflags passed on the command line
*/
namespace folly {
void init(int* argc, char*** argv, bool removeFlags = true);
} // folly
#endif
SUBDIRS = .
lib_LTLIBRARIES = libfollyinit.la
libfollyinit_la_SOURCES = Init.cpp
libfollyinit_la_LIBADD = $(top_builddir)/libfolly.la $(top_builddir)/experimental/symbolizer/libfollysymbolizer.la
libfollyinit_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LT_VERSION)
This diff is collapsed.
/*
* Copyright 2016 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/init/Init.h>
#include <gtest/gtest.h>
/*
* This is the recommended main function for all tests.
* The Makefile links it into all of the test programs so that tests do not need
* to - and indeed should typically not - define their own main() functions
*/
int main(int argc, char** argv) __attribute__((__weak__));
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
folly::init(&argc, &argv);
return RUN_ALL_TESTS();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment