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>
46 #include <netinet/in.h>
56 typedef std::vector
< std::pair
<std::string
, std::string
> > Options
;
63 std::string _pid_file
;
64 std::string _log_file
;
65 std::string _base_command
; // executable command which include libtool, valgrind, gdb, etc
66 std::string _running
; // Current string being used for system()
70 std::string _hostname
;
71 std::string _extra_args
;
74 Server(const std::string
& hostname
, const in_port_t port_arg
,
75 const std::string
& executable
, const bool _is_libtool
,
76 const bool is_socket_arg
= false);
80 virtual const char *name()= 0;
81 virtual bool is_libtool()= 0;
83 virtual bool has_socket_file_option() const
88 virtual void socket_file_option(Application
& app
, const std::string
& socket_arg
)
90 if (socket_arg
.empty() == false)
92 std::string
buffer("--socket=");
94 app
.add_option(buffer
);
98 virtual bool has_log_file_option() const
103 virtual void log_file_option(Application
& app
, const std::string
& arg
)
105 if (arg
.empty() == false)
107 std::string
buffer("--log-file=");
109 app
.add_option(buffer
);
113 virtual void pid_file_option(Application
& app
, const std::string
& arg
)
115 if (arg
.empty() == false)
117 std::string
buffer("--pid-file=");
119 app
.add_option(buffer
);
123 virtual bool has_port_option() const
128 virtual void port_option(Application
& app
, in_port_t arg
)
133 snprintf(buffer
, sizeof(buffer
), "--port=%d", int(arg
));
134 app
.add_option(buffer
);
138 virtual bool broken_socket_cleanup()
143 virtual bool broken_pid_file()
148 const std::string
& pid_file() const
153 const std::string
& base_command() const
155 return _base_command
;
158 const std::string
& log_file() const
163 const std::string
& hostname() const
168 const std::string
& socket() const
173 bool has_socket() const
180 virtual bool ping()= 0;
182 virtual bool build(size_t argc
, const char *argv
[])= 0;
184 void add_option(const std::string
&);
185 void add_option(const std::string
&, const std::string
&);
187 in_port_t
port() const
192 bool has_port() const
197 virtual bool has_syslog() const
202 // Reset a server if another process has killed the server
211 bool has_pid() const;
213 virtual bool has_pid_file() const
218 const std::string
& error()
223 void error(std::string arg
)
233 virtual bool wait_for_pidfile() const;
235 bool check_pid(pid_t pid_arg
) const
237 return (pid_arg
> 1);
240 bool is_socket() const
245 const std::string
running() const
252 std::string
log_and_pid();
256 bool command(libtest::Application
& app
);
260 void out_of_ban_killed(bool arg
)
262 out_of_ban_killed_
= arg
;
265 bool out_of_ban_killed()
267 return out_of_ban_killed_
;
270 void timeout(uint32_t timeout_
)
281 bool is_helgrind() const;
282 bool is_valgrind() const;
283 bool is_debug() const;
285 bool set_socket_file();
287 bool out_of_ban_killed_
;
288 bool args(Application
&);
291 uint32_t _timeout
; // This number should be high enough for valgrind startup (which is slow)
294 std::ostream
& operator<<(std::ostream
& output
, const libtest::Server
&arg
);
296 } // namespace libtest