diff options
Diffstat (limited to 'staging_vespalib')
-rw-r--r-- | staging_vespalib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | staging_vespalib/src/tests/assert/.gitignore | 1 | ||||
-rw-r--r-- | staging_vespalib/src/tests/assert/CMakeLists.txt | 16 | ||||
-rw-r--r-- | staging_vespalib/src/tests/assert/assert_test.cpp | 39 | ||||
-rw-r--r-- | staging_vespalib/src/tests/assert/asserter.cpp | 25 | ||||
-rw-r--r-- | staging_vespalib/src/vespa/vespalib/gtest/gtest.h | 14 | ||||
-rw-r--r-- | staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt | 1 | ||||
-rw-r--r-- | staging_vespalib/src/vespa/vespalib/util/assert.cpp | 77 | ||||
-rw-r--r-- | staging_vespalib/src/vespa/vespalib/util/assert.h | 38 | ||||
-rw-r--r-- | staging_vespalib/src/vespa/vespalib/util/rand48.h | 41 |
10 files changed, 0 insertions, 253 deletions
diff --git a/staging_vespalib/CMakeLists.txt b/staging_vespalib/CMakeLists.txt index b95b4fda01f..095caf17a56 100644 --- a/staging_vespalib/CMakeLists.txt +++ b/staging_vespalib/CMakeLists.txt @@ -9,7 +9,6 @@ vespa_define_module( TESTS src/tests/array - src/tests/assert src/tests/benchmark src/tests/bits src/tests/clock diff --git a/staging_vespalib/src/tests/assert/.gitignore b/staging_vespalib/src/tests/assert/.gitignore deleted file mode 100644 index d0e23fcd846..00000000000 --- a/staging_vespalib/src/tests/assert/.gitignore +++ /dev/null @@ -1 +0,0 @@ -staging_vespalib_asserter_app diff --git a/staging_vespalib/src/tests/assert/CMakeLists.txt b/staging_vespalib/src/tests/assert/CMakeLists.txt deleted file mode 100644 index 7403a488645..00000000000 --- a/staging_vespalib/src/tests/assert/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -vespa_add_executable(staging_vespalib_assert_test_app TEST - SOURCES - assert_test.cpp - DEPENDS - staging_vespalib -) -vespa_add_test(NAME staging_vespalib_assert_test_app COMMAND staging_vespalib_assert_test_app) - -vespa_add_executable(staging_vespalib_asserter_app TEST - SOURCES - asserter.cpp - DEPENDS - staging_vespalib -) diff --git a/staging_vespalib/src/tests/assert/assert_test.cpp b/staging_vespalib/src/tests/assert/assert_test.cpp deleted file mode 100644 index 454c0957974..00000000000 --- a/staging_vespalib/src/tests/assert/assert_test.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/testkit/test_kit.h> -#include <vespa/vespalib/util/slaveproc.h> -#include <vespa/vespalib/util/stringfmt.h> -#include <vespa/vespalib/util/assert.h> -#include <vespa/vespalib/io/fileutil.h> -#include <sys/stat.h> -#include <unistd.h> -#include <vespa/defaults.h> - -using namespace vespalib; - -TEST("that it borks the first time.") { - std::string assertName; - const char * assertDir = "var/db/vespa/tmp"; - vespalib::rmdir("var", true); - ASSERT_TRUE(vespalib::mkdir(assertDir, true)); - { - SlaveProc proc("ulimit -c 0 && exec env VESPA_HOME=./ ./staging_vespalib_asserter_app myassert 10000"); - proc.wait(); - ASSERT_EQUAL(proc.getExitCode() & 0x7f, 6); - } - { - SlaveProc proc("ulimit -c 0 && exec env VESPA_HOME=./ ./staging_vespalib_asserter_app myassert 10000"); - proc.readLine(assertName); - proc.wait(); - ASSERT_EQUAL(proc.getExitCode() & 0x7f, 0); - } - ASSERT_EQUAL(0, unlink(assertName.c_str())); - { - SlaveProc proc("ulimit -c 0 && exec env VESPA_HOME=./ ./staging_vespalib_asserter_app myassert 10000"); - proc.wait(); - ASSERT_EQUAL(proc.getExitCode() & 0x7f, 6); - } - ASSERT_EQUAL(0, unlink(assertName.c_str())); - ASSERT_TRUE(vespalib::rmdir("var", true)); -} - -TEST_MAIN_WITH_PROCESS_PROXY() { TEST_RUN_ALL(); } diff --git a/staging_vespalib/src/tests/assert/asserter.cpp b/staging_vespalib/src/tests/assert/asserter.cpp deleted file mode 100644 index 640464889c0..00000000000 --- a/staging_vespalib/src/tests/assert/asserter.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/util/assert.h> -#include <cassert> -#include <cstdlib> -#include <fstream> -#include <string> - -int main(int argc, char *argv[]) { - assert(argc == 3); - const char * assertKey = argv[1]; - size_t assertCount = strtoul(argv[2], nullptr, 0); - for (size_t i(0); i < assertCount; i++) { - ASSERT_ONCE_OR_LOG(true, assertKey, 100); - ASSERT_ONCE_OR_LOG(false, assertKey, 100); - } - std::string filename = vespalib::assert::getAssertLogFileName(assertKey); - std::ifstream is(filename.c_str()); - assert(is); - std::string line; - std::getline(is, line); - printf("%s\n", filename.c_str()); - assert(line.find(assertKey) != std::string::npos); - assert(assertCount == vespalib::assert::getNumAsserts(assertKey)); - return 0; -} diff --git a/staging_vespalib/src/vespa/vespalib/gtest/gtest.h b/staging_vespalib/src/vespa/vespalib/gtest/gtest.h deleted file mode 100644 index 67d3d438a52..00000000000 --- a/staging_vespalib/src/vespa/vespalib/gtest/gtest.h +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include <gtest/gtest.h> - -/** - * Macro for creating a main function that runs all gtests. - */ -#define GTEST_MAIN_RUN_ALL_TESTS() \ -int \ -main(int argc, char* argv[]) \ -{ \ - ::testing::InitGoogleTest(&argc, argv); \ - return RUN_ALL_TESTS(); \ -} diff --git a/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt b/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt index c104c047cd0..20d47c90453 100644 --- a/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt +++ b/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt @@ -1,7 +1,6 @@ # Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. vespa_add_library(staging_vespalib_vespalib_util OBJECT SOURCES - assert.cpp bits.cpp clock.cpp crc.cpp diff --git a/staging_vespalib/src/vespa/vespalib/util/assert.cpp b/staging_vespalib/src/vespa/vespalib/util/assert.cpp deleted file mode 100644 index 0482d873f7f..00000000000 --- a/staging_vespalib/src/vespa/vespalib/util/assert.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "assert.h" -#include <vespa/defaults.h> -#include <vespa/vespalib/util/backtrace.h> -#include <vespa/vespalib/util/stringfmt.h> -#include <vespa/vespalib/component/vtag.h> -#include <fstream> -#include <map> -#include <mutex> -#include <chrono> -#include <iomanip> - -#include <vespa/log/log.h> -LOG_SETUP(".vespa.assert"); - -namespace vespalib::assert { - -namespace { - -std::mutex _G_lock; -std::map<std::string, size_t> _G_assertMap; - -} - -size_t -getNumAsserts(const char *key) -{ - std::lock_guard guard(_G_lock); - return _G_assertMap[key]; -} - -vespalib::string -getAssertLogFileName(const char *key) -{ - vespalib::string relative = make_string("var/db/vespa/tmp/%s.%s.assert", key, Vtag::currentVersion.toString().c_str()); - return vespa::Defaults::underVespaHome(relative.c_str()); -} - -void -assertOnceOrLog(const char *expr, const char *key, size_t freq) -{ - size_t count(0); - { - std::lock_guard guard(_G_lock); - count = _G_assertMap[key]++; - } - if (count) { - if ((count % freq) == 0) { - LOG(error, "assert(%s) named '%s' has failed %zu times. Stacktrace = %s", - expr, key, count+1, vespalib::getStackTrace(0).c_str()); - } - } else { - std::string rememberAssert = getAssertLogFileName(key); - std::ifstream prevAssertFile(rememberAssert.c_str()); - if (prevAssertFile) { - if ((count % freq) == 0) { - LOG(error, "assert(%s) named '%s' has failed %zu times. Stacktrace = %s", - expr, key, count + 1, vespalib::getStackTrace(0).c_str()); - } - } else { - { - LOG(error, "assert(%s) named '%s' failed first time. Stacktrace = %s", - expr, key, vespalib::getStackTrace(0).c_str()); - std::ofstream assertStream(rememberAssert.c_str()); - std::chrono::time_point now = std::chrono::system_clock::now(); - std::time_t now_c = std::chrono::system_clock::to_time_t(now); - assertStream << std::put_time(std::gmtime(&now_c), "%F %T") << " assert(" << expr - << ") named " << key << " failed" << std::endl; - assertStream.close(); - } - abort(); - } - } -} - -} diff --git a/staging_vespalib/src/vespa/vespalib/util/assert.h b/staging_vespalib/src/vespa/vespalib/util/assert.h deleted file mode 100644 index 698fa6774c1..00000000000 --- a/staging_vespalib/src/vespa/vespalib/util/assert.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - -#include <vespa/vespalib/stllike/string.h> - -namespace vespalib::assert { - -/** - * How many times has asserts against this key failed. - * @param key - * @return - */ -size_t getNumAsserts(const char *key); - -/** - * Get the filename that will be used for remembering asserts. - * @param key - * @return - */ -vespalib::string getAssertLogFileName(const char *key); - -/** - * If there is no record on file that this assert has failed, it will be recorded and aborted. - * However if there is a record of it, it will merely be logged the first and then every #freq time. - * @param expr that failed the assert - * @param key unique name of assert - * @param logFreq how often will a failing assert be logged. - */ -void assertOnceOrLog(const char *expr, const char *key, size_t logFreq); - -} - -#define ASSERT_ONCE_OR_LOG(expr, key, freq) { \ - if ( ! (expr) ) { \ - vespalib::assert::assertOnceOrLog(#expr, key, freq); \ - } \ -} diff --git a/staging_vespalib/src/vespa/vespalib/util/rand48.h b/staging_vespalib/src/vespa/vespalib/util/rand48.h deleted file mode 100644 index 441f8e6e10f..00000000000 --- a/staging_vespalib/src/vespa/vespalib/util/rand48.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - - -namespace search { - -/* - * Simple random generator based on lrand48() spec. - */ -class Rand48 -{ -private: - uint64_t _state; -public: - void - srand48(long seed) - { - _state = ((static_cast<uint64_t>(seed & 0xffffffffu)) << 16) + 0x330e; - } - - Rand48(void) - : _state(0) - { - srand48(0x1234abcd); - }; - void iterate(void) { - _state = (UINT64_C(0x5DEECE66D) * _state + 0xb) & - UINT64_C(0xFFFFFFFFFFFF); - } - /* - * Return value from 0 to 2^31 - 1 - */ - long lrand48(void) { - iterate(); - return static_cast<long>(_state >> 17); - } -}; - -} // namespace search - |