~ubuntu-branches/ubuntu/trusty/hyperestraier/trusty-proposed

« back to all changes in this revision

Viewing changes to estmttest.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2006-11-14 05:28:32 UTC
  • mfrom: (2.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061114052832-0lzqzcefn8mt4yqe
Tags: 1.4.9-1.1
* Non-maintainer upload.
* High-urgency upload for RC bugfix.
* Set HOME=$(CURDIR)/junkhome when building, otherwise the package build
  will incorrectly look for headers there -- and fail when the directory
  exists and is unreadable, as happens sometimes on sudo-using
  autobuilders!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*************************************************************************************************
2
2
 * The command line interface of the MT-safe API
3
 
 *                                                      Copyright (C) 2004-2005 Mikio Hirabayashi
 
3
 *                                                      Copyright (C) 2004-2006 Mikio Hirabayashi
4
4
 * This file is part of Hyper Estraier.
5
5
 * Hyper Estraier is free software; you can redistribute it and/or modify it under the terms of
6
6
 * the GNU Lesser General Public License as published by the Free Software Foundation; either
48
48
int main(int argc, char **argv);
49
49
static void printferror(const char *format, ...);
50
50
static void printfinfo(const char *format, ...);
51
 
static void dbinform(const char *msg);
 
51
static void dbinform(const char *message, void *opaque);
52
52
static void setsignals(void);
53
53
static void sigtermhandler(int num);
54
54
static void usage(void);
55
55
static int runwicked(int argc, char **argv);
 
56
static int runregression(int argc, char **argv);
56
57
static int procwicked(const char *dbname, int dnum, int tnum);
 
58
static int procregression(const char *dbname);
57
59
static void *mtwkfunc(void *mission);
58
60
static ESTDOC *est_doc_new_from_chaos(int cnum, int snum, int mode);
59
61
static char *est_random_str(int cnum, int mode);
64
66
  const char *tmp;
65
67
  int rv;
66
68
  if((tmp = getenv("ESTDBGFD")) != NULL) dpdbgfd = atoi(tmp);
67
 
  cbstdiobin();
 
69
  est_proc_env_reset();
68
70
  g_progname = argv[0];
69
71
  g_sigterm = FALSE;
70
72
  if(argc < 2) usage();
72
74
  if(!strcmp(argv[1], "wicked")){
73
75
    setsignals();
74
76
    rv = runwicked(argc, argv);
 
77
  } else if(!strcmp(argv[1], "regression")){
 
78
    setsignals();
 
79
    rv = runregression(argc, argv);
75
80
  } else {
76
81
    usage();
77
82
  }
107
112
 
108
113
 
109
114
/* callback function for database events */
110
 
static void dbinform(const char *msg){
111
 
  printfinfo("%s", msg);
 
115
static void dbinform(const char *message, void *opaque){
 
116
  printfinfo("%s", message);
112
117
}
113
118
 
114
119
 
141
146
  fprintf(stderr, "\n");
142
147
  fprintf(stderr, "usage:\n");
143
148
  fprintf(stderr, "  %s wicked db dnum tnum\n", g_progname);
 
149
  fprintf(stderr, "  %s regression db\n", g_progname);
144
150
  fprintf(stderr, "\n");
145
151
  exit(1);
146
152
}
174
180
}
175
181
 
176
182
 
 
183
/* parse arguments of the regression command */
 
184
static int runregression(int argc, char **argv){
 
185
  char *dbname;
 
186
  int i, rv;
 
187
  dbname = NULL;
 
188
  for(i = 2; i < argc; i++){
 
189
    if(!dbname && argv[i][0] == '-'){
 
190
      usage();
 
191
    } else if(!dbname){
 
192
      dbname = argv[i];
 
193
    } else {
 
194
      usage();
 
195
    }
 
196
  }
 
197
  if(!dbname) usage();
 
198
  rv = procregression(dbname);
 
199
  return rv;
 
200
}
 
201
 
 
202
 
177
203
/* perform the wicked command */
178
204
static int procwicked(const char *dbname, int dnum, int tnum){
179
205
  ESTMTDB *dbs[BRANCHDBNUM];
195
221
      free(name);
196
222
      return -1;
197
223
    }
198
 
    est_mtdb_set_informer(dbs[i], dbinform);
 
224
    est_mtdb_set_informer(dbs[i], dbinform, NULL);
199
225
    est_mtdb_set_cache_size(dbs[i], 1024 * 1024 * 32, 1024, 256, 64);
200
226
    est_mtdb_set_special_cache(dbs[i], ESTDATTRURI, 128);
201
227
    free(name);
246
272
}
247
273
 
248
274
 
 
275
/* perform the regression command */
 
276
static int procregression(const char *dbname){
 
277
  ESTMTDB *dbs[10], *db, *tdbs[5];
 
278
  ESTDOC *doc;
 
279
  ESTCOND *cond;
 
280
  CBMAP *hints;
 
281
  char wbuf[URIBUFSIZ];
 
282
  int i, j, ecode, err, *res, rnum;
 
283
  time_t curtime;
 
284
  curtime = time(NULL);
 
285
  printfinfo("# opening databases");
 
286
  for(i = 0; i < 10; i++){
 
287
    sprintf(wbuf, "%s-%08d", dbname, i + 1);
 
288
    if(!(dbs[i] = est_mtdb_open(wbuf, ESTDBWRITER | ESTDBCREAT | ESTDBTRUNC, &ecode))){
 
289
      printferror("%s: %s", wbuf, est_err_msg(est_mtdb_error(dbs[i])));
 
290
      return 1;
 
291
    }
 
292
    est_mtdb_set_informer(dbs[i], dbinform, NULL);
 
293
  }
 
294
  err = FALSE;
 
295
  printfinfo("# registering documents");
 
296
  for(i = 0; i < 1000 && !g_sigterm; i++){
 
297
    doc = est_doc_new();
 
298
    sprintf(wbuf, "%d", rand() % (i + 100));
 
299
    est_doc_add_attr(doc, ESTDATTRURI, wbuf);
 
300
    for(j = 0; j < 100; j++){
 
301
      sprintf(wbuf, "%c%c", 'a' + rand() % 6, 'a' + rand() % 6);
 
302
      est_doc_add_text(doc, wbuf);
 
303
    }
 
304
    db = dbs[rand()%10];
 
305
    if(!est_mtdb_put_doc(db, doc, ESTPDCLEAN)){
 
306
      printferror("%s: %s", est_mtdb_name(db), est_err_msg(ecode));
 
307
      err = TRUE;
 
308
    }
 
309
    est_doc_delete(doc);
 
310
  }
 
311
  printfinfo("# flushing half of databases");
 
312
  for(i = 0; i < 10; i += 2){
 
313
    if(!est_mtdb_flush(dbs[i], -1)){
 
314
      printferror("%s: %s", est_mtdb_name(dbs[i]), est_err_msg(ecode));
 
315
      err = TRUE;
 
316
    }
 
317
  }
 
318
  printfinfo("# searching databases");
 
319
  for(i = 0; i < 1000 && !g_sigterm; i++){
 
320
    cond = est_cond_new();
 
321
    sprintf(wbuf, "%c%c", 'a' + rand() % 6, 'a' + rand() % 6);
 
322
    est_cond_set_phrase(cond, wbuf);
 
323
    switch(rand() % 5){
 
324
    case 0:
 
325
      est_cond_set_order(cond, ESTORDIDA);
 
326
      break;
 
327
    case 1:
 
328
      est_cond_set_order(cond, ESTORDSCA);
 
329
      break;
 
330
    case 2:
 
331
      est_cond_set_order(cond, ESTDATTRURI " " ESTORDSTRA);
 
332
      break;
 
333
    }
 
334
    hints = cbmapopen();
 
335
    res = est_mtdb_search_meta(dbs, 10, cond, &rnum, hints);
 
336
    for(j = 0; j < rnum; j += 2){
 
337
      if(res[j] < 0 || res[j] >= 10){
 
338
        printferror("%s: search result is invalid", dbname);
 
339
        err = TRUE;
 
340
        break;
 
341
      }
 
342
    }
 
343
    free(res);
 
344
    cbmapclose(hints);
 
345
    est_cond_delete(cond);
 
346
  }
 
347
  printfinfo("# searching certainly same databases");
 
348
  tdbs[0] = dbs[0];
 
349
  tdbs[1] = dbs[1];
 
350
  tdbs[2] = dbs[2];
 
351
  tdbs[3] = dbs[0];
 
352
  tdbs[4] = dbs[1];
 
353
  for(i = 0; i < 100 && !g_sigterm; i++){
 
354
    cond = est_cond_new();
 
355
    sprintf(wbuf, "%c%c", 'a' + rand() % 6, 'a' + rand() % 6);
 
356
    est_cond_set_phrase(cond, wbuf);
 
357
    switch(rand() % 5){
 
358
    case 0:
 
359
      est_cond_set_order(cond, ESTORDIDA);
 
360
      break;
 
361
    case 1:
 
362
      est_cond_set_order(cond, ESTORDSCA);
 
363
      break;
 
364
    case 2:
 
365
      est_cond_set_order(cond, ESTDATTRURI " " ESTORDSTRA);
 
366
      break;
 
367
    }
 
368
    hints = cbmapopen();
 
369
    res = est_mtdb_search_meta(tdbs, 5, cond, &rnum, hints);
 
370
    for(j = 0; j < rnum; j += 2){
 
371
      if(res[j] < 0 || res[j] >= 5){
 
372
        printferror("%s: search result is invalid", dbname);
 
373
        err = TRUE;
 
374
        break;
 
375
      }
 
376
    }
 
377
    free(res);
 
378
    cbmapclose(hints);
 
379
    est_cond_delete(cond);
 
380
  }
 
381
  printfinfo("# closing databases");
 
382
  for(i = 0; i < 10; i++){
 
383
    if(!est_mtdb_close(dbs[i], &ecode)){
 
384
      printferror("%s: %s", est_mtdb_name(dbs[i]), est_err_msg(ecode));
 
385
      err = TRUE;
 
386
    }
 
387
  }
 
388
  curtime = time(NULL) - curtime;
 
389
  if(!err) printfinfo("# finished successfully: elapsed time: %dh %dm %ds",
 
390
                      (int)(curtime / 3600), (int)((curtime / 60) % 60), (int)(curtime % 60));
 
391
  return err ? 1 : 0;
 
392
}
 
393
 
 
394
 
249
395
/* Thread function for wicked command */
250
396
static void *mtwkfunc(void *mission){
251
397
  ESTMTDB *db, **others;
333
479
      doc = est_doc_new_from_chaos(100, 3, est_random() < 0.5 ? RD_EURO : RD_RAND);
334
480
      if(est_random() < 0.2){
335
481
        sprintf(uri, "file:///tmp/wicked-%08d-%05d.est",
336
 
                (int)(est_random() * INT_MAX) % (i + 1) + 1, getpid());
 
482
                (int)(est_random() * INT_MAX) % (i + 1) + 1, (int)getpid());
337
483
      } else {
338
 
        sprintf(uri, "file:///tmp/wicked-%08d-%05d.est", i + 1, getpid());
 
484
        sprintf(uri, "file:///tmp/wicked-%08d-%05d.est", i + 1, (int)getpid());
339
485
      }
340
486
      est_doc_add_attr(doc, ESTDATTRURI, uri);
341
487
      if(!est_mtdb_put_doc(db, doc, est_random() < 0.5 ? ESTPDCLEAN : 0)) err = TRUE;