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>
49 #ifdef HAVE_NETINET_IN_H
50 # include <netinet/in.h>
61 typedef std::vector
< std::pair
<std::string
, std::string
> > Options
;
68 std::string _pid_file
;
69 std::string _log_file
;
70 std::string _base_command
; // executable command which include libtool, valgrind, gdb, etc
71 std::string _running
; // Current string being used for system()
75 std::string _hostname
;
76 std::string _extra_args
;
79 Server(const std::string
& hostname
, const in_port_t port_arg
,
80 const std::string
& executable
, const bool _is_libtool
,
81 const bool is_socket_arg
= false);
85 virtual const char *name()= 0;
86 virtual bool is_libtool()= 0;
88 virtual bool has_socket_file_option() const
93 virtual void socket_file_option(Application
& app
, const std::string
& socket_arg
)
95 if (socket_arg
.empty() == false)
97 std::string
buffer("--socket=");
99 app
.add_option(buffer
);
103 virtual bool has_log_file_option() const
108 virtual void log_file_option(Application
& app
, const std::string
& arg
)
110 if (arg
.empty() == false)
112 std::string
buffer("--log-file=");
114 app
.add_option(buffer
);
118 virtual void pid_file_option(Application
& app
, const std::string
& arg
)
120 if (arg
.empty() == false)
122 std::string
buffer("--pid-file=");
124 app
.add_option(buffer
);
128 virtual bool has_port_option() const
133 virtual void port_option(Application
& app
, in_port_t arg
)
138 snprintf(buffer
, sizeof(buffer
), "--port=%d", int(arg
));
139 app
.add_option(buffer
);
143 virtual bool broken_socket_cleanup()
148 virtual bool broken_pid_file()
153 const std::string
& pid_file() const
158 const std::string
& base_command() const
160 return _base_command
;
163 const std::string
& log_file() const
168 const std::string
& hostname() const
173 const std::string
& socket() const
178 bool has_socket() const
185 virtual bool ping()= 0;
187 virtual bool build(size_t argc
, const char *argv
[])= 0;
189 void add_option(const std::string
&);
190 void add_option(const std::string
&, const std::string
&);
192 in_port_t
port() const
197 bool has_port() const
202 virtual bool has_syslog() const
207 // Reset a server if another process has killed the server
216 bool has_pid() const;
218 virtual bool has_pid_file() const
223 const std::string
& error()
228 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
242 return _hostname
[0] == '/';
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_
;
276 bool is_helgrind() const;
277 bool is_valgrind() const;
278 bool is_debug() const;
280 bool set_socket_file();
282 bool out_of_ban_killed_
;
283 bool args(Application
&);
288 std::ostream
& operator<<(std::ostream
& output
, const libtest::Server
&arg
);
290 } // namespace libtest