From a643c0eb4147ef6d0366de2af3b2fb3004fb47b7 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 14 Oct 2020 18:54:34 +0200 Subject: [PATCH] remove src/libtest --- src/libtest/CMakeLists.txt | 70 -- src/libtest/alarm.cc | 102 -- src/libtest/alarm.h | 46 - src/libtest/backtrace_test.cc | 123 --- src/libtest/binaries.cc | 41 - src/libtest/binaries.h | 41 - src/libtest/blobslap_worker.cc | 165 ---- src/libtest/blobslap_worker.h | 43 - src/libtest/callbacks.h | 52 - src/libtest/client.cc | 389 -------- src/libtest/client.hpp | 80 -- src/libtest/cmdline.cc | 868 ----------------- src/libtest/cmdline.h | 256 ----- src/libtest/collection.cc | 216 ----- src/libtest/collection.h | 112 --- src/libtest/common.h | 121 --- src/libtest/comparison.cc | 87 -- src/libtest/comparison.hpp | 160 --- src/libtest/core.cc | 66 -- src/libtest/core.h | 44 - src/libtest/core_count.cc | 135 --- src/libtest/cpu.cc | 85 -- src/libtest/cpu.hpp | 43 - src/libtest/dns.cc | 118 --- src/libtest/dns.hpp | 44 - src/libtest/dream.cc | 58 -- src/libtest/dream.h | 44 - src/libtest/drizzled.cc | 210 ---- src/libtest/drizzled.h | 50 - src/libtest/error.h | 54 -- src/libtest/exception.cc | 108 --- src/libtest/exception.hpp | 94 -- src/libtest/exception/disconnected.hpp | 62 -- src/libtest/exception/fatal.cc | 119 --- src/libtest/exception/fatal.hpp | 87 -- src/libtest/failed.cc | 80 -- src/libtest/formatter.cc | 275 ------ src/libtest/formatter.hpp | 85 -- src/libtest/framework.cc | 234 ----- src/libtest/framework.h | 200 ---- src/libtest/gearmand.cc | 178 ---- src/libtest/gearmand.h | 45 - src/libtest/get.h | 51 - src/libtest/has.cc | 232 ----- src/libtest/has.hpp | 76 -- src/libtest/http.cc | 217 ----- src/libtest/http.hpp | 132 --- src/libtest/is_local.cc | 60 -- src/libtest/is_local.hpp | 50 - src/libtest/is_pid.hpp | 43 - src/libtest/killpid.cc | 225 ----- src/libtest/killpid.h | 51 - src/libtest/libtool.cc | 73 -- src/libtest/libtool.hpp | 43 - src/libtest/lite.h | 413 -------- src/libtest/main.cc | 396 -------- src/libtest/memcached.cc | 261 ----- src/libtest/memcached.h | 48 - src/libtest/memcached.hpp | 100 -- src/libtest/poll_error.hpp | 100 -- src/libtest/port.cc | 231 ----- src/libtest/port.h | 56 -- src/libtest/result.cc | 82 -- src/libtest/result.hpp | 56 -- src/libtest/result/base.hpp | 54 -- src/libtest/result/fail.hpp | 56 -- src/libtest/result/skip.hpp | 54 -- src/libtest/result/success.hpp | 59 -- src/libtest/run-ci.gdb | 7 - src/libtest/run.gdb | 7 - src/libtest/runner.cc | 203 ---- src/libtest/runner.h | 73 -- src/libtest/server.cc | 532 ---------- src/libtest/server.h | 302 ------ src/libtest/server_container.cc | 403 -------- src/libtest/server_container.h | 151 --- src/libtest/signal.cc | 259 ----- src/libtest/signal.h | 80 -- src/libtest/skiptest.cc | 57 -- src/libtest/socket.cc | 62 -- src/libtest/socket.hpp | 47 - src/libtest/stream.h | 266 ----- src/libtest/strerror.cc | 71 -- src/libtest/strerror.h | 54 -- src/libtest/string.hpp | 46 - src/libtest/test.h | 210 ---- src/libtest/test.hpp | 102 -- src/libtest/thread.hpp | 329 ------- src/libtest/timer.cc | 150 --- src/libtest/timer.hpp | 73 -- src/libtest/tmpfile.cc | 70 -- src/libtest/tmpfile.hpp | 47 - src/libtest/unittest.cc | 1233 ------------------------ src/libtest/valgrind.h | 55 -- src/libtest/vchar.cc | 169 ---- src/libtest/vchar.hpp | 71 -- src/libtest/version.h.in | 42 - src/libtest/visibility.h | 77 -- src/libtest/wait.cc | 194 ---- src/libtest/wait.h | 114 --- src/libtest/yatl.h | 43 - src/libtest/yatlcon.h.in | 47 - 102 files changed, 14355 deletions(-) delete mode 100644 src/libtest/CMakeLists.txt delete mode 100644 src/libtest/alarm.cc delete mode 100644 src/libtest/alarm.h delete mode 100644 src/libtest/backtrace_test.cc delete mode 100644 src/libtest/binaries.cc delete mode 100644 src/libtest/binaries.h delete mode 100644 src/libtest/blobslap_worker.cc delete mode 100644 src/libtest/blobslap_worker.h delete mode 100644 src/libtest/callbacks.h delete mode 100644 src/libtest/client.cc delete mode 100644 src/libtest/client.hpp delete mode 100644 src/libtest/cmdline.cc delete mode 100644 src/libtest/cmdline.h delete mode 100644 src/libtest/collection.cc delete mode 100644 src/libtest/collection.h delete mode 100644 src/libtest/common.h delete mode 100644 src/libtest/comparison.cc delete mode 100644 src/libtest/comparison.hpp delete mode 100644 src/libtest/core.cc delete mode 100644 src/libtest/core.h delete mode 100644 src/libtest/core_count.cc delete mode 100644 src/libtest/cpu.cc delete mode 100644 src/libtest/cpu.hpp delete mode 100644 src/libtest/dns.cc delete mode 100644 src/libtest/dns.hpp delete mode 100644 src/libtest/dream.cc delete mode 100644 src/libtest/dream.h delete mode 100644 src/libtest/drizzled.cc delete mode 100644 src/libtest/drizzled.h delete mode 100644 src/libtest/error.h delete mode 100644 src/libtest/exception.cc delete mode 100644 src/libtest/exception.hpp delete mode 100644 src/libtest/exception/disconnected.hpp delete mode 100644 src/libtest/exception/fatal.cc delete mode 100644 src/libtest/exception/fatal.hpp delete mode 100644 src/libtest/failed.cc delete mode 100644 src/libtest/formatter.cc delete mode 100644 src/libtest/formatter.hpp delete mode 100644 src/libtest/framework.cc delete mode 100644 src/libtest/framework.h delete mode 100644 src/libtest/gearmand.cc delete mode 100644 src/libtest/gearmand.h delete mode 100644 src/libtest/get.h delete mode 100644 src/libtest/has.cc delete mode 100644 src/libtest/has.hpp delete mode 100644 src/libtest/http.cc delete mode 100644 src/libtest/http.hpp delete mode 100644 src/libtest/is_local.cc delete mode 100644 src/libtest/is_local.hpp delete mode 100644 src/libtest/is_pid.hpp delete mode 100644 src/libtest/killpid.cc delete mode 100644 src/libtest/killpid.h delete mode 100644 src/libtest/libtool.cc delete mode 100644 src/libtest/libtool.hpp delete mode 100644 src/libtest/lite.h delete mode 100644 src/libtest/main.cc delete mode 100644 src/libtest/memcached.cc delete mode 100644 src/libtest/memcached.h delete mode 100644 src/libtest/memcached.hpp delete mode 100644 src/libtest/poll_error.hpp delete mode 100644 src/libtest/port.cc delete mode 100644 src/libtest/port.h delete mode 100644 src/libtest/result.cc delete mode 100644 src/libtest/result.hpp delete mode 100644 src/libtest/result/base.hpp delete mode 100644 src/libtest/result/fail.hpp delete mode 100644 src/libtest/result/skip.hpp delete mode 100644 src/libtest/result/success.hpp delete mode 100644 src/libtest/run-ci.gdb delete mode 100644 src/libtest/run.gdb delete mode 100644 src/libtest/runner.cc delete mode 100644 src/libtest/runner.h delete mode 100644 src/libtest/server.cc delete mode 100644 src/libtest/server.h delete mode 100644 src/libtest/server_container.cc delete mode 100644 src/libtest/server_container.h delete mode 100644 src/libtest/signal.cc delete mode 100644 src/libtest/signal.h delete mode 100644 src/libtest/skiptest.cc delete mode 100644 src/libtest/socket.cc delete mode 100644 src/libtest/socket.hpp delete mode 100644 src/libtest/stream.h delete mode 100644 src/libtest/strerror.cc delete mode 100644 src/libtest/strerror.h delete mode 100644 src/libtest/string.hpp delete mode 100644 src/libtest/test.h delete mode 100644 src/libtest/test.hpp delete mode 100644 src/libtest/thread.hpp delete mode 100644 src/libtest/timer.cc delete mode 100644 src/libtest/timer.hpp delete mode 100644 src/libtest/tmpfile.cc delete mode 100644 src/libtest/tmpfile.hpp delete mode 100644 src/libtest/unittest.cc delete mode 100644 src/libtest/valgrind.h delete mode 100644 src/libtest/vchar.cc delete mode 100644 src/libtest/vchar.hpp delete mode 100644 src/libtest/version.h.in delete mode 100644 src/libtest/visibility.h delete mode 100644 src/libtest/wait.cc delete mode 100644 src/libtest/wait.h delete mode 100644 src/libtest/yatl.h delete mode 100644 src/libtest/yatlcon.h.in diff --git a/src/libtest/CMakeLists.txt b/src/libtest/CMakeLists.txt deleted file mode 100644 index 794d7bd0..00000000 --- a/src/libtest/CMakeLists.txt +++ /dev/null @@ -1,70 +0,0 @@ - -file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tmp_chroot) -file(WRITE ${CMAKE_BINARY_DIR}/libtool -"#!/bin/bash -shift -exec $@ -") -if(UNIX) - if(EXISTS ${CMAKE_BINARY_DIR}/libtool) - execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/libtool) - endif() -endif() - -add_library(libtest STATIC - alarm.cc - binaries.cc - client.cc - cmdline.cc - collection.cc - comparison.cc - core.cc - cpu.cc - dns.cc - dream.cc - drizzled.cc - exception.cc - exception/fatal.cc - formatter.cc - framework.cc - gearmand.cc - has.cc - http.cc - is_local.cc - killpid.cc - libtool.cc - main.cc - memcached.cc - port.cc - result.cc - runner.cc - server.cc - server_container.cc - signal.cc - socket.cc - strerror.cc - timer.cc - tmpfile.cc - vchar.cc - ) -set_target_properties(libtest PROPERTIES LIBRARY_OUTPUT_NAME test) -target_compile_definitions(libtest PRIVATE - BUILDING_LIBTEST=1 - LIBTEST_TEMP=\"${CMAKE_BINARY_DIR}/tmp_chroot\" - - DRIZZLED_BINARY=\"drizzled\" - GEARMAND_BINARY=\"gearmand\" - MEMCACHED_BINARY=\"${MEMCACHED_BINARY}\" - HAVE_MEMCACHED_BINARY=1 - ) -target_link_libraries(libtest PRIVATE Threads::Threads ${CMAKE_DL_LIBS}) - -add_executable(wait wait.cc dream.cc) - -add_executable(core_count core_count.cc cpu.cc) - -add_executable(backtrace backtrace_test.cc ../libmemcached/backtrace.cc) -target_link_libraries(backtrace PRIVATE ${CMAKE_DL_LIBS}) - -configure_file(yatlcon.h.in yatlcon.h @ONLY) -configure_file(version.h.in version.h @ONLY) diff --git a/src/libtest/alarm.cc b/src/libtest/alarm.cc deleted file mode 100644 index 027a646a..00000000 --- a/src/libtest/alarm.cc +++ /dev/null @@ -1,102 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" - -#include "libtest/common.h" - -#include -#include - -namespace libtest { - -static const struct timeval default_it_value= { 600, 0 }; -static const struct timeval default_it_interval= { 0, 0 }; -static const struct itimerval defualt_timer= { default_it_interval, default_it_value }; - -static const struct itimerval cancel_timer= { default_it_interval, default_it_interval }; - - -void set_alarm() -{ - if (setitimer(ITIMER_VIRTUAL, &defualt_timer, NULL) == -1) - { - Error << "setitimer() failed"; - } -} - -void set_alarm(long tv_sec, long tv_usec) -{ - // For the moment use any value to YATL_ALARM to cancel alarming. - if (getenv("YATL_ALARM")) - { - errno= 0; - tv_sec= strtol(getenv("YATL_ALARM"), (char **) NULL, 10); - - if (errno != 0) - { - FATAL("Bad value for YATL_ALARM"); - } - else if (tv_sec == 0) - { - cancel_alarm(); - } - } - -#ifdef __APPLE__ - struct timeval it_value= { time_t(tv_sec), suseconds_t(tv_usec) }; -#else - struct timeval it_value= { tv_sec, tv_usec }; -#endif - - struct itimerval timer= { default_it_interval, it_value }; - - if (setitimer(ITIMER_VIRTUAL, &timer, NULL) == -1) - { - Error << "setitimer() failed"; - } -} - -void cancel_alarm() -{ - if (setitimer(ITIMER_VIRTUAL, &cancel_timer, NULL) == -1) - { - Error << "setitimer() failed"; - } -} - -} // namespace libtest - diff --git a/src/libtest/alarm.h b/src/libtest/alarm.h deleted file mode 100644 index f675c580..00000000 --- a/src/libtest/alarm.h +++ /dev/null @@ -1,46 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -void set_alarm(long tv_sec, long tv_usec); -void set_alarm(); -void cancel_alarm(); - -} // namespace libtest - diff --git a/src/libtest/backtrace_test.cc b/src/libtest/backtrace_test.cc deleted file mode 100644 index d4af4515..00000000 --- a/src/libtest/backtrace_test.cc +++ /dev/null @@ -1,123 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include -#include -#include -#include -#include -#include - -#include "libmemcached/backtrace.hpp" - -class Test { -public: - Test() - { - } - - void call_backtrace() - { - std::cerr << __func__ << std::endl; - custom_backtrace(); - } -}; - -void SIGSEGV_handler(int sig_num, siginfo_t* info, void* ucontext) -{ - std::cerr << __func__ << std::endl; - (void)sig_num; - (void)info; - (void)ucontext; - - custom_backtrace(); -} - -int raise_SIGSEGV() -{ - std::cerr << std::endl << "Calling backtrace()" << std::endl; - custom_backtrace(); - std::cerr << std::endl << "Calling raise()" << std::endl; - return raise(SIGSEGV); -} - -int layer4() -{ - return raise_SIGSEGV(); -} - -int layer3() -{ - return layer4(); -} - -int layer2() -{ - return layer3(); -} - -int layer1() -{ - return layer2(); -} - -int main(int, char **) -{ - Test t; - - t.call_backtrace(); - - struct sigaction sigact; - - sigact.sa_sigaction= SIGSEGV_handler; - sigact.sa_flags= SA_RESTART | SA_SIGINFO; - - if (sigaction(SIGSEGV, &sigact, (struct sigaction *)NULL) != 0) - { - std::cerr << "error setting signal handler for " << strsignal(SIGSEGV) << "(" << SIGSEGV << ")" << std::endl; - - exit(EXIT_FAILURE); - } - - int ret= layer1(); - if (ret) - { - std::cerr << "raise() " << strerror(errno) << std::endl; - exit(EXIT_FAILURE); - } - - exit(EXIT_SUCCESS); -} diff --git a/src/libtest/binaries.cc b/src/libtest/binaries.cc deleted file mode 100644 index 9adfb893..00000000 --- a/src/libtest/binaries.cc +++ /dev/null @@ -1,41 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" - -namespace libtest { - -} diff --git a/src/libtest/binaries.h b/src/libtest/binaries.h deleted file mode 100644 index 7829f3f0..00000000 --- a/src/libtest/binaries.h +++ /dev/null @@ -1,41 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -} // namespace libtest diff --git a/src/libtest/blobslap_worker.cc b/src/libtest/blobslap_worker.cc deleted file mode 100644 index 54a0353c..00000000 --- a/src/libtest/blobslap_worker.cc +++ /dev/null @@ -1,165 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - -#include "libtest/blobslap_worker.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef __INTEL_COMPILER -#pragma GCC diagnostic ignored "-Wold-style-cast" -#endif - -namespace libtest { - -class BlobslapWorker : public Server -{ -private: -public: - BlobslapWorker(in_port_t port_arg) : - Server("localhost", port_arg, "benchmark/blobslap_worker", true) - { - set_pid_file(); - } - - pid_t get_pid(bool error_is_ok) - { - if (pid_file().empty()) - { - Error << "pid_file was empty"; - return -1; - } - - Wait wait(pid_file(), 0); - - if (error_is_ok and not wait.successful()) - { - Error << "Pidfile was not found:" << pid_file(); - return -1; - } - - std::stringstream error_message; - pid_t ret= get_pid_from_file(pid_file(), error_message); - - if (error_is_ok and is_pid_valid(ret) == false) - { - Error << error_message.str(); - } - - return ret; - } - - bool ping() - { - if (pid_file().empty()) - { - Error << "No pid file available"; - return false; - } - - Wait wait(pid_file(), 0); - if (not wait.successful()) - { - Error << "Pidfile was not found:" << pid_file(); - return false; - } - - std::stringstream error_message; - pid_t local_pid= get_pid_from_file(pid_file(), error_message); - if (is_pid_valid(local_pid) == false) - { - Error << error_message.str(); - return false; - } - - // Use kill to determine is the process exist - if (::kill(local_pid, 0) == 0) - { - return true; - } - - return false; - } - - const char *name() - { - return "blobslap_worker"; - }; - - bool has_port_option() const - { - return true; - } - - bool has_log_file_option() const - { - return true; - } - - bool is_libtool() - { - return true; - } - - bool build(); -}; - - -#include - -bool BlobslapWorker::build() -{ - return true; -} - -Server *build_blobslap_worker(in_port_t try_port) -{ - return new BlobslapWorker(try_port); -} - -} // namespace libtest diff --git a/src/libtest/blobslap_worker.h b/src/libtest/blobslap_worker.h deleted file mode 100644 index 907ae6e7..00000000 --- a/src/libtest/blobslap_worker.h +++ /dev/null @@ -1,43 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -Server *build_blobslap_worker(in_port_t try_port); - -} diff --git a/src/libtest/callbacks.h b/src/libtest/callbacks.h deleted file mode 100644 index 1e617b40..00000000 --- a/src/libtest/callbacks.h +++ /dev/null @@ -1,52 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void* (test_callback_create_fn)(libtest::server_startup_st&, test_return_t&); -typedef bool test_callback_destroy_fn(void *); -typedef enum test_return_t (test_callback_fn)(void *); -typedef enum test_return_t (test_callback_runner_fn)(test_callback_fn*, void *); -typedef enum test_return_t (test_callback_error_fn)(const test_return_t, void *); - -#ifdef __cplusplus -} -#endif - diff --git a/src/libtest/client.cc b/src/libtest/client.cc deleted file mode 100644 index c6e8604e..00000000 --- a/src/libtest/client.cc +++ /dev/null @@ -1,389 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - -#include -#include -#include -#include - -#ifdef HAVE_POLL_H -# include -#endif - -#ifndef HAVE_MSG_NOSIGNAL -# define MSG_NOSIGNAL 0 -#endif - -namespace libtest { - -SimpleClient::SimpleClient(const std::string& hostname_, in_port_t port_) : - _is_connected(false), - _hostname(hostname_), - _port(port_), - sock_fd(INVALID_SOCKET), - requested_message(1) - { - } - -bool SimpleClient::ready(int event_) -{ - struct pollfd fds[1]; - fds[0].fd= sock_fd; - fds[0].events= event_; - fds[0].revents= 0; - - int timeout= 5000; - if (_is_connected == false) - { - timeout= timeout * 30; - } - - int ready_fds= poll(fds, 1, timeout); - - if (ready_fds == -1) - { - _error= strerror(errno); - return false; - } - else if (ready_fds == 1) - { - if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) - { - int err; - socklen_t len= sizeof (err); - // We replace errno with err if getsockopt() passes, but err has been - // set. - if (getsockopt(fds[0].fd, SOL_SOCKET, SO_ERROR, &err, &len) == 0) - { - // We check the value to see what happened wth the socket. - if (err == 0) - { - _error= "getsockopt() returned no error but poll() indicated one existed"; - return false; - } - errno= err; - } - _error= strerror(errno); - - return false; - } - - _is_connected= true; - if (fds[0].revents & event_) - { - return true; - } - } - - fatal_assert(ready_fds == 0); - _error= "TIMEOUT"; - - return false; -} - -struct addrinfo* SimpleClient::lookup() -{ - struct addrinfo *ai= NULL; - struct addrinfo hints; - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_socktype= SOCK_STREAM; - hints.ai_protocol= IPPROTO_TCP; - - libtest::vchar_t service; - service.resize(NI_MAXSERV); - (void)snprintf(&service[0], service.size(), "%d", _port); - - int getaddrinfo_error; - if ((getaddrinfo_error= getaddrinfo(_hostname.c_str(), &service[0], &hints, &ai)) != 0) - { - if (getaddrinfo_error != EAI_SYSTEM) - { - _error= gai_strerror(getaddrinfo_error); - return NULL; - } - else - { - _error= strerror(getaddrinfo_error); - return NULL; - } - } - - return ai; -} - -SimpleClient::~SimpleClient() -{ - close_socket(); -} - -void SimpleClient::close_socket() -{ - if (sock_fd != INVALID_SOCKET) - { - close(sock_fd); - sock_fd= INVALID_SOCKET; - } -} - -bool SimpleClient::instance_connect() -{ - _is_connected= false; - struct addrinfo *ai; - if ((ai= lookup())) - { - { - struct addrinfo* address_info_next= ai; - - while (address_info_next and sock_fd == INVALID_SOCKET) - { - if ((sock_fd= socket(address_info_next->ai_family, address_info_next->ai_socktype, address_info_next->ai_protocol)) != SOCKET_ERROR) - { - if (connect(sock_fd, address_info_next->ai_addr, address_info_next->ai_addrlen) == SOCKET_ERROR) - { - switch (errno) - { - case EINTR: - close_socket(); - continue; - - case EINPROGRESS: // nonblocking mode - first return - case EALREADY: // nonblocking mode - subsequent returns - continue; // Jump to while() and continue on - - - case ECONNREFUSED: - default: - break; - } - - close_socket(); - _error= strerror(errno); - } - } - else - { - FATAL(strerror(errno)); - } - address_info_next= address_info_next->ai_next; - } - - freeaddrinfo(ai); - } - - if (sock_fd == INVALID_SOCKET) - { - fatal_assert(_error.size()); - } - - return bool(sock_fd != INVALID_SOCKET); - } - - return false; -} - -bool SimpleClient::is_valid() -{ - _error.clear(); - if (sock_fd == INVALID_SOCKET) - { - return instance_connect(); - } - - return true; -} - -bool SimpleClient::message(const char* ptr, const size_t len) -{ - if (is_valid()) - { - if (ready(POLLOUT)) - { - off_t offset= 0; - do - { - ssize_t nw= send(sock_fd, ptr + offset, len - offset, MSG_NOSIGNAL); - if (nw == -1) - { - if (errno != EINTR) - { - _error= strerror(errno); - return false; - } - } - else - { - offset += nw; - } - } while (offset < ssize_t(len)); - - return true; - } - } - - fatal_assert(_error.size()); - - return false; -} - -bool SimpleClient::send_message(const std::string& arg) -{ - if (message(arg.c_str(), arg.size()) == true) - { - return message("\r\n", 2); - } - - return false; -} - -bool SimpleClient::send_data(const libtest::vchar_t& message_, libtest::vchar_t& response_) -{ - requested_message++; - if (message(&message_[0], message_.size())) - { - return response(response_); - } - - return false; -} - -bool SimpleClient::send_message(const std::string& message_, std::string& response_) -{ - requested_message++; - if (send_message(message_)) - { - return response(response_); - } - - return false; -} - -bool SimpleClient::response(libtest::vchar_t& response_) -{ - response_.clear(); - - if (is_valid()) - { - if (ready(POLLIN)) - { - bool more= true; - char buffer[2]; - buffer[1]= 0; - do - { - ssize_t nr= recv(sock_fd, buffer, 1, MSG_NOSIGNAL); - if (nr == -1) - { - if (errno != EINTR) - { - _error= strerror(errno); - return false; - } - } - else if (nr == 0) - { - close_socket(); - more= false; - } - else - { - response_.reserve(response_.size() + nr +1); - fatal_assert(nr == 1); - if (buffer[0] == '\n') - { - more= false; - } - response_.insert(response_.end(), buffer, buffer +nr); - } - } while (more); - - return response_.size(); - } - } - - fatal_assert(_error.size()); - return false; -} - -bool SimpleClient::response(std::string& response_) -{ - response_.clear(); - - if (is_valid()) - { - if (ready(POLLIN)) - { - bool more= true; - char buffer[2]; - buffer[1]= 0; - do - { - ssize_t nr= recv(sock_fd, buffer, 1, MSG_NOSIGNAL); - if (nr == -1) - { - if (errno != EINTR) - { - _error= strerror(errno); - return false; - } - } - else if (nr == 0) - { - close_socket(); - more= false; - } - else - { - fatal_assert(nr == 1); - if (buffer[0] == '\n') - { - more= false; - } - response_.append(buffer); - } - } while (more); - - return response_.size(); - } - } - - fatal_assert(_error.size()); - return false; -} - -} // namespace libtest diff --git a/src/libtest/client.hpp b/src/libtest/client.hpp deleted file mode 100644 index 979a532a..00000000 --- a/src/libtest/client.hpp +++ /dev/null @@ -1,80 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -class SimpleClient { -public: - SimpleClient(const std::string& hostname_, in_port_t port_); - ~SimpleClient(); - - bool send_data(const libtest::vchar_t&, libtest::vchar_t&); - bool send_message(const std::string&); - bool send_message(const std::string&, std::string&); - bool response(std::string&); - bool response(libtest::vchar_t&); - - bool is_valid(); - - const std::string& error() const - { - return _error; - } - - bool is_error() const - { - return _error.size() ? true : false; - } - -private: // Methods - void close_socket(); - bool instance_connect(); - struct addrinfo* lookup(); - bool message(const char* ptr, const size_t len); - bool ready(int event_); - -private: - bool _is_connected; - std::string _hostname; - in_port_t _port; - int sock_fd; - std::string _error; - int requested_message; -}; - -} // namespace libtest diff --git a/src/libtest/cmdline.cc b/src/libtest/cmdline.cc deleted file mode 100644 index 375b00a1..00000000 --- a/src/libtest/cmdline.cc +++ /dev/null @@ -1,868 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" - -#include "libtest/common.h" - -using namespace libtest; - -#include -#include -#include -#include -#include -#include -#ifdef HAVE_POLL_H -# include -#endif -#ifdef HAVE_SPAWN_H -# include -#endif -#include -#include -#include -#include -#include - -#include -#include - -#ifndef __USE_GNU -static char **environ= NULL; -#endif - -#ifndef FD_CLOEXEC -# define FD_CLOEXEC 0 -#endif - -namespace { - - std::string print_argv(libtest::vchar_ptr_t& built_argv) - { - std::stringstream arg_buffer; - - for (vchar_ptr_t::iterator iter= built_argv.begin(); - iter != built_argv.end(); - ++iter) - { - if (*iter) - { - arg_buffer << *iter << " "; - } - } - - return arg_buffer.str(); - } - -#if 0 - std::string print_argv(char** argv) - { - std::stringstream arg_buffer; - - for (char** ptr= argv; *ptr; ++ptr) - { - arg_buffer << *ptr << " "; - } - - return arg_buffer.str(); - } -#endif - - static Application::error_t int_to_error_t(int arg) - { - switch (arg) - { - case 127: - return Application::INVALID_POSIX_SPAWN; - - case 0: - return Application::SUCCESS; - - case 1: - return Application::FAILURE; - - default: - return Application::UNKNOWN; - } - } -} - -namespace libtest { - -Application::Application(const std::string& arg, const bool _use_libtool_arg) : - _use_libtool(_use_libtool_arg), - _use_valgrind(false), - _use_gdb(false), - _use_ptrcheck(false), - _will_fail(false), - _argc(0), - _exectuble(arg), - stdin_fd(STDIN_FILENO), - stdout_fd(STDOUT_FILENO), - stderr_fd(STDERR_FILENO), - _pid(-1), - _status(0), - _app_exit_state(UNINITIALIZED) - { - if (_use_libtool) - { - if (libtool() == NULL) - { - FATAL("libtool requested, but no libtool was found"); - } - } - - // Find just the name of the application with no path - { - size_t found= arg.find_last_of("/\\"); - if (found) - { - _exectuble_name= arg.substr(found +1); - } - else - { - _exectuble_name= arg; - } - } - - if (_use_libtool and getenv("PWD")) - { - _exectuble_with_path+= getenv("PWD"); - _exectuble_with_path+= "/"; - } - _exectuble_with_path+= _exectuble; - } - -Application::~Application() -{ - murder(); - delete_argv(); -} - -Application::error_t Application::run(const char *args[]) -{ - stdin_fd.reset(); - stdout_fd.reset(); - stderr_fd.reset(); - _stdout_buffer.clear(); - _stderr_buffer.clear(); - - posix_spawn_file_actions_t file_actions; - posix_spawn_file_actions_init(&file_actions); - - stdin_fd.dup_for_spawn(file_actions); - stdout_fd.dup_for_spawn(file_actions); - stderr_fd.dup_for_spawn(file_actions); - - posix_spawnattr_t spawnattr; - posix_spawnattr_init(&spawnattr); - - short flags= 0; - - // Child should not block signals - flags |= POSIX_SPAWN_SETSIGMASK; - - sigset_t mask; - sigemptyset(&mask); - - fatal_assert(posix_spawnattr_setsigmask(&spawnattr, &mask) == 0); - -#if defined(POSIX_SPAWN_USEVFORK) || defined(__linux__) - // Use USEVFORK on linux - flags |= POSIX_SPAWN_USEVFORK; -#endif - - flags |= POSIX_SPAWN_SETPGROUP; - fatal_assert(posix_spawnattr_setpgroup(&spawnattr, 0) == 0); - - fatal_assert(posix_spawnattr_setflags(&spawnattr, flags) == 0); - - create_argv(args); - - int spawn_ret; - if (_use_gdb) - { - std::string gdb_run_file= create_tmpfile(_exectuble_name); - std::fstream file_stream; - file_stream.open(gdb_run_file.c_str(), std::fstream::out | std::fstream::trunc); - - _gdb_filename= create_tmpfile(_exectuble_name); - file_stream - << "set logging redirect on" << std::endl - << "set logging file " << _gdb_filename << std::endl - << "set logging overwrite on" << std::endl - << "set logging on" << std::endl - << "set environment LIBTEST_IN_GDB=1" << std::endl - << "run " << arguments() << std::endl - << "thread apply all bt" << std::endl - << "quit" << std::endl; - - fatal_assert(file_stream.good()); - file_stream.close(); - - if (_use_libtool) - { - // libtool --mode=execute gdb -f -x binary - char *argv[]= { - const_cast(libtool()), - const_cast("--mode=execute"), - const_cast("gdb"), - const_cast("-batch"), - const_cast("-f"), - const_cast("-x"), - const_cast(gdb_run_file.c_str()), - const_cast(_exectuble_with_path.c_str()), - 0}; - - spawn_ret= posix_spawnp(&_pid, libtool(), &file_actions, &spawnattr, argv, environ); - } - else - { - // gdb binary - char *argv[]= { - const_cast("gdb"), - const_cast("-batch"), - const_cast("-f"), - const_cast("-x"), - const_cast(gdb_run_file.c_str()), - const_cast(_exectuble_with_path.c_str()), - 0}; - spawn_ret= posix_spawnp(&_pid, "gdb", &file_actions, &spawnattr, argv, environ); - } - } - else - { - spawn_ret= posix_spawn(&_pid, built_argv[0], &file_actions, &spawnattr, &built_argv[0], environ); - } - - posix_spawn_file_actions_destroy(&file_actions); - posix_spawnattr_destroy(&spawnattr); - - stdin_fd.close(Application::Pipe::READ); - stdout_fd.close(Application::Pipe::WRITE); - stderr_fd.close(Application::Pipe::WRITE); - - if (spawn_ret != 0) - { - if (_will_fail == false) - { - std::string sb; - char buf[1024]; - - std::for_each(built_argv.begin(), built_argv.end()-1, [&sb](const char *a) { - if (sb.size()) { - sb.append(" "); - } - sb.append(a); - }); - Error << strerror(spawn_ret) << "(" << spawn_ret << "): " << sb << " cwd:" << getcwd(buf, sizeof(buf)-1); - } - _pid= -1; - return Application::INVALID_POSIX_SPAWN; - } - - assert(_pid != -1); - if (_pid == -1) - { - return Application::INVALID_POSIX_SPAWN; - } - -#if 0 - app_thread_st* _app_thread= new app_thread_st(_pid, _status, built_argv[0], _app_exit_state); - int error; - if ((error= pthread_create(&_thread, NULL, &app_thread, _app_thread)) != 0) - { - Error << "pthread_create() died during pthread_create(" << strerror(error) << ")"; - return Application::FAILURE; - } -#endif - - return Application::SUCCESS; -} - -bool Application::check() const -{ - if (_pid > 1 and kill(_pid, 0) == 0) - { - return true; - } - - return false; -} - -void Application::murder() -{ - if (check()) - { - int count= 5; - while ((count--) > 0 and check()) - { - if (kill(_pid, SIGTERM) == 0) - { - join(); - } - else - { - Error << "kill(pid, SIGTERM) failed after kill with error of " << strerror(errno); - continue; - } - - break; - } - - // If for whatever reason it lives, kill it hard - if (check()) - { - Error << "using SIGKILL, things will likely go poorly from this point"; - (void)kill(_pid, SIGKILL); - } - } - slurp(); -} - -// false means that no data was returned -bool Application::slurp() -{ - struct pollfd fds[2]; - fds[0].fd= stdout_fd.fd(); - fds[0].events= POLLRDNORM; - fds[0].revents= 0; - fds[1].fd= stderr_fd.fd(); - fds[1].events= POLLRDNORM; - fds[1].revents= 0; - - int active_fd; - if ((active_fd= poll(fds, 2, 0)) == -1) - { - int error; - switch ((error= errno)) - { -#ifdef __linux - case ERESTART: -#endif - case EINTR: - break; - - case EFAULT: - case ENOMEM: - FATAL(strerror(error)); - break; - - case EINVAL: - FATAL("RLIMIT_NOFILE exceeded, or if OSX the timeout value was invalid"); - break; - - default: - FATAL(strerror(error)); - break; - } - - return false; - } - - if (active_fd == 0) - { - return false; - } - - bool data_was_read= false; - if (fds[0].revents & POLLRDNORM) - { - if (stdout_fd.read(_stdout_buffer) == true) - { - data_was_read= true; - } - } - - if (fds[1].revents & POLLRDNORM) - { - if (stderr_fd.read(_stderr_buffer) == true) - { - data_was_read= true; - } - } - - return data_was_read; -} - -std::pair Application::output() -{ - slurp(); - return { - std::string { - stdout_result().data(), - stdout_result().size() - }, - std::string { - stderr_result().data(), - stderr_result().size() - } - }; - -} - -Application::error_t Application::join() -{ - pid_t waited_pid= waitpid(_pid, &_status, WUNTRACED); - slurp(); - if (waited_pid == _pid and WIFEXITED(_status) == false) - { - /* - What we are looking for here is how the exit status happened. - - 127 means that posix_spawn() itself had an error. - - If WEXITSTATUS is positive we need to see if it is a signal that we sent to kill the process. If not something bad happened in the process itself. - - Finally something has happened that we don't currently understand. - */ - if (WEXITSTATUS(_status) == 127) - { - _app_exit_state= Application::INVALID_POSIX_SPAWN; - std::string error_string("posix_spawn() failed pid:"); - error_string+= _pid; - error_string+= " name:"; - error_string+= print_argv(built_argv); - if (stderr_result_length()) - { - error_string+= " stderr: "; - error_string+= stderr_c_str(); - } - throw std::logic_error(error_string); - } - else if (WIFSIGNALED(_status)) - { - if (WTERMSIG(_status) != SIGTERM and WTERMSIG(_status) != SIGHUP) - { - slurp(); - _app_exit_state= Application::INVALID_POSIX_SPAWN; - std::string error_string(print_argv(built_argv)); - error_string+= " was killed by signal "; - error_string+= strsignal(WTERMSIG(_status)); - - if (stdout_result_length()) - { - error_string+= " stdout: "; - error_string+= stdout_c_str(); - } - - if (stderr_result_length()) - { - error_string+= " stderr: "; - error_string+= stderr_c_str(); - } - - throw std::runtime_error(error_string); - } - - // If we terminted it on purpose then it counts as a success. -#if defined(DEBUG) - if (DEBUG) - { - Out << "waitpid() application terminated at request" - << " pid:" << _pid - << " name:" << built_argv[0]; - } -#endif - } - else - { - _app_exit_state= Application::UNKNOWN; - Error << "Unknown logic state at exit:" << WEXITSTATUS(_status) - << " pid:" << _pid - << " name:" << built_argv[0]; - } - } - else if (waited_pid == _pid and WIFEXITED(_status)) - { - _app_exit_state= int_to_error_t(WEXITSTATUS(_status)); - } - else if (waited_pid == -1) - { - std::string error_string; - if (stdout_result_length()) - { - error_string+= " stdout: "; - error_string+= stdout_c_str(); - } - - if (stderr_result_length()) - { - error_string+= " stderr: "; - error_string+= stderr_c_str(); - } - Error << "waitpid() returned errno:" << strerror(errno) << " " << error_string; - _app_exit_state= Application::UNKNOWN; - } - else - { - _app_exit_state= Application::UNKNOWN; - throw std::logic_error("waitpid() returned an unknown value"); - } - - return _app_exit_state; -} - -void Application::add_long_option(const std::string& name, const std::string& option_value) -{ - std::string arg(name); - arg+= option_value; - _options.push_back(std::make_pair(arg, std::string())); -} - -void Application::add_option(const std::string& arg) -{ - _options.push_back(std::make_pair(arg, std::string())); -} - -void Application::add_option(const std::string& name, const std::string& value) -{ - _options.push_back(std::make_pair(name, value)); -} - -Application::Pipe::Pipe(int arg) : - _std_fd(arg) -{ - _pipe_fd[READ]= -1; - _pipe_fd[WRITE]= -1; - _open[READ]= false; - _open[WRITE]= false; -} - -int Application::Pipe::Pipe::fd() -{ - if (_std_fd == STDOUT_FILENO) - { - return _pipe_fd[READ]; - } - else if (_std_fd == STDERR_FILENO) - { - return _pipe_fd[READ]; - } - - return _pipe_fd[WRITE]; // STDIN_FILENO -} - - -bool Application::Pipe::read(libtest::vchar_t& arg) -{ - fatal_assert(_std_fd == STDOUT_FILENO or _std_fd == STDERR_FILENO); - - bool data_was_read= false; - - libtest::vchar_t buffer; - buffer.resize(1024); - ssize_t read_length; - while ((read_length= ::read(_pipe_fd[READ], &buffer[0], buffer.size()))) - { - if (read_length == -1) - { - switch(errno) - { - case EAGAIN: - break; - - default: - Error << strerror(errno); - break; - } - - break; - } - - data_was_read= true; - arg.reserve(read_length +1); - for (size_t x= 0; x < size_t(read_length); ++x) - { - arg.push_back(buffer[x]); - } - // @todo Suck up all errput code here - } - - return data_was_read; -} - -void Application::Pipe::nonblock() -{ - int flags; - do - { - flags= fcntl(_pipe_fd[READ], F_GETFL, 0); - } while (flags == -1 and (errno == EINTR or errno == EAGAIN)); - - if (flags == -1) - { - Error << "fcntl(F_GETFL) " << strerror(errno); - throw strerror(errno); - } - - int rval; - do - { - rval= fcntl(_pipe_fd[READ], F_SETFL, flags | O_NONBLOCK); - } while (rval == -1 and (errno == EINTR or errno == EAGAIN)); - - if (rval == -1) - { - Error << "fcntl(F_SETFL) " << strerror(errno); - throw strerror(errno); - } -} - -void Application::Pipe::reset() -{ - close(READ); - close(WRITE); - -#ifdef HAVE_PIPE2 - if (pipe2(_pipe_fd, O_NONBLOCK|O_CLOEXEC) == -1) -#endif - { - if (pipe(_pipe_fd) == -1) - { - FATAL(strerror(errno)); - } - - // Since either pipe2() was not found/called we set the pipe directly - nonblock(); - cloexec(); - } - _open[0]= true; - _open[1]= true; -} - -void Application::Pipe::cloexec() -{ - //if (SOCK_CLOEXEC == 0) - { - if (FD_CLOEXEC) - { - int flags; - do - { - flags= fcntl(_pipe_fd[WRITE], F_GETFD, 0); - } while (flags == -1 and (errno == EINTR or errno == EAGAIN)); - - if (flags == -1) - { - Error << "fcntl(F_GETFD) " << strerror(errno); - throw strerror(errno); - } - - int rval; - do - { - rval= fcntl(_pipe_fd[WRITE], F_SETFD, flags | FD_CLOEXEC); - } while (rval == -1 && (errno == EINTR or errno == EAGAIN)); - - if (rval == -1) - { - Error << "fcntl(F_SETFD) " << strerror(errno); - throw strerror(errno); - } - } - } -} - -Application::Pipe::~Pipe() -{ - if (_pipe_fd[0] != -1) - { - ::close(_pipe_fd[0]); - } - - if (_pipe_fd[1] != -1) - { - ::close(_pipe_fd[1]); - } -} - -void Application::Pipe::dup_for_spawn(posix_spawn_file_actions_t& file_actions) -{ - int type= STDIN_FILENO == _std_fd ? 0 : 1; - - int ret; - if ((ret= posix_spawn_file_actions_adddup2(&file_actions, _pipe_fd[type], _std_fd )) < 0) - { - FATAL("posix_spawn_file_actions_adddup2(%s)", strerror(ret)); - } - - if ((ret= posix_spawn_file_actions_addclose(&file_actions, _pipe_fd[type])) < 0) - { - FATAL("posix_spawn_file_actions_addclose(%s)", strerror(ret)); - } -} - -void Application::Pipe::close(const close_t& arg) -{ - int type= int(arg); - - if (_open[type]) - { - if (::close(_pipe_fd[type]) == -1) - { - Error << "close(" << strerror(errno) << ")"; - } - _open[type]= false; - _pipe_fd[type]= -1; - } -} - -void Application::create_argv(const char *args[]) -{ - delete_argv(); - if (_use_libtool) - { - assert(libtool()); - vchar::append(built_argv, libtool()); - vchar::append(built_argv, "--mode=execute"); - } - - if (_use_valgrind) - { - /* - valgrind --error-exitcode=1 --leak-check=yes --track-fds=yes --malloc-fill=A5 --free-fill=DE - */ - vchar::append(built_argv, "valgrind"); - vchar::append(built_argv, "--error-exitcode=1"); - vchar::append(built_argv, "--leak-check=yes"); -#if 0 - vchar::append(built_argv, "--show-reachable=yes")); -#endif - vchar::append(built_argv, "--track-fds=yes"); -#if 0 - built_argv[x++]= strdup("--track-origin=yes"); -#endif - vchar::append(built_argv, "--malloc-fill=A5"); - vchar::append(built_argv, "--free-fill=DE"); - - std::string log_file= create_tmpfile("valgrind"); - libtest::vchar_t buffer; - buffer.resize(1024); - int length= snprintf(&buffer[0], buffer.size(), "--log-file=%s", log_file.c_str()); - fatal_assert(length > 0 and size_t(length) < buffer.size()); - vchar::append(built_argv, &buffer[0]); - } - else if (_use_ptrcheck) - { - /* - valgrind --error-exitcode=1 --tool=exp-ptrcheck --log-file= - */ - vchar::append(built_argv, "valgrind"); - vchar::append(built_argv, "--error-exitcode=1"); - vchar::append(built_argv, "--tool=exp-ptrcheck"); - std::string log_file= create_tmpfile("ptrcheck"); - libtest::vchar_t buffer; - buffer.resize(1024); - int length= snprintf(&buffer[0], buffer.size(), "--log-file=%s", log_file.c_str()); - fatal_assert(length > 0 and size_t(length) < buffer.size()); - vchar::append(built_argv, &buffer[0]); - } - else if (_use_gdb) - { - vchar::append(built_argv, "gdb"); - } - - vchar::append(built_argv, _exectuble_with_path.c_str()); - - for (Options::const_iterator iter= _options.begin(); iter != _options.end(); ++iter) - { - vchar::append(built_argv, (*iter).first.c_str()); - if ((*iter).second.empty() == false) - { - vchar::append(built_argv, (*iter).second.c_str()); - } - } - - if (args) - { - for (const char **ptr= args; *ptr; ++ptr) - { - vchar::append(built_argv, *ptr); - } - } - built_argv.push_back(nullptr); -} - -std::string Application::print() -{ - return print_argv(built_argv); -} - -std::string Application::arguments() -{ - std::stringstream arg_buffer; - - // Skip printing out the libtool reference - for (size_t x= _use_libtool ? 2 : 0; x < _argc; ++x) - { - if (built_argv[x]) - { - arg_buffer << built_argv[x] << " "; - } - } - - return arg_buffer.str(); -} - -void Application::delete_argv() -{ - std::for_each(built_argv.begin(), built_argv.end(), FreeFromVector()); - - built_argv.clear(); - _argc= 0; -} - - -int exec_cmdline(const std::string& command, const char *args[], bool use_libtool) -{ - Application app(command, use_libtool); - - Application::error_t ret= app.run(args); - - if (Application::SUCCESS == ret) { - ret = app.join(); - } - - if (ret != Application::SUCCESS) - { - auto out = app.output(); - Error << command << " stdout: " << out.first; - Error << command << " stderr: " << out.second; - } - - return int(ret); -} - -} // namespace exec_cmdline diff --git a/src/libtest/cmdline.h b/src/libtest/cmdline.h deleted file mode 100644 index 244c6464..00000000 --- a/src/libtest/cmdline.h +++ /dev/null @@ -1,256 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include - -// http://www.gnu.org/software/automake/manual/automake.html#Using-the-TAP-test-protocol -#ifndef EXIT_SKIP -# define EXIT_SKIP 77 -#endif - -#ifndef EXIT_FATAL -# define EXIT_FATAL 99 -#endif - -#ifndef EX_NOEXEC -# define EX_NOEXEC 126 -#endif - -#ifndef EX_NOTFOUND -# define EX_NOTFOUND 127 -#endif - -namespace libtest { - -class Application { -private: - typedef std::vector< std::pair > Options; - -public: - - enum error_t { - SUCCESS= EXIT_SUCCESS, - FAILURE= EXIT_FAILURE, - UNINITIALIZED, - SIGTERM_KILLED, - UNKNOWN, - UNKNOWN_SIGNAL, - INVALID_POSIX_SPAWN= 127 - }; - - static const char* toString(error_t arg) - { - switch (arg) - { - case Application::SUCCESS: - return "EXIT_SUCCESS"; - - case Application::UNINITIALIZED: - return "UNINITIALIZED"; - - case Application::SIGTERM_KILLED: - return "Exit happened via SIGTERM"; - - case Application::FAILURE: - return "EXIT_FAILURE"; - - case Application::UNKNOWN_SIGNAL: - return "Exit happened via a signal which was not SIGTERM"; - - case Application::INVALID_POSIX_SPAWN: - return "127: Invalid call to posix_spawn()"; - - case Application::UNKNOWN: - default: - break; - } - - return "EXIT_UNKNOWN"; - } - - class Pipe { - public: - Pipe(int); - ~Pipe(); - - int fd(); - - enum close_t { - READ= 0, - WRITE= 1 - }; - - void reset(); - void close(const close_t& arg); - void dup_for_spawn(posix_spawn_file_actions_t& file_actions); - - void nonblock(); - void cloexec(); - bool read(libtest::vchar_t&); - - private: - const int _std_fd; - int _pipe_fd[2]; - bool _open[2]; - }; - -public: - Application(const std::string& arg, const bool _use_libtool_arg= false); - - virtual ~Application(); - - void add_option(const std::string&); - void add_option(const std::string&, const std::string&); - void add_long_option(const std::string& option_name, const std::string& option_value); - error_t run(const char *args[]= NULL); - Application::error_t join(); - - libtest::vchar_t stdout_result() const - { - return _stdout_buffer; - } - - size_t stdout_result_length() const - { - return _stdout_buffer.size(); - } - - const char* stdout_c_str() const - { - return &_stdout_buffer[0]; - } - - libtest::vchar_t stderr_result() const - { - return _stderr_buffer; - } - - const char* stderr_c_str() const - { - return &_stderr_buffer[0]; - } - - size_t stderr_result_length() const - { - return _stderr_buffer.size(); - } - - std::string print(); - - void use_valgrind(bool arg) - { - _use_valgrind= arg; - } - - bool check() const; - - bool slurp(); - std::pair output(); - void murder(); - - void clear() - { - slurp(); - _stdout_buffer.clear(); - _stderr_buffer.clear(); - } - - void use_gdb(bool arg) - { - _use_gdb= arg; - } - - void use_ptrcheck(bool arg) - { - _use_ptrcheck= arg; - } - - std::string arguments(); - - std::string gdb_filename() - { - return _gdb_filename; - } - - pid_t pid() const - { - return _pid; - } - - void will_fail() - { - _will_fail= true; - } - -private: - void create_argv(const char *args[]); - void delete_argv(); - void add_to_build_argv(const char*); - -private: - const bool _use_libtool; - bool _use_valgrind; - bool _use_gdb; - bool _use_ptrcheck; - bool _will_fail; - size_t _argc; - std::string _exectuble_name; - std::string _exectuble; - std::string _exectuble_with_path; - std::string _gdb_filename; - Options _options; - Pipe stdin_fd; - Pipe stdout_fd; - Pipe stderr_fd; - libtest::vchar_ptr_t built_argv; - pid_t _pid; - libtest::vchar_t _stdout_buffer; - libtest::vchar_t _stderr_buffer; - int _status; - pthread_t _thread; - error_t _app_exit_state; -}; - -static inline std::ostream& operator<<(std::ostream& output, const enum Application::error_t &arg) -{ - return output << Application::toString(arg); -} - -int exec_cmdline(const std::string& executable, const char *args[], bool use_libtool= false); - -} diff --git a/src/libtest/collection.cc b/src/libtest/collection.cc deleted file mode 100644 index 2bf15fec..00000000 --- a/src/libtest/collection.cc +++ /dev/null @@ -1,216 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" - -#include "libtest/common.h" - -// @todo possibly have this code fork off so if it fails nothing goes bad -static test_return_t runner_code(libtest::Framework* frame, - test_st* run, - libtest::Timer& _timer) -{ // Runner Code - - assert(frame->runner()); - assert(run->test_fn); - - test_return_t return_code; - try - { - _timer.reset(); - assert(frame); - assert(frame->runner()); - assert(run->test_fn); - return_code= frame->runner()->main(run->test_fn, frame->creators_ptr()); - } - // Special case where check for the testing of the exception - // system. - catch (const libtest::fatal& e) - { - if (libtest::fatal::is_disabled()) - { - libtest::fatal::increment_disabled_counter(); - return_code= TEST_SUCCESS; - } - else - { - throw; - } - } - - _timer.sample(); - - return return_code; -} - -namespace libtest { - -Collection::Collection(Framework* frame_arg, - collection_st* arg) : - _name(arg->name), - _pre(arg->pre), - _post(arg->post), - _tests(arg->tests), - _frame(frame_arg), - _success(0), - _skipped(0), - _failed(0), - _total(0), - _formatter(frame_arg->name(), _name) -{ - fatal_assert(arg); -} - -test_return_t Collection::exec() -{ - if (test_success(_frame->runner()->setup(_pre, _frame->creators_ptr()))) - { - for (test_st *run= _tests; run->name; run++) - { - formatter()->push_testcase(run->name); - if (_frame->match(run->name)) - { - formatter()->skipped(); - continue; - } - _total++; - - test_return_t return_code; - try - { - if (run->requires_flush) - { - if (test_failed(_frame->runner()->flush(_frame->creators_ptr()))) - { - Error << "frame->runner()->flush(creators_ptr)"; - _skipped++; - formatter()->skipped(); - continue; - } - } - - set_alarm(); - - try - { - return_code= runner_code(_frame, run, _timer); - } - catch (...) - { - cancel_alarm(); - - throw; - } - libtest::cancel_alarm(); - } - catch (const libtest::fatal& e) - { - _failed++; - formatter()->failed(); - stream::make_cerr err(e.file(), e.line(), e.func()); - err << e.what(); - for (auto server : _frame->servers().servers) - { - auto output = server->output(); - if (output.first.size()) - { - err << "Server(" << server->port() << ") stdout:\n" << output.first << "\n"; - } - if (output.second.size()) - { - err << "Server(" << server->port() << ") stderr:\n" << output.second << "\n"; - } - } - throw; - } - - switch (return_code) - { - case TEST_SUCCESS: - _success++; - formatter()->success(_timer); - break; - - case TEST_FAILURE: - _failed++; - formatter()->failed(); - for (auto server : _frame->servers().servers) - { - auto output = server->output(); - if (output.first.size()) - { - Out << "Server(" << server->port() << ") stdout:\n" << output.first << "\n"; - } - if (output.second.size()) - { - Out << "Server(" << server->port() << ") stderr:\n" << output.second << "\n"; - } - } - break; - - case TEST_SKIPPED: - _skipped++; - formatter()->skipped(); - break; - - default: - FATAL("invalid return code"); - } -#if 0 - @TODO add code here to allow for a collection to define a method to reset to allow tests to continue. -#endif - } - - (void) _frame->runner()->teardown(_post, _frame->creators_ptr()); - } - - if (_failed == 0 and _skipped == 0 and _success) - { - return TEST_SUCCESS; - } - - if (_failed) - { - return TEST_FAILURE; - } - - fatal_assert(_skipped or _success == 0); - - return TEST_SKIPPED; -} - -} // namespace libtest - diff --git a/src/libtest/collection.h b/src/libtest/collection.h deleted file mode 100644 index 2657449d..00000000 --- a/src/libtest/collection.h +++ /dev/null @@ -1,112 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include "libtest/formatter.hpp" - -#include "libtest/timer.hpp" - -namespace { class Framework; } - - -/** - A structure which describes a collection of test cases. -*/ -struct collection_st { - const char *name; - test_callback_fn *pre; - test_callback_fn *post; - struct test_st *tests; -}; - -namespace libtest { - -class Collection { -public: - Collection(libtest::Framework*, collection_st*); - - test_return_t exec(); - - const char* name() - { - return _name.c_str(); - } - - uint32_t success() - { - return _success; - } - - uint32_t skipped() - { - return _skipped; - } - - uint32_t failed() - { - return _failed; - } - - uint32_t total() - { - return _total; - } - - libtest::Formatter* formatter() - { - return &_formatter; - } - -private: - std::string _name; - test_callback_fn *_pre; - test_callback_fn *_post; - struct test_st *_tests; - libtest::Framework* _frame; - uint32_t _success; - uint32_t _skipped; - uint32_t _failed; - uint32_t _total; - libtest::Timer _timer; - libtest::Formatter _formatter; - -private: - Collection( const Collection& ); - const Collection& operator=( const Collection& ); -}; - -} // namespace libtest diff --git a/src/libtest/common.h b/src/libtest/common.h deleted file mode 100644 index bba458fd..00000000 --- a/src/libtest/common.h +++ /dev/null @@ -1,121 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ -/* - Common include file for libtest -*/ - -#pragma once - -#include -#include -#include -#include -#include - -#ifdef HAVE_SYS_TYPES_H -# include -#endif - -#ifdef HAVE_SYS_TIME_H -# include -#endif - -#ifdef HAVE_SYS_WAIT_H -# include -#endif - -#ifdef HAVE_SYS_RESOURCE_H -# include -#endif - -#ifdef HAVE_FNMATCH_H -# include -#endif - -#ifdef HAVE_ARPA_INET_H -# include -#endif - -#if defined(WIN32) -# include "win32/wrappers.h" -# define get_socket_errno() WSAGetLastError() -#else -# ifdef HAVE_UNISTD_H -# include -# endif -# define INVALID_SOCKET -1 -# define SOCKET_ERROR -1 -# define closesocket(a) close(a) -# define get_socket_errno() errno -#endif - -#include "libtest/test.hpp" - -#include "libtest/is_pid.hpp" - -#include "libtest/gearmand.h" -#include "libtest/blobslap_worker.h" -#include "libtest/memcached.h" -#include "libtest/drizzled.h" - -#include "libtest/libtool.hpp" -#include "libtest/killpid.h" -#include "libtest/signal.h" -#include "libtest/dns.hpp" -#include "libtest/formatter.hpp" - -struct FreeFromVector -{ - template - void operator() ( T* ptr) const - { - if (ptr) - { - free(ptr); - ptr= NULL; - } - } -}; - -struct DeleteFromVector -{ - template - void operator() ( T* ptr) const - { - delete ptr; - ptr= NULL; - } -}; diff --git a/src/libtest/comparison.cc b/src/libtest/comparison.cc deleted file mode 100644 index b9c748ea..00000000 --- a/src/libtest/comparison.cc +++ /dev/null @@ -1,87 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - -namespace libtest { - -bool jenkins_is_caller(void) -{ - if (bool(getenv("JENKINS_HOME"))) - { - return true; - } - - return false; -} - -bool gdb_is_caller(void) -{ - if (bool(getenv("LOG_COMPILER")) and strstr(getenv("LOG_COMPILER"), "gdb")) - { - return true; - } - - if (bool(getenv("LIBTEST_IN_GDB"))) - { - return true; - } - - return false; -} - -bool helgrind_is_caller(void) -{ - if (bool(getenv("LOG_COMPILER")) and strstr(getenv("LOG_COMPILER"), "helgrind")) - { - return true; - } - - return false; -} - -bool _in_valgrind(const char*, int, const char*) -{ - if (valgrind_is_caller()) - { - return true; - } - - return false; -} - -} // namespace libtest diff --git a/src/libtest/comparison.hpp b/src/libtest/comparison.hpp deleted file mode 100644 index b238697c..00000000 --- a/src/libtest/comparison.hpp +++ /dev/null @@ -1,160 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include - -#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED -#include "libmemcached-1.0/memcached.h" -#include "libmemcachedutil-1.0/ostream.hpp" -#include "libtest/memcached.hpp" -#endif - -#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN -#include -#endif - -namespace libtest { - -LIBTEST_API -bool jenkins_is_caller(void); - -LIBTEST_API -bool gdb_is_caller(void); - -LIBTEST_API -bool _in_valgrind(const char *file, int line, const char *func); - -LIBTEST_API -bool helgrind_is_caller(void); - -template -bool _compare_truth(const char *file, int line, const char *func, T_comparable __expected, const char *assertation_label) -{ - if (__expected == false) - { - libtest::stream::make_cerr(file, line, func) << "Assertation \"" << assertation_label << "\""; - return false; - } - - return true; -} - -template -bool _compare(const char *file, int line, const char *func, const T1_comparable& __expected, const T2_comparable& __actual, bool use_io) -{ - if (__expected != __actual) - { - if (use_io) - { - libtest::stream::make_cerr(file, line, func) << "Expected \"" << __expected << "\" got \"" << __actual << "\""; - } - - return false; - } - - return true; -} - -template -bool _compare_strcmp(const char *file, int line, const char *func, const T1_comparable *__expected, const T2_comparable *__actual) -{ - if (__expected == NULL) - { - FATAL("Expected value was NULL, programmer error"); - } - - if (__actual == NULL) - { - libtest::stream::make_cerr(file, line, func) << "Expected " << __expected << " but got NULL"; - return false; - } - - if (strncmp(__expected, __actual, strlen(__expected))) - { - libtest::stream::make_cerr(file, line, func) << "Expected " << __expected << " passed \"" << __actual << "\""; - return false; - } - - return true; -} - -template -bool _compare_zero(const char *file, int line, const char *func, T_comparable __actual) -{ - if (T_comparable(0) != __actual) - { - libtest::stream::make_cerr(file, line, func) << "Expected 0 got \"" << __actual << "\""; - return false; - } - - return true; -} - -template -bool _ne_compare(const char *file, int line, const char *func, T1_comparable __expected, T2_comparable __actual, bool io_error= true) -{ - if (__expected == __actual) - { - if (io_error) - { - libtest::stream::make_cerr(file, line, func) << "Expected \"" << __expected << "\" got \"" << __actual << "\""; - } - - return false; - } - - return true; -} - -template -bool _assert_truth(const char *file, int line, const char *func, T_comparable __truth, T_expression_string __expression, const char* __explain= NULL) -{ - if (__truth) - { - return true; - } - - if (__explain) - { - libtest::stream::make_cerr(file, line, func) << "Assertion \"" << __expression << "\" warning:" << __explain; - } - - return false; -} - -} // namespace libtest diff --git a/src/libtest/core.cc b/src/libtest/core.cc deleted file mode 100644 index 84014956..00000000 --- a/src/libtest/core.cc +++ /dev/null @@ -1,66 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - - -namespace libtest { - -void create_core(void) -{ -#if defined(__APPLE__) && __APPLE__ - if (__APPLE__) - { - return; - } -#endif - if (getenv("YATL_COREDUMP")) - { - pid_t pid= fork(); - - if (pid == 0) - { - abort(); - } - else - { - while (waitpid(pid, NULL, 0) != pid) {}; - } - } -} - -} // namespace libtest diff --git a/src/libtest/core.h b/src/libtest/core.h deleted file mode 100644 index 654fcaf1..00000000 --- a/src/libtest/core.h +++ /dev/null @@ -1,44 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -LIBTEST_API -void create_core(void); - -} // namespace libtest diff --git a/src/libtest/core_count.cc b/src/libtest/core_count.cc deleted file mode 100644 index 40306fdc..00000000 --- a/src/libtest/core_count.cc +++ /dev/null @@ -1,135 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "libtest/cpu.hpp" - -static void version_command(const char *command_name, int major_version, int minor_version) -{ - std::cout << command_name << " " << major_version << "." << minor_version << std::endl; -} - -static void help_command(const char *command_name, - int major_version, int minor_version, - const struct option *long_options) -{ - std::cout << command_name << " " << major_version << "." << minor_version << std::endl; - std::cout << "Prints the number of cores found on the local host." << std::endl << std::endl; - - for (uint32_t x= 0; long_options[x].name; x++) - { - std::cout << "\t --" << long_options[x].name << char(long_options[x].has_arg ? '=' : ' ') << std::endl; - } - - std::cout << std::endl; -} - -enum { - OPT_HELP, - OPT_VERSION -}; - -static void options_parse(int argc, char *argv[]) -{ - static struct option long_options[]= - { - { "version", no_argument, NULL, OPT_VERSION}, - { "help", no_argument, NULL, OPT_HELP}, - {0, 0, 0, 0}, - }; - - bool opt_version= false; - bool opt_help= false; - int option_index= 0; - - while (1) - { - int option_rv= getopt_long(argc, argv, "", long_options, &option_index); - if (option_rv == -1) - { - break; - } - - switch (option_rv) - { - case OPT_HELP: /* --help or -h */ - opt_help= true; - break; - - case OPT_VERSION: /* --version or -v */ - opt_version= true; - break; - - case '?': - /* getopt_long already printed an error message. */ - exit(EXIT_FAILURE); - - default: - help_command(argv[0], 1, 0, long_options); - exit(EXIT_FAILURE); - } - } - - if (opt_version) - { - version_command(argv[0], 1, 0); - exit(EXIT_SUCCESS); - } - - if (opt_help) - { - help_command(argv[0], 1, 0, long_options); - exit(EXIT_SUCCESS); - } -} - -int main(int argc, char *argv[]) -{ - options_parse(argc, argv); - - std::cout << libtest::number_of_cpus() << std::endl; - - return EXIT_SUCCESS; -} diff --git a/src/libtest/cpu.cc b/src/libtest/cpu.cc deleted file mode 100644 index 1ae99a7f..00000000 --- a/src/libtest/cpu.cc +++ /dev/null @@ -1,85 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - -#include - -#pragma GCC diagnostic ignored "-Wundef" - -#if defined(HAVE_LINUX_SYSCTL_H) && HAVE_LINUX_SYSCTL_H -#include -#elif defined(HAVE_SYS_SYSCTL_H) && HAVE_SYS_SYSCTL_H -#include -#endif - -namespace libtest { - -size_t number_of_cpus() -{ - size_t number_of_cpu= 1; -#if defined(__linux) && __linux - number_of_cpu= sysconf(_SC_NPROCESSORS_ONLN); -#elif defined(HAVE_SYS_SYSCTL_H) && defined(CTL_HW) && defined(HW_NCPU) && defined(HW_AVAILCPU) && defined(HW_NCPU) - int mib[4]; - size_t len= sizeof(number_of_cpu); - - /* set the mib for hw.ncpu */ - mib[0] = CTL_HW; - mib[1] = HW_AVAILCPU; // alternatively, try HW_NCPU; - - /* get the number of CPUs from the system */ - sysctl(mib, 2, &number_of_cpu, &len, NULL, 0); - - if (number_of_cpu < 1) - { - mib[1]= HW_NCPU; - sysctl(mib, 2, &number_of_cpu, &len, NULL, 0 ); - - if (number_of_cpu < 1 ) - { - number_of_cpu = 1; - } - } -#else - // Guessing number of CPU -#endif - - return number_of_cpu; -} - -} // namespace libtest diff --git a/src/libtest/cpu.hpp b/src/libtest/cpu.hpp deleted file mode 100644 index 41277096..00000000 --- a/src/libtest/cpu.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -size_t number_of_cpus(); - -} // namespace libtest diff --git a/src/libtest/dns.cc b/src/libtest/dns.cc deleted file mode 100644 index cbc81123..00000000 --- a/src/libtest/dns.cc +++ /dev/null @@ -1,118 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - -#include -#include -#include - -namespace libtest { - -bool lookup(const char* host) -{ - bool success= false; - assert(host and host[0]); - if (host and host[0]) - { - struct addrinfo *addrinfo= NULL; - struct addrinfo hints; - memset(&hints, 0, sizeof(hints)); - hints.ai_socktype= SOCK_STREAM; - hints.ai_protocol= IPPROTO_TCP; - - int limit= 5; - while (--limit and success == false) - { - if (addrinfo) - { - freeaddrinfo(addrinfo); - addrinfo= NULL; - } - - int ret; - if ((ret= getaddrinfo(host, "echo", &hints, &addrinfo)) == 0) - { - success= true; - break; - } - - switch (ret) - { - case EAI_AGAIN: - continue; - - case EAI_NONAME: - default: - break; - } - - break; - } - - if (addrinfo) - { - freeaddrinfo(addrinfo); - } - } - - return success; -} - - -bool check_dns() -{ - if (valgrind_is_caller()) - { - return false; - } - - if (lookup("exist.gearman.info") == false) - { - return false; - } - - if (lookup("does_not_exist.gearman.info")) // This should fail, if it passes,... - { - fatal_assert("Your service provider sucks and is providing bogus DNS. You might be in an airport."); - } - - return true; -} - -} // namespace libtest - diff --git a/src/libtest/dns.hpp b/src/libtest/dns.hpp deleted file mode 100644 index 438a922c..00000000 --- a/src/libtest/dns.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -bool check_dns(); -bool lookup(const char*); - -} // namespace libtest diff --git a/src/libtest/dream.cc b/src/libtest/dream.cc deleted file mode 100644 index 6d42efa9..00000000 --- a/src/libtest/dream.cc +++ /dev/null @@ -1,58 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - -namespace libtest { - -void dream(time_t tv_sec, long tv_nsec) -{ -#if defined(WIN32) - if (tv_sec == 0 and tv_nsec) - { - tv_sec++; - } - sleep(tv_sec); -#else - struct timespec requested; - requested.tv_sec= tv_sec; - requested.tv_nsec= tv_nsec; - nanosleep(&requested, NULL); -#endif -} - -} diff --git a/src/libtest/dream.h b/src/libtest/dream.h deleted file mode 100644 index 41cabafc..00000000 --- a/src/libtest/dream.h +++ /dev/null @@ -1,44 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -void dream(time_t tv_sec, long tv_nsec= 0); - -} - diff --git a/src/libtest/drizzled.cc b/src/libtest/drizzled.cc deleted file mode 100644 index 9d58ce7e..00000000 --- a/src/libtest/drizzled.cc +++ /dev/null @@ -1,210 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - -#include "libtest/drizzled.h" - -#include "util/instance.hpp" -#include "util/operation.hpp" - -using namespace datadifferential; -using namespace libtest; - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef __INTEL_COMPILER -#pragma GCC diagnostic ignored "-Wold-style-cast" -#endif - -#if defined(HAVE_LIBDRIZZLE) && HAVE_LIBDRIZZLE -# include -#endif - -using namespace libtest; - -namespace libtest { -bool ping_drizzled(const in_port_t _port) -{ - (void)(_port); -#if defined(HAVE_LIBDRIZZLE) && HAVE_LIBDRIZZLE - if (HAVE_LIBDRIZZLE) - { - drizzle_st *drizzle= drizzle_create(getenv("MYSQL_SERVER"), - getenv("MYSQL_PORT") ? atoi("MYSQL_PORT") : DRIZZLE_DEFAULT_TCP_PORT, - getenv("MYSQL_USER"), - getenv("MYSQL_PASSWORD"), - getenv("MYSQL_SCHEMA"), 0); - - if (drizzle == NULL) - { - return false; - } - - bool success= false; - - drizzle_return_t rc; - if ((rc= drizzle_connect(drizzle)) == DRIZZLE_RETURN_OK) - { - drizzle_result_st *result= drizzle_ping(drizzle, &rc); - success= bool(result); - drizzle_result_free(result); - } - - if (success == true) - { } - else if (rc != DRIZZLE_RETURN_OK) - { - Error << drizzle_error(drizzle) << " localhost:" << _port; - } - - drizzle_quit(drizzle); - - return success; - } -#endif - - return false; -} -} // namespace libtest - -class Drizzle : public libtest::Server -{ -private: -public: - Drizzle(const std::string& host_arg, in_port_t port_arg) : - libtest::Server(host_arg, port_arg, DRIZZLED_BINARY, false) - { - set_pid_file(); - } - - bool ping() - { - size_t limit= 5; - while (_app.check() and --limit) - { - if (ping_drizzled(_port)) - { - return true; - } - libtest::dream(1, 0); - } - - return false; - } - - const char *name() - { - return "drizzled"; - }; - - void log_file_option(Application&, const std::string&) - { - } - - bool has_log_file_option() const - { - return true; - } - - bool broken_pid_file() - { - return true; - } - - bool is_libtool() - { - return false; - } - - bool has_syslog() const - { - return true; - } - - bool has_port_option() const - { - return true; - } - - void port_option(Application& app, in_port_t arg) - { - if (arg > 0) - { - libtest::vchar_t buffer; - buffer.resize(1024); - snprintf(&buffer[1024], buffer.size(), "--drizzle-protocol.port=%d", int(arg)); - app.add_option(&buffer[1024]); - } - } - - bool build(); -}; - -bool Drizzle::build() -{ - if (getuid() == 0 or geteuid() == 0) - { - add_option("--user=root"); - } - - add_option("--verbose=INSPECT"); -#if 0 - add_option("--datadir=var/drizzle"); -#endif - - return true; -} - -namespace libtest { - -libtest::Server *build_drizzled(const char *hostname, in_port_t try_port) -{ - return new Drizzle(hostname, try_port); -} - -} diff --git a/src/libtest/drizzled.h b/src/libtest/drizzled.h deleted file mode 100644 index c3e3055a..00000000 --- a/src/libtest/drizzled.h +++ /dev/null @@ -1,50 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include - -namespace libtest { struct Server; } - -namespace libtest { - -libtest::Server *build_drizzled(const char *hostname, in_port_t try_port); - -bool ping_drizzled(const in_port_t); - -} - diff --git a/src/libtest/error.h b/src/libtest/error.h deleted file mode 100644 index f567d2a3..00000000 --- a/src/libtest/error.h +++ /dev/null @@ -1,54 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -enum test_return_t { - TEST_SUCCESS, - TEST_FAILURE, - TEST_SKIPPED -}; - - -static inline bool test_success(test_return_t rc) -{ - return (rc == TEST_SUCCESS); -} - -static inline bool test_failed(test_return_t rc) -{ - return (rc != TEST_SUCCESS); -} diff --git a/src/libtest/exception.cc b/src/libtest/exception.cc deleted file mode 100644 index d1fa0768..00000000 --- a/src/libtest/exception.cc +++ /dev/null @@ -1,108 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" -#include - -namespace libtest { - -exception::exception(const char *file_arg, int line_arg, const char *func_arg): - std::exception(), - _line(line_arg), - _file(file_arg), - _func(func_arg), - _error_message(NULL), - _error_message_size(0) -{ -} - -#ifndef __INTEL_COMPILER -# pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -void exception::init(va_list args_) -{ - const char *format= va_arg(args_, const char *); - int error_message_length= vasprintf(&_error_message, format, args_); - assert(error_message_length != -1); - if (error_message_length > 0) - { - _error_message_size= error_message_length +1; - } -} - -exception::~exception() throw() -{ - if (_error_message) - { - free(_error_message); - } -} - -void exception::what(size_t length_, const char* message_) -{ - if (length_ > 0 and message_) - { - char *ptr= (char*) realloc(_error_message, length_ +1); - if (ptr) - { - _error_message= ptr; - memcpy(_error_message, message_, length_); - _error_message[length_]= 0; - } - } -} - -exception::exception(const exception& other) : - std::exception(), - _line(other._line), - _file(other._file), - _func(other._func), - _error_message_size(0) -{ - if (other.length() > 0) - { - _error_message= (char*) malloc(other.length() +1); - if (_error_message) - { - memcpy(_error_message, other._error_message, other.length()); - _error_message_size= other.length(); - } - } -} - -} // namespace libtest - diff --git a/src/libtest/exception.hpp b/src/libtest/exception.hpp deleted file mode 100644 index 3d20e8ba..00000000 --- a/src/libtest/exception.hpp +++ /dev/null @@ -1,94 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -class exception : public std::exception -{ -public: - exception(const char *file, int line, const char *func); - - exception( const exception& ); - - virtual ~exception() throw(); - - virtual const char* what() const throw() - { - if (_error_message) - { - return _error_message; - } - - return ""; - } - - void what(size_t, const char*); - - size_t length() const - { - return _error_message_size; - } - - int line() const - { - return _line; - } - - const char* file() const - { - return _file; - } - - const char* func() const - { - return _func; - } - -protected: - void init(va_list); - -private: - int _line; - const char* _file; - const char* _func; - char* _error_message; - size_t _error_message_size; -}; - -} // namespace libtest - diff --git a/src/libtest/exception/disconnected.hpp b/src/libtest/exception/disconnected.hpp deleted file mode 100644 index 6e9f4c45..00000000 --- a/src/libtest/exception/disconnected.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include "libtest/exception.hpp" - -namespace libtest { - -class disconnected : public libtest::exception -{ -public: - disconnected(const char *file, int line, const char *func, const std::string&, const unsigned port, ...); - - disconnected(const disconnected&); - - // The following are just for unittesting the exception class - static bool is_disabled(); - static void disable(); - static void enable(); - static uint32_t disabled_counter(); - static void increment_disabled_counter(); - -private: - in_port_t _port; - char _instance[BUFSIZ]; -}; - -} // namespace libtest diff --git a/src/libtest/exception/fatal.cc b/src/libtest/exception/fatal.cc deleted file mode 100644 index 7f391994..00000000 --- a/src/libtest/exception/fatal.cc +++ /dev/null @@ -1,119 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" -#include "libtest/exception.hpp" -#include - -namespace libtest { - -#pragma GCC diagnostic ignored "-Wformat-nonliteral" - -fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, ...) : - libtest::exception(file_arg, line_arg, func_arg) -{ - va_list args; - va_start(args, func_arg); - init(args); - va_end(args); -} - -fatal::fatal( const fatal& other ) : - libtest::exception(other) -{ -} - -static bool _disabled= false; -static uint32_t _counter= 0; - -bool fatal::is_disabled() throw() -{ - return _disabled; -} - -void fatal::disable() throw() -{ - _counter= 0; - _disabled= true; -} - -void fatal::enable() throw() -{ - _counter= 0; - _disabled= false; -} - -uint32_t fatal::disabled_counter() throw() -{ - return _counter; -} - -void fatal::increment_disabled_counter() throw() -{ - _counter++; -} - -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -disconnected::disconnected(const char *file_arg, int line_arg, const char *func_arg, - const std::string& instance, const unsigned port, ...) : - libtest::exception(file_arg, line_arg, func_arg), - _port(port) -{ - va_list args; - va_start(args, port); - const char *format= va_arg(args, const char *); - char last_error[BUFSIZ]; - (void)vsnprintf(last_error, sizeof(last_error), format, args); - va_end(args); - - char buffer_error[BUFSIZ]; - int error_length= snprintf(buffer_error, sizeof(buffer_error), "%s:%u %s", instance.c_str(), uint32_t(port), last_error); - - if (error_length > 0) - { - what(size_t(error_length), buffer_error); - } -} - -disconnected::disconnected(const disconnected& other): - libtest::exception(other), - _port(other._port) -{ - strncpy(_instance, other._instance, BUFSIZ); -} - -} // namespace libtest diff --git a/src/libtest/exception/fatal.hpp b/src/libtest/exception/fatal.hpp deleted file mode 100644 index 5ee1aac5..00000000 --- a/src/libtest/exception/fatal.hpp +++ /dev/null @@ -1,87 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -class fatal : public libtest::exception -{ -public: - fatal(const char *file, int line, const char *func, ...); - - fatal(const fatal&); - - // The following are just for unittesting the exception class - static bool is_disabled() throw(); - static void disable() throw(); - static void enable() throw(); - static uint32_t disabled_counter() throw(); - static void increment_disabled_counter() throw(); - - test_return_t return_code() const - { - return TEST_SKIPPED; - } - -private: -}; - -} // namespace libtest - -#define FATAL(...) \ -do \ -{ \ - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \ -} while (0) - -#define FATAL_IF(__expression, ...) \ -do \ -{ \ - if ((__expression)) { \ - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, (#__expression)); \ - } \ -} while (0) - -#define FATAL_IF_(__expression, ...) \ -do \ -{ \ - if ((__expression)) { \ - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \ - } \ -} while (0) - -#define fatal_assert(__assert) if((__assert)) {} else { throw libtest::fatal(LIBYATL_DEFAULT_PARAM, #__assert); } diff --git a/src/libtest/failed.cc b/src/libtest/failed.cc deleted file mode 100644 index 4e687074..00000000 --- a/src/libtest/failed.cc +++ /dev/null @@ -1,80 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - -#include "libtest/failed.h" - -#include -#include -#include - -namespace libtest { - -struct failed_st { - failed_st(const std::string& collection_arg, const std::string& test_arg) : - collection(collection_arg), - test(test_arg) - { } - - std::string collection; - std::string test; -}; - -typedef std::vector Failures; - -class Failed -{ -private: - Failures failures; - -public: - void push(const char *collection, const char *test) - { - failures.push_back(failed_st(collection, test)); - } - - void print_failed_test(void) - { - for (Failures::iterator iter= failures.begin(); iter != failures.end(); ++iter) - { - Error << "\t" << (*iter).collection << " " << (*iter).test; - } - } -}; - -} // namespace libtest diff --git a/src/libtest/formatter.cc b/src/libtest/formatter.cc deleted file mode 100644 index 296c056b..00000000 --- a/src/libtest/formatter.cc +++ /dev/null @@ -1,275 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" - -#include "libtest/common.h" - -#include -#include -#include -#include - -namespace libtest { - -std::string& escape4XML(std::string const& arg, std::string& escaped_string) -{ - escaped_string.clear(); - - escaped_string+= '"'; - for (std::string::const_iterator x= arg.begin(), end= arg.end(); x != end; ++x) - { - unsigned char c= *x; - if (c == '&') - { - escaped_string+= "&"; - } - else if (c == '>') - { - escaped_string+= ">"; - } - else if (c == '<') - { - escaped_string+= "<"; - } - else if (c == '\'') - { - escaped_string+= "'"; break; - } - else if (c == '"') - { - escaped_string+= """; - } - else if (c == ' ') - { - escaped_string+= ' '; - } - else if (isalnum(c)) - { - escaped_string+= c; - } - else - { - char const* const hexdig= "0123456789ABCDEF"; - escaped_string+= "&#x"; - escaped_string+= hexdig[c >> 4]; - escaped_string+= hexdig[c & 0xF]; - escaped_string+= ';'; - } - } - escaped_string+= '"'; - - return escaped_string; -} - -class TestCase { -public: - TestCase(const std::string& arg): - _name(arg), - _result(TEST_FAILURE) - { - } - - const std::string& name() const - { - return _name; - } - - test_return_t result() const - { - return _result; - } - - void result(test_return_t arg) - { - _result= arg; - } - - void result(test_return_t arg, const libtest::Timer& timer_) - { - _result= arg; - _timer= timer_; - } - - const libtest::Timer& timer() const - { - return _timer; - } - - void timer(libtest::Timer& arg) - { - _timer= arg; - } - -private: - std::string _name; - test_return_t _result; - libtest::Timer _timer; -}; - -Formatter::Formatter(const std::string& frame_name, const std::string& arg) -{ - _suite_name= frame_name; - _suite_name+= "."; - _suite_name+= arg; -} - -Formatter::~Formatter() -{ - std::for_each(_testcases.begin(), _testcases.end(), DeleteFromVector()); - _testcases.clear(); -} - -TestCase* Formatter::current() -{ - return _testcases.back(); -} - -void Formatter::skipped() -{ - assert(current()); - current()->result(TEST_SKIPPED); - - Out - << "[ " << test_strerror(current()->result()) << " ]" - << "\t\t" - << name() << "." << current()->name() - ; - - reset(); -} - -void Formatter::failed() -{ - assert(current()); - current()->result(TEST_FAILURE); - - Out - << "[ " << test_strerror(current()->result()) << " ]" - << "\t\t" - << name() << "." << current()->name() - ; - - reset(); -} - -void Formatter::success(const libtest::Timer& timer_) -{ - assert(current()); - current()->result(TEST_SUCCESS, timer_); - - Out - << "[ " << test_strerror(current()->result()) << " ]" - << "\t" - << current()->timer() - << "\t" - << name() << "." << current()->name() - ; - - reset(); -} - -void Formatter::xml(libtest::Framework& framework_, std::ofstream& output) -{ - std::string escaped_string; - - output << "" << std::endl; - - for (Suites::iterator framework_iter= framework_.suites().begin(); - framework_iter != framework_.suites().end(); - ++framework_iter) - { - output << "\t" << std::endl; - - for (TestCases::iterator case_iter= (*framework_iter)->formatter()->testcases().begin(); - case_iter != (*framework_iter)->formatter()->testcases().end(); - ++case_iter) - { - output << "\t\ttimer().elapsed_milliseconds() - << "\""; - - switch ((*case_iter)->result()) - { - case TEST_SKIPPED: - output << ">" << std::endl; - output << "\t\t " << std::endl; - output << "\t\t" << std::endl; - break; - - case TEST_FAILURE: - output << ">" << std::endl; - output << "\t\t "<< std::endl; - output << "\t\t" << std::endl; - break; - - case TEST_SUCCESS: - output << "/>" << std::endl; - break; - } - } - output << "\t" << std::endl; - } - output << "" << std::endl; -} - -void Formatter::push_testcase(const std::string& arg) -{ - assert(_suite_name.empty() == false); - TestCase* _current_testcase= new TestCase(arg); - _testcases.push_back(_current_testcase); - - assert(current()); - - Echo - << "\t\t\t" - << name() << "." << current()->name() - << "... \r" - ; -} - -void Formatter::reset() -{ -} -} // namespace libtest diff --git a/src/libtest/formatter.hpp b/src/libtest/formatter.hpp deleted file mode 100644 index 10818d40..00000000 --- a/src/libtest/formatter.hpp +++ /dev/null @@ -1,85 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include - -namespace libtest { class Framework; } - - -namespace libtest { - -class TestCase; -typedef std::vector TestCases; - -class Formatter { -public: - Formatter(const std::string& frame_name, const std::string& arg); - - ~Formatter(); - - void skipped(); - - void failed(); - - void success(const libtest::Timer&); - - void push_testcase(const std::string&); - - const std::string& name() const - { - return _suite_name; - } - - TestCases& testcases() - { - return _testcases; - } - - static void xml(libtest::Framework&, std::ofstream&); - -private: - void reset(); - - TestCase* current(); - -private: - std::string _suite_name; - TestCases _testcases; -}; - -} // namespace libtest diff --git a/src/libtest/framework.cc b/src/libtest/framework.cc deleted file mode 100644 index 2565e9c0..00000000 --- a/src/libtest/framework.cc +++ /dev/null @@ -1,234 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" - -#include "libtest/common.h" -#include "libtest/collection.h" -#include "libtest/signal.h" - -#include -#include -#include - -namespace libtest { - -Framework::Framework(libtest::SignalThread& signal_, - const std::string& name_, - const std::string& only_run_arg, - const std::string& wildcard_arg) : - _total(0), - _success(0), - _skipped(0), - _failed(0), - _create(NULL), - _destroy(NULL), - _on_error(NULL), - _runner(NULL), - _socket(false), - _creators_ptr(NULL), - _signal(signal_), - _only_run(only_run_arg), - _wildcard(wildcard_arg), - _name(name_) -{ - get_world(this); -} - -void Framework::collections(collection_st collections_[]) -{ - for (collection_st *next= collections_; next and next->name; next++) - { - _collection.push_back(new Collection(this, next)); - } -} - -Framework::~Framework() -{ - if (_destroy and _destroy(_creators_ptr)) - { - Error << "Failure in _destroy(), some resources may not have been cleaned up."; - } - - _servers.shutdown(); - - delete _runner; - - std::for_each(_collection.begin(), _collection.end(), DeleteFromVector()); - _collection.clear(); -} - -bool Framework::match(const char* arg) -{ - if (_wildcard.empty() == false and fnmatch(_wildcard.c_str(), arg, 0)) - { - return true; - } - - return false; -} - -void Framework::exec() -{ - for (std::vector::iterator iter= _collection.begin(); - iter != _collection.end() and (_signal.is_shutdown() == false); - ++iter) - { - if (*iter) - { - if (_only_run.empty() == false and - fnmatch(_only_run.c_str(), (*iter)->name(), 0)) - { - continue; - } - - _total++; - - try { - switch ((*iter)->exec()) - { - case TEST_FAILURE: - _failed++; - break; - - case TEST_SKIPPED: - _skipped++; - break; - - // exec() can return SUCCESS, but that doesn't mean that some tests did - // not fail or get skipped. - case TEST_SUCCESS: - _success++; - break; - } - } - catch (const libtest::fatal& e) - { - _failed++; - stream::cerr(e.file(), e.line(), e.func()) << e.what(); - } - catch (const libtest::disconnected& e) - { - _failed++; - Error << "Unhandled disconnection occurred:" << e.what(); - throw; - } - catch (...) - { - _failed++; - throw; - } - } - } - - void xml(const std::string& testsuites_name, std::ostream& output); -} - -uint32_t Framework::sum_total() -{ - uint32_t count= 0; - for (std::vector::iterator iter= _collection.begin(); - iter != _collection.end(); - ++iter) - { - count+= (*iter)->total(); - } - - return count; -} - -uint32_t Framework::sum_success() -{ - uint32_t count= 0; - for (std::vector::iterator iter= _collection.begin(); - iter != _collection.end(); - ++iter) - { - count+= (*iter)->success(); - } - - return count; -} - -uint32_t Framework::sum_skipped() -{ - uint32_t count= 0; - for (std::vector::iterator iter= _collection.begin(); - iter != _collection.end(); - ++iter) - { - count+= (*iter)->skipped(); - } - - return count; -} - -uint32_t Framework::sum_failed() -{ - uint32_t count= 0; - for (std::vector::iterator iter= _collection.begin(); - iter != _collection.end(); - ++iter) - { - count+= (*iter)->failed(); - } - - return count; -} - -libtest::Runner *Framework::runner() -{ - if (_runner == NULL) - { - _runner= new Runner; - } - _runner->set_servers(_servers); - - return _runner; -} - -test_return_t Framework::create() -{ - test_return_t rc= TEST_SUCCESS; - if (_create) - { - _creators_ptr= _create(_servers, rc); - } - - return rc; -} - -} // namespace libtest diff --git a/src/libtest/framework.h b/src/libtest/framework.h deleted file mode 100644 index 58c7ad99..00000000 --- a/src/libtest/framework.h +++ /dev/null @@ -1,200 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include "libtest/signal.h" - -/** - Framework is the structure which is passed to the test implementation to be filled. - This must be implemented in order for the test framework to load the tests. We call - get_world() in order to fill this structure. -*/ - -#include - -namespace { class Collection; } -typedef std::vector Suites; - -namespace libtest { - -class Framework { -public: - -public: - test_return_t create(); - - const std::string& name() const - { - return _name; - } - - void create(test_callback_create_fn* arg) - { - _create= arg; - } - - void destroy(test_callback_destroy_fn* arg) - { - _destroy= arg; - } - - void collections(collection_st arg[]); - - void set_on_error(test_callback_error_fn *arg) - { - _on_error= arg; - } - - test_return_t on_error(const enum test_return_t, void *); - - void set_socket() - { - _servers.set_socket(); - } - - void set_sasl(const std::string& username_arg, const std::string& password_arg) - { - _servers.set_sasl(username_arg, password_arg); - } - - libtest::server_startup_st& servers() - { - return _servers; - } - - void set_runner(libtest::Runner *arg) - { - _runner= arg; - } - - libtest::Runner *runner(); - - void exec(); - - libtest::Collection& collection(); - - virtual ~Framework(); - - Framework(libtest::SignalThread&, - const std::string&, - const std::string&, - const std::string&); - - bool match(const char* arg); - - void *creators_ptr() - { - return _creators_ptr; - } - - libtest::SignalThread& signal() - { - return _signal; - } - - uint32_t sum_total(); - uint32_t sum_success(); - uint32_t sum_skipped(); - uint32_t sum_failed(); - - size_t size() - { - return _collection.size(); - } - - uint32_t total() const - { - return _total; - } - - uint32_t success() const - { - return _success; - } - - uint32_t skipped() const - { - return _skipped; - } - - uint32_t failed() const - { - return _failed; - } - - Suites& suites() - { - return _collection; - } - -private: - uint32_t _total; - uint32_t _success; - uint32_t _skipped; - uint32_t _failed; - - /* These methods are called outside of any collection call. */ - test_callback_create_fn *_create; - test_callback_destroy_fn *_destroy; - - /** - If an error occurs during the test, this is called. - */ - test_callback_error_fn *_on_error; - - /** - Runner represents the callers for the tests. If not implemented we will use - a set of default implementations. - */ - libtest::Runner *_runner; - - libtest::server_startup_st _servers; - bool _socket; - void *_creators_ptr; - unsigned long int _servers_to_run; - Suites _collection; - libtest::SignalThread& _signal; - std::string _only_run; - std::string _wildcard; - std::string _name; - -private: - Framework( const Framework& ); - const Framework& operator=( const Framework& ); -}; - -} // namespace libtest diff --git a/src/libtest/gearmand.cc b/src/libtest/gearmand.cc deleted file mode 100644 index 6ff824ca..00000000 --- a/src/libtest/gearmand.cc +++ /dev/null @@ -1,178 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - -#include "libtest/gearmand.h" - -using namespace libtest; - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef __INTEL_COMPILER -#pragma GCC diagnostic ignored "-Wold-style-cast" -#endif - -using namespace libtest; - -class Gearmand : public libtest::Server -{ -private: -public: - Gearmand(const std::string& host_arg, in_port_t port_arg, bool libtool_, const char* binary); - - bool ping() - { - reset_error(); - - if (out_of_ban_killed()) - { - return false; - } - - SimpleClient client(_hostname, _port); - - std::string response; - bool ret= client.send_message("version", response); - - if (client.is_error()) - { - error(client.error()); - } - - return ret; - } - - const char *name() - { - return "gearmand"; - }; - - void log_file_option(Application& app, const std::string& arg) - { - if (arg.empty() == false) - { - std::string buffer("--log-file="); - buffer+= arg; - app.add_option("--verbose=DEBUG"); - app.add_option(buffer); - } - } - - bool has_log_file_option() const - { - return true; - } - - bool is_libtool() - { - return true; - } - - bool has_syslog() const - { - return false; // --syslog.errmsg-enable - } - - bool has_port_option() const - { - return true; - } - - bool build(); -}; - -Gearmand::Gearmand(const std::string& host_arg, in_port_t port_arg, bool libtool_, const char* binary_arg) : - libtest::Server(host_arg, port_arg, binary_arg, libtool_) -{ - set_pid_file(); -} - -bool Gearmand::build() -{ - if (getuid() == 0 or geteuid() == 0) - { - add_option("-u", "root"); - } - - add_option("--listen=localhost"); - - return true; -} - -namespace libtest { - -libtest::Server *build_gearmand(const char *hostname, in_port_t try_port, const char* binary) -{ - if (binary == NULL) - { -#if defined(HAVE_GEARMAND_BINARY) -# if defined(GEARMAND_BINARY) - if (HAVE_GEARMAND_BINARY) - { - binary= GEARMAND_BINARY; - } -# endif -#endif - } - - if (binary == NULL) - { - return NULL; - } - - bool is_libtool_script= true; - - if (binary[0] == '/') - { - is_libtool_script= false; - } - - return new Gearmand(hostname, try_port, is_libtool_script, binary); -} - -} diff --git a/src/libtest/gearmand.h b/src/libtest/gearmand.h deleted file mode 100644 index 41317d7f..00000000 --- a/src/libtest/gearmand.h +++ /dev/null @@ -1,45 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { struct Server; } - -namespace libtest { - -libtest::Server *build_gearmand(const char *hostname, in_port_t try_port, const char* binary= NULL); - -} diff --git a/src/libtest/get.h b/src/libtest/get.h deleted file mode 100644 index e21ac0a4..00000000 --- a/src/libtest/get.h +++ /dev/null @@ -1,51 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - - /* How we make all of this work :) */ - LIBTEST_API - void get_world(libtest::Framework *world); - -#ifdef __cplusplus -} -#endif - - diff --git a/src/libtest/has.cc b/src/libtest/has.cc deleted file mode 100644 index 031f2a7b..00000000 --- a/src/libtest/has.cc +++ /dev/null @@ -1,232 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - -#include -#include -#include - -namespace libtest { - -bool has_libmemcached_sasl(void) -{ -#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT - return LIBMEMCACHED_WITH_SASL_SUPPORT; -#else - return false; -#endif -} - -bool has_libmemcached(void) -{ -#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED - if (HAVE_LIBMEMCACHED) - { - return true; - } -#endif - - return false; -} - -bool has_libdrizzle(void) -{ -#if defined(HAVE_LIBDRIZZLE) && HAVE_LIBDRIZZLE - if (HAVE_LIBDRIZZLE) - { - return true; - } -#endif - - return false; -} - -bool has_postgres_support(void) -{ - char *getenv_ptr; - if (bool((getenv_ptr= getenv("POSTGRES_IS_RUNNING_AND_SETUP")))) - { - (void)(getenv_ptr); -#if defined(HAVE_LIBPQ) && HAVE_LIBPQ - if (HAVE_LIBPQ) - { - return true; - } -#endif - } - - return false; -} - - -bool has_gearmand() -{ -#if defined(GEARMAND_BINARY) && defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY - if (HAVE_GEARMAND_BINARY) - { - std::stringstream arg_buffer; - - char *getenv_ptr; - if (bool((getenv_ptr= getenv("PWD"))) and - ((strcmp(GEARMAND_BINARY, "./gearmand/gearmand") == 0) or (strcmp(GEARMAND_BINARY, "gearmand/gearmand") == 0))) - { - arg_buffer << getenv_ptr; - arg_buffer << "/"; - } - arg_buffer << GEARMAND_BINARY; - - if (access(arg_buffer.str().c_str(), X_OK) == 0) - { - return true; - } - } -#endif - - return false; -} - -bool has_drizzled() -{ -#if defined(DRIZZLED_BINARY) && defined(HAVE_DRIZZLED_BINARY) && HAVE_DRIZZLED_BINARY - if (HAVE_DRIZZLED_BINARY) - { - if (access(DRIZZLED_BINARY, X_OK) == 0) - { - return true; - } - } -#endif - - return false; -} - -bool has_mysqld() -{ -#if defined(MYSQLD_BINARY) && defined(HAVE_MYSQLD_BUILD) && HAVE_MYSQLD_BUILD - if (HAVE_MYSQLD_BUILD) - { - if (access(MYSQLD_BINARY, X_OK) == 0) - { - return true; - } - } -#endif - - return false; -} - -static char memcached_binary_path[FILENAME_MAX]; - -static void initialize_memcached_binary_path() -{ - memcached_binary_path[0]= 0; - -#if defined(MEMCACHED_BINARY) && defined(HAVE_MEMCACHED_BINARY) && HAVE_MEMCACHED_BINARY - if (HAVE_MEMCACHED_BINARY) - { - std::stringstream arg_buffer; - - char *getenv_ptr; - if (bool((getenv_ptr= getenv("PWD"))) and strcmp(MEMCACHED_BINARY, "memcached/memcached") == 0) - { - arg_buffer << getenv_ptr; - arg_buffer << "/"; - } - arg_buffer << MEMCACHED_BINARY; - - if (access(arg_buffer.str().c_str(), X_OK) == 0) - { - strncpy(memcached_binary_path, arg_buffer.str().c_str(), FILENAME_MAX-1); - } - } -#endif -} - -static pthread_once_t memcached_binary_once= PTHREAD_ONCE_INIT; -static void initialize_memcached_binary(void) -{ - int ret; - if ((ret= pthread_once(&memcached_binary_once, initialize_memcached_binary_path)) != 0) - { - FATAL(strerror(ret)); - } -} - -bool has_memcached() -{ - initialize_memcached_binary(); - - if (memcached_binary_path[0] and (strlen(memcached_binary_path) > 0)) - { - return true; - } - - return false; -} - -const char* memcached_binary() -{ - initialize_memcached_binary(); - - if (memcached_binary_path[0]) - { - return memcached_binary_path; - } - - return NULL; -} - -const char *gearmand_binary() -{ -#if defined(GEARMAND_BINARY) - return GEARMAND_BINARY; -#else - return NULL; -#endif -} - -const char *drizzled_binary() -{ -#if defined(DRIZZLED_BINARY) - return DRIZZLED_BINARY; -#else - return NULL; -#endif -} - -} // namespace libtest diff --git a/src/libtest/has.hpp b/src/libtest/has.hpp deleted file mode 100644 index 59ee88f9..00000000 --- a/src/libtest/has.hpp +++ /dev/null @@ -1,76 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -LIBTEST_API -bool has_libmemcached_sasl(void); - -LIBTEST_API -bool has_libmemcached(); - -LIBTEST_API -bool has_libdrizzle(); - -LIBTEST_API -bool has_postgres_support(); - -LIBTEST_API -bool has_memcached(); - -LIBTEST_API -bool has_memcached_sasl(); - -LIBTEST_API -bool has_gearmand(); - -LIBTEST_API -bool has_drizzled(); - -LIBTEST_API -bool has_mysqld(); - -LIBTEST_API -const char* memcached_binary(); - -LIBTEST_API -const char *gearmand_binary(); - -LIBTEST_API -const char *drizzled_binary(); -} // namespace libtest diff --git a/src/libtest/http.cc b/src/libtest/http.cc deleted file mode 100644 index cf85cdf7..00000000 --- a/src/libtest/http.cc +++ /dev/null @@ -1,217 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" - -#include "libtest/common.h" - -#if defined(HAVE_LIBCURL) && HAVE_LIBCURL -#include -#else -class CURL; -#endif - - -static void cleanup_curl(void) -{ -#if defined(HAVE_LIBCURL) && HAVE_LIBCURL - curl_global_cleanup(); -#endif -} - -static void initialize_curl_startup() -{ -#if defined(HAVE_LIBCURL) && HAVE_LIBCURL - if (curl_global_init(CURL_GLOBAL_ALL)) - { - FATAL("curl_global_init(CURL_GLOBAL_ALL) failed"); - } -#endif - - if (atexit(cleanup_curl)) - { - FATAL("atexit() failed"); - } -} - -static pthread_once_t start_key_once= PTHREAD_ONCE_INIT; -static void initialize_curl(void) -{ - int ret; - if ((ret= pthread_once(&start_key_once, initialize_curl_startup)) != 0) - { - FATAL(strerror(ret)); - } -} - -namespace libtest { -namespace http { - -#define YATL_USERAGENT "YATL/1.0" - -static size_t http_get_result_callback(void *ptr, size_t size, size_t nmemb, void *data) -{ - vchar_t *_body= (vchar_t*)data; - - _body->resize(size * nmemb); - memcpy(&(*_body)[0], ptr, _body->size()); - - return _body->size(); -} - -static void init(CURL *curl, const std::string& url) -{ - (void)http_get_result_callback; - (void)curl; - (void)url; -#if defined(HAVE_LIBCURL) && HAVE_LIBCURL - if (HAVE_LIBCURL) - { - assert(curl); - curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - curl_easy_setopt(curl, CURLOPT_USERAGENT, YATL_USERAGENT); - } -#endif -} - -HTTP::HTTP(const std::string& url_arg) : - _url(url_arg), - _response(0) -{ - initialize_curl(); -} - -bool GET::execute() -{ - (void)init; - -#if defined(HAVE_LIBCURL) && HAVE_LIBCURL - if (HAVE_LIBCURL) - { - CURL *curl= curl_easy_init(); - - init(curl, url()); - - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, http_get_result_callback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&_body); - - CURLcode retref= curl_easy_perform(curl); - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, _response); - - curl_easy_cleanup(curl); - - return bool(retref == CURLE_OK); - } -#endif - - return false; -} - -bool POST::execute() -{ -#if defined(HAVE_LIBCURL) && HAVE_LIBCURL - if (HAVE_LIBCURL) - { - CURL *curl= curl_easy_init();; - - init(curl, url()); - - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, _body.size()); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (void *)&_body[0]); - - CURLcode retref= curl_easy_perform(curl); - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, _response); - - curl_easy_cleanup(curl); - - return bool(retref == CURLE_OK); - } -#endif - - return false; -} - -bool TRACE::execute() -{ -#if defined(HAVE_LIBCURL) && HAVE_LIBCURL - if (HAVE_LIBCURL) - { - CURL *curl= curl_easy_init();; - - init(curl, url()); - - curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "TRACE"); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, http_get_result_callback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&_body[0]); - - CURLcode retref= curl_easy_perform(curl); - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, _response); - - curl_easy_cleanup(curl); - - return retref == CURLE_OK; - } -#endif - - return false; -} - -bool HEAD::execute() -{ -#if defined(HAVE_LIBCURL) && HAVE_LIBCURL - if (HAVE_LIBCURL) - { - CURL *curl= curl_easy_init(); - - init(curl, url()); - - curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "HEAD"); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, http_get_result_callback); - - CURLcode retref= curl_easy_perform(curl); - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, _response); - - curl_easy_cleanup(curl); - - return retref == CURLE_OK; - } -#endif - - return false; -} - -} // namespace http -} // namespace libtest diff --git a/src/libtest/http.hpp b/src/libtest/http.hpp deleted file mode 100644 index 4c326117..00000000 --- a/src/libtest/http.hpp +++ /dev/null @@ -1,132 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include "libtest/vchar.hpp" - -namespace libtest { -namespace http { - -class HTTP { -public: - - HTTP(const std::string& url_arg); - - virtual bool execute()= 0; - - virtual ~HTTP() - { } - - const std::string& url() const - { - return _url; - } - - long response() - { - return _response; - } - -private: - std::string _url; - -protected: - long _response; -}; - -class GET: public HTTP { -public: - - GET(const std::string& url_arg) : - HTTP(url_arg) - { - } - - bool execute(); - -private: - libtest::vchar_t _body; -}; - -class POST: public HTTP { -public: - - POST(const std::string& url_arg, - const vchar_t& post_arg) : - HTTP(url_arg), - _post(post_arg) - { - } - - bool execute(); - -private: - libtest::vchar_t _post; - libtest::vchar_t _body; -}; - -class TRACE: public HTTP { -public: - - TRACE(const std::string& url_arg, - const vchar_t& body_arg) : - HTTP(url_arg), - _body(body_arg) - { - } - - bool execute(); - -private: - libtest::vchar_t _body; -}; - -class HEAD: public HTTP { -public: - - HEAD(const std::string& url_arg) : - HTTP(url_arg) - { - } - - bool execute(); - -private: -}; - -} // namespace http -} // namespace libtest diff --git a/src/libtest/is_local.cc b/src/libtest/is_local.cc deleted file mode 100644 index 1473df14..00000000 --- a/src/libtest/is_local.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - - -namespace libtest { - -bool test_is_local() -{ - return (getenv("LIBTEST_LOCAL")); -} - -static bool _is_massive= false; -void is_massive(bool arg) -{ - _is_massive= arg; -} - -bool is_massive() -{ - return _is_massive; -} - -} // namespace libtest - diff --git a/src/libtest/is_local.hpp b/src/libtest/is_local.hpp deleted file mode 100644 index 08355533..00000000 --- a/src/libtest/is_local.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -LIBTEST_API -bool test_is_local(); - -LIBTEST_API -void is_massive(bool); - -LIBTEST_API -bool is_massive(); - -} // namespace libtest diff --git a/src/libtest/is_pid.hpp b/src/libtest/is_pid.hpp deleted file mode 100644 index 3c514a90..00000000 --- a/src/libtest/is_pid.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -static inline bool is_pid_valid(const pid_t pid) -{ - return (pid > 1) ? true : false; -} - diff --git a/src/libtest/killpid.cc b/src/libtest/killpid.cc deleted file mode 100644 index af74442f..00000000 --- a/src/libtest/killpid.cc +++ /dev/null @@ -1,225 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - -#include -#include -#include -#include -#include -#include -#include -#include - - -#include "libtest/killpid.h" -#include "libtest/stream.h" - -using namespace libtest; - -bool kill_pid(pid_t pid_arg) -{ - assert(pid_arg > 0); - if (pid_arg < 1) - { - Error << "Invalid pid:" << pid_arg; - return false; - } - - if ((::kill(pid_arg, SIGTERM) == -1)) - { - switch (errno) - { - case EPERM: - Error << "Does someone else have a process running locally for " << int(pid_arg) << "?"; - return false; - - case ESRCH: - Error << "Process " << int(pid_arg) << " not found."; - return false; - - default: - case EINVAL: - Error << "kill() " << strerror(errno); - return false; - } - } - - { - uint32_t this_wait= 0; - uint32_t timeout= 20; // This number should be high enough for valgrind startup (which is slow) - uint32_t waited; - uint32_t retry; - - for (waited= 0, retry= 1; ; retry++, waited+= this_wait) - { - int status= 0; - if (waitpid(pid_arg, &status, WNOHANG) == 0) - { - break; - } - else if (errno == ECHILD) - { - // Server has already gone away - break; - } - else if (waited >= timeout) - { - // Timeout failed - kill(pid_arg, SIGKILL); - break; - } - - this_wait= retry * retry / 3 + 1; - libtest::dream(this_wait, 0); - } - } - - return true; -} - -bool check_pid(const std::string &filename) -{ - if (filename.empty()) - { - return false; - } - - FILE *fp; - if ((fp= fopen(filename.c_str(), "r"))) - { - libtest::vchar_t pid_buffer; - pid_buffer.resize(1024); - - char *ptr= fgets(&pid_buffer[0], int(pid_buffer.size()), fp); - fclose(fp); - - if (ptr) - { - pid_t pid= (pid_t)atoi(&pid_buffer[0]); - if (pid > 0) - { - return (::kill(pid, 0) == 0); - } - } - } - - return false; -} - - -bool kill_file(const std::string &filename) -{ - if (filename.empty()) - { - return true; - } - - FILE *fp; - if ((fp= fopen(filename.c_str(), "r"))) - { - libtest::vchar_t pid_buffer; - pid_buffer.resize(1024); - - char *ptr= fgets(&pid_buffer[0], int(pid_buffer.size()), fp); - fclose(fp); - - if (ptr) - { - pid_t pid= (pid_t)atoi(&pid_buffer[0]); - if (pid != 0) - { - bool ret= kill_pid(pid); - unlink(filename.c_str()); // If this happens we may be dealing with a dead server that left its pid file. - - return ret; - } - } - } - - return false; -} - -#define STRINGIFY(x) #x -#define TOSTRING(x) STRINGIFY(x) -#define LIBTEST_AT __FILE__ ":" TOSTRING(__LINE__) - -pid_t get_pid_from_file(const std::string &filename, std::stringstream& error_message) -{ - pid_t ret= -1; - - if (filename.empty()) - { - error_message << LIBTEST_AT << " empty pid file"; - return ret; - } - - FILE *fp; - if ((fp= fopen(filename.c_str(), "r"))) - { - libtest::vchar_t pid_buffer; - pid_buffer.resize(1024); - - char *ptr= fgets(&pid_buffer[0], int(pid_buffer.size()), fp); - if (ptr) - { - ret= (pid_t)atoi(&pid_buffer[0]); - if (ret < 1) - { - error_message << LIBTEST_AT << " Invalid pid was read from file " << filename; - } - } - else - { - error_message << LIBTEST_AT << " File " << filename << " was empty "; - } - - fclose(fp); - - return ret; - } - else - { - libtest::vchar_t buffer; - buffer.resize(1024); - char *current_directory= getcwd(&buffer[0], buffer.size()); - error_message << "Error while opening " << current_directory << "/" << filename << " " << strerror(errno); - } - - return ret; -} diff --git a/src/libtest/killpid.h b/src/libtest/killpid.h deleted file mode 100644 index 6bf5dee3..00000000 --- a/src/libtest/killpid.h +++ /dev/null @@ -1,51 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - - -bool kill_pid(pid_t pid_arg); - -bool kill_file(const std::string &filename); - -bool check_pid(const std::string &filename); - -pid_t get_pid_from_file(const std::string &filename, std::stringstream& error_message); - -static inline bool check_pid(pid_t pid_arg) -{ - return (pid_arg > 1); -} diff --git a/src/libtest/libtool.cc b/src/libtest/libtool.cc deleted file mode 100644 index 7a8e838c..00000000 --- a/src/libtest/libtool.cc +++ /dev/null @@ -1,73 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" -#include - -char _libtool[1024]= { 0 }; - -namespace libtest { - -const char *libtool(void) -{ - if (_libtool[0] == 0) - { - std::string libtool_buffer; - if (getenv("PWD")) - { - libtool_buffer+= getenv("PWD"); - libtool_buffer+= "/"; - } - else - { - libtool_buffer+= "./"; - } - - libtool_buffer+= "libtool"; - if (access(libtool_buffer.c_str(), R_OK | W_OK | X_OK)) - { - Error << "Could not find libtool via access(" << libtool_buffer << ") :" << strerror(errno); - return NULL; - } - - snprintf(_libtool, sizeof(_libtool), "%s", libtool_buffer.c_str()); - } - - return _libtool; -} - -} // namespace libtest diff --git a/src/libtest/libtool.hpp b/src/libtest/libtool.hpp deleted file mode 100644 index 925b55d3..00000000 --- a/src/libtest/libtool.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -const char *libtool(void); - -} diff --git a/src/libtest/lite.h b/src/libtest/lite.h deleted file mode 100644 index a0bdc57a..00000000 --- a/src/libtest/lite.h +++ /dev/null @@ -1,413 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#ifdef __cplusplus -# include -# include -# include -# include -# include -#else -# include -# include -# include -# include -# include -# include -#endif - -#if defined(WIN32) -# include -#else -# include -#endif - -#ifndef __PRETTY_FUNCTION__ -# define __PRETTY_FUNCTION__ __func__ -#endif - -#ifndef EXIT_SKIP -# define EXIT_SKIP 77 -#endif - -#ifndef YATL_FULL -# define YATL_FULL 0 -#endif - -#ifndef FAIL -# define FAIL(__message_format, ...) -#endif - -#ifndef SKIP -# define SKIP(__message_format, ...) -#endif - -#include "libtest/valgrind.h" - -static inline size_t yatl_strlen(const char *s) -{ - if (s) - { - return strlen(s); - } - - return (size_t)(0); -} - -static inline int yatl_strcmp(const char *s1, const char *s2, size_t *s1_length, size_t *s2_length) -{ - *s1_length= yatl_strlen(s1); - *s2_length= yatl_strlen(s2); - - if (*s1_length == 0 && *s1_length == *s2_length) - { - return 0; - } - - if (*s1_length == 0 && *s2_length) - { - return 1; - } - - if (*s1_length && *s2_length == 0) - { - return 1; - } - - return strcmp(s1, s2); -} - -#define SKIP_IF(__expression) \ -do \ -{ \ - if ((__expression)) { \ - if (YATL_FULL) { \ - SKIP(#__expression); \ - } \ - fprintf(stdout, "\n%s:%d: %s SKIP '!(%s)'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression); \ - exit(EXIT_SKIP); \ - } \ -} while (0) - -#define SKIP_IF_(__expression, ...) \ -do \ -{ \ - if ((__expression)) { \ - size_t ask= snprintf(0, 0, __VA_ARGS__); \ - ask++; \ - char *buffer= (char*)alloca(sizeof(char) * ask); \ - snprintf(buffer, ask, __VA_ARGS__); \ - if (YATL_FULL) { \ - SKIP(#__expression, buffer); \ - } \ - fprintf(stdout, "\n%s:%d: %s SKIP '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \ - exit(EXIT_SKIP); \ - } \ -} while (0) - -#define SKIP_UNLESS(__expression) \ -do \ -{ \ - if (! (__expression)) { \ - if (YATL_FULL) { \ - SKIP(#__expression); \ - } \ - fprintf(stdout, "\n%s:%d: %s SKIP '(%s)'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression); \ - exit(EXIT_SKIP); \ - } \ -} while (0) - -#define SKIP_UNLESS_(__expression, ...) \ -do \ -{ \ - if (! (__expression)) { \ - size_t ask= snprintf(0, 0, __VA_ARGS__); \ - ask++; \ - char *buffer= (char*)alloca(sizeof(char) * ask); \ - snprintf(buffer, ask, __VA_ARGS__); \ - if (YATL_FULL) { \ - SKIP(#__expression, buffer); \ - } \ - fprintf(stdout, "\n%s:%d: %s SKIP '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \ - exit(EXIT_SKIP); \ - } \ -} while (0) - -#define ASSERT_TRUE(__expression) \ -do \ -{ \ - if (! (__expression)) { \ - if (YATL_FULL) { \ - FAIL("Assertion '%s'", #__expression); \ - } \ - fprintf(stderr, "\n%s:%d: %s Assertion '%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression);\ - exit(EXIT_FAILURE); \ - } \ -} while (0) - -#define ASSERT_FALSE(__expression) \ -do \ -{ \ - if ((__expression)) { \ - if (YATL_FULL) { \ - FAIL("Assertion '!%s'", #__expression); \ - } \ - fprintf(stderr, "\n%s:%d: %s Assertion '!%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression);\ - exit(EXIT_FAILURE); \ - } \ -} while (0) - -#define ASSERT_NULL_(__expression, ...) \ -do \ -{ \ - if ((__expression) != NULL) { \ - size_t ask= snprintf(0, 0, __VA_ARGS__); \ - ask++; \ - char *buffer= (char*)alloca(sizeof(char) * ask); \ - snprintf(buffer, ask, __VA_ARGS__); \ - if (YATL_FULL) { \ - FAIL("Assertion '%s' != NULL [ %s ]", #__expression, buffer);\ - } \ - fprintf(stderr, "\n%s:%d: %s Assertion '%s' != NULL [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer);\ - exit(EXIT_FAILURE); \ - } \ -} while (0) - -#define ASSERT_NOT_NULL(__expression) \ -do \ -{ \ - if ((__expression) == NULL) { \ - if (YATL_FULL) { \ - FAIL("Assertion '%s' == NULL", #__expression,);\ - } \ - fprintf(stderr, "\n%s:%d: %s Assertion '%s' == NULL\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression,);\ - exit(EXIT_FAILURE); \ - } \ -} while (0) - -#define ASSERT_NOT_NULL_(__expression, ...) \ -do \ -{ \ - if ((__expression) == NULL) { \ - size_t ask= snprintf(0, 0, __VA_ARGS__); \ - ask++; \ - char *buffer= (char*)alloca(sizeof(char) * ask); \ - snprintf(buffer, ask, __VA_ARGS__); \ - if (YATL_FULL) { \ - FAIL("Assertion '%s' == NULL [ %s ]", #__expression, buffer);\ - } \ - fprintf(stderr, "\n%s:%d: %s Assertion '%s' == NULL [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer);\ - exit(EXIT_FAILURE); \ - } \ -} while (0) - -#define ASSERT_TRUE_(__expression, ...) \ -do \ -{ \ - if (! (__expression)) { \ - size_t ask= snprintf(0, 0, __VA_ARGS__); \ - ask++; \ - char *buffer= (char*)alloca(sizeof(char) * ask); \ - snprintf(buffer, ask, __VA_ARGS__); \ - if (YATL_FULL) { \ - FAIL("Assertion '%s' [ %s ]", #__expression, buffer); \ - } \ - fprintf(stderr, "\n%s:%d: %s Assertion '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \ - exit(EXIT_FAILURE); \ - } \ -} while (0) - -#define ASSERT_EQ(__expected, __actual) \ -do \ -{ \ - if ((__expected) != (__actual)) { \ - if (YATL_FULL) { \ - FAIL("Assertion '%s' != '%s'", #__expected, #__actual); \ - } \ - fprintf(stderr, "\n%s:%d: %s Assertion '%s' != '%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual); \ - exit(EXIT_FAILURE); \ - } \ -} while (0) - -#define ASSERT_EQ_(__expected, __actual, ...) \ -do \ -{ \ - if ((__expected) != (__actual)) { \ - size_t ask= snprintf(0, 0, __VA_ARGS__); \ - ask++; \ - char *buffer= (char*)alloca(sizeof(char) * ask); \ - snprintf(buffer, ask, __VA_ARGS__); \ - if (YATL_FULL) { \ - FAIL("Assertion '%s' != '%s' [ %s ]", #__expected, #__actual, buffer); \ - } \ - fprintf(stderr, "\n%s:%d: %s Assertion '%s' != '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual, buffer); \ - exit(EXIT_FAILURE); \ - } \ -} while (0) - -#define ASSERT_STREQ(__expected_str, __actual_str) \ -do \ -{ \ - size_t __expected_length; \ - size_t __actual_length; \ - int ret= yatl_strcmp(__expected_str, __actual_str, &__expected_length, &__actual_length); \ - if (ret) { \ - if (YATL_FULL) { \ - FAIL("Assertion '%.*s' != '%.*s'\n", \ - (int)(__expected_length), (__expected_str), \ - (int)__actual_length, (__actual_str)) ; \ - } \ - fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' != '%.*s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \ - (int)(__expected_length), (__expected_str), \ - (int)__actual_length, (__actual_str)) ; \ - exit(EXIT_FAILURE); \ - } \ -} while (0) - -#define ASSERT_STREQ_(__expected_str, __actual_str, ...) \ -do \ -{ \ - size_t __expected_length; \ - size_t __actual_length; \ - int ret= yatl_strcmp(__expected_str, __actual_str, &__expected_length, &__actual_length); \ - if (ret) { \ - size_t ask= snprintf(0, 0, __VA_ARGS__); \ - ask++; \ - char *buffer= (char*)alloca(sizeof(char) * ask); \ - ask= snprintf(buffer, ask, __VA_ARGS__); \ - if (YATL_FULL) { \ - FAIL("Assertion '%.*s' != '%.*s' [ %.*s ]", \ - (int)(__expected_length), (__expected_str), \ - (int)(__actual_length), (__actual_str), \ - (int)(ask), buffer); \ - } \ - fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' != '%.*s' [ %.*s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \ - (int)(__expected_length), (__expected_str), \ - (int)(__actual_length), (__actual_str), \ - (int)(ask), buffer); \ - exit(EXIT_FAILURE); \ - } \ -} while (0) - -#define ASSERT_STRNE(__expected_str, __actual_str) \ -do \ -{ \ - size_t __expected_length; \ - size_t __actual_length; \ - int ret= yatl_strcmp(__expected_str, __actual_str, &__expected_length, &__actual_length); \ - if (ret == 0) { \ - if (YATL_FULL) { \ - FAIL("Assertion '%.*s' == '%.*s'", \ - (int)(__expected_length), (__expected_str), \ - (int)__actual_length, (__actual_str)) ; \ - } \ - fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' == '%.*s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \ - (int)(__expected_length), (__expected_str), \ - (int)__actual_length, (__actual_str)) ; \ - exit(EXIT_FAILURE); \ - } \ -} while (0) - -#define ASSERT_STRNE_(__expected_str, __actual_str, ...) \ -do \ -{ \ - size_t __expected_length; \ - size_t __actual_length; \ - int ret= yatl_strcmp(__expected_str, __actual_str, &__expected_length, &__actual_length); \ - if (ret == 0) { \ - size_t ask= snprintf(0, 0, __VA_ARGS__); \ - ask++; \ - char *buffer= (char*)alloca(sizeof(char) * ask); \ - ask= snprintf(buffer, ask, __VA_ARGS__); \ - if (YATL_FULL) { \ - FAIL("Assertion '%.*s' == '%.*s' [ %.*s ]", \ - (int)(__expected_length), (__expected_str), \ - (int)(__actual_length), (__actual_str), \ - (int)(ask), buffer); \ - } \ - fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' == '%.*s' [ %.*s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \ - (int)(__expected_length), (__expected_str), \ - (int)(__actual_length), (__actual_str), \ - (int)(ask), buffer); \ - exit(EXIT_FAILURE); \ - } \ -} while (0) - -#define ASSERT_NEQ(__expected, __actual) \ -do \ -{ \ - if ((__expected) == (__actual)) { \ - if (YATL_FULL) { \ - FAIL("Assertion '%s' == '%s'", #__expected, #__actual); \ - } \ - fprintf(stderr, "\n%s:%d: %s Assertion '%s' == '%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual); \ - exit(EXIT_FAILURE); \ - } \ -} while (0) - -#define ASSERT_NEQ_(__expected, __actual, ...) \ -do \ -{ \ - if ((__expected) == (__actual)) { \ - size_t ask= snprintf(0, 0, __VA_ARGS__); \ - ask++; \ - char *buffer= (char*)alloca(sizeof(char) * ask); \ - snprintf(buffer, ask, __VA_ARGS__); \ - if (YATL_FULL) { \ - FAIL("Assertion '%s' == '%s' [ %s ]", #__expected, #__actual, buffer); \ - } \ - fprintf(stderr, "\n%s:%d: %s Assertion '%s' == '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual, buffer); \ - exit(EXIT_FAILURE); \ - } \ -} while (0) - -#define ASSERT_FALSE_(__expression, ...) \ -do \ -{ \ - if ((__expression)) { \ - size_t ask= snprintf(0, 0, __VA_ARGS__); \ - ask++; \ - char *buffer= (char*)alloca(sizeof(char) * ask); \ - snprintf(buffer, ask, __VA_ARGS__); \ - if (YATL_FULL) { \ - FAIL("Assertion '!%s' [ %s ]", #__expression, buffer); \ - } \ - fprintf(stderr, "\n%s:%d: %s Assertion '!%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \ - exit(EXIT_FAILURE); \ - } \ -} while (0) diff --git a/src/libtest/main.cc b/src/libtest/main.cc deleted file mode 100644 index 5684ba46..00000000 --- a/src/libtest/main.cc +++ /dev/null @@ -1,396 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - -#include -#include -#include -#include -#include -#include -#ifdef HAVE_STRINGS_H -# include -#endif -#include -#include -#include -#include -#include -#include -#include - -#include - -#ifndef __INTEL_COMPILER -#pragma GCC diagnostic ignored "-Wold-style-cast" -#endif - -#if __cplusplus >= 201103L -# define UNIQUE_PTR std::unique_ptr -#else -# define UNIQUE_PTR std::auto_ptr -#endif - -using namespace libtest; - -static void stats_print(libtest::Framework *frame) -{ - if (frame->failed() == 0 and frame->success() == 0) - { - return; - } - - Outn(); - Out << "Collections\t\t\t\t\t" << frame->total(); - Out << "\tFailed\t\t\t\t\t" << frame->failed(); - Out << "\tSkipped\t\t\t\t\t" << frame->skipped(); - Out << "\tSucceeded\t\t\t\t" << frame->success(); - Outn(); - Out << "Tests\t\t\t\t\t" << frame->sum_total(); - Out << "\tFailed\t\t\t\t" << frame->sum_failed(); - Out << "\tSkipped\t\t\t\t" << frame->sum_skipped(); - Out << "\tSucceeded\t\t\t" << frame->sum_success(); -} - -#include -#include - -int main(int argc, char *argv[]) -{ - bool opt_massive= false; - unsigned long int opt_repeat= 1; // Run all tests once - bool opt_quiet= false; - std::string collection_to_run; - std::string wildcard; - std::string binary_name; - - const char *just_filename= rindex(argv[0], '/'); - if (just_filename) - { - just_filename++; - } - else - { - just_filename= argv[0]; - } - - if (just_filename[0] == 'l' and just_filename[1] == 't' and just_filename[2] == '-') - { - just_filename+= 3; - } - binary_name.append(just_filename); - - /* - Valgrind does not currently work reliably, or sometimes at all, on OSX - - Fri Jun 15 11:24:07 EDT 2012 - */ -#if defined(__APPLE__) && __APPLE__ - if (valgrind_is_caller()) - { - return EXIT_SKIP; - } -#endif - - // Options parsing - { - enum long_option_t { - OPT_LIBYATL_VERSION, - OPT_LIBYATL_MATCH_COLLECTION, - OPT_LIBYATL_MASSIVE, - OPT_LIBYATL_QUIET, - OPT_LIBYATL_MATCH_WILDCARD, - OPT_LIBYATL_REPEAT - }; - - static struct option long_options[]= - { - { "version", no_argument, NULL, OPT_LIBYATL_VERSION }, - { "quiet", no_argument, NULL, OPT_LIBYATL_QUIET }, - { "repeat", required_argument, NULL, OPT_LIBYATL_REPEAT }, - { "collection", required_argument, NULL, OPT_LIBYATL_MATCH_COLLECTION }, - { "wildcard", required_argument, NULL, OPT_LIBYATL_MATCH_WILDCARD }, - { "massive", no_argument, NULL, OPT_LIBYATL_MASSIVE }, - { 0, 0, 0, 0 } - }; - - int option_index= 0; - while (1) - { - int option_rv= getopt_long(argc, argv, "", long_options, &option_index); - if (option_rv == -1) - { - break; - } - - switch (option_rv) - { - case OPT_LIBYATL_VERSION: - break; - - case OPT_LIBYATL_QUIET: - opt_quiet= true; - break; - - case OPT_LIBYATL_REPEAT: - errno= 0; - opt_repeat= strtoul(optarg, (char **) NULL, 10); - if (errno != 0) - { - Error << "unknown value passed to --repeat: `" << optarg << "`"; - exit(EXIT_FAILURE); - } - break; - - case OPT_LIBYATL_MATCH_COLLECTION: - collection_to_run= optarg; - break; - - case OPT_LIBYATL_MATCH_WILDCARD: - wildcard= optarg; - break; - - case OPT_LIBYATL_MASSIVE: - opt_massive= true; - break; - - case '?': - /* getopt_long already printed an error message. */ - Error << "unknown option to getopt_long()"; - exit(EXIT_FAILURE); - - default: - break; - } - } - } - - srandom((unsigned int)time(NULL)); - - errno= 0; - if (bool(getenv("YATL_REPEAT"))) - { - errno= 0; - opt_repeat= strtoul(getenv("YATL_REPEAT"), (char **) NULL, 10); - if (errno != 0) - { - Error << "ENV YATL_REPEAT passed an invalid value: `" << getenv("YATL_REPEAT") << "`"; - exit(EXIT_FAILURE); - } - } - - if ((bool(getenv("YATL_QUIET")) and (strcmp(getenv("YATL_QUIET"), "0") == 0)) or opt_quiet) - { - opt_quiet= true; - } - else if (getenv("JENKINS_URL")) - { - if (bool(getenv("YATL_QUIET")) and (strcmp(getenv("YATL_QUIET"), "1") == 0)) - { } - else - { - opt_quiet= true; - } - } - - if ((bool(getenv("YATL_RUN_MASSIVE_TESTS"))) or opt_massive) - { - opt_massive= true; - } - - if (opt_quiet) - { - close(STDOUT_FILENO); - } - - if (opt_massive) - { - is_massive(opt_massive); - } - - libtest::vchar_t tmp_directory; - tmp_directory.resize(1024); - if (getenv("LIBTEST_TMP")) - { - snprintf(&tmp_directory[0], tmp_directory.size(), "%s", getenv("LIBTEST_TMP")); - } - else - { - snprintf(&tmp_directory[0], tmp_directory.size(), "%s", LIBTEST_TEMP); - } - - if (chdir(&tmp_directory[0]) == -1) - { - libtest::vchar_t getcwd_buffer; - getcwd_buffer.resize(1024); - char *dir= getcwd(&getcwd_buffer[0], getcwd_buffer.size()); - - Error << "Unable to chdir() from " << dir << " to " << &tmp_directory[0] << " errno:" << strerror(errno); - return EXIT_FAILURE; - } - - if (getenv("YATL_COLLECTION_TO_RUN")) - { - if (strlen(getenv("YATL_COLLECTION_TO_RUN"))) - { - collection_to_run= getenv("YATL_COLLECTION_TO_RUN"); - } - } - - if (collection_to_run.compare("none") == 0) - { - return EXIT_SUCCESS; - } - - if (collection_to_run.empty() == false) - { - Out << "Only testing " << collection_to_run; - } - - int exit_code; - - try - { - do - { - exit_code= EXIT_SUCCESS; - fatal_assert(sigignore(SIGPIPE) == 0); - - libtest::SignalThread signal; - if (signal.setup() == false) - { - Error << "Failed to setup signals"; - return EXIT_FAILURE; - } - - UNIQUE_PTR frame(new libtest::Framework(signal, binary_name, collection_to_run, wildcard)); - - // Run create(), bail on error. - { - switch (frame->create()) - { - case TEST_SUCCESS: - break; - - case TEST_SKIPPED: - SKIP("SKIP was returned from framework create()"); - break; - - case TEST_FAILURE: - std::cerr << "Could not call frame->create()" << std::endl; - return EXIT_FAILURE; - } - } - - frame->exec(); - - if (signal.is_shutdown() == false) - { - signal.set_shutdown(SHUTDOWN_GRACEFUL); - } - - shutdown_t status= signal.get_shutdown(); - if (status == SHUTDOWN_FORCED) - { - Out << "Tests were aborted."; - exit_code= EXIT_FAILURE; - } - else if (frame->failed()) - { - Out << "Some test failed."; - exit_code= EXIT_FAILURE; - } - else if (frame->skipped() and frame->failed() and frame->success()) - { - Out << "Some tests were skipped."; - } - else if (frame->success() and (frame->failed() == 0)) - { - Out; - Out << "All tests completed successfully."; - } - - stats_print(frame.get()); - - std::ofstream xml_file; - std::string file_name; - file_name.append(&tmp_directory[0]); - file_name.append(frame->name()); - file_name.append(".xml"); - xml_file.open(file_name.c_str(), std::ios::trunc); - libtest::Formatter::xml(*frame, xml_file); - - Outn(); // Generate a blank to break up the messages if make check/test has been run - } while (exit_code == EXIT_SUCCESS and --opt_repeat); - } - catch (const libtest::__skipped& e) - { - return EXIT_SKIP; - } - catch (const libtest::__failure& e) - { - libtest::stream::make_cout(e.file(), e.line(), e.func()) << e.what(); - exit_code= EXIT_FAILURE; - } - catch (const libtest::fatal& e) - { - std::cerr << "FATAL:" << e.what() << std::endl; - exit_code= EXIT_FAILURE; - } - catch (const libtest::disconnected& e) - { - std::cerr << "Unhandled disconnection occurred:" << e.what() << std::endl; - exit_code= EXIT_FAILURE; - } - catch (const std::exception& e) - { - std::cerr << "std::exception:" << e.what() << std::endl; - exit_code= EXIT_FAILURE; - } - catch (char const* s) - { - std::cerr << "Exception:" << s << std::endl; - exit_code= EXIT_FAILURE; - } - catch (...) - { - std::cerr << "Unknown exception halted execution." << std::endl; - exit_code= EXIT_FAILURE; - } - - return exit_code; -} diff --git a/src/libtest/memcached.cc b/src/libtest/memcached.cc deleted file mode 100644 index 0c16383e..00000000 --- a/src/libtest/memcached.cc +++ /dev/null @@ -1,261 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" - -#include "libtest/common.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "libtest/server.h" -#include "libtest/wait.h" - -#include "libtest/memcached.h" - -#ifndef __INTEL_COMPILER -#pragma GCC diagnostic ignored "-Wold-style-cast" -#endif - -namespace libtest { - -class Memcached : public libtest::Server -{ - std::string _username; - std::string _password; - -public: - Memcached(const std::string& host_arg, - const in_port_t port_arg, - const bool is_socket_arg, - const std::string& username_arg, - const std::string& password_arg) : - libtest::Server(host_arg, port_arg, - memcached_binary(), false, is_socket_arg), - _username(username_arg), - _password(password_arg) - { } - - Memcached(const std::string& host_arg, const in_port_t port_arg, const bool is_socket_arg) : - libtest::Server(host_arg, port_arg, - memcached_binary(), false, is_socket_arg) - { - set_pid_file(); - } - - virtual const char *sasl() const - { - return "-S"; - } - - bool is_sasl() const - { - return _username.size() && _password.size(); - } - - const std::string& password() const - { - return _password; - } - - const std::string& username() const - { - return _username; - } - - bool wait_for_pidfile() const - { - Wait wait(pid(), 4); - - return wait.successful(); - } - - bool ping() - { - if (out_of_ban_killed()) - { - return false; - } - - if (is_socket() or is_sasl()) - { - return _app.check(); - } - - SimpleClient client(_hostname, _port); - - std::string response; - return client.send_message("version", response); - } - - const char *name() - { - return "memcached"; - }; - - const char *executable() - { - return memcached_binary(); - } - - bool is_libtool() - { - return false; - } - - virtual void pid_file_option(Application& app, const std::string& arg) - { - if (arg.empty() == false) - { - app.add_option("-P", arg); - } - } - - const char *socket_file_option() const - { - return "-s "; - } - - virtual void port_option(Application& app, in_port_t arg) - { - char buffer[30]; - snprintf(buffer, sizeof(buffer), "%d", int(arg)); - app.add_option("-p", buffer); - - if(!is_sasl()) - { - app.add_option("-U", buffer); - } - } - - bool has_port_option() const - { - return true; - } - - bool has_socket_file_option() const - { - return has_socket(); - } - - void socket_file_option(Application& app, const std::string& socket_arg) - { - if (socket_arg.empty() == false) - { - app.add_option("-s", socket_arg); - } - } - - bool broken_socket_cleanup() - { - return true; - } - - // Memcached's pidfile is broken - bool broken_pid_file() - { - return true; - } - - bool build(); -}; - - -#include - -bool Memcached::build() -{ - if (getuid() == 0 or geteuid() == 0) - { - add_option("-u", "root"); - } - - add_option("-l", "localhost"); -#ifdef __APPLE__ -#else - add_option("-m", "128"); - add_option("-M"); -#endif - - if (is_sasl()) - { - add_option(sasl()); - } - - //add_option("-vvv"); - - return true; -} - -libtest::Server *build_memcached(const std::string& hostname, const in_port_t try_port) -{ - if (has_memcached()) - { - return new Memcached(hostname, try_port, false); - } - - return NULL; -} - -libtest::Server *build_memcached_socket(const std::string& socket_file, const in_port_t try_port) -{ - if (has_memcached()) - { - return new Memcached(socket_file, try_port, true); - } - - return NULL; -} - -libtest::Server *build_memcached_sasl(const std::string &hostname, const in_port_t try_port, const std::string &username, const std::string &password) -{ - if (has_memcached()) - { - return new Memcached(hostname, try_port, false, username, password); - } - - return NULL; -} - -} // namespace libtest diff --git a/src/libtest/memcached.h b/src/libtest/memcached.h deleted file mode 100644 index 7dc9c4d1..00000000 --- a/src/libtest/memcached.h +++ /dev/null @@ -1,48 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -libtest::Server *build_memcached(const std::string& hostname, const in_port_t try_port); - -libtest::Server *build_memcached_socket(const std::string& socket_file, const in_port_t try_port); - -libtest::Server *build_memcached_sasl(const std::string &hostname, const in_port_t try_port, const std::string &username, const std::string &password); - -} - diff --git a/src/libtest/memcached.hpp b/src/libtest/memcached.hpp deleted file mode 100644 index 5d010faf..00000000 --- a/src/libtest/memcached.hpp +++ /dev/null @@ -1,100 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED -inline bool operator== (const memcached_st& memc, const memcached_return_t rc) -{ - if (memcached_last_error(const_cast(&memc)) == rc) - { - return true; - } - - return false; -} - -inline bool operator!= (const memcached_st& memc, memcached_return_t rc) -{ - if (memcached_last_error(const_cast(&memc)) != rc) - { - return true; - } - - return false; -} - -inline bool operator== (memcached_st* const memc, memcached_return_t rc) -{ - if (memcached_last_error(memc) == rc) - { - return true; - } - - return false; -} - -inline bool operator!= (memcached_st* const memc, memcached_return_t rc) -{ - if (memcached_last_error(memc) != rc) - { - return true; - } - - return false; -} - -inline bool operator!= (memcached_return_t rc, const memcached_st& memc) -{ - if (memcached_last_error(const_cast(&memc)) != rc) - { - return true; - } - - return false; -} - -inline bool operator!= (memcached_return_t rc, memcached_st* const memc) -{ - if (memcached_last_error(memc) != rc) - { - return true; - } - - return false; -} -#endif - diff --git a/src/libtest/poll_error.hpp b/src/libtest/poll_error.hpp deleted file mode 100644 index b75066f9..00000000 --- a/src/libtest/poll_error.hpp +++ /dev/null @@ -1,100 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/* - Structures for generic tests. -*/ - -#include -#include - -void print_poll(pollfd& fds) -{ - if (fds.revents & POLLERR) - { - fprintf(stderr, "\tPOLLERR\n"); - } - - if (fds.revents & POLLHUP) - { - fprintf(stderr, "\tPOLLHUP\n"); - } - - if (fds.revents & POLLIN) - { - fprintf(stderr, "\tPOLLIN\n"); - } - - if (fds.revents & POLLIN) - { - fprintf(stderr, "\tPOLLIN\n"); - } - - if (fds.revents & POLLNVAL) - { - fprintf(stderr, "\tPOLLNVAL\n"); - } - - if (fds.revents & POLLOUT) - { - fprintf(stderr, "\tPOLLOUT\n"); - } - - if (fds.revents & POLLPRI) - { - fprintf(stderr, "\tPOLLPRI\n"); - } - - if (fds.revents & POLLRDBAND) - { - fprintf(stderr, "\tPOLLPRI\n"); - } - - if (fds.revents & POLLRDNORM) - { - fprintf(stderr, "\tPOLLRDNORM\n"); - } - - if (fds.revents & POLLWRBAND) - { - fprintf(stderr, "\tPOLLWRBAND\n"); - } - - if (fds.revents & POLLWRNORM) - { - fprintf(stderr, "\tPOLLWRNORM\n"); - } -} diff --git a/src/libtest/port.cc b/src/libtest/port.cc deleted file mode 100644 index 73ac67d0..00000000 --- a/src/libtest/port.cc +++ /dev/null @@ -1,231 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include "libtest/signal.h" - -#ifndef SOCK_CLOEXEC -# define SOCK_CLOEXEC 0 -#endif - -#ifndef SOCK_NONBLOCK -# define SOCK_NONBLOCK 0 -#endif - -#ifndef FD_CLOEXEC -# define FD_CLOEXEC 0 -#endif - -#ifndef __INTEL_COMPILER -#pragma GCC diagnostic ignored "-Wold-style-cast" -#endif - -using namespace libtest; - -struct socket_st { - typedef std::vector< std::pair< int, in_port_t> > socket_port_t; - socket_port_t _pair; - in_port_t last_port; - - socket_st(): - last_port(0) - { } - - void release(in_port_t _arg) - { - for (socket_port_t::iterator iter= _pair.begin(); - iter != _pair.end(); - ++iter) - { - if ((*iter).second == _arg) - { - shutdown((*iter).first, SHUT_RDWR); - close((*iter).first); - } - } - } - - ~socket_st() - { - for (socket_port_t::iterator iter= _pair.begin(); - iter != _pair.end(); - ++iter) - { - shutdown((*iter).first, SHUT_RDWR); - close((*iter).first); - } - } -}; - -static socket_st all_socket_fd; - -static in_port_t global_port= 0; - -namespace libtest { - -in_port_t default_port() -{ - if (global_port == 0) - { - global_port= get_free_port(); - } - - return global_port; -} - -void release_port(in_port_t arg) -{ - all_socket_fd.release(arg); -} - -in_port_t get_free_port() -{ - const in_port_t default_port= in_port_t(-1); - - int retries= 1024; - - in_port_t ret_port; - while (--retries) - { - ret_port= default_port; - int sd; - if ((sd= socket(AF_INET, SOCK_STREAM, 0)) != SOCKET_ERROR) - { - int optval= 1; - if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) != SOCKET_ERROR) - { - struct sockaddr_in sin; - sin.sin_port= 0; - sin.sin_addr.s_addr= 0; - sin.sin_addr.s_addr= INADDR_ANY; - sin.sin_family= AF_INET; - - int bind_ret; - do - { - if ((bind_ret= bind(sd, (struct sockaddr *)&sin, sizeof(struct sockaddr_in) )) != SOCKET_ERROR) - { - socklen_t addrlen= sizeof(sin); - - if (getsockname(sd, (struct sockaddr *)&sin, &addrlen) != -1) - { - ret_port= sin.sin_port; - } - } - else - { - if (errno != EADDRINUSE) - { - Error << strerror(errno); - } - } - - if (errno == EADDRINUSE) - { - libtest::dream(2, 0); - } - } while (bind_ret == -1 and errno == EADDRINUSE); - - all_socket_fd._pair.push_back(std::make_pair(sd, ret_port)); - } - else - { - Error << strerror(errno); - } - } - else - { - Error << strerror(errno); - } - - if (ret_port == default_port) - { - Error << "no ret_port set:" << strerror(errno); - } - else if (ret_port > 1024 and ret_port != all_socket_fd.last_port) - { - break; - } - } - - // We handle the case where if we max out retries, we still abort. - if (retries == 0) - { - FATAL("No port could be found, exhausted retry"); - } - - if (ret_port == 0) - { - FATAL("No port could be found"); - } - - if (ret_port == default_port) - { - FATAL("No port could be found"); - } - - if (ret_port <= 1024) - { - FATAL("No port could be found, though some where available below or at 1024"); - } - - all_socket_fd.last_port= ret_port; - release_port(ret_port); - - return ret_port; -} - -} // namespace libtest diff --git a/src/libtest/port.h b/src/libtest/port.h deleted file mode 100644 index 55cef532..00000000 --- a/src/libtest/port.h +++ /dev/null @@ -1,56 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/* - Structures for generic tests. -*/ - -#pragma once - -#define LIBTEST_FAIL_PORT 23 - -namespace libtest { - -LIBTEST_API -in_port_t default_port(); - -LIBTEST_API -in_port_t get_free_port(); - -LIBTEST_API -void release_port(in_port_t arg); - -} // namespace libtest diff --git a/src/libtest/result.cc b/src/libtest/result.cc deleted file mode 100644 index 84b50676..00000000 --- a/src/libtest/result.cc +++ /dev/null @@ -1,82 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" -#include - -namespace libtest { - -__test_result::__test_result(const char *file_arg, int line_arg, const char *func_arg): - libtest::exception(file_arg, line_arg, func_arg) - { - } - -__success::__success(const char *file_arg, int line_arg, const char *func_arg): - __test_result(file_arg, line_arg, func_arg) -{ -} - -__skipped::__skipped(const char *file_arg, int line_arg, const char *func_arg, ...): - __test_result(file_arg, line_arg, func_arg) -{ - va_list args; - va_start(args, func_arg); - init(args); - va_end(args); -} - -__skipped::__skipped(const __skipped& other) : - __test_result(other) -{ -} - -__failure::__failure(const char *file_arg, int line_arg, const char *func_arg, ...) : - __test_result(file_arg, line_arg, func_arg) -{ - va_list args; - va_start(args, func_arg); - init(args); - va_end(args); -} - -__failure::__failure(const __failure& other) : - __test_result(other) -{ -} - - -} // namespace libtest diff --git a/src/libtest/result.hpp b/src/libtest/result.hpp deleted file mode 100644 index 66461de5..00000000 --- a/src/libtest/result.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include "libtest/result/base.hpp" -#include "libtest/result/fail.hpp" -#include "libtest/result/skip.hpp" -#include "libtest/result/success.hpp" - -#define _SUCCESS throw libtest::__success(LIBYATL_DEFAULT_PARAM) - -#define SKIP(...) \ -do \ -{ \ - throw libtest::__skipped(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \ -} while (0) - -#define FAIL(...) \ -do \ -{ \ - throw libtest::__failure(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \ -} while (0) diff --git a/src/libtest/result/base.hpp b/src/libtest/result/base.hpp deleted file mode 100644 index 5f093f83..00000000 --- a/src/libtest/result/base.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include "libtest/exception.hpp" -#include "libtest/error.h" - -namespace libtest { - -class __test_result : public libtest::exception -{ -public: - __test_result(const char *file, int line, const char *func); - - virtual test_return_t return_code() const= 0; - -private: -}; - -} // namespace libtest diff --git a/src/libtest/result/fail.hpp b/src/libtest/result/fail.hpp deleted file mode 100644 index 3aec9c1e..00000000 --- a/src/libtest/result/fail.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -class __failure : public __test_result -{ -public: - __failure(const char *file, int line, const char *func, ...); - - __failure(const __failure&); - - test_return_t return_code() const - { - return TEST_FAILURE; - } - -private: -}; - -} // namespace libtest diff --git a/src/libtest/result/skip.hpp b/src/libtest/result/skip.hpp deleted file mode 100644 index 7409d718..00000000 --- a/src/libtest/result/skip.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -class __skipped : public __test_result -{ -public: - __skipped(const char *file, int line, const char *func, ...); - - __skipped(const __skipped&); - - test_return_t return_code() const - { - return TEST_SKIPPED; - } -}; - -} // namespace libtest diff --git a/src/libtest/result/success.hpp b/src/libtest/result/success.hpp deleted file mode 100644 index a34e677e..00000000 --- a/src/libtest/result/success.hpp +++ /dev/null @@ -1,59 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -class __success : public __test_result -{ -public: - __success(const char *file, int line, const char *func); - - const char* what() const throw() - { - return "SUCCESS"; - } - - test_return_t return_code() const - { - return TEST_SUCCESS; - } - -private: -}; - -} // namespace libtest diff --git a/src/libtest/run-ci.gdb b/src/libtest/run-ci.gdb deleted file mode 100644 index 20724b00..00000000 --- a/src/libtest/run-ci.gdb +++ /dev/null @@ -1,7 +0,0 @@ -set logging on -set logging overwrite on -set environment LIBTEST_IN_GDB=1 -set ASAN_OPTIONS=abort_on_error=1 -run -thread apply all bt -quit diff --git a/src/libtest/run.gdb b/src/libtest/run.gdb deleted file mode 100644 index c35ab767..00000000 --- a/src/libtest/run.gdb +++ /dev/null @@ -1,7 +0,0 @@ -set logging on -set logging overwrite on -set environment LIBTEST_IN_GDB=1 -#set ASAN_OPTIONS=abort_on_error=1 -handle SIGVTALRM stop -run -thread apply all bt diff --git a/src/libtest/runner.cc b/src/libtest/runner.cc deleted file mode 100644 index d5d8d5be..00000000 --- a/src/libtest/runner.cc +++ /dev/null @@ -1,203 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - -namespace libtest { - -Runner::Runner() : - _servers(NULL) -{ -} - -test_return_t Runner::main(test_callback_fn* func, void *object) -{ - test_return_t ret; - try { - ret= run(func, object); - } - catch (const libtest::__skipped& e) - { - ret= TEST_SKIPPED; - } - catch (const libtest::__failure& e) - { - libtest::stream::make_cerr(e.file(), e.line(), e.func()) << e.what(); - ret= TEST_FAILURE; - } - catch (const libtest::__success&) - { - ret= TEST_SUCCESS; - } - catch (const libtest::fatal&) - { - throw; - } - catch (const std::exception& e) - { - libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what(); - throw; - } - catch (...) - { - libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << "Unknown exception thrown"; - throw; - } - - return ret; -} - -test_return_t Runner::setup(test_callback_fn* func, void *object) -{ - test_return_t ret; - try { - ret= pre(func, object); - } - catch (const libtest::__skipped& e) - { - ret= TEST_SKIPPED; - } - catch (const libtest::__failure& e) - { - libtest::stream::make_cout(e.file(), e.line(), e.func()) << e.what(); - ret= TEST_FAILURE; - } - catch (const libtest::__success&) - { - ret= TEST_SUCCESS; - } - catch (const libtest::fatal& e) - { - throw; - } - catch (const std::exception& e) - { - libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what(); - throw; - } - catch (...) - { - libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << "Unknown exception thrown"; - throw; - } - - return ret; -} - -test_return_t Runner::teardown(test_callback_fn* func, void *object) -{ - test_return_t ret; - try { - ret= post(func, object); - } - catch (const libtest::__skipped& e) - { - ret= TEST_SKIPPED; - } - catch (const libtest::__failure& e) - { - libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what(); - ret= TEST_FAILURE; - } - catch (const libtest::__success&) - { - ret= TEST_SUCCESS; - } - catch (const libtest::fatal& e) - { - throw; - } - catch (const std::exception& e) - { - libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what(); - throw; - } - catch (...) - { - libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << "Unknown exception thrown"; - throw; - } - - return ret; -} - -test_return_t Runner::flush(void*) -{ - return TEST_SUCCESS; -} - -test_return_t Runner::run(test_callback_fn* func, void *object) -{ - if (func) - { - return func(object); - } - - return TEST_SUCCESS; -} - -test_return_t Runner::pre(test_callback_fn* func, void *object) -{ - if (func) - { - return func(object); - } - - return TEST_SUCCESS; -} - -test_return_t Runner::post(test_callback_fn* func, void *object) -{ - if (func) - { - return func(object); - } - - return TEST_SUCCESS; -} - -void Runner::set_servers(libtest::server_startup_st& arg) -{ - _servers= &arg; -} - -bool Runner::check() -{ - return _servers ? _servers->check() : true; -} - -} // namespace libtest diff --git a/src/libtest/runner.h b/src/libtest/runner.h deleted file mode 100644 index 627a0a8e..00000000 --- a/src/libtest/runner.h +++ /dev/null @@ -1,73 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - - -namespace libtest { - -/** - Structure which houses the actual callers for the test cases contained in - the collections. -*/ -class Runner { -public: - test_return_t main(test_callback_fn* func, void *object); - test_return_t setup(test_callback_fn* func, void *object); - test_return_t teardown(test_callback_fn* func, void *object); - - Runner(); - - void set_servers(libtest::server_startup_st& arg); - - bool check(); - - virtual ~Runner() { } - - virtual test_return_t flush(void*); - virtual test_return_t run(test_callback_fn* func, void *object); - virtual test_return_t pre(test_callback_fn* func, void *object); - virtual test_return_t post(test_callback_fn* func, void *object); - -private: - libtest::server_startup_st* _servers; - -private: - Runner( const Runner& ); - const Runner& operator=( const Runner& ); -}; - -} // namespace Runner diff --git a/src/libtest/server.cc b/src/libtest/server.cc deleted file mode 100644 index 3c60143b..00000000 --- a/src/libtest/server.cc +++ /dev/null @@ -1,532 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" - -#include "libtest/common.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -// trim from end -static inline std::string &rtrim(std::string &s) -{ - s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), s.end()); - return s; -} - -#include "libtest/server.h" -#include "libtest/stream.h" -#include "libtest/killpid.h" - -namespace libtest { - -std::ostream& operator<<(std::ostream& output, const Server &arg) -{ - if (arg.is_socket()) - { - output << arg.hostname(); - } - else - { - output << arg.hostname() << ":" << arg.port(); - } - - if (arg.has_pid()) - { - output << " Pid:" << arg.pid(); - } - - if (arg.has_socket()) - { - output << " Socket:" << arg.socket(); - } - - if (arg.running().empty() == false) - { - output << " Exec:" << arg.running(); - } - - return output; // for multiple << operators -} - -#ifdef __GLIBC__ -namespace { - -class Buffer -{ -public: - Buffer(char *b) : b_(b) {} - ~Buffer() { if (b_) free(b_); } - char* buf() { return b_; } -private: - char *b_; -}; - -} -#endif // __GLIBC__ - -#define MAGIC_MEMORY 123570 - -Server::Server(const std::string& host_arg, const in_port_t port_arg, - const std::string& executable, const bool _is_libtool, - bool is_socket_arg) : - _magic(MAGIC_MEMORY), - _is_socket(is_socket_arg), - _port(port_arg), - _hostname(host_arg), - _app(executable, _is_libtool), - out_of_ban_killed_(false), - _timeout(40) -{ -} - -Server::~Server() -{ - kill(); -} - -bool Server::check() -{ - _app.clear(); - return _app.check(); -} - -bool Server::validate() -{ - return _magic == MAGIC_MEMORY; -} - -// If the server exists, kill it -bool Server::cycle() -{ - uint32_t limit= 3; - - // Try to ping, and kill the server #limit number of times - while (--limit and - is_pid_valid(_app.pid())) - { - if (kill()) - { - Log << "Killed existing server," << *this; - dream(0, 50000); - continue; - } - } - - // For whatever reason we could not kill it, and we reached limit - if (limit == 0) - { - Error << "Reached limit, could not kill server"; - return false; - } - - return true; -} - -bool Server::wait_for_pidfile() const -{ - Wait wait(pid_file(), 4); - - return wait.successful(); -} - -bool Server::init(const char *argv[]) -{ - if (argv) - { - for (const char **ptr= argv; *ptr ; ++ptr) - { - if (ptr) - { - add_option(*ptr); - } - } - } - - return build(); -} - -bool Server::has_pid() const -{ - return (_app.pid() > 1); -} - - -bool Server::start() -{ - if (getenv("YATL_GDB_SERVER")) - { - _app.use_gdb(true); - } - - if (port() == LIBTEST_FAIL_PORT) - { - throw libtest::disconnected(LIBYATL_DEFAULT_PARAM, - hostname(), port(), "Called failure"); - } - - if (getenv("YATL_PTRCHECK_SERVER")) - { - _app.use_ptrcheck(true); - } - else if (getenv("YATL_VALGRIND_SERVER")) - { - _app.use_valgrind(true); - } - - out_of_ban_killed(false); - if (args(_app) == false) - { - throw libtest::disconnected(LIBYATL_DEFAULT_PARAM, - hostname(), port(), "Could not build command()"); - } - - libtest::release_port(_port); - - Application::error_t ret; - if (Application::SUCCESS != (ret= _app.run())) - { - throw libtest::disconnected(LIBYATL_DEFAULT_PARAM, - hostname(), port(), "Application::run() %s", libtest::Application::toString(ret)); - return false; - } - _running= _app.print(); - - if (valgrind_is_caller()) - { - dream(5, 50000); - } - - size_t repeat= 5; - _app.slurp(); - while (--repeat) - { - if (pid_file().empty() == false) - { - Wait wait(pid_file(), 8); - - if (wait.successful() == false) - { - if (_app.check()) - { - _app.slurp(); - continue; - } - -#ifdef __GLIBC__ - Buffer buf( get_current_dir_name()); - char *getcwd_buf= buf.buf(); -#else - libtest::vchar_t buf; - buf.resize(PATH_MAX); - char *getcwd_buf= getcwd(&buf[0], buf.size()); -#endif // __GLIBC__ - throw libtest::disconnected(LIBYATL_DEFAULT_PARAM, - hostname(), port(), - "Unable to open pidfile in %s for: %s stderr:%s", - getcwd_buf ? getcwd_buf : "", - _running.c_str(), - _app.stderr_c_str()); - } - } - } - - bool pinged= false; - uint32_t this_wait= 0; - { - uint32_t waited; - uint32_t retry; - - for (waited= 0, retry= 1; ; retry++, waited+= this_wait) - { - if (_app.check() == false) - { - break; - } - - if ((pinged= ping()) == true) - { - break; - } - else if (waited >= _timeout) - { - break; - } - - this_wait= retry * retry / 3 + 1; - libtest::dream(this_wait, 0); - } - } - - if (pinged == false) - { -#if 0 - Error << "Failed to ping(" << _app.pid() << ") wait: " << this_wait << " " << hostname() << ":" << port() << " run:" << _running << " " << error(); -#endif - - // If we happen to have a pid file, lets try to kill it - if ((pid_file().empty() == false) and (access(pid_file().c_str(), R_OK) == 0)) - { - _app.slurp(); - if (kill_file(pid_file()) == false) - { - throw libtest::disconnected(LIBYATL_DEFAULT_PARAM, - hostname(), port(), - "Failed to kill off server, waited: %u after startup occurred, when pinging failed: %.*s stderr:%.*s", - this_wait, - int(_running.size()), _running.c_str(), - int(_app.stderr_result_length()), _app.stderr_c_str()); - } - else - { - throw libtest::disconnected(LIBYATL_DEFAULT_PARAM, - hostname(), port(), - "Failed native ping(), pid: %d was alive: %s waited: %u server started, having pid_file. exec: %.*s stderr:%.*s", - int(_app.pid()), - _app.check() ? "true" : "false", - this_wait, - int(_running.size()), _running.c_str(), - int(_app.stderr_result_length()), _app.stderr_c_str()); - } - } - else - { - throw libtest::disconnected(LIBYATL_DEFAULT_PARAM, - hostname(), port(), - "Failed native ping(), pid: %d is alive: %s waited: %u server started. exec: %.*s stderr:%.*s", - int(_app.pid()), - _app.check() ? "true" : "false", - this_wait, - int(_running.size()), _running.c_str(), - int(_app.stderr_result_length()), _app.stderr_c_str()); - } - _running.clear(); - - return false; - } - - return has_pid(); -} - -void Server::reset_pid() -{ - _running.clear(); - _pid_file.clear(); -} - -pid_t Server::pid() const -{ - return _app.pid(); -} - -void Server::add_option(const std::string& arg) -{ - _options.push_back(std::make_pair(arg, std::string())); -} - -void Server::add_option(const std::string& name_, const std::string& value_) -{ - _options.push_back(std::make_pair(name_, value_)); -} - -bool Server::set_socket_file() -{ - libtest::vchar_t file_buffer; - file_buffer.resize(FILENAME_MAX); - file_buffer[0]= 0; - - if (broken_pid_file()) - { - snprintf(&file_buffer[0], file_buffer.size(), "/tmp/%s.socketXXXXXX", name()); - } - else - { - snprintf(&file_buffer[0], file_buffer.size(), "var/run/%s.socketXXXXXX", name()); - } - - int fd; - if ((fd= mkstemp(&file_buffer[0])) == -1) - { - perror(&file_buffer[0]); - return false; - } - close(fd); - unlink(&file_buffer[0]); - - _socket= &file_buffer[0]; - - return true; -} - -bool Server::set_pid_file() -{ - libtest::vchar_t file_buffer; - file_buffer.resize(FILENAME_MAX); - file_buffer[0]= 0; - - if (broken_pid_file()) - { - snprintf(&file_buffer[0], file_buffer.size(), "/tmp/%s.pidXXXXXX", name()); - } - else - { - snprintf(&file_buffer[0], file_buffer.size(), "var/run/%s.pidXXXXXX", name()); - } - - int fd; - if ((fd= mkstemp(&file_buffer[0])) == -1) - { - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "mkstemp() failed on %s with %s", &file_buffer[0], strerror(errno)); - } - close(fd); - unlink(&file_buffer[0]); - - _pid_file= &file_buffer[0]; - - return true; -} - -bool Server::set_log_file() -{ - libtest::vchar_t file_buffer; - file_buffer.resize(FILENAME_MAX); - file_buffer[0]= 0; - - snprintf(&file_buffer[0], file_buffer.size(), "var/log/%s.logXXXXXX", name()); - int fd; - if ((fd= mkstemp(&file_buffer[0])) == -1) - { - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "mkstemp() failed on %s with %s", &file_buffer[0], strerror(errno)); - } - close(fd); - - _log_file= &file_buffer[0]; - - return true; -} - -bool Server::args(Application& app) -{ - - // Set a log file if it was requested (and we can) - if (has_log_file_option()) - { - set_log_file(); - log_file_option(app, _log_file); - } - - if (getenv("LIBTEST_SYSLOG") and has_syslog()) - { - app.add_option("--syslog"); - } - - // Update pid_file - { - if (_pid_file.empty() and set_pid_file() == false) - { - return false; - } - - pid_file_option(app, pid_file()); - } - - if (has_socket_file_option()) - { - if (set_socket_file() == false) - { - return false; - } - - socket_file_option(app, _socket); - } - - if (has_port_option()) - { - port_option(app, _port); - } - - for (Options::const_iterator iter= _options.begin(); iter != _options.end(); ++iter) - { - if ((*iter).first.empty() == false) - { - if ((*iter).second.empty() == false) - { - app.add_option((*iter).first, (*iter).second); - } - else - { - app.add_option((*iter).first); - } - } - } - - return true; -} - -bool Server::kill() -{ - if (check_pid(_app.pid())) // If we kill it, reset - { - _app.murder(); - if (broken_pid_file() and pid_file().empty() == false) - { - unlink(pid_file().c_str()); - } - - if (broken_socket_cleanup() and has_socket() and not socket().empty()) - { - unlink(socket().c_str()); - } - - reset_pid(); - - return true; - } - - return false; -} - -} // namespace libtest diff --git a/src/libtest/server.h b/src/libtest/server.h deleted file mode 100644 index 3e6f1724..00000000 --- a/src/libtest/server.h +++ /dev/null @@ -1,302 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include "libtest/cmdline.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace libtest { - -struct Server { -private: - typedef std::vector< std::pair > Options; - -private: - uint64_t _magic; - bool _is_socket; - std::string _socket; - std::string _sasl; - std::string _pid_file; - std::string _log_file; - std::string _base_command; // executable command which include libtool, valgrind, gdb, etc - std::string _running; // Current string being used for system() - -protected: - in_port_t _port; - std::string _hostname; - std::string _extra_args; - -public: - Server(const std::string& hostname, const in_port_t port_arg, - const std::string& executable, const bool _is_libtool, - const bool is_socket_arg= false); - - virtual ~Server(); - - virtual const char *name()= 0; - virtual bool is_libtool()= 0; - - virtual bool has_socket_file_option() const - { - return false; - } - - virtual void socket_file_option(Application& app, const std::string& socket_arg) - { - if (socket_arg.empty() == false) - { - std::string buffer("--socket="); - buffer+= socket_arg; - app.add_option(buffer); - } - } - - virtual bool has_log_file_option() const - { - return false; - } - - virtual void log_file_option(Application& app, const std::string& arg) - { - if (arg.empty() == false) - { - std::string buffer("--log-file="); - buffer+= arg; - app.add_option(buffer); - } - } - - virtual void pid_file_option(Application& app, const std::string& arg) - { - if (arg.empty() == false) - { - std::string buffer("--pid-file="); - buffer+= arg; - app.add_option(buffer); - } - } - - virtual bool has_port_option() const - { - return false; - } - - virtual void port_option(Application& app, in_port_t arg) - { - if (arg > 0) - { - char buffer[1024]; - snprintf(buffer, sizeof(buffer), "--port=%d", int(arg)); - app.add_option(buffer); - } - } - - virtual bool broken_socket_cleanup() - { - return false; - } - - virtual bool broken_pid_file() - { - return false; - } - - const std::string& pid_file() const - { - return _pid_file; - } - - const std::string& base_command() const - { - return _base_command; - } - - const std::string& log_file() const - { - return _log_file; - } - - const std::string& hostname() const - { - return _hostname; - } - - const std::string& socket() const - { - return _socket; - } - - bool has_socket() const - { - return _is_socket; - } - - bool cycle(); - - virtual bool ping()= 0; - - bool init(const char *argv[]); - virtual bool build()= 0; - - void add_option(const std::string&); - void add_option(const std::string&, const std::string&); - - in_port_t port() const - { - return _port; - } - - bool has_port() const - { - return (_port != 0); - } - - virtual bool has_syslog() const - { - return false; - } - - // Reset a server if another process has killed the server - void reset() - { - _pid_file.clear(); - _log_file.clear(); - } - - std::pair output() - { - return _app.output(); - } - - pid_t pid() const; - - bool has_pid() const; - - virtual bool has_pid_file() const - { - return true; - } - - const std::string& error() - { - return _error; - } - - void error(std::string arg) - { - _error= arg; - } - - void reset_error() - { - _error.clear(); - } - - virtual bool wait_for_pidfile() const; - - bool check_pid(pid_t pid_arg) const - { - return (pid_arg > 1); - } - - bool is_socket() const - { - return _is_socket; - } - - const std::string running() const - { - return _running; - } - - bool check(); - - std::string log_and_pid(); - - bool kill(); - bool start(); - bool command(libtest::Application& app); - - bool validate(); - - void out_of_ban_killed(bool arg) - { - out_of_ban_killed_= arg; - } - - bool out_of_ban_killed() - { - return out_of_ban_killed_; - } - - void timeout(uint32_t timeout_) - { - _timeout= timeout_; - } - -protected: - bool set_pid_file(); - Options _options; - Application _app; - -private: - bool is_helgrind() const; - bool is_valgrind() const; - bool is_debug() const; - bool set_log_file(); - bool set_socket_file(); - void reset_pid(); - bool out_of_ban_killed_; - bool args(Application&); - - std::string _error; - uint32_t _timeout; // This number should be high enough for valgrind startup (which is slow) -}; - -std::ostream& operator<<(std::ostream& output, const libtest::Server &arg); - -} // namespace libtest - - diff --git a/src/libtest/server_container.cc b/src/libtest/server_container.cc deleted file mode 100644 index e6d2f1df..00000000 --- a/src/libtest/server_container.cc +++ /dev/null @@ -1,403 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" - -#include "libtest/common.h" - -#include -#include -#include - -#include -#include -#include - -// trim from end -static inline std::string &rtrim(std::string &s) -{ - s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), s.end()); - return s; -} - -namespace libtest { - -Server* server_startup_st::last() -{ - return servers.back(); -} - -void server_startup_st::push_server(Server *arg) -{ - servers.push_back(arg); - - std::string server_config_string; - if (arg->has_socket()) - { - server_config_string+= "--socket="; - server_config_string+= '"'; - server_config_string+= arg->socket(); - server_config_string+= '"'; - server_config_string+= " "; - } - else - { - libtest::vchar_t port_str; - port_str.resize(NI_MAXSERV); - snprintf(&port_str[0], port_str.size(), "%u", int(arg->port())); - - server_config_string+= "--server="; - server_config_string+= arg->hostname(); - server_config_string+= ":"; - server_config_string+= &port_str[0]; - server_config_string+= " "; - } - - server_list+= server_config_string; -} - -Server* server_startup_st::pop_server() -{ - Server *tmp= servers.back(); - servers.pop_back(); - return tmp; -} - -// host_to_shutdown => host number to shutdown in array -bool server_startup_st::shutdown(uint32_t host_to_shutdown) -{ - if (servers.size() > host_to_shutdown) - { - Server* tmp= servers[host_to_shutdown]; - - if (tmp and tmp->kill() == false) - { } - else - { - return true; - } - } - - return false; -} - -void server_startup_st::clear() -{ - std::for_each(servers.begin(), servers.end(), DeleteFromVector()); - servers.clear(); -} - -bool server_startup_st::check() const -{ - bool success= true; - for (std::vector::const_iterator iter= servers.begin(); iter != servers.end(); ++iter) - { - if ((*iter)->check() == false) - { - success= false; - } - } - - return success; -} - -bool server_startup_st::shutdown() -{ - bool success= true; - for (std::vector::iterator iter= servers.begin(); iter != servers.end(); ++iter) - { - if ((*iter)->has_pid() and (*iter)->kill() == false) - { - Error << "Unable to kill:" << *(*iter); - success= false; - } - } - - return success; -} - -void server_startup_st::restart() -{ - for (std::vector::iterator iter= servers.begin(); iter != servers.end(); ++iter) - { - Server *server = *iter; - - if (server->check()) { - server->kill(); - } - server->start(); - } -} - -#define MAGIC_MEMORY 123575 -server_startup_st::server_startup_st() : - _magic(MAGIC_MEMORY), - _socket(false), - _sasl(false), - udp(0), - _servers_to_run(5) -{ } - -server_startup_st::~server_startup_st() -{ - clear(); -} - -bool server_startup_st::validate() -{ - return _magic == MAGIC_MEMORY; -} - -bool server_startup(server_startup_st& construct, const std::string& server_type, in_port_t try_port, const char *argv[]) -{ - return construct.start_server(server_type, try_port, argv); -} - -libtest::Server* server_startup_st::create(const std::string& server_type, in_port_t try_port, const bool is_socket) -{ - libtest::Server *server= NULL; - - if (is_socket == false) - { - if (try_port <= 0) - { - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "was passed the invalid port number %d", int(try_port)); - } - } - - if (is_socket) - { - if (server_type.compare("memcached") == 0) - { - server= build_memcached_socket("localhost", try_port); - } - else - { - Error << "Socket is not support for server: " << server_type; - return NULL; - } - } - else if (server_type.compare("gearmand") == 0) - { - server= build_gearmand("localhost", try_port); - } - else if (server_type.compare("hostile-gearmand") == 0) - { - server= build_gearmand("localhost", try_port, "gearmand/hostile_gearmand"); - } - else if (server_type.compare("drizzled") == 0) - { - if (has_drizzled()) - { - if (has_libdrizzle()) - { - server= build_drizzled("localhost", try_port); - } - } - } - else if (server_type.compare("blobslap_worker") == 0) - { - if (has_gearmand()) - { -#ifdef GEARMAND_BLOBSLAP_WORKER - if (GEARMAND_BLOBSLAP_WORKER) - { - if (HAVE_LIBGEARMAN) - { - server= build_blobslap_worker(try_port); - } - } -#endif // GEARMAND_BLOBSLAP_WORKER - } - } - else if (server_type.compare("memcached") == 0) - { - if (has_memcached()) - { - server= build_memcached("localhost", try_port); - } - } - else if (server_type == "memcached-sasl") - { - server = build_memcached_sasl("localhost", try_port, _username, _password); - } - - return server; -} - -class ServerPtr { -public: - ServerPtr(libtest::Server* server_): - _server(server_) - { } - - ~ServerPtr() - { - delete _server; - } - - void reset() - { - delete _server; - _server= NULL; - } - - libtest::Server* release(libtest::Server* server_= NULL) - { - libtest::Server* tmp= _server; - _server= server_; - return tmp; - } - - libtest::Server* operator->() const - { - return _server; - } - - libtest::Server* operator&() const - { - return _server; - } - -private: - libtest::Server* _server; -}; - -bool server_startup_st::_start_server(const bool is_socket, - const std::string& server_type, - in_port_t try_port, - const char *argv[]) -{ - try { - ServerPtr server(create(server_type, try_port, is_socket)); - - if (&server == NULL) - { - Error << "Could not allocate server: " << server_type; - return false; - } - - /* - We will now cycle the server we have created. - */ - if (server->cycle() == false) - { - Error << "Could not start up server " << &server; - return false; - } - - server->init(argv); - -#if 0 - if (false) - { - Out << "Pausing for startup, hit return when ready."; - std::string gdb_command= server->base_command(); - getchar(); - } - else -#endif - - if (server->start() == false) - { - return false; - } - else - { - { -#ifdef DEBUG - if (DEBUG) - { - Outn(); - Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running(); - } -#endif - } - } - - push_server(server.release()); - - if (is_socket and &server) - { - set_default_socket(server->socket().c_str()); - } - } - catch (const libtest::disconnected& err) - { - if (fatal::is_disabled() == false and try_port != LIBTEST_FAIL_PORT) - { - stream::cerr(err.file(), err.line(), err.func()) << err.what(); - return false; - } - } - catch (const libtest::__test_result& err) - { - stream::cerr(err.file(), err.line(), err.func()) << err.what(); - return false; - } - catch (const std::exception& err) - { - Error << err.what(); - return false; - } - catch (...) - { - Error << "error occured while creating server: " << server_type; - return false; - } - - return true; -} - -bool server_startup_st::start_server(const std::string& server_type, in_port_t try_port, const char *argv[]) -{ - return _start_server(false, server_type, try_port, argv); -} - -bool server_startup_st::start_socket_server(const std::string& server_type, const in_port_t try_port, const char *argv[]) -{ - return _start_server(true, server_type, try_port, argv); -} - -std::string server_startup_st::option_string() const -{ - std::string temp= server_list; - rtrim(temp); - return temp; -} - - -} // namespace libtest diff --git a/src/libtest/server_container.h b/src/libtest/server_container.h deleted file mode 100644 index 88e4763d..00000000 --- a/src/libtest/server_container.h +++ /dev/null @@ -1,151 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace libtest { - -class server_startup_st -{ -private: - uint64_t _magic; - std::string server_list; - bool _socket; - bool _sasl; - std::string _username; - std::string _password; - -public: - - uint8_t udp; - std::vector servers; - - server_startup_st(); - ~server_startup_st(); - - bool validate(); - - bool start_socket_server(const std::string& server_type, const in_port_t try_port, const char *argv[]); - bool start_server(const std::string& server_type, const in_port_t try_port, const char *argv[]); - - uint32_t count() const - { - return uint32_t(servers.size()); - } - - void restart(); - - std::string option_string() const; - - const std::string& password() const - { - return _password; - } - - const std::string& username() const - { - return _username; - } - - bool socket() - { - return _socket; - } - - bool sasl() - { - return _sasl; - } - - void set_socket() - { - _socket= true; - } - - void set_sasl(const std::string& username_arg, const std::string& password_arg) - { - _sasl= true; - _username= username_arg; - _password= password_arg; - } - - - // Just remove everything after shutdown - void clear(); - - bool shutdown(); - bool shutdown(uint32_t number_of_host); - - bool check() const; - - void push_server(Server *); - Server* last(); - Server *pop_server(); - - Server* create(const std::string& server_type, in_port_t try_port, const bool is_socket); - - unsigned long int servers_to_run() const - { - return _servers_to_run; - } - - void set_servers_to_run(unsigned long int arg) - { - _servers_to_run= arg; - } - -private: - bool _start_server(const bool is_socket, - const std::string& server_type, - const in_port_t try_port, - const char *argv[]); - -private: - unsigned long int _servers_to_run; -}; - -bool server_startup(server_startup_st&, const std::string&, in_port_t try_port, const char *argv[]); - -} // namespace libtest diff --git a/src/libtest/signal.cc b/src/libtest/signal.cc deleted file mode 100644 index bf257251..00000000 --- a/src/libtest/signal.cc +++ /dev/null @@ -1,259 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - -#include - -#include "libtest/signal.h" - -using namespace libtest; - -#define MAGIC_MEMORY 123569 - -bool SignalThread::is_shutdown() -{ - bool ret; - pthread_mutex_lock(&shutdown_mutex); - ret= bool(__shutdown != SHUTDOWN_RUNNING); - pthread_mutex_unlock(&shutdown_mutex); - - return ret; -} - -void SignalThread::set_shutdown(shutdown_t arg) -{ - pthread_mutex_lock(&shutdown_mutex); - __shutdown= arg; - pthread_mutex_unlock(&shutdown_mutex); - - if (arg == SHUTDOWN_GRACEFUL) - { - if (pthread_kill(thread, SIGUSR2) == 0) - { - void *retval; - pthread_join(thread, &retval); - } - } -} - -shutdown_t SignalThread::get_shutdown() -{ - shutdown_t local; - pthread_mutex_lock(&shutdown_mutex); - local= __shutdown; - pthread_mutex_unlock(&shutdown_mutex); - - return local; -} - -void SignalThread::post() -{ - sem_post(&lock); -} - -void SignalThread::test() -{ - assert(magic_memory == MAGIC_MEMORY); - if (bool(getenv("LIBTEST_IN_GDB")) == false) - { - assert(sigismember(&set, SIGALRM)); - assert(sigismember(&set, SIGABRT)); - assert(sigismember(&set, SIGQUIT)); - assert(sigismember(&set, SIGINT)); - assert(sigismember(&set, SIGVTALRM)); - } - assert(sigismember(&set, SIGUSR2)); -} - -bool SignalThread::unblock() -{ - int error; - if ((error= pthread_sigmask(SIG_UNBLOCK, &set, NULL)) != 0) - { - Error << "While trying to reset signal mask to original set, pthread_sigmask() died during pthread_sigmask(" << strerror(error) << ")"; - return false; - } - - return true; -} - -SignalThread::~SignalThread() -{ - if (is_shutdown() == false) - { - set_shutdown(SHUTDOWN_GRACEFUL); - } - -#if 0 - if (pthread_equal(thread, pthread_self()) != 0 and (pthread_kill(thread, 0) == ESRCH) == true) - { - void *retval; - pthread_join(thread, &retval); - } -#endif - sem_destroy(&lock); - - unblock(); -} - -extern "C" { - -static void *sig_thread(void *arg) -{ - SignalThread *context= (SignalThread*)arg; - - context->test(); - context->post(); - - while (context->get_shutdown() == SHUTDOWN_RUNNING) - { - int sig; - - if (context->wait(sig) == -1) - { - Error << "sigwait() returned errno:" << strerror(errno); - continue; - } - - switch (sig) - { - case SIGALRM: - case SIGVTALRM: - Error << strsignal(sig); - if (gdb_is_caller()) - { - abort(); - } - exit(EXIT_FAILURE); - - case SIGABRT: - case SIGUSR2: - case SIGINT: - case SIGQUIT: - if (context->is_shutdown() == false) - { - context->set_shutdown(SHUTDOWN_FORCED); - } - break; - case SIGPIPE: - { - Error << "Ignoring SIGPIPE"; - } - break; - - case 0: - Error << "Inside of gdb"; - break; - - default: - Error << "Signal handling thread got unexpected signal " << strsignal(sig); - break; - } - } - - return NULL; -} - -} - -SignalThread::SignalThread() : - magic_memory(MAGIC_MEMORY), - thread(pthread_self()) -{ - pthread_mutex_init(&shutdown_mutex, NULL); - sigemptyset(&set); - if (bool(getenv("LIBTEST_IN_GDB")) == false) - { - sigaddset(&set, SIGALRM); - sigaddset(&set, SIGABRT); - sigaddset(&set, SIGQUIT); - sigaddset(&set, SIGINT); - sigaddset(&set, SIGVTALRM); - } - sigaddset(&set, SIGPIPE); - - sigaddset(&set, SIGUSR2); - - sem_init(&lock, 0, 0); - - sigemptyset(&original_set); - pthread_sigmask(SIG_BLOCK, NULL, &original_set); -} - - -bool SignalThread::setup() -{ - set_shutdown(SHUTDOWN_RUNNING); - - if (sigismember(&original_set, SIGQUIT)) - { - Error << strsignal(SIGQUIT) << " has been previously set."; - } - - if (sigismember(&original_set, SIGINT)) - { - Error << strsignal(SIGINT) << " has been previously set."; - } - - if (sigismember(&original_set, SIGVTALRM)) - { - Error << strsignal(SIGVTALRM) << " has been previously set."; - } - - if (sigismember(&original_set, SIGUSR2)) - { - Error << strsignal(SIGUSR2) << " has been previously set."; - } - - int error; - if ((error= pthread_sigmask(SIG_BLOCK, &set, NULL)) != 0) - { - Error << "pthread_sigmask() died during pthread_sigmask(" << strerror(error) << ")"; - return false; - } - - if ((error= pthread_create(&thread, NULL, &sig_thread, this)) != 0) - { - Error << "pthread_create() died during pthread_create(" << strerror(error) << ")"; - return false; - } - - sem_wait(&lock); - - return true; -} diff --git a/src/libtest/signal.h b/src/libtest/signal.h deleted file mode 100644 index 6e68bb38..00000000 --- a/src/libtest/signal.h +++ /dev/null @@ -1,80 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include -#include -#include - -enum shutdown_t { - SHUTDOWN_RUNNING, - SHUTDOWN_GRACEFUL, - SHUTDOWN_FORCED -}; - -namespace libtest { - -class SignalThread { - sigset_t set; - sem_t lock; - uint64_t magic_memory; - volatile shutdown_t __shutdown; - pthread_mutex_t shutdown_mutex; - pthread_t thread; - sigset_t original_set; - -public: - - SignalThread(); - ~SignalThread(); - - void test(); - void post(); - bool setup(); - bool unblock(); - - int wait(int& sig) - { - return sigwait(&set, &sig); - } - - void set_shutdown(shutdown_t arg); - bool is_shutdown(); - shutdown_t get_shutdown(); -}; - -} // namespace libtest diff --git a/src/libtest/skiptest.cc b/src/libtest/skiptest.cc deleted file mode 100644 index 6ff0e7e8..00000000 --- a/src/libtest/skiptest.cc +++ /dev/null @@ -1,57 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" - -#include "libtest/test.hpp" - -#include -#include - -using namespace libtest; - - -static void *world_create(server_startup_st&, test_return_t& rc) -{ - rc= TEST_SKIPPED; - - return NULL; -} - -void get_world(libtest::Framework *world) -{ - world->create(world_create); -} diff --git a/src/libtest/socket.cc b/src/libtest/socket.cc deleted file mode 100644 index a681dd82..00000000 --- a/src/libtest/socket.cc +++ /dev/null @@ -1,62 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "libtest/yatlcon.h" -#include "libtest/common.h" - -static char global_socket[1024]= { 0 }; - -namespace libtest { - -const char *default_socket() -{ - if (global_socket[0] == 0) - { - return NULL; - } - - return global_socket; -} - -void set_default_socket(const char *socket) -{ - if (socket) - { - strncpy(global_socket, socket, sizeof(global_socket)-1); - } -} - -} diff --git a/src/libtest/socket.hpp b/src/libtest/socket.hpp deleted file mode 100644 index 9d13c341..00000000 --- a/src/libtest/socket.hpp +++ /dev/null @@ -1,47 +0,0 @@ - -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -namespace libtest { - -const char *default_socket(); - -void set_default_socket(const char *socket); - -} // namespace libtest - diff --git a/src/libtest/stream.h b/src/libtest/stream.h deleted file mode 100644 index 0124b9d2..00000000 --- a/src/libtest/stream.h +++ /dev/null @@ -1,266 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Data Differential YATL (i.e. libtest) library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace libtest { -namespace stream { - -namespace detail { - -template - class channel { - private: - - public: - typedef std::basic_ostringstream stream_buffer; - - public: - void operator()(const stream_buffer& s, std::ostream& _out, - const char* filename, int line_number, const char* func) - { - if (filename) - { - _out - << filename - << ":" - << line_number - << ": in " - << func << "() " - << s.str() - << std::endl; - } - else - { - _out - << s.str() - << std::endl; - } - } - }; - -template - class channelln { - private: - - public: - typedef std::basic_ostringstream stream_buffer; - - public: - void operator()(const stream_buffer& s, std::ostream& _out, - const char* filename, int line_number, const char* func) - { - if (filename) - { - _out - << std::endl - << filename - << ":" - << line_number - << ": in " - << func << "() " - << s.str() - << std::endl; - } - else - { - _out - << std::endl - << s.str() - << std::endl; - } - } - }; - -template - class channelfl { - private: - - public: - typedef std::basic_ostringstream stream_buffer; - - public: - void operator()(const stream_buffer& s, std::ostream& _out, - const char* filename, int line_number, const char* func) - { - if (filename) - { - _out - << filename - << ":" - << line_number - << ": in " - << func << "() " - << s.str() - << std::flush; - } - else - { - _out - << s.str() - << std::flush; - } - } - }; - -template