1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 3 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <libtest/common.h>
26 #include <libtest/drizzled.h>
28 #include "util/instance.hpp"
29 #include "util/operation.hpp"
31 using namespace datadifferential
;
32 using namespace libtest
;
42 #include <sys/types.h>
46 #ifndef __INTEL_COMPILER
47 #pragma GCC diagnostic ignored "-Wold-style-cast"
50 #if defined(HAVE_LIBDRIZZLE) && HAVE_LIBDRIZZLE
51 #include <libdrizzle-1.0/drizzle_client.h>
54 using namespace libtest
;
57 bool ping_drizzled(const in_port_t _port
)
59 #if defined(HAVE_LIBDRIZZLE) && HAVE_LIBDRIZZLE
61 drizzle_st
*drizzle
= drizzle_create(NULL
);
70 if ((con
= drizzle_con_create(drizzle
, NULL
)) == NULL
)
72 drizzle_free(drizzle
);
76 drizzle_con_set_tcp(con
, "localhost", _port
);
77 drizzle_con_set_auth(con
, "root", 0);
82 if ((rc
= drizzle_con_connect(con
)) == DRIZZLE_RETURN_OK
)
84 drizzle_result_st
*result
= drizzle_ping(con
, NULL
, &rc
);
85 success
= bool(result
);
86 drizzle_result_free(result
);
91 else if (rc
!= DRIZZLE_RETURN_OK
)
93 Error
<< drizzle_error(drizzle
) << " localhost:" << _port
;
96 drizzle_con_free(con
);
97 drizzle_free(drizzle
);
105 } // namespace libtest
107 class Drizzle
: public libtest::Server
111 Drizzle(const std::string
& host_arg
, in_port_t port_arg
) :
112 libtest::Server(host_arg
, port_arg
, DRIZZLED_BINARY
, false)
120 while (_app
.check() and --limit
)
122 if (ping_drizzled(_port
))
126 libtest::dream(1, 0);
137 void log_file_option(Application
& app
, const std::string
& arg
)
141 bool has_log_file_option() const
146 bool broken_pid_file()
156 bool has_syslog() const
161 bool has_port_option() const
166 void port_option(Application
& app
, in_port_t arg
)
171 snprintf(buffer
, sizeof(buffer
), "--drizzle-protocol.port=%d", int(arg
));
172 app
.add_option(buffer
);
176 bool build(size_t argc
, const char *argv
[]);
179 bool Drizzle::build(size_t argc
, const char *argv
[])
181 if (getuid() == 0 or geteuid() == 0)
183 add_option("--user=root");
186 add_option("--verbose=INSPECT");
188 add_option("--datadir=var/drizzle");
191 for (size_t x
= 0 ; x
< argc
; x
++)
201 libtest::Server
*build_drizzled(const char *hostname
, in_port_t try_port
)
203 return new Drizzle(hostname
, try_port
);