+++ /dev/null
-
-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)
+++ /dev/null
-/* 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 <sys/time.h>
-#include <cstdlib>
-
-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
-
+++ /dev/null
-/* 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
-
+++ /dev/null
-/* 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 <cerrno>
-#include <csignal>
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-#include <iostream>
-
-#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);
-}
+++ /dev/null
-/* 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 {
-
-}
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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 <cassert>
-#include <cerrno>
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-#include <iostream>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-#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 <sstream>
-
-bool BlobslapWorker::build()
-{
- return true;
-}
-
-Server *build_blobslap_worker(in_port_t try_port)
-{
- return new BlobslapWorker(try_port);
-}
-
-} // namespace libtest
+++ /dev/null
-/* 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);
-
-}
+++ /dev/null
-/* 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
-
+++ /dev/null
-/* 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 <sys/types.h>
-#include <sys/socket.h>
-#include <unistd.h>
-#include <string>
-
-#ifdef HAVE_POLL_H
-# include <poll.h>
-#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
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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 <cstdlib>
-#include <cstring>
-#include <cerrno>
-#include <fcntl.h>
-#include <fstream>
-#include <memory>
-#ifdef HAVE_POLL_H
-# include <poll.h>
-#endif
-#ifdef HAVE_SPAWN_H
-# include <spawn.h>
-#endif
-#include <sstream>
-#include <string>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <algorithm>
-#include <stdexcept>
-
-#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<char *>(libtool()),
- const_cast<char *>("--mode=execute"),
- const_cast<char *>("gdb"),
- const_cast<char *>("-batch"),
- const_cast<char *>("-f"),
- const_cast<char *>("-x"),
- const_cast<char *>(gdb_run_file.c_str()),
- const_cast<char *>(_exectuble_with_path.c_str()),
- 0};
-
- spawn_ret= posix_spawnp(&_pid, libtool(), &file_actions, &spawnattr, argv, environ);
- }
- else
- {
- // gdb binary
- char *argv[]= {
- const_cast<char *>("gdb"),
- const_cast<char *>("-batch"),
- const_cast<char *>("-f"),
- const_cast<char *>("-x"),
- const_cast<char *>(gdb_run_file.c_str()),
- const_cast<char *>(_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<std::string, std::string> 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
+++ /dev/null
-/* 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 <spawn.h>
-
-// 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<std::string, std::string> > 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<std::string, std::string> 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);
-
-}
+++ /dev/null
-/* 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
-
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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 <cassert>
-#include <cerrno>
-#include <cstdlib>
-#include <sstream>
-#include <string>
-
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
-#endif
-
-#ifdef HAVE_SYS_WAIT_H
-# include <sys/wait.h>
-#endif
-
-#ifdef HAVE_SYS_RESOURCE_H
-# include <sys/resource.h>
-#endif
-
-#ifdef HAVE_FNMATCH_H
-# include <fnmatch.h>
-#endif
-
-#ifdef HAVE_ARPA_INET_H
-# include <arpa/inet.h>
-#endif
-
-#if defined(WIN32)
-# include "win32/wrappers.h"
-# define get_socket_errno() WSAGetLastError()
-#else
-# ifdef HAVE_UNISTD_H
-# include <unistd.h>
-# 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 <class T>
- void operator() ( T* ptr) const
- {
- if (ptr)
- {
- free(ptr);
- ptr= NULL;
- }
- }
-};
-
-struct DeleteFromVector
-{
- template <class T>
- void operator() ( T* ptr) const
- {
- delete ptr;
- ptr= NULL;
- }
-};
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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 <typeinfo>
-
-#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 <libgearman-1.0/ostream.hpp>
-#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 <class T_comparable>
-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 <class T1_comparable, class T2_comparable>
-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 <class T1_comparable, class T2_comparable>
-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 <class T_comparable>
-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 <class T1_comparable, class T2_comparable>
-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 <class T_comparable, class T_expression_string>
-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
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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 <cstdlib>
-#include <fcntl.h>
-#include <getopt.h>
-#include <iostream>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#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;
-}
+++ /dev/null
-/* 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 <unistd.h>
-
-#pragma GCC diagnostic ignored "-Wundef"
-
-#if defined(HAVE_LINUX_SYSCTL_H) && HAVE_LINUX_SYSCTL_H
-#include <linux/sysctl.h>
-#elif defined(HAVE_SYS_SYSCTL_H) && HAVE_SYS_SYSCTL_H
-#include <sys/sysctl.h>
-#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
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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 <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-
-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
-
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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
-}
-
-}
+++ /dev/null
-/* 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);
-
-}
-
+++ /dev/null
-/* 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 <cassert>
-#include <cerrno>
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-#include <iostream>
-#include <signal.h>
-#include <sstream>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-#ifndef __INTEL_COMPILER
-#pragma GCC diagnostic ignored "-Wold-style-cast"
-#endif
-
-#if defined(HAVE_LIBDRIZZLE) && HAVE_LIBDRIZZLE
-# include <libdrizzle-5.1/drizzle_client.h>
-#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);
-}
-
-}
+++ /dev/null
-/* 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 <arpa/inet.h>
-
-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);
-
-}
-
+++ /dev/null
-/* 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);
-}
+++ /dev/null
-/* 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 <cstdarg>
-
-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
-
+++ /dev/null
-/* 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
-
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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 <cstdarg>
-
-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
+++ /dev/null
-/* 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); }
+++ /dev/null
-/* 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 <iostream>
-#include <string>
-#include <vector>
-
-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<failed_st> 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
+++ /dev/null
-/* 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 <algorithm>
-#include <fstream>
-#include <iostream>
-#include <ostream>
-
-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 << "<testsuites name="
- << escape4XML(framework_.name(), escaped_string) << ">" << std::endl;
-
- for (Suites::iterator framework_iter= framework_.suites().begin();
- framework_iter != framework_.suites().end();
- ++framework_iter)
- {
- output << "\t<testsuite name="
- << escape4XML((*framework_iter)->name(), escaped_string)
-#if 0
- << " classname=\"\" package=\"\""
-#endif
- << ">" << std::endl;
-
- for (TestCases::iterator case_iter= (*framework_iter)->formatter()->testcases().begin();
- case_iter != (*framework_iter)->formatter()->testcases().end();
- ++case_iter)
- {
- output << "\t\t<testcase name="
- << escape4XML((*case_iter)->name(), escaped_string)
- << " time=\""
- << (*case_iter)->timer().elapsed_milliseconds()
- << "\"";
-
- switch ((*case_iter)->result())
- {
- case TEST_SKIPPED:
- output << ">" << std::endl;
- output << "\t\t <skipped/>" << std::endl;
- output << "\t\t</testcase>" << std::endl;
- break;
-
- case TEST_FAILURE:
- output << ">" << std::endl;
- output << "\t\t <failure message=\"\" type=\"\"/>"<< std::endl;
- output << "\t\t</testcase>" << std::endl;
- break;
-
- case TEST_SUCCESS:
- output << "/>" << std::endl;
- break;
- }
- }
- output << "\t</testsuite>" << std::endl;
- }
- output << "</testsuites>" << 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
+++ /dev/null
-/* 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 <string>
-
-namespace libtest { class Framework; }
-
-
-namespace libtest {
-
-class TestCase;
-typedef std::vector<libtest::TestCase*> 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
+++ /dev/null
-/* 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 <algorithm>
-#include <fnmatch.h>
-#include <iostream>
-
-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<Collection*>::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<Collection*>::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<Collection*>::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<Collection*>::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<Collection*>::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
+++ /dev/null
-/* 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 <vector>
-
-namespace { class Collection; }
-typedef std::vector<libtest::Collection*> 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
+++ /dev/null
-/* 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 <cassert>
-#include <cerrno>
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-#include <iostream>
-#include <signal.h>
-#include <sstream>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-#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);
-}
-
-}
+++ /dev/null
-/* 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);
-
-}
+++ /dev/null
-/* 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
-
-
+++ /dev/null
-/* 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 <cstdio>
-#include <cstdlib>
-#include <unistd.h>
-
-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
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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 <curl/curl.h>
-#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
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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
-
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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;
-}
-
+++ /dev/null
-/* 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 <cstdlib>
-#include <cstring>
-#include <iostream>
-#include <sstream>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
-
-#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;
-}
+++ /dev/null
-/* 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);
-}
+++ /dev/null
-/* 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 <string>
-
-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
+++ /dev/null
-/* 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);
-
-}
+++ /dev/null
-/* 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 <cstdarg>
-# include <cstddef>
-# include <cstdio>
-# include <cstdlib>
-# include <cstring>
-#else
-# include <stdarg.h>
-# include <stdbool.h>
-# include <stddef.h>
-# include <stdio.h>
-# include <stdlib.h>
-# include <string.h>
-#endif
-
-#if defined(WIN32)
-# include <malloc.h>
-#else
-# include <alloca.h>
-#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)
+++ /dev/null
-/* 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 <cassert>
-#include <cstdlib>
-#include <cstring>
-#include <ctime>
-#include <fnmatch.h>
-#include <iostream>
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-#include <fstream>
-#include <memory>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-#include <signal.h>
-
-#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 <getopt.h>
-#include <unistd.h>
-
-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<libtest::Framework> 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;
-}
+++ /dev/null
-/* 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 <cassert>
-#include <cerrno>
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-#include <iostream>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-#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 <sstream>
-
-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
+++ /dev/null
-/* 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);
-
-}
-
+++ /dev/null
-/* 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<memcached_st *>(&memc)) == rc)
- {
- return true;
- }
-
- return false;
-}
-
-inline bool operator!= (const memcached_st& memc, memcached_return_t rc)
-{
- if (memcached_last_error(const_cast<memcached_st *>(&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<memcached_st *>(&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
-
+++ /dev/null
-/* 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 <cstdio>
-#include <poll.h>
-
-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");
- }
-}
+++ /dev/null
-/* 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 <cassert>
-#include <cstdlib>
-#include <cstring>
-#include <ctime>
-#include <fnmatch.h>
-#include <iostream>
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-#include <utility>
-#include <vector>
-
-#include <signal.h>
-
-#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
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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 <cstdarg>
-
-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
+++ /dev/null
-/* 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)
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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
+++ /dev/null
-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
+++ /dev/null
-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
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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
+++ /dev/null
-/* 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 <cassert>
-#include <cerrno>
-#include <climits>
-#include <cstdlib>
-#include <iostream>
-#include <string>
-
-#include <algorithm>
-#include <functional>
-#include <locale>
-#include <unistd.h>
-
-// 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<int, int>(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
+++ /dev/null
-/* 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 <cassert>
-#include <cstdio>
-#include <cstring>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <string>
-#include <unistd.h>
-#include <vector>
-
-namespace libtest {
-
-struct Server {
-private:
- typedef std::vector< std::pair<std::string, std::string> > 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<std::string, std::string> 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
-
-
+++ /dev/null
-/* 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 <cerrno>
-#include <cstdlib>
-#include <iostream>
-
-#include <algorithm>
-#include <functional>
-#include <locale>
-
-// 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<int, int>(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<Server *>::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<Server *>::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<Server *>::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
+++ /dev/null
-/* 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 <cassert>
-#include <cstdio>
-#include <cstring>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <string>
-#include <unistd.h>
-#include <vector>
-
-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<Server *> 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
+++ /dev/null
-/* 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 <csignal>
-
-#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;
-}
+++ /dev/null
-/* 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 <pthread.h>
-#include <semaphore.h>
-#include <signal.h>
-
-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
+++ /dev/null
-/* 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 <cstdlib>
-#include <unistd.h>
-
-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);
-}
+++ /dev/null
-/* 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);
- }
-}
-
-}
+++ /dev/null
-
-/* 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
-
+++ /dev/null
-/* 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 <iostream>
-#include <cassert>
-#include <sstream>
-#include <ctime>
-#include <ostream>
-
-namespace libtest {
-namespace stream {
-
-namespace detail {
-
-template<class Ch, class Tr, class A>
- class channel {
- private:
-
- public:
- typedef std::basic_ostringstream<Ch, Tr, A> 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 Ch, class Tr, class A>
- class channelln {
- private:
-
- public:
- typedef std::basic_ostringstream<Ch, Tr, A> 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 Ch, class Tr, class A>
- class channelfl {
- private:
-
- public:
- typedef std::basic_ostringstream<Ch, Tr, A> 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<template <class Ch, class Tr, class A> class OutputPolicy, class Ch = char, class Tr = std::char_traits<Ch>, class A = std::allocator<Ch> >
- class log {
- private:
- typedef OutputPolicy<Ch, Tr, A> output_policy;
-
- private:
- std::ostream& _out;
- const char *_filename;
- int _line_number;
- const char *_func;
-
- public:
- log(std::ostream& out_arg, const char* filename, int line_number, const char* func) :
- _out(out_arg),
- _filename(filename),
- _line_number(line_number),
- _func(func)
- { }
-
- virtual ~log()
- {
- output_policy()(arg, _out, _filename, _line_number, _func);
- }
-
- public:
- template<class T>
- log &operator<<(const T &x)
- {
- arg << x;
- return *this;
- }
-
- private:
- typename output_policy::stream_buffer arg;
-
- private:
- log( const log& );
- const log& operator=( const log& );
- };
-} // namespace detail
-
-class make_cerr : public detail::log<detail::channelln> {
-public:
- make_cerr(const char* filename, int line_number, const char* func) :
- detail::log<detail::channelln>(std::cerr, filename, line_number, func)
- { }
-
-private:
- make_cerr( const make_cerr& );
- const make_cerr& operator=( const make_cerr& );
-};
-
-class cerr : public detail::log<detail::channel> {
-public:
- cerr(const char* filename, int line_number, const char* func) :
- detail::log<detail::channel>(std::cout, filename, line_number, func)
- { }
-
-private:
- cerr( const cerr& );
- const cerr& operator=( const cerr& );
-};
-
-class clog : public detail::log<detail::channel> {
-public:
- clog(const char* filename, int line_number, const char* func) :
- detail::log<detail::channel>(std::clog, filename, line_number, func)
- { }
-
-private:
- clog( const clog& );
- const clog& operator=( const clog& );
-};
-
-class make_cout : public detail::log<detail::channelln> {
-public:
- make_cout(const char* filename, int line_number, const char* func) :
- detail::log<detail::channelln>(std::cout, filename, line_number, func)
- { }
-
-private:
- make_cout( const make_cout& );
- const make_cout& operator=( const make_cout& );
-};
-
-class cout : public detail::log<detail::channel> {
-public:
- cout(const char* filename, int line_number, const char* func) :
- detail::log<detail::channel>(std::cout, filename, line_number, func)
- { }
-
-private:
- cout( const cout& );
- const cout& operator=( const cout& );
-};
-
-class cecho : public detail::log<detail::channelfl> {
-public:
- cecho(const char* filename, int line_number, const char* func) :
- detail::log<detail::channelfl>(std::cout, filename, line_number, func)
- { }
-
-private:
- cecho( const cecho& );
- const cecho& operator=( const cecho& );
-};
-
-} // namespace stream
-
-#define Error stream::cerr(__FILE__, __LINE__, __func__)
-
-#define Echo stream::cecho(NULL, __LINE__, __func__)
-
-#define Out stream::cout(NULL, __LINE__, __func__)
-
-#define Outn() stream::cout(NULL, __LINE__, __func__) << " "
-
-#define Log stream::clog(NULL, __LINE__, __func__)
-
-#define Logn() stream::clog(NULL, __LINE__, __func__) << " "
-
-} // namespace libtest
+++ /dev/null
-/* 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 {
-
-const char *test_strerror(test_return_t code)
-{
- switch (code) {
- case TEST_SUCCESS:
- return "ok";
-
- case TEST_FAILURE:
- return "failed";
-
- case TEST_SKIPPED:
- return "skipped";
- }
-
- FATAL("No port could be found");
-}
-
-} // namespace libtest
-
-
-std::ostream& operator<<(std::ostream& output, const enum test_return_t &arg)
-{
- output << libtest::test_strerror(arg);
- return output;
-}
-
-std::ostream& operator<<(std::ostream& output, const std::vector<char> &arg)
-{
- output << "std::vector<char>:" << arg.size();
- return output;
-}
+++ /dev/null
-/* 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 <vector>
-#include <iostream>
-
-namespace libtest {
-
-/**
- @note Friendly print function for errors.
-*/
-LIBTEST_API
-const char *test_strerror(test_return_t code);
-
-} // namespace libtest
-
-std::ostream& operator<<(std::ostream& output, const enum test_return_t &arg);
-std::ostream& operator<<(std::ostream& output, const std::vector<char> &arg);
-
+++ /dev/null
-/* 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 "util/string.hpp"
-
-#define test_literal_param util_literal_param
-#define test_literal_compare_param util_literal_compare_param
-#define test_literal_param_size util_literal_param_size
-#define test_string_make_from_cstr util_string_make_from_cstr
-#define test_string_make_from_array util_string_make_from_array
-#define test_array_length util_array_length
+++ /dev/null
-/* 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
-
-#ifndef __INTEL_COMPILER
-#pragma GCC diagnostic ignored "-Wold-style-cast"
-#endif
-
-#include "libtest/lite.h"
-
-/**
- A structure describing the test case.
-*/
-struct test_st {
- const char *name;
- bool requires_flush;
- test_callback_fn *test_fn;
-};
-
-#define test_assert_errno(A) \
-do \
-{ \
- if ((A)) { \
- fprintf(stderr, "\n%s:%d: Assertion failed for %s: ", __FILE__, __LINE__, __func__);\
- perror(#A); \
- fprintf(stderr, "\n"); \
- libtest::create_core(); \
- assert((A)); \
- } \
-} while (0)
-
-#define test_truth(A) \
-do \
-{ \
- if (! (A)) { \
- fprintf(stderr, "\n%s:%d: Assertion \"%s\" failed, in %s\n", __FILE__, __LINE__, #A, __func__);\
- libtest::create_core(); \
- return TEST_FAILURE; \
- } \
-} while (0)
-
-#define test_true(A) \
-do \
-{ \
- if (! (A)) { \
- fprintf(stderr, "\n%s:%d: Assertion \"%s\" failed, in %s\n", __FILE__, __LINE__, #A, __func__);\
- libtest::create_core(); \
- return TEST_FAILURE; \
- } \
-} while (0)
-
-#define test_true_got(A, B) test_true(A);
-#define test_true_hint(A, B) test_true(A);
-
-#define test_compare_hint(A, B, C) test_compare(A, B);
-#define test_compare_got(A, B, C) test_compare(A, B);
-
-#define test_skip(__expected, __actual) \
-do \
-{ \
- if (libtest::_compare(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)), false) == false) \
- { \
- return TEST_SKIPPED; \
- } \
-} while (0)
-
-#define test_skip_valgrind() \
-do \
-{ \
- if (libtest::_in_valgrind(__FILE__, __LINE__, __func__)) \
- { \
- return TEST_SKIPPED; \
- } \
-} while (0)
-
-#define test_fail(A) \
-do \
-{ \
- if (1) { \
- fprintf(stderr, "\n%s:%d: Failed with %s, in %s\n", __FILE__, __LINE__, #A, __func__);\
- libtest::create_core(); \
- return TEST_FAILURE; \
- } \
-} while (0)
-
-
-#define test_false(A) \
-do \
-{ \
- if ((A)) { \
- fprintf(stderr, "\n%s:%d: Assertion failed %s, in %s\n", __FILE__, __LINE__, #A, __func__);\
- libtest::create_core(); \
- return TEST_FAILURE; \
- } \
-} while (0)
-
-#define test_false_with(A,B) \
-do \
-{ \
- if ((A)) { \
- fprintf(stderr, "\n%s:%d: Assertion failed %s with %s\n", __FILE__, __LINE__, #A, (B));\
- libtest::create_core(); \
- return TEST_FAILURE; \
- } \
-} while (0)
-
-#define test_ne_compare(__expected, __actual) \
-do \
-{ \
- if (libtest::_ne_compare(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)), true) == false) \
- { \
- libtest::create_core(); \
- return TEST_FAILURE; \
- } \
-} while (0)
-
-#define test_compare(__expected, __actual) \
-do \
-{ \
- if (libtest::_compare(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)), true) == false) \
- { \
- libtest::create_core(); \
- return TEST_FAILURE; \
- } \
-} while (0)
-
-#define test_zero(__actual) \
-do \
-{ \
- if (libtest::_compare_zero(__FILE__, __LINE__, __func__, ((__actual))) == false) \
- { \
- libtest::create_core(); \
- return TEST_FAILURE; \
- } \
-} while (0)
-
-#define test_null test_zero
-
-#define test_compare_warn(__expected, __actual) \
-do \
-{ \
- void(libtest::_compare(__FILE__, __LINE__, __func__, (__expected), (__actual)), true); \
-} while (0)
-
-#define test_warn(__truth, __explain) \
-do \
-{ \
- void(libtest::_assert_truth(__FILE__, __LINE__, __func__, bool((__truth)), #__truth, __explain)); \
-} while (0)
-
-#define test_strcmp(__expected, __actual) \
-do \
-{ \
- void(libtest::_compare_strcmp(__FILE__, __LINE__, __func__, (__expected), (__actual))); \
-} while (0)
-
-#define test_memcmp(A,B,C) \
-do \
-{ \
- if ((A) == NULL or (B) == NULL or memcmp((A), (B), (C))) \
- { \
- fprintf(stderr, "\n%s:%d: %.*s -> %.*s\n", __FILE__, __LINE__, (int)(C), (char *)(A), (int)(C), (char *)(B)); \
- libtest::create_core(); \
- return TEST_FAILURE; \
- } \
-} while (0)
-
-#define test_return_if(__test_return_t) \
-do \
-{ \
- if ((__test_return_t) != TEST_SUCCESS) \
- { \
- return __test_return_t; \
- } \
-} while (0)
-
+++ /dev/null
-/* 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
-
-#ifndef YATL_FULL
-# define YATL_FULL 1
-#endif
-
-#ifndef __PRETTY_FUNCTION__
-# define __PRETTY_FUNCTION__ __func__
-#endif
-
-#define YATL_STRINGIFY(x) #x
-#define YATL_TOSTRING(x) YATL_STRINGIFY(x)
-#define YATL_AT __FILE__ ":" YATL_TOSTRING(__LINE__)
-#define YATL_AT_PARAM __func__, AT
-#define YATL_UNIQUE __FILE__ ":" YATL_TOSTRING(__LINE__) "_unique"
-#define YATL_UNIQUE_FUNC_NAME __FILE__ ":" YATL_TOSTRING(__LINE__) "_unique_func"
-
-#define LIBYATL_DEFAULT_PARAM __FILE__, __LINE__, __PRETTY_FUNCTION__
-
-#include <cstdio>
-#include <cstdlib>
-#include <arpa/inet.h>
-
-#include "libtest/visibility.h"
-#include "libtest/version.h"
-
-#include "libtest/vchar.hpp"
-#include "libtest/error.h"
-#include "libtest/exception.hpp"
-#include "libtest/exception/disconnected.hpp"
-#include "libtest/exception/fatal.hpp"
-#include "libtest/result.hpp"
-
-#include "libtest/has.hpp"
-#include "libtest/error.h"
-#include "libtest/strerror.h"
-#include "libtest/timer.hpp"
-#include "libtest/alarm.h"
-#include "libtest/stream.h"
-#include "libtest/comparison.hpp"
-#include "libtest/server.h"
-#include "libtest/server_container.h"
-#include "libtest/wait.h"
-#include "libtest/callbacks.h"
-#include "libtest/test.h"
-#include "libtest/dream.h"
-#include "libtest/core.h"
-#include "libtest/runner.h"
-#include "libtest/port.h"
-#include "libtest/is_local.hpp"
-#include "libtest/socket.hpp"
-#include "libtest/collection.h"
-#include "libtest/framework.h"
-#include "libtest/get.h"
-#include "libtest/cmdline.h"
-#include "libtest/string.hpp"
-#include "libtest/binaries.h"
-#include "libtest/http.hpp"
-#include "libtest/cpu.hpp"
-#include "libtest/tmpfile.hpp"
-#include "libtest/client.hpp"
-#include "libtest/thread.hpp"
+++ /dev/null
-/* 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 <pthread.h>
-
-#if __cplusplus < 201103L
-# define noexcept(a)
-#endif
-
-namespace libtest
-{
-namespace thread
-{
-
-class Mutex
-{
-public:
- Mutex() :
- _err(0)
- {
- _err= pthread_mutex_init(&_mutex, NULL);
- }
-
- ~Mutex() noexcept(false)
- {
- if ((_err= pthread_mutex_destroy(&_mutex)))
- {
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_cond_destroy: %s", strerror(_err));
- }
- }
-
- pthread_mutex_t* handle()
- {
- if (_err != 0)
- {
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_mutex_init: %s", strerror(_err));
- }
-
- return &_mutex;
- }
-
-private:
- int _err;
- pthread_mutex_t _mutex;
-};
-
-class ScopedLock
-{
-public:
- ScopedLock(Mutex& mutex_) :
- _mutex(mutex_)
- {
- init();
- }
-
- ~ScopedLock() noexcept(false)
- {
- int err;
- if ((err= pthread_mutex_unlock(_mutex.handle())))
- {
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_mutex_unlock: %s", strerror(err));
- }
- }
-
- Mutex* handle()
- {
- return &_mutex;
- }
-
-private:
- void init()
- {
- int err;
- if ((err= pthread_mutex_lock(_mutex.handle())))
- {
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_mutex_lock: %s", strerror(err));
- }
- }
-
-private:
- Mutex& _mutex;
-};
-
-class Condition
-{
-public:
- Condition()
- {
- int err;
- if ((err= pthread_cond_init(&_cond, NULL)))
- {
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_mutex_init: %s", strerror(err));
- }
- }
-
- ~Condition() noexcept(false)
- {
- int err;
- if ((err= pthread_cond_destroy(&_cond)))
- {
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_cond_destroy: %s", strerror(err));
- }
- }
-
- void broadcast()
- {
- int err;
- if ((err= pthread_cond_broadcast(&_cond)))
- {
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_cond_broadcast: %s", strerror(err));
- }
- }
-
- void signal()
- {
- int err;
- if ((err= pthread_cond_signal(&_cond)))
- {
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_cond_broadcast: %s", strerror(err));
- }
- }
-
- void wait(ScopedLock& lock_)
- {
- int err;
- if ((err= pthread_cond_wait(&_cond, lock_.handle()->handle())))
- {
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_cond_wait: %s", strerror(err));
- }
- }
-
-private:
- pthread_cond_t _cond;
-};
-
-class Barrier
-{
-public:
- explicit Barrier(uint32_t count):
- _threshold(count),
- _count(count),
- _generation(0)
- {
- if (_count == 0)
- {
- fatal_assert("Zero is an invalid value");
- }
- }
-
- ~Barrier()
- {
- }
-
- bool wait()
- {
- ScopedLock l(_mutex);
- uint32_t gen = _generation;
-
- if (--_count == 0)
- {
- _generation++;
- _count = _threshold;
- _cond.broadcast();
-
- return true;
- }
-
- while (gen == _generation)
- {
- _cond.wait(l);
- }
-
- return false;
- }
-
-private:
- Mutex _mutex;
- Condition _cond;
- uint32_t _threshold;
- uint32_t _count;
- uint32_t _generation;
-};
-
-class Thread
-{
-private:
- typedef void *(*start_routine_fn) (void *);
-
-public:
- template <class Function,class Arg1>
- Thread(Function func, Arg1 arg):
- _joined(false),
- _func((start_routine_fn)func),
- _context(arg)
- {
- int err;
- if ((err= pthread_create(&_thread, NULL, entry_func, (void*)this)))
- {
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_create: %s", strerror(err));
- }
- _owner= pthread_self();
- }
-
- bool running() const
- {
- return (pthread_kill(_thread, 0) == 0);
- }
-
- bool detached()
- {
- if (EDEADLK == pthread_join(_thread, NULL))
- {
- return true;
- }
-
- /* Result of pthread_join was EINVAL == detached thread */
- return false;
- }
-
- bool join()
- {
- if (_thread == pthread_self())
- {
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Thread cannot join on itself");
- }
-
- if (_owner != pthread_self())
- {
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Attempt made by a non-owner thead to join on thread");
- }
-
- bool ret= false;
- {
- ScopedLock l(_join_mutex);
- if (_joined == false)
- {
- int err;
- if ((err= pthread_join(_thread, NULL)))
- {
- switch(err)
- {
- case EINVAL:
- break;
-
- case ESRCH:
- ret= true;
- break;
-
- case EDEADLK:
- default:
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_join: %s", strerror(err));
- }
- }
- else
- {
- ret= true;
- }
-
- _joined= true;
- }
- }
-
- return ret;
- }
-
- ~Thread()
- {
- join();
- }
-
-protected:
- void run()
- {
- _func(_context);
- }
-
-private:
- static void * entry_func(void* This)
- {
- ((Thread *)This)->run();
- return NULL;
- }
-
-private:
- bool _joined;
- pthread_t _thread;
- pthread_t _owner;
- start_routine_fn _func;
- void* _context;
- Mutex _join_mutex;
-};
-
-} // namespace thread
-} // namespace libtest
+++ /dev/null
-/* 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/timer.hpp"
-
-#include <ctime>
-#include <iomanip>
-
-#ifdef __MACH__
-# include <mach/clock.h>
-# include <mach/mach.h>
-#else
-# include <sys/time.h>
-#endif
-
-namespace libtest {
-
-Timer::Timer()
-{
- _begin.tv_sec= 0;
- _begin.tv_nsec= 0;
- _end.tv_sec= 0;
- _end.tv_nsec= 0;
-}
-
-void Timer::reset()
-{
- _end.tv_sec= 0;
- _end.tv_nsec= 0;
- _time(_begin);
-}
-
-void Timer::sample()
-{
- _time(_end);
-}
-
-void Timer::offset(int64_t minutes_arg, int64_t seconds_arg, int64_t nanoseconds)
-{
- reset();
- _end= _begin;
- _end.tv_sec+= (minutes_arg * 60) +seconds_arg;
- _end.tv_nsec+= nanoseconds;
-}
-
-int64_t Timer::minutes()
-{
- struct timespec result;
- difference(result);
- return int64_t(result.tv_sec / 60);
-}
-
-uint64_t Timer::elapsed_milliseconds() const
-{
- struct timespec temp;
- difference(temp);
-
- return temp.tv_sec*1000 +temp.tv_nsec/1000000;
-}
-
-void Timer::difference(struct timespec& arg) const
-{
- if ((_end.tv_nsec -_begin.tv_nsec) < 0)
- {
- arg.tv_sec= _end.tv_sec -_begin.tv_sec -1;
- arg.tv_nsec= 1000000000 +_end.tv_nsec -_begin.tv_nsec;
-
- }
- else
- {
- arg.tv_sec= _end.tv_sec -_begin.tv_sec;
- arg.tv_nsec= _end.tv_nsec -_begin.tv_nsec;
- }
-}
-
-void Timer::_time(struct timespec& ts)
-{
-#ifdef __MACH__ // OSX lacks clock_gettime()
- clock_serv_t _clock_serv;
- mach_timespec_t _mach_timespec;
- host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &_clock_serv);
- clock_get_time(_clock_serv, &_mach_timespec);
- mach_port_deallocate(mach_task_self(), _clock_serv);
- ts.tv_sec= _mach_timespec.tv_sec;
- ts.tv_nsec= _mach_timespec.tv_nsec;
-#elif defined(_WIN32)
- ts.tv_sec= time(NULL);
- ts.tv_nsec= 0;
-#else
- clock_gettime(CLOCK_REALTIME, &ts);
-#endif
-}
-
-std::ostream& operator<<(std::ostream& output, const libtest::Timer& arg)
-{
- struct timespec temp;
- arg.difference(temp);
-
- if (temp.tv_sec > 60)
- {
- output << temp.tv_sec / 60;
- output << "." << temp.tv_sec % 60;
- }
- else
- {
- output << temp.tv_sec;
- }
-
- output << ":";
- output << std::setfill('0') << std::setw(9) << temp.tv_nsec;
-
- return output;
-}
-
-} // namespace libtest
+++ /dev/null
-/* 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 <cstdlib>
-#include <ctime>
-#include <iostream>
-
-
-namespace libtest {
-
-class Timer {
-public:
-
- Timer();
-
- void reset();
-
- void sample();
-
- void offset(int64_t minutes_arg, int64_t seconds_arg, int64_t nanoseconds);
-
- int64_t minutes();
-
- uint64_t elapsed_milliseconds() const;
-
- void difference(struct timespec& arg) const;
-
-private:
- void _time(struct timespec& ts);
-
-private:
- struct timespec _begin;
- struct timespec _end;
-};
-
-std::ostream& operator<<(std::ostream& output, const libtest::Timer& arg);
-
-} // namespace libtest
+++ /dev/null
-/* 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 {
-
-std::string create_tmpfile(const std::string& name, int& fd)
-{
- libtest::vchar_t file_buffer;
- file_buffer.resize(FILENAME_MAX);
- file_buffer[0]= 0;
-
- int length= snprintf(&file_buffer[0], file_buffer.size(), "var/tmp/%s.XXXXXX", name.c_str());
- fatal_assert(length > 0);
-
- if ((fd= mkstemp(&file_buffer[0])) == -1)
- {
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "mkstemp() failed on %s with %s", &file_buffer[0], strerror(errno));
- }
-
- return &file_buffer[0];
-}
-
-std::string create_tmpfile(const std::string& name)
-{
- int fd;
- std::string ret_file= create_tmpfile(name, fd);
- close(fd);
- unlink(ret_file.c_str());
-
- return ret_file.c_str();
-}
-
-} // namespace libtest
+++ /dev/null
-/* 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/common.h"
-
-namespace libtest {
-
-std::string create_tmpfile(const std::string&, int&);
-std::string create_tmpfile(const std::string&);
-
-} // namespace libtest
-
+++ /dev/null
-/* 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/yatl.h"
-
-#if defined(HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H) && HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H
-# include "libmemcached-1.0/types/return.h"
-#endif
-
-#if defined(HAVE_LIBGEARMAN_1_0_RETURN_H) && HAVE_LIBGEARMAN_1_0_RETURN_H
-# include <libgearman-1.0/return.h>
-#endif
-
-#include <cstdlib>
-#include <unistd.h>
-
-using namespace libtest;
-
-static std::string testing_service;
-
-// Used to track setups where we see if failure is happening
-static uint32_t fatal_calls= 0;
-
-static test_return_t getenv_TEST(void *)
-{
-#if 0
- for (char **ptr= environ; *ptr; ptr++)
- {
- Error << *ptr;
- }
-#endif
-
- return TEST_SUCCESS;
-}
-
-static test_return_t LIBTOOL_COMMAND_test(void *)
-{
- test_true(getenv("LIBTOOL_COMMAND"));
- return TEST_SUCCESS;
-}
-
-static test_return_t VALGRIND_COMMAND_test(void *)
-{
- test_true(getenv("VALGRIND_COMMAND"));
- return TEST_SUCCESS;
-}
-
-static test_return_t HELGRIND_COMMAND_test(void *)
-{
- test_true(getenv("HELGRIND_COMMAND"));
- return TEST_SUCCESS;
-}
-
-static test_return_t GDB_COMMAND_test(void *)
-{
- test_true(getenv("GDB_COMMAND"));
- return TEST_SUCCESS;
-}
-
-static test_return_t test_success_equals_one_test(void *)
-{
- test_skip(HAVE_LIBMEMCACHED, 1);
-#if defined(HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H) && HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H
- test_zero(MEMCACHED_SUCCESS);
-#endif
- return TEST_SUCCESS;
-}
-
-static test_return_t test_success_test(void *)
-{
- return TEST_SUCCESS;
-}
-
-static test_return_t test_throw_success_TEST(void *)
-{
- try {
- _SUCCESS;
- }
- catch (const libtest::__success&)
- {
- return TEST_SUCCESS;
- }
- catch (...)
- {
- return TEST_FAILURE;
- }
-
- return TEST_FAILURE;
-}
-
-static test_return_t test_throw_skip_macro_TEST(void *)
-{
- try {
- SKIP_IF(true);
- }
- catch (const libtest::__skipped&)
- {
- return TEST_SUCCESS;
- }
- catch (...)
- {
- FAIL("SLIP_IF() failed to throw libtest::_skipped");
- }
-
- FAIL("SLIP_IF() failed to throw");
-
- return TEST_FAILURE;
-}
-
-static test_return_t test_throw_skip_unless_macro_TEST(void *)
-{
- try {
- SKIP_UNLESS(false);
- }
- catch (const libtest::__skipped&)
- {
- return TEST_SUCCESS;
- }
- catch (...)
- {
- FAIL("SLIP_UNLESS() failed to throw libtest::_skipped");
- }
-
- FAIL("SLIP_UNLESS() failed to throw");
-
- return TEST_FAILURE;
-}
-
-static test_return_t test_throw_skip_TEST(void *)
-{
- try {
- throw libtest::__skipped(LIBYATL_DEFAULT_PARAM, "basic test");
- }
- catch (const libtest::__skipped&)
- {
- return TEST_SUCCESS;
- }
- catch (...)
- {
- FAIL("SLIP_IF() failed to throw libtest::_skipped");
- }
-
- FAIL("SLIP_IF() failed to throw");
-
- return TEST_FAILURE;
-}
-
-static test_return_t test_throw_fail_TEST(void *)
-{
- try {
- FAIL("test message!");
- }
- catch (const libtest::__failure& e)
- {
- std::string compare_message("test message!");
- test_zero(compare_message.compare(e.what()));
- return TEST_SUCCESS;
- }
- catch (...)
- {
- return TEST_FAILURE;
- }
-
- return TEST_FAILURE;
-}
-#pragma GCC diagnostic ignored "-Wstack-protector"
-
-#ifdef __clang__
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wformat-security"
-#endif
-
-static test_return_t ASSERT_FALSE__TEST(void *)
-{
- try {
- ASSERT_FALSE(true);
- }
- catch (const libtest::__failure& e)
- {
- ASSERT_STREQ(e.what(), "Assertion '!true'");
- return TEST_SUCCESS;
- }
- catch (...)
- {
- return TEST_FAILURE;
- }
-
- return TEST_FAILURE;
-}
-
-#ifdef __clang__
-# pragma GCC diagnostic pop
-#endif
-
-static test_return_t ASSERT_NEQ_FAIL_TEST(void *)
-{
- try {
- ASSERT_NEQ(1,1);
- }
- catch (const libtest::__failure& e)
- {
- ASSERT_STREQ(e.what(), "Assertion '1' == '1'");
- return TEST_SUCCESS;
- }
- catch (...)
- {
- return TEST_FAILURE;
- }
-
- return TEST_FAILURE;
-}
-
-static test_return_t ASSERT_NEQ_TEST(void *)
-{
- ASSERT_NEQ(1,0);
-
- return TEST_SUCCESS;
-}
-
-static test_return_t ASSERT_FALSE_TEST(void *)
-{
- try {
- FAIL(__func__);
- }
- catch (const libtest::__failure& e)
- {
- ASSERT_STREQ(e.what(), __func__);
- return TEST_SUCCESS;
- }
- catch (...)
- {
- return TEST_FAILURE;
- }
-
- return TEST_FAILURE;
-}
-
-static test_return_t test_failure_test(void *)
-{
- return TEST_SKIPPED; // Only run this when debugging
-
- ASSERT_EQ(1, 2);
- return TEST_SUCCESS;
-}
-
-static test_return_t local_test(void *)
-{
- if (getenv("LIBTEST_LOCAL"))
- {
- test_true(test_is_local());
- }
- else
- {
- test_false(test_is_local());
- }
-
- return TEST_SUCCESS;
-}
-
-static test_return_t local_not_test(void *)
-{
- return TEST_SKIPPED;
-
- std::string temp;
-
- const char *ptr;
- if ((ptr= getenv("LIBTEST_LOCAL")) == NULL)
- {
- temp.append(ptr);
- }
-
- // unsetenv() will cause issues with valgrind
- _compare(__FILE__, __LINE__, __func__, 0, unsetenv("LIBTEST_LOCAL"), true);
- ASSERT_EQ(0, unsetenv("LIBTEST_LOCAL"));
- test_false(test_is_local());
-
- ASSERT_EQ(0, setenv("LIBTEST_LOCAL", "1", 1));
- test_true(test_is_local());
-
- if (temp.empty())
- {
- ASSERT_EQ(0, unsetenv("LIBTEST_LOCAL"));
- }
- else
- {
- char *old_string= strdup(temp.c_str());
- ASSERT_EQ(0, setenv("LIBTEST_LOCAL", old_string, 1));
- }
-
- return TEST_SUCCESS;
-}
-
-static test_return_t var_exists_test(void *)
-{
- ASSERT_EQ(0, access("var", R_OK | W_OK | X_OK));
- return TEST_SUCCESS;
-}
-
-static test_return_t var_tmp_exists_test(void *)
-{
- ASSERT_EQ(0, access("var/tmp", R_OK | W_OK | X_OK));
- return TEST_SUCCESS;
-}
-
-static test_return_t var_run_exists_test(void *)
-{
- ASSERT_EQ(0, access("var/run", R_OK | W_OK | X_OK));
- return TEST_SUCCESS;
-}
-
-static test_return_t var_log_exists_test(void *)
-{
- ASSERT_EQ(0, access("var/log", R_OK | W_OK | X_OK));
- return TEST_SUCCESS;
-}
-
-static test_return_t var_drizzle_exists_test(void *)
-{
- ASSERT_EQ(0, access("var/drizzle", R_OK | W_OK | X_OK));
- return TEST_SUCCESS;
-}
-
-static test_return_t var_tmp_test(void *)
-{
- FILE *file= fopen("var/tmp/junk", "w+");
- test_true(file);
- fclose(file);
- return TEST_SUCCESS;
-}
-
-static test_return_t var_run_test(void *)
-{
- FILE *file= fopen("var/run/junk", "w+");
- test_true(file);
- fclose(file);
- return TEST_SUCCESS;
-}
-
-static test_return_t var_log_test(void *)
-{
- FILE *file= fopen("var/log/junk", "w+");
- test_true(file);
- fclose(file);
- return TEST_SUCCESS;
-}
-
-static test_return_t var_drizzle_test(void *)
-{
- FILE *file= fopen("var/drizzle/junk", "w+");
- test_true(file);
- fclose(file);
- return TEST_SUCCESS;
-}
-
-static test_return_t var_tmp_rm_test(void *)
-{
- test_true(unlink("var/tmp/junk") == 0);
- return TEST_SUCCESS;
-}
-
-static test_return_t var_run_rm_test(void *)
-{
- test_true(unlink("var/run/junk") == 0);
- return TEST_SUCCESS;
-}
-
-static test_return_t var_log_rm_test(void *)
-{
- test_true(unlink("var/log/junk") == 0);
- return TEST_SUCCESS;
-}
-
-static test_return_t var_drizzle_rm_test(void *)
-{
- test_true(unlink("var/drizzle/junk") == 0);
- return TEST_SUCCESS;
-}
-
-static test_return_t _compare_test_return_t_test(void *)
-{
- ASSERT_EQ(TEST_SUCCESS, TEST_SUCCESS);
-
- return TEST_SUCCESS;
-}
-
-static test_return_t _compare_memcached_return_t_test(void *)
-{
- test_skip(HAVE_LIBMEMCACHED, true);
-#if defined(HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H) && HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H
- ASSERT_EQ(MEMCACHED_SUCCESS, MEMCACHED_SUCCESS);
-#endif
-
- return TEST_SUCCESS;
-}
-
-static test_return_t _compare_gearman_return_t_test(void *)
-{
- test_skip(HAVE_LIBGEARMAN, true);
-#if defined(HAVE_LIBGEARMAN_1_0_RETURN_H) && HAVE_LIBGEARMAN_1_0_RETURN_H
- ASSERT_EQ(GEARMAN_SUCCESS, GEARMAN_SUCCESS);
-#endif
-
- return TEST_SUCCESS;
-}
-
-static test_return_t drizzled_cycle_test(void *object)
-{
- server_startup_st *servers= (server_startup_st*)object;
- test_true(servers and servers->validate());
-
-#if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
- test_true(has_drizzled());
-#endif
-
- test_skip(true, has_drizzled());
-
- test_skip(true, server_startup(*servers, "drizzled", get_free_port(), NULL));
-
- return TEST_SUCCESS;
-}
-
-static test_return_t gearmand_cycle_test(void *object)
-{
- server_startup_st *servers= (server_startup_st*)object;
- test_true(servers and servers->validate());
-
- test_skip(true, has_gearmand());
- test_skip(true, server_startup(*servers, "gearmand", get_free_port(), NULL));
- servers->clear();
-
- return TEST_SUCCESS;
-}
-
-static test_return_t skip_shim(bool a, bool b)
-{
- test_skip(a, b);
- return TEST_SUCCESS;
-}
-
-static test_return_t test_skip_true_TEST(void*)
-{
- ASSERT_EQ(true, true);
- ASSERT_EQ(false, false);
- ASSERT_EQ(TEST_SUCCESS, skip_shim(true, true));
- ASSERT_EQ(TEST_SUCCESS, skip_shim(false, false));
-
- return TEST_SUCCESS;
-}
-
-static test_return_t test_skip_false_TEST(void*)
-{
- ASSERT_EQ(TEST_SKIPPED, skip_shim(true, false));
- ASSERT_EQ(TEST_SKIPPED, skip_shim(false, true));
- return TEST_SUCCESS;
-}
-
-static test_return_t server_startup_fail_TEST(void *object)
-{
- server_startup_st *servers= (server_startup_st*)object;
- test_true(servers);
-
- fatal::disable();
- ASSERT_EQ(servers->start_server(testing_service, LIBTEST_FAIL_PORT, NULL), true);
- fatal::enable();
-
- return TEST_SUCCESS;
-}
-
-static test_return_t server_startup_TEST(void *object)
-{
- server_startup_st *servers= (server_startup_st*)object;
- test_true(servers);
-
- ASSERT_EQ(servers->start_server(testing_service, get_free_port(), NULL), true);
-
- test_true(servers->last());
- pid_t last_pid= servers->last()->pid();
-
- ASSERT_EQ(servers->last()->pid(), last_pid);
- test_true(last_pid > 1);
- ASSERT_EQ(kill(last_pid, 0), 0);
-
- test_true(servers->shutdown());
-#if 0
- ASSERT_EQ(servers->last()->pid(), -1);
- ASSERT_EQ(kill(last_pid, 0), -1);
-#endif
-
- return TEST_SUCCESS;
-}
-
-static test_return_t socket_server_startup_TEST(void *object)
-{
- server_startup_st *servers= (server_startup_st*)object;
- test_true(servers);
-
- test_true(servers->start_socket_server(testing_service, get_free_port(), NULL));
-
- return TEST_SUCCESS;
-}
-
-#if 0
-static test_return_t memcached_sasl_test(void *object)
-{
- server_startup_st *servers= (server_startup_st*)object;
- test_true(servers);
-
- test_skip(false, bool(getenv("LOG_COMPILER")));
-
- if (MEMCACHED_SASL_BINARY)
- {
- if (HAVE_LIBMEMCACHED)
- {
- test_true(has_memcached_sasl());
- test_true(server_startup(*servers, "memcached-sasl", get_free_port(), NULL));
-
- return TEST_SUCCESS;
- }
- }
-
- return TEST_SKIPPED;
-}
-#endif
-
-static test_return_t application_true_BINARY(void *)
-{
- test_skip(0, access("/usr/bin/true", X_OK ));
- Application true_app("/usr/bin/true");
-
- ASSERT_EQ(Application::SUCCESS, true_app.run());
- ASSERT_EQ(Application::SUCCESS, true_app.join());
-
- return TEST_SUCCESS;
-}
-
-static test_return_t application_gdb_true_BINARY2(void *)
-{
- test_skip(0, access("/usr/bin/gdb", X_OK ));
- test_skip(0, access("/usr/bin/true", X_OK ));
-
- Application true_app("/usr/bin/true");
- true_app.use_gdb(true);
-
- ASSERT_EQ(Application::SUCCESS, true_app.run());
- ASSERT_EQ(Application::SUCCESS, true_app.join());
-
- return TEST_SUCCESS;
-}
-
-static test_return_t application_gdb_true_BINARY(void *)
-{
- test_skip(0, access("/usr/bin/gdb", X_OK ));
- test_skip(0, access("/usr/bin/true", X_OK ));
-
- Application true_app("/usr/bin/true");
- true_app.use_gdb(true);
-
- const char *args[]= { "--fubar", 0 };
- ASSERT_EQ(Application::SUCCESS, true_app.run(args));
- ASSERT_EQ(Application::SUCCESS, true_app.join());
-
- return TEST_SUCCESS;
-}
-
-static test_return_t application_true_fubar_BINARY(void *)
-{
- test_skip(0, access("/usr/bin/true", X_OK ));
- Application true_app("/usr/bin/true");
-
- const char *args[]= { "--fubar", 0 };
- ASSERT_EQ(Application::SUCCESS, true_app.run(args));
- ASSERT_EQ(Application::SUCCESS, true_app.join());
- test_zero(true_app.stdout_result().size());
-
- return TEST_SUCCESS;
-}
-
-static test_return_t application_doesnotexist_BINARY(void *)
-{
-
- test_skip_valgrind();
- Application true_app("doesnotexist");
- true_app.will_fail();
-
- const char *args[]= { "--fubar", 0 };
-#if defined(__APPLE__) && __APPLE__
- ASSERT_EQ(Application::INVALID_POSIX_SPAWN, true_app.run(args));
-#elif defined(__FreeBSD__) && __FreeBSD__
- ASSERT_EQ(Application::INVALID_POSIX_SPAWN, true_app.run(args));
-#else
- Application::error_t rc = true_app.run(args);
- if (Application::SUCCESS == rc) {
- ASSERT_EQ(Application::INVALID_POSIX_SPAWN, true_app.join());
- } else {
- ASSERT_EQ(Application::INVALID_POSIX_SPAWN, rc);
- }
-#endif
-
- test_zero(true_app.stdout_result().size());
-
- return TEST_SUCCESS;
-}
-
-static test_return_t GET_TEST(void *)
-{
- libtest::http::GET get("http://foo.example.com/");
-
- ASSERT_EQ(false, get.execute());
-
- return TEST_SUCCESS;
-}
-
-static test_return_t POST_TEST(void *)
-{
- libtest::vchar_t body;
- libtest::http::POST post("http://foo.example.com/", body);
-
- ASSERT_EQ(false, post.execute());
-
- return TEST_SUCCESS;
-}
-
-static test_return_t TRACE_TEST(void *)
-{
- libtest::vchar_t body;
- libtest::http::TRACE trace("http://foo.example.com/", body);
-
- ASSERT_EQ(false, trace.execute());
-
- return TEST_SUCCESS;
-}
-
-
-static test_return_t vchar_t_TEST(void *)
-{
- libtest::vchar_t response;
- libtest::make_vector(response, test_literal_param("fubar\n"));
- ASSERT_EQ(response, response);
-
- return TEST_SUCCESS;
-}
-
-static test_return_t vchar_t_make_append_TEST(void *)
-{
- libtest::vchar_t hostname;
- libtest::vchar::make(hostname, 23);
- libtest::vchar::append(hostname, ".com");
- ASSERT_EQ(28, hostname.size());
- ASSERT_EQ(0, hostname[27]);
-
- return TEST_SUCCESS;
-}
-
-static test_return_t vchar_t_compare_neg_TEST(void *)
-{
- libtest::vchar_t response;
- libtest::vchar_t response2;
- libtest::make_vector(response, test_literal_param("fubar\n"));
- libtest::make_vector(response2, test_literal_param(__func__));
- test_true(response != response2);
-
- return TEST_SUCCESS;
-}
-
-static test_return_t application_echo_fubar_BINARY(void *)
-{
- if (0)
- {
- test_skip(0, access("/bin/echo", X_OK ));
- Application true_app("/bin/echo");
-
- const char *args[]= { "fubar", 0 };
- ASSERT_EQ(Application::SUCCESS, true_app.run(args));
-
- while (true_app.slurp() == false) {} ;
-
- libtest::vchar_t response;
- make_vector(response, test_literal_param("fubar\n"));
- ASSERT_EQ(response, true_app.stdout_result());
- }
-
- return TEST_SUCCESS;
-}
-
-static test_return_t application_echo_fubar_BINARY2(void *)
-{
- if (0)
- {
- test_skip(0, access("/bin/echo", X_OK ));
- Application true_app("/bin/echo");
-
- true_app.add_option("fubar");
-
- ASSERT_EQ(Application::SUCCESS, true_app.run());
- ASSERT_EQ(Application::SUCCESS, true_app.join());
-
- libtest::vchar_t response;
- make_vector(response, test_literal_param("fubar\n"));
- ASSERT_EQ(response, true_app.stdout_result());
- }
-
- return TEST_SUCCESS;
-}
-
-static test_return_t echo_fubar_BINARY(void *)
-{
- const char *args[]= { "fubar", 0 };
- ASSERT_EQ(EXIT_SUCCESS, exec_cmdline("/bin/echo", args));
-
- return TEST_SUCCESS;
-}
-
-static test_return_t core_count_BINARY(void *)
-{
- const char *args[]= { 0 };
-
- ASSERT_EQ(EXIT_SUCCESS, exec_cmdline("libtest/core-count", args, true));
-
- return TEST_SUCCESS;
-}
-
-static test_return_t wait_BINARY(void *)
-{
- const char *args[]= { "--quiet", 0 };
-
- ASSERT_EQ(EXIT_FAILURE, exec_cmdline("libtest/wait", args, true));
-
- return TEST_SUCCESS;
-}
-
-static test_return_t wait_help_BINARY(void *)
-{
- const char *args[]= { "--quiet", "--help", 0 };
-
- ASSERT_EQ(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
-
- return TEST_SUCCESS;
-}
-
-static test_return_t wait_version_BINARY(void *)
-{
- const char *args[]= { "--quiet", "--version", 0 };
-
- ASSERT_EQ(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
-
- return TEST_SUCCESS;
-}
-
-static test_return_t wait_services_BINARY(void *)
-{
- test_skip(0, access("/etc/services", R_OK ));
-
- const char *args[]= { "--quiet", "/etc/services", 0 };
-
- ASSERT_EQ(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
-
- return TEST_SUCCESS;
-}
-
-static test_return_t wait_services_BINARY2(void *)
-{
- test_skip(0, access("/etc/services", R_OK ));
-
- const char *args[]= { "/etc/services", 0 };
-
- ASSERT_EQ(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
-
- return TEST_SUCCESS;
-}
-
-static test_return_t wait_services_appliction_TEST(void *)
-{
- test_skip(0, access("/etc/services", R_OK ));
- test_skip(0, access("/usr/bin/gdb", X_OK ));
- test_skip(0, access("libtest/wait", X_OK ));
-
- libtest::Application wait_app("libtest/wait", true);
- wait_app.use_gdb(true);
-
- const char *args[]= { "/etc/services", 0 };
- ASSERT_EQ(Application::SUCCESS, wait_app.run(args));
- ASSERT_EQ(Application::SUCCESS, wait_app.join());
-
- return TEST_SUCCESS;
-}
-
-static test_return_t gdb_wait_services_appliction_TEST(void *)
-{
- test_skip(true, false);
-#if defined(__APPLE__) && __APPLE__
- test_skip(0, __APPLE__);
-#endif
-
- test_skip(0, access("/etc/services", R_OK ));
- test_skip(0, access("/usr/bin/gdb", X_OK ));
- test_skip(0, access("libtest/wait", X_OK ));
-
- libtest::Application wait_app("libtest/wait", true);
- wait_app.use_gdb(true);
-
- const char *args[]= { "/etc/services", 0 };
- ASSERT_EQ(Application::SUCCESS, wait_app.run(args));
- ASSERT_EQ(Application::SUCCESS, wait_app.join());
-
- return TEST_SUCCESS;
-}
-
-static test_return_t gdb_abort_services_appliction_TEST(void *)
-{
- test_skip(0, access("/usr/bin/gdb", X_OK ));
- test_skip(0, access("libtest/abort", X_OK ));
- test_skip(true, false);
-
-#if defined(__APPLE__) && __APPLE__
- test_skip(0, __APPLE__);
-#endif
-
- libtest::Application abort_app("libtest/abort", true);
- abort_app.use_gdb(true);
-
- ASSERT_EQ(Application::SUCCESS, abort_app.run());
- ASSERT_EQ(Application::SUCCESS, abort_app.join());
-
- std::string gdb_filename= abort_app.gdb_filename();
- test_skip(0, access(gdb_filename.c_str(), R_OK ));
- const char *args[]= { "SIGABRT", gdb_filename.c_str(), 0 };
- ASSERT_EQ(EXIT_SUCCESS, exec_cmdline("grep", args));
-
- // Sanity test
- args[0]= "THIS_WILL_NOT_BE_FOUND";
- ASSERT_EQ(EXIT_FAILURE, exec_cmdline("grep", args));
-
- return TEST_SUCCESS;
-}
-
-static test_return_t get_free_port_TEST(void *)
-{
- in_port_t ret_port;
- test_true((ret_port= get_free_port()));
- test_true(get_free_port() != default_port());
- test_true(get_free_port() != get_free_port());
-
- return TEST_SUCCESS;
-}
-
-static test_return_t fatal_TEST(void *)
-{
- ASSERT_EQ(fatal_calls++, fatal::disabled_counter());
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Testing va_args based fatal(): %d", 10);
-
- return TEST_SUCCESS;
-}
-
-static test_return_t number_of_cpus_TEST(void *)
-{
- test_true(number_of_cpus() >= 1);
-
- return TEST_SUCCESS;
-}
-
-static test_return_t check_dns_TEST(void *)
-{
- test_warn(libtest::check_dns(), "Broken DNS server/no DNS server found");
-
- return TEST_SUCCESS;
-}
-
-static test_return_t Timer_TEST(void *)
-{
- int64_t minutes= random() % 50;
- minutes++;
-
- Timer check;
-
- check.reset();
- check.offset(minutes, 2, 200);
-
- ASSERT_EQ(check.minutes(), minutes);
-
- return TEST_SUCCESS;
-}
-
-static test_return_t lookup_true_TEST(void *)
-{
- test_warn(libtest::lookup("exist.gearman.info"), "dns is not currently working");
- return TEST_SUCCESS;
-}
-
-static test_return_t lookup_false_TEST(void *)
-{
- SKIP_IF_(libtest::lookup("does_not_exist.gearman.info"),
- "Broken DNS server detected");
-
- return TEST_SUCCESS;
-}
-
-static test_return_t create_tmpfile_TEST(void *)
-{
- test_skip(0, access("/usr/bin/touch", X_OK ));
- std::string tmp= create_tmpfile(__func__);
- ASSERT_EQ(-1, access(tmp.c_str(), R_OK));
- ASSERT_EQ(-1, access(tmp.c_str(), F_OK));
-
- Application touch_app("/usr/bin/touch");
- const char *args[]= { tmp.c_str(), 0 };
- ASSERT_EQ(Application::SUCCESS, touch_app.run(args));
- ASSERT_EQ(Application::SUCCESS, touch_app.join());
-
- ASSERT_EQ(0, access(tmp.c_str(), R_OK));
- ASSERT_EQ(0, unlink(tmp.c_str()));
-
- return TEST_SUCCESS;
-}
-
-static test_return_t fatal_message_TEST(void *)
-{
- ASSERT_EQ(fatal_calls++, fatal::disabled_counter());
- FATAL("Fatal test");
-
- return TEST_SUCCESS;
-}
-
-static test_return_t default_port_TEST(void *)
-{
- in_port_t ret_port= default_port();
- ASSERT_EQ(ret_port, libtest::default_port());
- ASSERT_EQ(ret_port, libtest::default_port());
-
- return TEST_SUCCESS;
-}
-
-static test_return_t check_for_VALGRIND(void *)
-{
- test_skip_valgrind();
- return TEST_SUCCESS;
-}
-
-static test_return_t check_for_gearman(void *)
-{
- test_skip(true, HAVE_LIBGEARMAN);
- test_skip(true, has_gearmand());
-#if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
- if (GEARMAND_BINARY)
- {
- if (strcmp(GEARMAND_BINARY, "./gearmand/gearmand"))
- {
- test_zero(access(GEARMAND_BINARY, X_OK ));
- }
- }
- else
- {
- return TEST_SKIPPED;
- }
-#endif
-
- testing_service= "gearmand";
-
- return TEST_SUCCESS;
-}
-
-static test_return_t check_for_drizzle(void *)
-{
- test_skip(true, has_drizzled());
-
- testing_service= "drizzled";
-
- return TEST_SUCCESS;
-}
-
-
-test_st drizzled_tests[] ={
- {"drizzled startup-shutdown", 0, drizzled_cycle_test },
- {0, 0, 0}
-};
-
-test_st gearmand_tests[] ={
-#if 0
- {"pause", 0, pause_test },
-#endif
- {"gearmand startup-shutdown", 0, gearmand_cycle_test },
- {"_compare(gearman_return_t)", 0, _compare_gearman_return_t_test },
- {"server_startup(fail)", 0, server_startup_fail_TEST },
- {0, 0, 0}
-};
-
-static test_return_t clear_servers(void* object)
-{
- server_startup_st *servers= (server_startup_st*)object;
- test_true(servers);
- servers->clear();
-
- testing_service.clear();
-
- return TEST_SUCCESS;
-}
-
-static test_return_t check_for_memcached(void* object)
-{
- test_skip(true, has_memcached());
-
- server_startup_st *servers= (server_startup_st*)object;
- test_true(servers);
- servers->clear();
-
- testing_service= "memcached";
-
- return TEST_SUCCESS;
-}
-
-test_st memcached_TESTS[] ={
- {"memcached startup-shutdown", 0, server_startup_TEST },
- {"memcached(socket file) startup-shutdown", 0, socket_server_startup_TEST },
- {"_compare(memcached_return_t)", 0, _compare_memcached_return_t_test },
- {"server_startup(fail)", 0, server_startup_fail_TEST },
- {0, 0, 0}
-};
-
-test_st test_skip_TESTS[] ={
- {"true, true", 0, test_skip_true_TEST },
- {"true, false", 0, test_skip_false_TEST },
- {0, 0, 0}
-};
-
-test_st environment_tests[] ={
- {"getenv()", 0, getenv_TEST },
- {"LIBTOOL_COMMAND", 0, LIBTOOL_COMMAND_test },
- {"VALGRIND_COMMAND", 0, VALGRIND_COMMAND_test },
- {"HELGRIND_COMMAND", 0, HELGRIND_COMMAND_test },
- {"GDB_COMMAND", 0, GDB_COMMAND_test },
- {0, 0, 0}
-};
-
-test_st tests_log[] ={
- {"TEST_SUCCESS", false, test_success_test },
- {"TEST_FAILURE", false, test_failure_test },
- {"TEST_SUCCESS == 0", false, test_success_equals_one_test },
- {"SUCCESS", false, test_throw_success_TEST },
- {"libtest::__skipped", false, test_throw_skip_TEST },
- {"SKIP_IF", false, test_throw_skip_macro_TEST },
- {"SKIP_UNLESS", false, test_throw_skip_unless_macro_TEST },
- {"FAIL", false, test_throw_fail_TEST },
- {"ASSERT_FALSE_", false, ASSERT_FALSE__TEST },
- {"ASSERT_FALSE", false, ASSERT_FALSE_TEST },
- {"ASSERT_NEQ", false, ASSERT_NEQ_TEST },
- {"ASSERT_NEQ FAIL", false, ASSERT_NEQ_FAIL_TEST },
- {0, 0, 0}
-};
-
-test_st local_log[] ={
- {"test_is_local()", 0, local_test },
- {"test_is_local(NOT)", 0, local_not_test },
- {0, 0, 0}
-};
-
-test_st directories_tests[] ={
- {"var exists", 0, var_exists_test },
- {"var/tmp exists", 0, var_tmp_exists_test },
- {"var/run exists", 0, var_run_exists_test },
- {"var/log exists", 0, var_log_exists_test },
- {"var/drizzle exists", 0, var_drizzle_exists_test },
- {"var/tmp", 0, var_tmp_test },
- {"var/run", 0, var_run_test },
- {"var/log", 0, var_log_test },
- {"var/drizzle", 0, var_drizzle_test },
- {"var/tmp rm", 0, var_tmp_rm_test },
- {"var/run rm", 0, var_run_rm_test },
- {"var/log rm", 0, var_log_rm_test },
- {"var/drizzle rm", 0, var_drizzle_rm_test },
- {0, 0, 0}
-};
-
-test_st comparison_tests[] ={
- {"_compare(test_return_t)", 0, _compare_test_return_t_test },
- {0, 0, 0}
-};
-
-test_st cmdline_tests[] ={
- {"echo fubar", 0, echo_fubar_BINARY },
- {"core-count", 0, core_count_BINARY },
- {"wait --quiet", 0, wait_BINARY },
- {"wait --quiet --help", 0, wait_help_BINARY },
- {"wait --quiet --version", 0, wait_version_BINARY },
- {"wait --quiet /etc/services", 0, wait_services_BINARY },
- {"wait /etc/services", 0, wait_services_BINARY2 },
- {"wait /etc/services", 0, wait_services_appliction_TEST },
- {"gdb wait /etc/services", 0, gdb_wait_services_appliction_TEST },
- {"gdb abort", 0, gdb_abort_services_appliction_TEST },
- {0, 0, 0}
-};
-
-test_st get_free_port_TESTS[] ={
- {"get_free_port()", 0, get_free_port_TEST },
- {"default_port()", 0, default_port_TEST },
- {0, 0, 0}
-};
-
-test_st fatal_message_TESTS[] ={
- {"libtest::fatal", 0, fatal_TEST },
- {"fatal_message()", 0, fatal_message_TEST },
- {0, 0, 0}
-};
-
-test_st number_of_cpus_TESTS[] ={
- {"libtest::number_of_cpus()", 0, number_of_cpus_TEST },
- {0, 0, 0}
-};
-
-test_st create_tmpfile_TESTS[] ={
- {"libtest::create_tmpfile()", 0, create_tmpfile_TEST },
- {0, 0, 0}
-};
-
-test_st timer_TESTS[] ={
- {"libtest::Timer", 0, Timer_TEST },
- {0, 0, 0}
-};
-
-test_st dns_TESTS[] ={
- {"libtest::lookup(true)", 0, lookup_true_TEST },
- {"libtest::lookup(false)", 0, lookup_false_TEST },
- {"libtest::check_dns()", 0, check_dns_TEST },
- {0, 0, 0}
-};
-
-test_st application_tests[] ={
- {"vchar_t", 0, vchar_t_TEST },
- {"vchar_t make() append()", 0, vchar_t_make_append_TEST },
- {"vchar_t compare()", 0, vchar_t_compare_neg_TEST },
- {"true", 0, application_true_BINARY },
- {"gbd true --fubar", 0, application_gdb_true_BINARY },
- {"gbd true", 0, application_gdb_true_BINARY2 },
- {"true --fubar", 0, application_true_fubar_BINARY },
- {"doesnotexist --fubar", 0, application_doesnotexist_BINARY },
- {"echo fubar", 0, application_echo_fubar_BINARY },
- {"echo fubar (as option)", 0, application_echo_fubar_BINARY2 },
- {0, 0, 0}
-};
-
-static test_return_t check_for_curl(void *)
-{
- test_skip_valgrind();
- test_skip(true, HAVE_LIBCURL);
- return TEST_SUCCESS;
-}
-
-static test_return_t disable_fatal_exception(void *)
-{
- fatal_calls= 0;
- fatal::disable();
- return TEST_SUCCESS;
-}
-
-static test_return_t enable_fatal_exception(void *)
-{
- fatal::enable();
- return TEST_SUCCESS;
-}
-
-test_st http_tests[] ={
- {"GET", 0, GET_TEST },
- {"POST", 0, POST_TEST },
- {"TRACE", 0, TRACE_TEST },
- {0, 0, 0}
-};
-
-collection_st collection[] ={
- {"environment", 0, 0, environment_tests},
- {"return values", 0, 0, tests_log},
- {"test_skip()", 0, 0, test_skip_TESTS },
- {"local", 0, 0, local_log},
- {"directories", 0, 0, directories_tests},
- {"comparison", 0, 0, comparison_tests},
- {"gearmand", check_for_gearman, clear_servers, gearmand_tests},
- {"memcached", check_for_memcached, clear_servers, memcached_TESTS },
- {"drizzled", check_for_drizzle, clear_servers, drizzled_tests},
- {"cmdline", 0, 0, cmdline_tests},
- {"application", 0, 0, application_tests},
- {"http", check_for_curl, 0, http_tests},
- {"http", check_for_curl, 0, http_tests},
- {"get_free_port()", 0, 0, get_free_port_TESTS },
- {"fatal", disable_fatal_exception, enable_fatal_exception, fatal_message_TESTS },
- {"number_of_cpus()", 0, 0, number_of_cpus_TESTS },
- {"create_tmpfile()", 0, 0, create_tmpfile_TESTS },
- {"dns", check_for_VALGRIND, 0, dns_TESTS },
- {"libtest::Timer", 0, 0, timer_TESTS },
- {0, 0, 0, 0}
-};
-
-static void *world_create(server_startup_st& servers, test_return_t&)
-{
- return &servers;
-}
-
-void get_world(libtest::Framework *world)
-{
- world->collections(collection);
- world->create(world_create);
-}
+++ /dev/null
-/* 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
-
-static inline bool valgrind_is_caller(void)
-{
- if (getenv("LOG_COMPILER") && strstr(getenv("LOG_COMPILER"), "valgrind"))
- {
- if (strstr(getenv("LOG_COMPILER"), "--tool") == NULL)
- {
- return true;
- }
-
- if (strstr(getenv("LOG_COMPILER"), "--tool=memcheck"))
- {
- return true;
- }
- }
-
- return false;
-}
+++ /dev/null
-/* 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"
-
-/* Use this for string generation */
-static const char ALPHANUMERICS[]=
- "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
-
-#define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1)
-
-static size_t get_alpha_num(void)
-{
- return (size_t)random() % ALPHANUMERICS_SIZE;
-}
-
-namespace libtest {
-
-int random_alpha_num(void)
-{
- return ALPHANUMERICS[get_alpha_num()];
-}
-
-static std::string printer(const char *str, size_t length)
-{
- std::ostringstream buf;
- for (size_t x= 0; x < length; x++)
- {
- if (isprint(str[x]))
- {
- buf << str[x];
- }
- else
- {
- buf << "(" << int(str[x]) << ")";
- }
- }
-
- return buf.str();
-}
-
-namespace vchar {
-
-int compare(libtest::vchar_t& arg, const char *str, size_t length)
-{
- if (arg.size() == length and (memcmp(&arg[0], str, length) == 0))
- {
- return 0;
- }
- else if (arg.size() > length)
- {
- return 1;
- }
-
- return -1;
-}
-
-void make(libtest::vchar_t& arg)
-{
- size_t length= rand() % 1024;
- make(arg, length);
-}
-
-void make(libtest::vchar_t& arg, size_t length)
-{
- arg.reserve(length);
- for (uint32_t x= 0; x < length; ++x)
- {
- arg.push_back(ALPHANUMERICS[get_alpha_num()]);
- }
-}
-
-void chomp(libtest::vchar_t& arg)
-{
- while(arg.size())
- {
- if (arg.back() == 0)
- {
- arg.pop_back();
- }
- else
- {
- break;
- }
- }
-}
-
-void append(libtest::vchar_ptr_t& arg, const char* ptr)
-{
- if (ptr)
- {
- char* new_ptr= strdup(ptr);
- if (new_ptr == NULL)
- {
- FATAL("UNABLE to allocate %s(%p)", ptr, ptr);
- }
-
- arg.push_back(new_ptr);
- }
-}
-
-void append(libtest::vchar_t& arg, const char* ptr)
-{
- if (ptr)
- {
- size_t length= strlen(ptr);
- ASSERT_TRUE(length);
- arg.reserve(length);
- do
- {
- arg.push_back(*ptr);
- ++ptr;
- } while (*ptr);
-
- arg.push_back(0);
- }
-}
-
-} // namespace vchar
-
-void make_vector(libtest::vchar_t& arg, const char *str, size_t length)
-{
- arg.resize(length);
- memcpy(&arg[0], str, length);
-}
-
-std::ostream& operator<<(std::ostream& output, const libtest::vchar_t& arg)
-{
- std::string tmp= libtest::printer(arg.data(), arg.size());
- output << tmp << "[" << arg.size() << "]";
-
- return output;
-}
-
-} // namespace libtest
+++ /dev/null
-/* 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 <cstring>
-#include <iostream>
-#include <ostream>
-#include <sstream>
-#include <vector>
-
-namespace libtest {
-
-int random_alpha_num(void);
-
-typedef std::vector<char*> vchar_ptr_t;
-typedef std::vector<char> vchar_t;
-
-void make_vector(libtest::vchar_t& arg, const char *str, size_t length);
-
-namespace vchar {
-
-int compare(libtest::vchar_t& arg, const char *str, size_t length);
-void chomp(libtest::vchar_t& arg);
-void make(libtest::vchar_t& arg);
-void make(libtest::vchar_t& arg, size_t length);
-void append(libtest::vchar_ptr_t& arg, const char*);
-void append(libtest::vchar_t& arg, const char*);
-
-} // namespace vchar
-
-#define vchar_param(__arg) (&__arg[0]), (__arg.size())
-#define vchar_printf(__arg) int(__arg.size()), (&__arg[0])
-
-std::ostream& operator<<(std::ostream& output, const libtest::vchar_t& arg);
-
-} // namespace libtest
-
+++ /dev/null
-/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
- *
- * Data Differential YATL (i.e. libtest) library
- *
- * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
- * All rights reserved.
- *
- * 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
-
-#define LIBTEST_VERSION @LIBTEST_VERSION@
-#define LIBTEST_VERSION_STRING "@LIBTEST_VERSION@"
+++ /dev/null
-/* 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(BUILDING_LIBTEST)
-# if defined(HAVE_VISIBILITY) && HAVE_VISIBILITY
-# define LIBTEST_API __attribute__ ((visibility("default")))
-# define LIBTEST_LOCAL __attribute__ ((visibility("default")))
-# elif defined (__SUNPRO_C) && (__SUNPRO_C >= 0x550)
-# define LIBTEST_API __global
-# define LIBTEST_LOCAL __global
-# elif defined(_MSC_VER)
-# define LIBTEST_API extern __declspec(dllexport)
-# define LIBTEST_LOCAL extern __declspec(dllexport)
-# else
-# define LIBTEST_API
-# define LIBTEST_LOCAL
-# endif
-#else
-# if defined(BUILDING_LIBTEST)
-# if defined(HAVE_VISIBILITY) && HAVE_VISIBILITY
-# define LIBTEST_API __attribute__ ((visibility("default")))
-# define LIBTEST_LOCAL __attribute__ ((visibility("hidden")))
-# elif defined (__SUNPRO_C) && (__SUNPRO_C >= 0x550)
-# define LIBTEST_API __global
-# define LIBTEST_LOCAL __hidden
-# elif defined(_MSC_VER)
-# define LIBTEST_API extern __declspec(dllexport)
-# define LIBTEST_LOCAL
-# else
-# define LIBTEST_API
-# define LIBTEST_LOCAL
-# endif /* defined(HAVE_VISIBILITY) */
-# else /* defined(BUILDING_LIBTEST) */
-# if defined(_MSC_VER)
-# define LIBTEST_API extern __declspec(dllimport)
-# define LIBTEST_LOCAL
-# else
-# define LIBTEST_API
-# define LIBTEST_LOCAL
-# endif /* defined(_MSC_VER) */
-# endif /* defined(BUILDING_LIBTEST) */
-#endif /* defined(BUILDING_LIBTESTINTERNAL) */
+++ /dev/null
-/* 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 <cstdlib>
-#include <fcntl.h>
-#include <getopt.h>
-#include <iostream>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "libtest/wait.h"
-
-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 << "Current options. A '=' means the option takes a value." << 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;
-}
-
-static void close_stdio(void)
-{
- int fd;
- if ((fd = open("/dev/null", O_RDWR, 0)) < 0)
- {
- return;
- }
- else
- {
- if (dup2(fd, STDIN_FILENO) < 0)
- {
- return;
- }
-
- if (dup2(fd, STDOUT_FILENO) < 0)
- {
- return;
- }
-
- if (dup2(fd, STDERR_FILENO) < 0)
- {
- return;
- }
-
- if (fd > STDERR_FILENO)
- {
- close(fd);
- }
- }
-}
-
-enum {
- OPT_HELP,
- OPT_QUIET,
- 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},
- { "quiet", no_argument, NULL, OPT_QUIET},
- {0, 0, 0, 0},
- };
-
- bool opt_version= false;
- bool opt_help= false;
- bool opt_quiet= 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 OPT_QUIET:
- opt_quiet= 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_quiet)
- {
- close_stdio();
- }
-
- 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[])
-{
- if (argc == 1)
- {
- return EXIT_FAILURE;
- }
-
- options_parse(argc, argv);
-
- int ret= EXIT_FAILURE;
- while (optind < argc)
- {
- libtest::Wait wait(argv[optind++]);
-
- if (wait.successful() == false)
- {
- return EXIT_FAILURE;
- }
-
- ret= EXIT_SUCCESS;
- }
-
- return ret;
-}
+++ /dev/null
-/* 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 <unistd.h>
-#include <string>
-#include <signal.h>
-
-#include "libtest/dream.h"
-
-namespace libtest {
-
-class Wait
-{
-public:
-
- Wait(const std::string &filename, uint32_t timeout= 6) :
- _successful(false)
- {
- uint32_t waited;
- uint32_t this_wait;
- uint32_t retry;
-
- if (filename.empty())
- {
- _successful= false;
- return;
- }
-
- for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
- {
- if (access(filename.c_str(), R_OK) == 0)
- {
- _successful= true;
- break;
- }
- else if (waited >= timeout)
- {
- break;
- }
-
- this_wait= retry * retry / 3 + 1;
- libtest::dream(0, this_wait * 10000000);
- }
- }
-
- Wait(const pid_t &_pid_arg, uint32_t timeout= 6) :
- _successful(false)
- {
- uint32_t waited;
- uint32_t this_wait;
- uint32_t retry;
-
- for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
- {
- if (kill(_pid_arg, 0) == 0)
- {
- _successful= true;
- break;
- }
- else if (waited >= timeout)
- {
- break;
- }
-
- this_wait= retry * retry / 3 + 1;
- libtest::dream(0, this_wait * 10000000);
- }
- }
-
- bool successful() const
- {
- return _successful;
- }
-
-private:
- bool _successful;
-};
-
-} // namespace libtest
+++ /dev/null
-/* 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
-
-#ifndef YATL_FULL
-# define YATL_FULL 1
-#endif
-
-#include "libtest/test.hpp"
+++ /dev/null
-/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
- *
- * Data Differential YATL (i.e. libtest) library
- *
- * Copyright (C) 2012 Data Differential, http://datadifferential.com/
- * All rights reserved.
- *
- * 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 "@AUTOHEADER_FILE@"
-
-#ifndef LIBTEST_TEMP
-# define LIBTEST_TEMP "/tmp"
-#endif
-
-#define HAVE_LIBMEMCACHED 1