1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 * Data Differential YATL (i.e. libtest) library
5 * Copyright (C) 2012 Data Differential, http://datadifferential.com/
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <libtest/cmdline.h>
45 #include <netinet/in.h>
54 typedef std::vector
< std::pair
<std::string
, std::string
> > Options
;
61 std::string _pid_file
;
62 std::string _log_file
;
63 std::string _base_command
; // executable command which include libtool, valgrind, gdb, etc
64 std::string _running
; // Current string being used for system()
68 std::string _hostname
;
69 std::string _extra_args
;
72 Server(const std::string
& hostname
, const in_port_t port_arg
,
73 const std::string
& executable
, const bool _is_libtool
,
74 const bool is_socket_arg
= false);
78 virtual const char *name()= 0;
79 virtual bool is_libtool()= 0;
81 virtual bool has_socket_file_option() const
86 virtual void socket_file_option(Application
& app
, const std::string
& socket_arg
)
88 if (socket_arg
.empty() == false)
90 std::string
buffer("--socket=");
92 app
.add_option(buffer
);
96 virtual bool has_log_file_option() const
101 virtual void log_file_option(Application
& app
, const std::string
& arg
)
103 if (arg
.empty() == false)
105 std::string
buffer("--log-file=");
107 app
.add_option(buffer
);
111 virtual void pid_file_option(Application
& app
, const std::string
& arg
)
113 if (arg
.empty() == false)
115 std::string
buffer("--pid-file=");
117 app
.add_option(buffer
);
121 virtual bool has_port_option() const
126 virtual void port_option(Application
& app
, in_port_t arg
)
131 snprintf(buffer
, sizeof(buffer
), "--port=%d", int(arg
));
132 app
.add_option(buffer
);
136 virtual bool broken_socket_cleanup()
141 virtual bool broken_pid_file()
146 const std::string
& pid_file() const
151 const std::string
& base_command() const
153 return _base_command
;
156 const std::string
& log_file() const
161 const std::string
& hostname() const
166 const std::string
& socket() const
171 bool has_socket() const
178 virtual bool ping()= 0;
180 virtual bool build(size_t argc
, const char *argv
[])= 0;
182 void add_option(const std::string
&);
183 void add_option(const std::string
&, const std::string
&);
185 in_port_t
port() const
190 bool has_port() const
195 virtual bool has_syslog() const
200 // Reset a server if another process has killed the server
209 bool has_pid() const;
211 virtual bool has_pid_file() const
216 const std::string
& error()
221 void error(std::string arg
)
231 virtual bool wait_for_pidfile() const;
233 bool check_pid(pid_t pid_arg
) const
235 return (pid_arg
> 1);
238 bool is_socket() const
243 const std::string
running() const
250 std::string
log_and_pid();
254 bool command(libtest::Application
& app
);
258 void out_of_ban_killed(bool arg
)
260 out_of_ban_killed_
= arg
;
263 bool out_of_ban_killed()
265 return out_of_ban_killed_
;
268 void timeout(uint32_t timeout_
)
279 bool is_helgrind() const;
280 bool is_valgrind() const;
281 bool is_debug() const;
283 bool set_socket_file();
285 bool out_of_ban_killed_
;
286 bool args(Application
&);
289 uint32_t _timeout
; // This number should be high enough for valgrind startup (which is slow)
292 std::ostream
& operator<<(std::ostream
& output
, const libtest::Server
&arg
);
294 } // namespace libtest