27 #include <sys/types.h>
30 #ifdef HAVE_SYS_WAIT_H
33 #ifdef HAVE_SYS_SOCKET_H
34 #include <sys/socket.h>
36 #ifdef HAVE_NETINET_IN_H
37 #include <netinet/in.h>
48 #include <sys/param.h>
49 #include <sys/utsname.h>
50 #include <sys/statvfs.h>
59 #define FTPUSER "anonymous"
60 #define FTPPASSWD "grntest"
61 #define FTPSERVER "ftp.groonga.org"
63 #define DEFAULT_PORT 10041
64 #define DEFAULT_DEST "localhost"
69 static int grntest_outtype =
OUT_JSON;
71 static grn_critical_section grntest_cs;
73 static int grntest_stop_flag = 0;
74 static int grntest_detail_on = 0;
75 static int grntest_remote_mode = 0;
76 static int grntest_localonly_mode = 0;
77 static int grntest_owndb_mode = 0;
78 static int grntest_onmemory_mode = 0;
80 #define TMPFILE "_grntest.tmp"
82 static grn_ctx grntest_server_context;
83 static FILE *grntest_log_file;
85 #define OS_LINUX64 "LINUX64"
86 #define OS_LINUX32 "LINUX32"
87 #define OS_WINDOWS64 "WINDOWS64"
88 #define OS_WINDOWS32 "WINDOWS32"
92 #define SOCKETERROR INVALID_SOCKET
93 #define socketclose closesocket
94 static const char *groonga_path =
"groonga.exe";
95 static PROCESS_INFORMATION grntest_pi;
97 static pid_t grntest_server_id = 0;
99 #define socketclose close
100 #define SOCKETERROR -1
101 static const char *groonga_path =
"groonga";
104 static const char *groonga_protocol =
"gqtp";
105 static const char *grntest_osinfo;
106 static int grntest_sigint = 0;
110 static grn_obj *grntest_db = NULL;
112 #define MAX_CON_JOB 10
116 #define MAX_PATH_LEN 256
121 #define J_REP_LOCAL 4
124 #define J_OUT_LOCAL 7
127 #define J_TEST_LOCAL 10
128 #define J_TEST_GQTP 11
129 #define J_TEST_HTTP 12
131 static char grntest_username[
BUF_LEN];
132 static char grntest_scriptname[
BUF_LEN];
133 static char grntest_date[
BUF_LEN];
134 static char grntest_serverhost[
BUF_LEN];
135 static int grntest_serverport;
136 static const char *grntest_dbpath;
168 static int grntest_jobdone;
169 static int grntest_jobnum;
173 static grn_obj grntest_starttime, grntest_jobs_start;
176 grntest_atoi(
const char *str,
const char *end,
const char **rest)
215 report_p(
int jobtype)
266 error_exit_in_thread(intptr_t code)
269 "Fatal error! Check script file or database!: %ld\n", (
long)code);
271 CRITICAL_SECTION_ENTER(grntest_cs);
272 grntest_stop_flag = 1;
273 CRITICAL_SECTION_LEAVE(grntest_cs);
277 pthread_exit((
void *)code);
284 escape_command(
grn_ctx *ctx,
const char *in,
int ilen,
grn_obj *escaped_command)
289 if ((in[i] ==
'\\') || (in[i] ==
'\"') || (in[i] ==
'/')) {
326 report_command(
grn_ctx *ctx,
const char *command,
const char *ret,
int task_id,
330 long long int start, end;
331 grn_obj result, escaped_command;
334 if (strncmp(ret,
"[[", 2) == 0) {
337 while (ret[i] !=
']') {
340 if (ret[i] ==
'\0') {
341 fprintf(stderr,
"Error results:command=[%s]\n", command);
342 error_exit_in_thread(3);
353 clen = strlen(command);
355 escape_command(ctx, command, clen, &escaped_command);
356 if (grntest_outtype ==
OUT_TSV) {
361 fprintf(grntest_log_file,
"[%d, \"%s\", %" GRN_FMT_LLD
", %" GRN_FMT_LLD
", %.*s],\n",
365 fflush(grntest_log_file);
375 long long int latency,
self;
383 sec =
self / (double)1000000;
384 qps = (double)qnum / sec;
385 if (grntest_outtype ==
OUT_TSV) {
386 fprintf(grntest_log_file,
"total\t%" GRN_FMT_LLD
"\t%f\t%d\n", latency, qps, qnum);
388 fprintf(grntest_log_file,
389 "{\"total\": %" GRN_FMT_LLD
", \"qps\": %f, \"queries\": %d}]\n", latency, qps, qnum);
396 output_sysinfo(
char *sysinfo)
398 if (grntest_outtype ==
OUT_TSV) {
399 fprintf(grntest_log_file,
"%s", sysinfo);
401 fprintf(grntest_log_file,
"[%s\n", sysinfo);
407 #ifdef ENABLE_ERROR_REPORT
409 error_command(
grn_ctx *ctx,
char *command,
int task_id)
411 fprintf(stderr,
"error!:command=[%s] task_id = %d\n", command, task_id);
413 error_exit_in_thread(1);
420 char **normalized_output,
int *normalized_length)
424 *normalized_output = NULL;
425 *normalized_length = length;
426 for (i = 0; i < length; i++) {
427 if (!strncmp(output + i,
"],", 2)) {
428 *normalized_output = output + i + 2;
429 *normalized_length -= i + 2;
434 if (!*normalized_output) {
435 if (length > 2 && strncmp(output + length - 2,
"]]", 2)) {
436 *normalized_output = output + length;
437 *normalized_length = 0;
439 *normalized_output = output;
445 same_result_p(
char *expect,
int expected_length,
char *result,
int result_length)
447 char *normalized_expected, *normalized_result;
448 int normalized_expected_length, normalized_result_length;
451 &normalized_expected, &normalized_expected_length);
453 &normalized_result, &normalized_result_length);
455 return((normalized_expected_length == normalized_result_length) &&
456 strncmp(normalized_expected, normalized_result,
457 normalized_expected_length) == 0);
461 open_socket(
const char *host,
int port)
464 struct hostent *servhost;
465 struct sockaddr_in server;
469 servhost = gethostbyname(host);
470 if (servhost == NULL){
471 fprintf(stderr,
"Bad hostname [%s]\n", host);
474 inaddr = *(u_long*)(servhost->h_addr_list[0]);
476 memset(&server, 0,
sizeof(
struct sockaddr_in));
477 server.sin_family = AF_INET;
478 server.sin_port = htons(port);
479 server.sin_addr = *(
struct in_addr*)&inaddr;
481 sock = socket(AF_INET, SOCK_STREAM, 0);
483 fprintf(stderr,
"socket error\n");
486 ret = connect(sock, (
struct sockaddr *)&server,
sizeof(
struct sockaddr_in));
488 fprintf(stderr,
"connect error\n");
495 write_to_server(
socket_t socket,
const char *buf)
498 fprintf(stderr,
"send:%s", buf);
500 send(socket, buf, strlen(buf), 0);
504 #define OUTPUT_TYPE "output_type"
505 #define OUTPUT_TYPE_LEN (sizeof(OUTPUT_TYPE) - 1)
508 command_line_to_uri_path(
grn_ctx *ctx,
grn_obj *uri,
const char *command)
511 int offset = 0, have_key = 0;
512 const char *p, *e, *v;
519 e = command + strlen(command);
539 if (
GRN_TEXT_LEN(&buf) > 2 && v[0] ==
'-' && v[1] ==
'-') {
558 if (offset < nvars) {
563 vars[offset].name, vars[offset].name_size);
591 command_send_http(
grn_ctx *ctx,
const char *command,
int type,
int task_id)
596 http_socket = open_socket(grntest_serverhost, grntest_serverport);
598 fprintf(stderr,
"failed to connect to groonga at %s:%d via HTTP: ",
599 grntest_serverhost, grntest_serverport);
601 fprintf(stderr,
"%d\n", GetLastError());
603 fprintf(stderr,
"%s\n", strerror(errno));
605 error_exit_in_thread(100);
612 if (strncmp(command,
"/d/", 3) == 0) {
615 command_line_to_uri_path(ctx, &buf, command);
618 fprintf(stderr,
"command: <%s>\n", command);
619 fprintf(stderr,
"path: <%.*s>\n",
637 command_send_ctx(
grn_ctx *ctx,
const char *command,
int type,
int task_id)
650 command_send(
grn_ctx *ctx,
const char *command,
int type,
int task_id)
653 command_send_http(ctx, command, type, task_id);
655 command_send_ctx(ctx, command, type, task_id);
660 command_recv_http(
grn_ctx *ctx,
int type,
int task_id,
661 char **res,
unsigned int *res_len,
int *flags)
671 while ((len = recv(http_socket, buf,
BUF_LEN - 1, 0))) {
673 fprintf(stderr,
"receive: <%.*s>\n", len, buf);
686 if (!memcmp(p,
"\r\n\r\n", 4)) {
690 fprintf(stderr,
"body: <%.*s>\n", *res_len, *res);
707 command_recv_ctx(
grn_ctx *ctx,
int type,
int task_id,
708 char **res,
unsigned int *res_len,
int *flags)
712 fprintf(stderr,
"ctx_recv:rc=%d\n", ctx->
rc);
713 error_exit_in_thread(1);
718 command_recv(
grn_ctx *ctx,
int type,
int task_id,
719 char **res,
unsigned int *res_len,
int *flags)
722 command_recv_http(ctx, type, task_id, res, res_len, flags);
724 command_recv_ctx(ctx, type, task_id, res, res_len, flags);
729 shutdown_server(
void)
733 unsigned int res_len;
737 if (grntest_remote_mode) {
740 job_type = grntest_task[task_id].
jobtype;
741 command_send(&grntest_server_context,
"shutdown", job_type, task_id);
742 if (grntest_server_context.
rc) {
743 fprintf(stderr,
"ctx_send:rc=%d\n", grntest_server_context.
rc);
746 command_recv(&grntest_server_context, job_type, task_id,
747 &res, &res_len, &flags);
753 do_load_command(
grn_ctx *ctx,
char *command,
int type,
int task_id,
754 long long int *load_start)
757 unsigned int res_len;
762 if (*load_start == 0) {
769 command_send(ctx, command, type, task_id);
771 command_recv(ctx, type, task_id, &res, &res_len, &flags);
779 if (grntest_task[task_id].max <
self) {
780 grntest_task[task_id].
max =
self;
782 if (grntest_task[task_id].min >
self) {
783 grntest_task[task_id].
min =
self;
786 if (report_p(grntest_task[task_id].jobtype)) {
790 strncpy(tmpbuf, res, res_len);
791 tmpbuf[res_len] =
'\0';
793 strncpy(tmpbuf, res,
BUF_LEN - 2);
796 report_command(ctx,
"load", tmpbuf, task_id, &start_time, &end_time);
798 if (out_p(grntest_task[task_id].jobtype)) {
799 fwrite(res, 1, res_len, grntest_job[grntest_task[task_id].job_id].outputlog);
800 fputc(
'\n', grntest_job[grntest_task[task_id].job_id].outputlog);
801 fflush(grntest_job[grntest_task[task_id].job_id].outputlog);
803 if (test_p(grntest_task[task_id].jobtype)) {
812 error_exit_in_thread(55);
820 fprintf(output,
"DIFF:command:%s\n", command);
821 fprintf(output,
"DIFF:result:");
822 fwrite(res, 1, res_len, output);
824 fprintf(output,
"DIFF:expect:%.*s\n",
845 do_command(
grn_ctx *ctx,
char *command,
int type,
int task_id)
848 unsigned int res_len;
855 command_send(ctx, command, type, task_id);
857 command_recv(ctx, type, task_id, &res, &res_len, &flags);
865 if (grntest_task[task_id].max <
self) {
866 grntest_task[task_id].
max =
self;
868 if (grntest_task[task_id].min >
self) {
869 grntest_task[task_id].
min =
self;
872 if (report_p(grntest_task[task_id].jobtype)) {
876 strncpy(tmpbuf, res, res_len);
877 tmpbuf[res_len] =
'\0';
879 strncpy(tmpbuf, res,
BUF_LEN - 2);
882 report_command(ctx, command, tmpbuf, task_id, &start_time, &end_time);
884 if (out_p(grntest_task[task_id].jobtype)) {
885 fwrite(res, 1, res_len, grntest_job[grntest_task[task_id].job_id].outputlog);
886 fputc(
'\n', grntest_job[grntest_task[task_id].job_id].outputlog);
887 fflush(grntest_job[grntest_task[task_id].job_id].outputlog);
889 if (test_p(grntest_task[task_id].jobtype)) {
898 error_exit_in_thread(55);
906 fprintf(output,
"DIFF:command:%s\n", command);
907 fprintf(output,
"DIFF:result:");
908 fwrite(res, 1, res_len, output);
910 fprintf(output,
"DIFF:expect:%.*s\n",
919 #ifdef ENABLE_ERROR_REPORT
920 error_command(ctx, command, task_id);
931 comment_p(
char *command)
933 if (command[0] ==
'#') {
940 load_command_p(
char *command)
947 if (command[i] ==
'\0') {
950 if (!strncmp(&command[i],
"load", 4)) {
959 int i, load_mode, load_count;
961 long long int total_elapsed_time, job_elapsed_time;
963 long long int load_start;
967 task = &(grntest_task[task_id]);
969 task->
min = 9223372036854775807LL;
972 for (i = 0; i < task->
ntimes; i++) {
973 if (task->
file != NULL) {
976 fp = fopen(task->
file,
"r");
978 fprintf(stderr,
"Cannot open %s\n",grntest_task[task_id].file);
979 error_exit_in_thread(1);
1002 if (load_mode == 1) {
1003 if (do_load_command(&grntest_ctx[task_id],
GRN_TEXT_VALUE(&line),
1005 task_id, &load_start)) {
1006 task->
qnum += load_count;
1020 if (grntest_sigint) {
1031 error_exit_in_thread(1);
1035 for (i = 0; i < n_commands; i++) {
1041 if (load_mode == 1) {
1042 if (do_load_command(&grntest_ctx[task_id],
1044 task->
jobtype, task_id, &load_start)) {
1051 do_command(&grntest_ctx[task_id],
1055 if (grntest_sigint) {
1068 CRITICAL_SECTION_ENTER(grntest_cs);
1069 job = &(grntest_job[task->
job_id]);
1070 if (job->
max < task->
max) {
1073 if (job->
min > task->
min) {
1081 sec = job_elapsed_time / (double)1000000;
1082 qps = (double)job->
qnum/ sec;
1084 if (grntest_outtype ==
OUT_TSV) {
1088 "%" GRN_FMT_LLD
"\t"
1089 "%" GRN_FMT_LLD
"\t"
1091 "%" GRN_FMT_LLD
"\t"
1092 "%" GRN_FMT_LLD
"\t"
1103 "{\"job\": \"%s\", "
1104 "\"total_elapsed_time\": %" GRN_FMT_LLD
", "
1105 "\"job_elapsed_time\": %" GRN_FMT_LLD
", "
1107 "\"min\": %" GRN_FMT_LLD
", "
1108 "\"max\": %" GRN_FMT_LLD
", "
1117 if (grntest_jobdone < grntest_jobnum) {
1118 strcat(tmpbuf,
",");
1122 if (grntest_jobdone == grntest_jobnum) {
1123 if (grntest_outtype ==
OUT_TSV) {
1124 fprintf(grntest_log_file,
"%.*s",
1127 if (grntest_detail_on) {
1128 fseek(grntest_log_file, -2, SEEK_CUR);
1129 fprintf(grntest_log_file,
"],\n");
1131 fprintf(grntest_log_file,
"\"summary\": [");
1132 fprintf(grntest_log_file,
"%.*s",
1134 fprintf(grntest_log_file,
"]");
1136 fflush(grntest_log_file);
1140 CRITICAL_SECTION_LEAVE(grntest_cs);
1172 thread_main(
grn_ctx *ctx,
int num)
1179 for (i = 0; i < num; i++) {
1181 workers[
i]->
ctx = &grntest_ctx[
i];
1184 pthread[
i] = (HANDLE)_beginthreadex(NULL, 0, worker, (
void *)workers[
i],
1186 if (pthread[i]== (HANDLE)0) {
1187 fprintf(stderr,
"thread failed:%d\n", i);
1188 error_exit_in_thread(1);
1192 ret = WaitForMultipleObjects(num, pthread,
TRUE, INFINITE);
1193 if (ret == WAIT_TIMEOUT) {
1194 fprintf(stderr,
"timeout\n");
1195 error_exit_in_thread(1);
1198 for (i = 0; i < num; i++) {
1199 CloseHandle(pthread[i]);
1207 thread_main(
grn_ctx *ctx,
int num)
1214 for (i = 0; i < num; i++) {
1216 workers[
i]->
ctx = &grntest_ctx[
i];
1219 ret = pthread_create(&pthread[i], NULL, worker, (
void *)workers[i]);
1221 fprintf(stderr,
"Cannot create thread:ret=%d\n", ret);
1222 error_exit_in_thread(1);
1226 for (i = 0; i < num; i++) {
1227 ret = pthread_join(pthread[i], NULL);
1231 fprintf(stderr,
"Cannot join thread:ret=%d\n", ret);
1232 error_exit_in_thread(1);
1240 error_exit(
grn_ctx *ctx,
int ret)
1250 get_sysinfo(
const char *path,
char *result,
int olen)
1256 ULARGE_INTEGER dinfo;
1259 MEMORYSTATUSEX minfo;
1260 OSVERSIONINFO osinfo;
1262 if (grntest_outtype ==
OUT_TSV) {
1264 sprintf(tmpbuf,
"script\t%s\n", grntest_scriptname);
1265 strcat(result, tmpbuf);
1266 sprintf(tmpbuf,
"user\t%s\n", grntest_username);
1267 strcat(result, tmpbuf);
1268 sprintf(tmpbuf,
"date\t%s\n", grntest_date);
1269 strcat(result, tmpbuf);
1271 strcpy(result,
"{");
1272 sprintf(tmpbuf,
"\"script\": \"%s.scr\",\n", grntest_scriptname);
1273 strcat(result, tmpbuf);
1274 sprintf(tmpbuf,
" \"user\": \"%s\",\n", grntest_username);
1275 strcat(result, tmpbuf);
1276 sprintf(tmpbuf,
" \"date\": \"%s\",\n", grntest_date);
1277 strcat(result, tmpbuf);
1280 memset(cpustring, 0, 64);
1282 __cpuid(cinfo, 0x80000002);
1283 memcpy(cpustring, cinfo, 16);
1284 __cpuid(cinfo, 0x80000003);
1285 memcpy(cpustring+16, cinfo, 16);
1286 __cpuid(cinfo, 0x80000004);
1287 memcpy(cpustring+32, cinfo, 16);
1290 if (grntest_outtype ==
OUT_TSV) {
1291 sprintf(tmpbuf,
"%s\n", cpustring);
1293 sprintf(tmpbuf,
" \"CPU\": \"%s\",\n", cpustring);
1295 strcat(result, tmpbuf);
1297 if (
sizeof(
int *) == 8) {
1299 if (grntest_outtype ==
OUT_TSV) {
1300 sprintf(tmpbuf,
"64BIT\n");
1302 sprintf(tmpbuf,
" \"BIT\": 64,\n");
1306 if (grntest_outtype ==
OUT_TSV) {
1307 sprintf(tmpbuf,
"32BIT\n");
1309 sprintf(tmpbuf,
" \"BIT\": 32,\n");
1312 strcat(result, tmpbuf);
1314 GetSystemInfo(&sinfo);
1315 if (grntest_outtype ==
OUT_TSV) {
1316 sprintf(tmpbuf,
"CORE\t%d\n", sinfo.dwNumberOfProcessors);
1318 sprintf(tmpbuf,
" \"CORE\": %d,\n", sinfo.dwNumberOfProcessors);
1320 strcat(result, tmpbuf);
1322 minfo.dwLength =
sizeof(MEMORYSTATUSEX);
1323 GlobalMemoryStatusEx(&minfo);
1324 if (grntest_outtype ==
OUT_TSV) {
1325 sprintf(tmpbuf,
"RAM\t%I64dMByte\n", minfo.ullTotalPhys/(1024*1024));
1327 sprintf(tmpbuf,
" \"RAM\": \"%I64dMByte\",\n", minfo.ullTotalPhys/(1024*1024));
1329 strcat(result, tmpbuf);
1331 GetDiskFreeSpaceEx(NULL, NULL, &dinfo, NULL);
1332 if (grntest_outtype ==
OUT_TSV) {
1333 sprintf(tmpbuf,
"HDD\t%I64dKBytes\n", dinfo.QuadPart/1024 );
1335 sprintf(tmpbuf,
" \"HDD\": \"%I64dKBytes\",\n", dinfo.QuadPart/1024 );
1337 strcat(result, tmpbuf);
1339 osinfo.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO); GetVersionEx(&osinfo);
1340 if (grntest_outtype ==
OUT_TSV) {
1341 sprintf(tmpbuf,
"Windows %d.%d\n", osinfo.dwMajorVersion, osinfo.dwMinorVersion);
1343 sprintf(tmpbuf,
" \"OS\": \"Windows %d.%d\",\n", osinfo.dwMajorVersion,
1344 osinfo.dwMinorVersion);
1346 strcat(result, tmpbuf);
1348 if (grntest_outtype ==
OUT_TSV) {
1349 sprintf(tmpbuf,
"%s\n", grntest_serverhost);
1351 sprintf(tmpbuf,
" \"HOST\": \"%s\",\n", grntest_serverhost);
1353 strcat(result, tmpbuf);
1355 if (grntest_outtype ==
OUT_TSV) {
1356 sprintf(tmpbuf,
"%d\n", grntest_serverport);
1358 sprintf(tmpbuf,
" \"PORT\": \"%d\",\n", grntest_serverport);
1360 strcat(result, tmpbuf);
1362 if (grntest_outtype ==
OUT_TSV) {
1368 strcat(result, tmpbuf);
1369 if (grntest_outtype !=
OUT_TSV) {
1370 strcat(result,
"}");
1378 int unevictable = 0;
1380 char cpustring[256];
1381 struct utsname ubuf;
1382 struct statvfs vfsbuf;
1384 if (grntest_outtype ==
OUT_TSV) {
1386 sprintf(tmpbuf,
"sctipt\t%s\n", grntest_scriptname);
1387 strcat(result, tmpbuf);
1388 sprintf(tmpbuf,
"user\t%s\n", grntest_username);
1389 strcat(result, tmpbuf);
1390 sprintf(tmpbuf,
"date\t%s\n", grntest_date);
1391 strcat(result, tmpbuf);
1393 strcpy(result,
"{");
1394 sprintf(tmpbuf,
"\"script\": \"%s.scr\",\n", grntest_scriptname);
1395 strcat(result, tmpbuf);
1396 sprintf(tmpbuf,
" \"user\": \"%s\",\n", grntest_username);
1397 strcat(result, tmpbuf);
1398 sprintf(tmpbuf,
" \"date\": \"%s\",\n", grntest_date);
1399 strcat(result, tmpbuf);
1402 fp = fopen(
"/proc/cpuinfo",
"r");
1404 fprintf(stderr,
"Cannot open cpuinfo\n");
1407 while (fgets(tmpbuf, 256, fp) != NULL) {
1408 tmpbuf[strlen(tmpbuf)-1] =
'\0';
1409 if (!strncmp(tmpbuf,
"model name\t: ", 13)) {
1410 strcpy(cpustring, &tmpbuf[13]);
1414 cpunum = sysconf(_SC_NPROCESSORS_CONF);
1416 if (grntest_outtype ==
OUT_TSV) {
1417 sprintf(tmpbuf,
"%s\n", cpustring);
1419 sprintf(tmpbuf,
" \"CPU\": \"%s\",\n", cpustring);
1421 strcat(result, tmpbuf);
1423 if (
sizeof(
int *) == 8) {
1425 if (grntest_outtype ==
OUT_TSV) {
1426 sprintf(tmpbuf,
"64BIT\n");
1428 sprintf(tmpbuf,
" \"BIT\": 64,\n");
1432 if (grntest_outtype ==
OUT_TSV) {
1433 sprintf(tmpbuf,
"32BIT\n");
1435 sprintf(tmpbuf,
" \"BIT\": 32,\n");
1438 strcat(result, tmpbuf);
1440 if (grntest_outtype ==
OUT_TSV) {
1441 sprintf(tmpbuf,
"CORE\t%d\n", cpunum);
1443 sprintf(tmpbuf,
" \"CORE\": %d,\n", cpunum);
1445 strcat(result, tmpbuf);
1447 fp = fopen(
"/proc/meminfo",
"r");
1449 fprintf(stderr,
"Cannot open meminfo\n");
1452 while (fgets(tmpbuf, 256, fp) != NULL) {
1453 tmpbuf[strlen(tmpbuf)-1] =
'\0';
1454 if (!strncmp(tmpbuf,
"MemTotal:", 9)) {
1455 minfo = grntest_atoi(&tmpbuf[10], &tmpbuf[10] + 40, NULL);
1457 if (!strncmp(tmpbuf,
"Unevictable:", 12)) {
1458 unevictable = grntest_atoi(&tmpbuf[13], &tmpbuf[13] + 40, NULL);
1460 if (!strncmp(tmpbuf,
"Mlocked:", 8)) {
1461 mlocked = grntest_atoi(&tmpbuf[9], &tmpbuf[9] + 40, NULL);
1465 if (grntest_outtype ==
OUT_TSV) {
1466 sprintf(tmpbuf,
"%dMBytes\n", minfo/1024);
1467 strcat(result, tmpbuf);
1468 sprintf(tmpbuf,
"%dMBytes_Unevictable\n", unevictable/1024);
1469 strcat(result, tmpbuf);
1470 sprintf(tmpbuf,
"%dMBytes_Mlocked\n", mlocked/1024);
1471 strcat(result, tmpbuf);
1473 sprintf(tmpbuf,
" \"RAM\": \"%dMBytes\",\n", minfo/1024);
1474 strcat(result, tmpbuf);
1475 sprintf(tmpbuf,
" \"Unevictable\": \"%dMBytes\",\n", unevictable/1024);
1476 strcat(result, tmpbuf);
1477 sprintf(tmpbuf,
" \"Mlocked\": \"%dMBytes\",\n", mlocked/1024);
1478 strcat(result, tmpbuf);
1481 ret = statvfs(path, &vfsbuf);
1483 fprintf(stderr,
"Cannot access %s\n", path);
1487 if (grntest_outtype ==
OUT_TSV) {
1488 sprintf(tmpbuf,
"%" GRN_FMT_INT64U "KBytes\n", vfsbuf.f_blocks * 4);
1492 vfsbuf.f_blocks * 4);
1494 strcat(result, tmpbuf);
1497 if (grntest_outtype ==
OUT_TSV) {
1498 sprintf(tmpbuf,
"%s %s\n", ubuf.sysname, ubuf.release);
1500 sprintf(tmpbuf,
" \"OS\": \"%s %s\",\n", ubuf.sysname, ubuf.release);
1502 strcat(result, tmpbuf);
1504 if (grntest_outtype ==
OUT_TSV) {
1505 sprintf(tmpbuf,
"%s\n", grntest_serverhost);
1507 sprintf(tmpbuf,
" \"HOST\": \"%s\",\n", grntest_serverhost);
1509 strcat(result, tmpbuf);
1511 if (grntest_outtype ==
OUT_TSV) {
1512 sprintf(tmpbuf,
"%d\n", grntest_serverport);
1514 sprintf(tmpbuf,
" \"PORT\": \"%d\",\n", grntest_serverport);
1516 strcat(result, tmpbuf);
1518 if (grntest_outtype ==
OUT_TSV) {
1523 strcat(result, tmpbuf);
1525 if (grntest_outtype !=
OUT_TSV) {
1526 strcat(result,
"},");
1529 if (strlen(result) >= olen) {
1530 fprintf(stderr,
"buffer overrun in get_sysinfo!\n");
1537 start_server(
const char *dbpath,
int r)
1546 if (strlen(dbpath) >
BUF_LEN - 100) {
1547 fprintf(stderr,
"too long dbpath!\n");
1551 strcpy(tmpbuf, groonga_path);
1552 strcat(tmpbuf,
" -s --protocol ");
1553 strcat(tmpbuf, groonga_protocol);
1554 strcat(tmpbuf,
" -p ");
1555 sprintf(optbuf,
"%d ", grntest_serverport);
1556 strcat(tmpbuf, optbuf);
1557 strcat(tmpbuf, dbpath);
1558 memset(&si, 0,
sizeof(STARTUPINFO));
1559 si.cb=
sizeof(STARTUPINFO);
1560 ret = CreateProcess(NULL, tmpbuf, NULL, NULL,
FALSE,
1561 0, NULL, NULL, &si, &grntest_pi);
1564 fprintf(stderr,
"Cannot start groonga server: <%s>: error=%d\n",
1565 groonga_path, GetLastError());
1573 fprintf(stderr,
"Cannot start groonga server:Cannot fork\n");
1576 sprintf(optbuf,
"%d", grntest_serverport);
1578 ret = execlp(groonga_path, groonga_path,
1580 "--protocol", groonga_protocol,
1582 dbpath, (
char*)NULL);
1584 fprintf(stderr,
"Cannot start groonga server: <%s>: errno=%d\n",
1585 groonga_path, errno);
1590 grntest_server_id = pid;
1599 parse_line(
char *buf,
int start,
int end,
int num)
1601 int i, j, error_flag = 0, out_or_test = 0;
1605 grntest_job[num].
ntimes = 1;
1606 grntest_job[num].
done = 0;
1607 grntest_job[num].
qnum = 0;
1608 grntest_job[num].
max = 0LL;
1609 grntest_job[num].
min = 9223372036854775807LL;
1613 strncpy(grntest_job[num].jobname, &buf[start], end - start);
1614 grntest_job[num].
jobname[end - start] =
'\0';
1621 if (!strncmp(&buf[i],
"do_local", 8)) {
1626 if (!strncmp(&buf[i],
"do_gqtp", 7)) {
1631 if (!strncmp(&buf[i],
"do_http", 7)) {
1636 if (!strncmp(&buf[i],
"rep_local", 9)) {
1641 if (!strncmp(&buf[i],
"rep_gqtp", 8)) {
1646 if (!strncmp(&buf[i],
"rep_http", 8)) {
1651 if (!strncmp(&buf[i],
"out_local", 9)) {
1657 if (!strncmp(&buf[i],
"out_gqtp", 8)) {
1663 if (!strncmp(&buf[i],
"out_http", 8)) {
1669 if (!strncmp(&buf[i],
"test_local", 10)) {
1675 if (!strncmp(&buf[i],
"test_gqtp", 9)) {
1681 if (!strncmp(&buf[i],
"test_http", 9)) {
1727 fprintf(stderr,
"log(test)_local(gqtp|http) needs log(test)_filename\n");
1747 if (out_p(grntest_job[num].jobtype)) {
1748 grntest_job[num].
outputlog = fopen(tmpbuf,
"wb");
1749 if (grntest_job[num].outputlog == NULL) {
1750 fprintf(stderr,
"Cannot open %s\n", tmpbuf);
1755 grntest_job[num].
inputlog = fopen(tmpbuf,
"rb");
1756 if (grntest_job[num].inputlog == NULL) {
1757 fprintf(stderr,
"Cannot open %s\n", tmpbuf);
1760 sprintf(outlog,
"%s.diff", tmpbuf);
1761 grntest_job[num].
outputlog = fopen(outlog,
"wb");
1762 if (grntest_job[num].outputlog == NULL) {
1763 fprintf(stderr,
"Cannot open %s\n", outlog);
1767 strcpy(grntest_job[num].logfile, tmpbuf);
1770 grntest_job[num].
concurrency = grntest_atoi(tmpbuf, tmpbuf + j, NULL);
1771 if (grntest_job[num].concurrency == 0) {
1797 grntest_job[num].
ntimes = grntest_atoi(tmpbuf, tmpbuf + j, NULL);
1798 if (grntest_job[num].ntimes == 0) {
1816 get_jobs(
grn_ctx *ctx,
char *buf,
int line)
1818 int i, len, start, end, ret;
1824 if ((buf[i] ==
'#') || (buf[i] ==
'\r') || (buf[i] ==
'\n')) {
1835 if (buf[i] ==
';') {
1837 ret = parse_line(buf, start, end, jnum);
1840 fprintf(stderr,
"Syntax error:line=%d:ret=%d:%s\n", line, ret, buf);
1851 ret = parse_line(buf, start, end, jnum);
1854 fprintf(stderr,
"Syntax error:line=%d:ret=%d:%s\n", line, ret, buf);
1864 make_task_table(
grn_ctx *ctx,
int jobnum)
1871 for (i = 0; i < jobnum; i++) {
1872 if ((grntest_job[i].concurrency == 1) && (!grntest_onmemory_mode)) {
1887 fprintf(stderr,
"Cannot alloc commands\n");
1890 fp = fopen(grntest_job[i].commandfile,
"r");
1892 fprintf(stderr,
"Cannot alloc commandfile:%s\n",
1893 grntest_job[i].commandfile);
1912 fprintf(stderr,
"Cannot alloc command: %s: %s\n",
1923 grntest_task[tid].
file = NULL;
1924 grntest_task[tid].
commands = commands;
1951 do_jobs(
grn_ctx *ctx,
int jobnum,
int line)
1953 int i, task_num, ret, qnum = 0, thread_num = 0;
1955 for (i = 0; i < jobnum; i++) {
1965 fprintf(stderr,
"Too many threads requested(MAX=64):line=%d\n", line);
1969 task_num = make_task_table(ctx, jobnum);
1970 if (task_num != thread_num) {
1971 fprintf(stderr,
"Logical error\n");
1975 grntest_detail_on = 0;
1976 for (i = 0; i < task_num; i++) {
1978 grntest_owndb[
i] = NULL;
1979 if (gqtp_p(grntest_task[i].jobtype)) {
1980 ret =
grn_ctx_connect(&grntest_ctx[i], grntest_serverhost, grntest_serverport, 0);
1982 fprintf(stderr,
"Cannot connect groonga server:host=%s:port=%d:ret=%d\n",
1983 grntest_serverhost, grntest_serverport, ret);
1986 }
else if (http_p(grntest_task[i].jobtype)) {
1989 if (grntest_owndb_mode) {
1990 grntest_owndb[
i] =
grn_db_open(&grntest_ctx[i], grntest_dbpath);
1991 if (grntest_owndb[i] == NULL) {
1992 fprintf(stderr,
"Cannot open db:%s\n", grntest_dbpath);
1999 if (grntest_owndb_mode) {
2000 grntest_owndb[
i] =
grn_db_open(&grntest_ctx[i], grntest_dbpath);
2001 if (grntest_owndb[i] == NULL) {
2002 fprintf(stderr,
"Cannot open db:%s\n", grntest_dbpath);
2010 if (report_p(grntest_task[i].jobtype)) {
2011 grntest_detail_on++;
2014 if (grntest_detail_on) {
2015 if (grntest_outtype ==
OUT_TSV) {
2019 fprintf(grntest_log_file,
"\"detail\": [\n");
2021 fflush(grntest_log_file);
2024 thread_main(ctx, task_num);
2026 for (i = 0; i < task_num; i++) {
2027 if (grntest_owndb[i]) {
2030 if (http_p(grntest_task[i].jobtype)) {
2031 GRN_OBJ_FIN(&grntest_ctx[i], &grntest_task[i].http_response);
2034 qnum = qnum + grntest_task[
i].
qnum;
2038 while (i < task_num) {
2040 if (grntest_task[i].commands) {
2041 job_id = grntest_task[
i].
job_id;
2043 while (job_id == grntest_task[i].job_id) {
2050 for (i = 0; i < jobnum; i++) {
2051 if (grntest_job[i].outputlog) {
2053 ret = fclose(grntest_job[i].outputlog);
2055 fprintf(stderr,
"Cannot close %s\n", grntest_job[i].logfile);
2059 if (grntest_job[i].inputlog) {
2061 ret = fclose(grntest_job[i].inputlog);
2063 fprintf(stderr,
"Cannot close %s\n", grntest_job[i].logfile);
2073 do_script(
grn_ctx *ctx,
const char *script_file_path)
2077 int n_queries, total_n_queries = 0;
2081 script_file = fopen(script_file_path,
"r");
2082 if (script_file == NULL) {
2083 fprintf(stderr,
"Cannot open script file: <%s>\n", script_file_path);
2089 if (grntest_sigint) {
2093 grntest_jobdone = 0;
2095 grntest_jobnum = n_jobs;
2100 if (grntest_outtype ==
OUT_TSV) {
2101 fprintf(grntest_log_file,
"jobs-start\t%s\n",
GRN_TEXT_VALUE(&line));
2103 fprintf(grntest_log_file,
"{\"jobs\": \"%s\",\n",
GRN_TEXT_VALUE(&line));
2105 n_queries = do_jobs(ctx, n_jobs, n_lines);
2106 if (grntest_outtype ==
OUT_TSV) {
2107 fprintf(grntest_log_file,
"jobs-end\t%s\n",
GRN_TEXT_VALUE(&line));
2109 fprintf(grntest_log_file,
"},\n");
2111 total_n_queries += n_queries;
2115 if (grntest_stop_flag) {
2116 fprintf(stderr,
"Error:Quit\n");
2123 fclose(script_file);
2125 return total_n_queries;
2129 start_local(
grn_ctx *ctx,
const char *dbpath)
2136 fprintf(stderr,
"Cannot open db:%s\n", dbpath);
2147 ret =
grn_ctx_connect(ctx, grntest_serverhost, grntest_serverport, 0);
2152 fprintf(stderr,
"Cannot connect groonga server:host=%s:port=%d:ret=%d\n",
2153 grntest_serverhost, grntest_serverport, ret);
2159 fprintf(stderr,
"Cannot connect groonga server:host=%s:port=%d:ret=%d\n",
2160 grntest_serverhost, grntest_serverport, ret);
2174 check_response(
char *buf)
2176 if (buf[0] ==
'1') {
2179 if (buf[0] ==
'2') {
2182 if (buf[0] ==
'3') {
2189 read_response(
socket_t socket,
char *buf)
2192 ret = recv(socket, buf,
BUF_LEN - 1, 0);
2194 fprintf(stderr,
"recv error:3\n");
2199 fprintf(stderr,
"recv:%s", buf);
2205 put_file(
socket_t socket,
const char *filename)
2208 int c, ret, size = 0;
2211 fp = fopen(filename,
"rb");
2213 fprintf(stderr,
"LOCAL:no such file:%s\n", filename);
2217 while ((c = fgetc(fp)) != EOF) {
2219 ret = send(socket, buf, 1, 0);
2221 fprintf(stderr,
"send error\n");
2237 ret = recv(data_socket, buf,
BUF_LEN - 2, 0);
2243 fprintf(stdout,
"%s", buf);
2250 get_file(
socket_t socket,
const char *filename,
int size)
2256 fp = fopen(filename,
"wb");
2258 fprintf(stderr,
"Cannot open %s\n", filename);
2263 while (total != size) {
2264 ret = recv(socket, buf,
FTPBUF, 0);
2266 fprintf(stderr,
"recv error:2:ret=%d:size=%d:total\n", ret, size);
2272 fwrite(buf, ret, 1, fp);
2273 total = total + ret;
2281 get_port(
char *buf,
char *host,
int *port)
2283 int ret,d1,d2,d3,d4,d5,d6;
2284 ret = sscanf(buf,
"227 Entering Passive Mode (%d,%d,%d,%d,%d,%d)",
2285 &d1, &d2, &d3, &d4, &d5, &d6);
2287 fprintf(stderr,
"Cannot enter passsive mode\n");
2291 *port = d5 * 256 + d6;
2292 sprintf(host,
"%d.%d.%d.%d", d1, d2, d3, d4);
2297 get_ftp_date(
char *buf)
2299 while (*buf !=
' ') {
2315 while (*buf !=
'(') {
2322 size = grntest_atoi(buf, buf + strlen(buf), NULL);
2328 ftp_sub(
const char *user,
const char *passwd,
const char *host,
2329 const char *filename,
int mode,
2330 const char *cd_dirname,
char *retval)
2334 socket_t command_socket, data_socket;
2350 WSAStartup(MAKEWORD(2,0), &ws);
2353 if ((filename != NULL) && (strlen(filename) >=
MAX_PATH_LEN)) {
2354 fprintf(stderr,
"too long filename\n");
2358 if ((cd_dirname != NULL) && (strlen(cd_dirname) >=
MAX_PATH_LEN)) {
2359 fprintf(stderr,
"too long dirname\n");
2363 command_socket = open_socket(host, 21);
2368 read_response(command_socket, buf);
2369 if (!check_response(buf)) {
2374 sprintf(send_mesg,
"USER %s\r\n", user);
2375 write_to_server(command_socket, send_mesg);
2376 read_response(command_socket, buf);
2377 if (!check_response(buf)) {
2382 sprintf(send_mesg,
"PASS %s\r\n", passwd);
2383 write_to_server(command_socket, send_mesg);
2384 read_response(command_socket, buf);
2385 if (!check_response(buf)) {
2390 sprintf(send_mesg,
"TYPE I\r\n");
2391 write_to_server(command_socket, send_mesg);
2392 read_response(command_socket, buf);
2393 if (!check_response(buf)) {
2398 sprintf(send_mesg,
"PASV\r\n");
2399 write_to_server(command_socket, send_mesg);
2400 read_response(command_socket, buf);
2401 if (!check_response(buf)) {
2405 if (!get_port(buf, data_host, &data_port)) {
2409 data_socket = open_socket(data_host, data_port);
2415 sprintf(send_mesg,
"CWD %s\r\n", cd_dirname);
2416 write_to_server(command_socket, send_mesg);
2419 read_response(command_socket, buf);
2420 if (!check_response(buf)) {
2426 _splitpath(filename, NULL, NULL, fname, ext);
2427 strcpy(base, fname);
2430 strcpy(buf, filename);
2431 base = basename(buf);
2437 sprintf(send_mesg,
"LIST %s\r\n", filename);
2439 sprintf(send_mesg,
"LIST \r\n");
2441 write_to_server(command_socket, send_mesg);
2444 sprintf(send_mesg,
"STOR %s\r\n", base);
2445 write_to_server(command_socket, send_mesg);
2448 sprintf(send_mesg,
"RETR %s\r\n", base);
2449 write_to_server(command_socket, send_mesg);
2452 sprintf(send_mesg,
"MDTM %s\r\n", base);
2453 write_to_server(command_socket, send_mesg);
2456 fprintf(stderr,
"invalid mode\n");
2461 read_response(command_socket, buf);
2462 if (!check_response(buf)) {
2466 if (!strncmp(buf,
"150", 3)) {
2467 size = get_size(buf);
2469 if (!strncmp(buf,
"213", 3)) {
2471 strcpy(retval, get_ftp_date(buf));
2472 if (retval[
BUF_LEN-2] !=
'\0' ) {
2473 fprintf(stderr,
"buffer over run in ftp\n");
2480 ftp_list(data_socket);
2483 if (get_file(data_socket, filename, size) == -1) {
2487 fprintf(stderr,
"get:%s\n", filename);
2490 if (put_file(data_socket, filename) == -1) {
2494 fprintf(stderr,
"put:%s\n", filename);
2502 read_response(command_socket, buf);
2504 write_to_server(command_socket,
"QUIT\n");
2531 get_username(
char *name,
int maxlen)
2534 strcpy(name,
"nobody");
2536 env = getenv(
"USERNAME");
2538 env = getenv(
"USER");
2540 if (strlen(env) > maxlen) {
2541 fprintf(stderr,
"too long username:%s\n", env);
2551 get_date(
char *
date, time_t *sec)
2553 #if defined(WIN32) && !defined(__GNUC__)
2555 struct tm *tm = &tmbuf;
2556 localtime_s(tm, sec);
2558 # ifdef HAVE_LOCALTIME_R
2560 struct tm *tm = &result;
2561 localtime_r(sec, tm);
2563 struct tm *tm = localtime(sec);
2568 strftime(date, 128,
"%Y-%m-%d %H:%M:%S", tm);
2570 strftime(date, 128,
"%F %T", tm);
2577 get_scriptname(
const char *path,
char *name,
const char *suffix)
2579 int slen = strlen(suffix);
2580 int len = strlen(path);
2583 fprintf(stderr,
"too long script name\n");
2587 fprintf(stderr,
"too long suffux\n");
2592 if (strncmp(&name[len-slen], suffix, slen)) {
2596 name[len-slen] =
'\0';
2602 get_tm_from_serverdate(
char *serverdate,
struct tm *tm)
2605 int year, month, day, hour, minute, second;
2607 res = sscanf(serverdate,
"%4d%2d%2d%2d%2d%2d",
2608 &year, &month, &day, &hour, &minute, &second);
2614 tm->tm_sec = second;
2615 tm->tm_min = minute;
2618 tm->tm_mon = month - 1;
2619 tm->tm_year = year - 1900;
2629 sync_sub(
grn_ctx *ctx,
const char *filename)
2634 struct _stat statbuf;
2636 struct stat statbuf;
2644 fprintf(stderr,
"[%s] does not exist in server\n", filename);
2648 get_tm_from_serverdate(serverdate, &stm);
2650 strptime(serverdate,
"%Y%m%d %H%M%S", &stm);
2654 st = mktime(&stm) + 3600 * 9;
2658 ret = _stat(filename, &statbuf);
2660 ret = stat(filename, &statbuf);
2664 lt = statbuf.st_mtime;
2666 fprintf(stderr,
"newer [%s] exists in server\n", filename);
2673 fprintf(stderr,
"[%s] does not exist in local\n", filename);
2683 cache_file(
grn_ctx *ctx,
char **flist,
char *file,
int fnum)
2687 for (i = 0; i < fnum; i++) {
2688 if (!strcmp(flist[i], file) ) {
2695 fprintf(stderr,
"too many uniq commands file!\n");
2702 sync_datafile(
grn_ctx *ctx,
const char *script_file_path)
2711 fp = fopen(script_file_path,
"r");
2713 fprintf(stderr,
"Cannot open script file: <%s>\n", script_file_path);
2717 while (fgets(buf,
BUF_LEN, fp) != NULL) {
2720 fprintf(stderr,
"Too long line in script file:%d\n", line);
2723 job_num = get_jobs(ctx, buf, line);
2726 for (i = 0; i < job_num; i++) {
2730 fnum = cache_file(ctx, filelist, grntest_job[i].commandfile, fnum);
2734 for (i = 0; i < fnum; i++) {
2735 if (sync_sub(ctx, filelist[i])) {
2736 fprintf(stderr,
"updated!:%s\n", filelist[i]);
2746 sync_script(
grn_ctx *ctx,
const char *filename)
2750 ret = sync_sub(ctx, filename);
2755 fprintf(stderr,
"updated!:%s\n", filename);
2757 filenum = sync_datafile(ctx, filename);
2765 "Usage: grntest [options...] [script] [db]\n"
2767 " --dir: show script files on ftp server\n"
2768 " -i, --host <ip/hostname>: server address to listen (default: %s)\n"
2769 " --localonly: omit server connection\n"
2770 " --log-output-dir: specify output dir (default: current)\n"
2771 " --ftp: connect to ftp server\n"
2772 " --onmemory: load all commands into memory\n"
2773 " --output-type <tsv/json>: specify output-type (default: json)\n"
2774 " --owndb: open dbs for each ctx\n"
2775 " -p, --port <port number>: server port number (default: %d)\n"
2776 " --groonga <groonga_path>: groonga command path (default: %s)\n"
2777 " --protocol <gqtp|http>: groonga server protocol (default: %s)\n"
2778 " --log-path <path>: specify log file path\n"
2779 " --pid-path <path>: specify file path to store PID file\n",
2781 groonga_path, groonga_protocol);
2791 #define MODE_MASK 0x007f
2792 #define MODE_FTP 0x0080
2793 #define MODE_LOCALONLY 0x0100
2794 #define MODE_OWNDB 0x0800
2795 #define MODE_ONMEMORY 0x1000
2799 get_token(
char *line,
char *token,
int maxlen,
char **next)
2834 if (*(line + 1) ==
';') {
2839 if (*(line + 1) ==
'#') {
2844 if (*(line + 1) ==
'\0') {
2856 check_script(
grn_ctx *ctx,
const char *script_file_path)
2864 script_file = fopen(script_file_path,
"r");
2866 fprintf(stderr,
"Cannot open script file: <%s>\n", script_file_path);
2874 strcpy(prev, token);
2877 get_token(next, token,
BUF_LEN, &next);
2878 if (!strncmp(prev,
"SET_PORT", 8)) {
2879 grntest_serverport =
grn_atoi(token, token + strlen(token), NULL);
2881 if (!strncmp(prev,
"SET_HOST", 8)) {
2882 strcpy(grntest_serverhost, token);
2883 grntest_remote_mode = 1;
2885 strcpy(prev, token);
2890 fclose(script_file);
2898 fprintf(stderr,
"timeout:groonga server cannot shutdown!!\n");
2899 fprintf(stderr,
"Use \"kill -9 %d\"\n", grntest_server_id);
2910 setsigalarm(
int sec)
2913 struct sigaction sig;
2916 sig.sa_handler = timeout;
2918 sigemptyset(&sig.sa_mask);
2919 ret = sigaction(SIGALRM, &sig, NULL);
2921 fprintf(stderr,
"setsigalarm:errno= %d\n", errno);
2930 struct sigaction sig;
2932 sig.sa_handler = setexit;
2934 sigemptyset(&sig.sa_mask);
2935 ret = sigaction(SIGINT, &sig, NULL);
2937 fprintf(stderr,
"setsigint:errno= %d\n", errno);
2946 int qnum,
i, mode = 0;
2947 int exit_code = EXIT_SUCCESS;
2950 char log_path_buffer[
BUF_LEN];
2951 const char *log_path = NULL;
2952 const char *pid_path = NULL;
2953 const char *portstr = NULL, *hoststr = NULL, *dbname = NULL, *scrname = NULL, *outdir = NULL, *outtype = NULL;
2971 {
'\0', NULL, NULL, 0, 0}
2974 opts[0].
arg = &hoststr;
2975 opts[1].
arg = &portstr;
2976 opts[2].
arg = &outdir;
2977 opts[3].
arg = &outtype;
2978 opts[10].
arg = &groonga_path;
2979 opts[11].
arg = &groonga_protocol;
2980 opts[12].
arg = &log_path;
2981 opts[13].
arg = &pid_path;
3003 pid_file = fopen(pid_path,
"w");
3005 fprintf(pid_file,
"%d", getpid());
3009 "failed to open PID file: <%s>: %s\n",
3010 pid_path, strerror(errno));
3020 grntest_dbpath = dbname;
3023 grntest_localonly_mode = 1;
3024 grntest_remote_mode = 1;
3028 grntest_localonly_mode = 1;
3029 grntest_remote_mode = 1;
3030 grntest_owndb_mode = 1;
3034 grntest_onmemory_mode= 1;
3041 if ((scrname == NULL) || (dbname == NULL)) {
3047 grntest_remote_mode = 1;
3048 strcpy(grntest_serverhost, hoststr);
3052 grntest_serverport =
grn_atoi(portstr, portstr + strlen(portstr), NULL);
3055 if (outtype && !strcmp(outtype,
"tsv")) {
3060 CRITICAL_SECTION_INIT(grntest_cs);
3067 if (grntest_ftp_mode) {
3068 sync_script(&context, scrname);
3070 if (!check_script(&context, scrname)) {
3071 exit_code = EXIT_FAILURE;
3075 start_local(&context, dbname);
3076 if (!grntest_remote_mode) {
3077 start_server(dbname, 0);
3080 if (!grntest_localonly_mode) {
3081 if (check_server(&grntest_server_context)) {
3086 get_scriptname(scrname, grntest_scriptname,
".scr");
3087 get_username(grntest_username, 256);
3092 get_date(grntest_date, &sec);
3096 sprintf(log_path_buffer,
3097 "%s/%s-%s-%" GRN_FMT_LLD
"-%s.log", outdir, grntest_scriptname,
3101 sprintf(log_path_buffer,
3102 "%s-%s-%" GRN_FMT_LLD
"-%s.log", grntest_scriptname,
3106 log_path = log_path_buffer;
3109 grntest_log_file = fopen(log_path,
"w+b");
3110 if (!grntest_log_file) {
3111 fprintf(stderr,
"Cannot open log file: <%s>\n", log_path);
3115 get_sysinfo(dbname, sysinfo,
BUF_LEN);
3116 output_sysinfo(sysinfo);
3121 qnum = do_script(&context, scrname);
3122 output_result_final(&context, qnum);
3123 fclose(grntest_log_file);
3125 if (grntest_ftp_mode) {
3129 fprintf(stderr,
"grntest done. logfile=%s\n", log_path);
3138 if (!grntest_remote_mode) {
3140 ret = WaitForSingleObject(grntest_pi.hProcess, 20000);
3141 if (ret == WAIT_TIMEOUT) {
3142 fprintf(stderr,
"timeout:groonga server cannot shutdown!!\n");
3143 fprintf(stderr,
"Cannot wait\n");
3148 if (grntest_server_id) {
3151 ret = waitpid(grntest_server_id, &pstatus, 0);
3153 fprintf(stderr,
"Cannot wait\n");
3164 CRITICAL_SECTION_FIN(grntest_cs);