~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzletest.cc

Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
#endif
73
73
 
74
74
using namespace std;
 
75
using namespace drizzled;
75
76
 
76
77
extern "C"
77
 
{
78
 
  unsigned char *get_var_key(const unsigned char* var, size_t *len, bool);
79
 
  bool get_one_option(int optid, const struct my_option *, char *argument);
80
 
}
 
78
unsigned char *get_var_key(const unsigned char* var, size_t *len, bool);
 
79
 
 
80
bool get_one_option(int optid, const struct my_option *, char *argument);
81
81
 
82
82
#define MAX_VAR_NAME_LENGTH    256
83
83
#define MAX_COLUMNS            256
920
920
 
921
921
  free_all_replace();
922
922
  free(opt_pass);
923
 
  free_defaults(default_argv);
 
923
  internal::free_defaults(default_argv);
924
924
 
925
925
  return;
926
926
}
929
929
static void cleanup_and_exit(int exit_code)
930
930
{
931
931
  free_used_memory();
932
 
  my_end();
 
932
  internal::my_end();
933
933
 
934
934
  if (!silent) {
935
935
    switch (exit_code) {
1142
1142
  uint32_t len;
1143
1143
  char buff[512];
1144
1144
 
1145
 
  if ((fd= my_open(filename, O_RDONLY, MYF(0))) < 0)
 
1145
  if ((fd= internal::my_open(filename, O_RDONLY, MYF(0))) < 0)
1146
1146
    die("Failed to open file '%s'", filename);
1147
 
  while((len= my_read(fd, (unsigned char*)&buff,
 
1147
  while((len= internal::my_read(fd, (unsigned char*)&buff,
1148
1148
                      sizeof(buff), MYF(0))) > 0)
1149
1149
  {
1150
1150
    char *p= buff, *start= buff;
1166
1166
    /* Output any chars that might be left */
1167
1167
    ds->append(start, p-start);
1168
1168
  }
1169
 
  my_close(fd, MYF(0));
 
1169
  internal::my_close(fd, MYF(0));
1170
1170
}
1171
1171
 
1172
1172
 
1351
1351
  const char *fname= filename2;
1352
1352
  string tmpfile;
1353
1353
 
1354
 
  if ((fd2= my_open(fname, O_RDONLY, MYF(0))) < 0)
 
1354
  if ((fd2= internal::my_open(fname, O_RDONLY, MYF(0))) < 0)
1355
1355
  {
1356
 
    my_close(fd, MYF(0));
 
1356
    internal::my_close(fd, MYF(0));
1357
1357
    if (opt_testdir != NULL)
1358
1358
    {
1359
1359
      tmpfile= opt_testdir;
1362
1362
      tmpfile.append(filename2);
1363
1363
      fname= tmpfile.c_str();
1364
1364
    }
1365
 
    if ((fd2= my_open(fname, O_RDONLY, MYF(0))) < 0)
 
1365
    if ((fd2= internal::my_open(fname, O_RDONLY, MYF(0))) < 0)
1366
1366
    {
1367
 
      my_close(fd, MYF(0));
 
1367
      internal::my_close(fd, MYF(0));
1368
1368
    
1369
1369
      die("Failed to open second file: '%s'", fname);
1370
1370
    }
1371
1371
  }
1372
 
  while((len= my_read(fd, (unsigned char*)&buff,
 
1372
  while((len= internal::my_read(fd, (unsigned char*)&buff,
1373
1373
                      sizeof(buff), MYF(0))) > 0)
1374
1374
  {
1375
 
    if ((len2= my_read(fd2, (unsigned char*)&buff2,
 
1375
    if ((len2= internal::my_read(fd2, (unsigned char*)&buff2,
1376
1376
                       sizeof(buff2), MYF(0))) < len)
1377
1377
    {
1378
1378
      /* File 2 was smaller */
1392
1392
      break;
1393
1393
    }
1394
1394
  }
1395
 
  if (!error && my_read(fd2, (unsigned char*)&buff2,
 
1395
  if (!error && internal::my_read(fd2, (unsigned char*)&buff2,
1396
1396
                        sizeof(buff2), MYF(0)) > 0)
1397
1397
  {
1398
1398
    /* File 1 was smaller */
1399
1399
    error= RESULT_LENGTH_MISMATCH;
1400
1400
  }
1401
1401
 
1402
 
  my_close(fd2, MYF(0));
 
1402
  internal::my_close(fd2, MYF(0));
1403
1403
 
1404
1404
  return error;
1405
1405
}
1423
1423
  int fd;
1424
1424
  int error;
1425
1425
 
1426
 
  if ((fd= my_open(filename1, O_RDONLY, MYF(0))) < 0)
 
1426
  if ((fd= internal::my_open(filename1, O_RDONLY, MYF(0))) < 0)
1427
1427
    die("Failed to open first file: '%s'", filename1);
1428
1428
 
1429
1429
  error= compare_files2(fd, filename2);
1430
1430
 
1431
 
  my_close(fd, MYF(0));
 
1431
  internal::my_close(fd, MYF(0));
1432
1432
 
1433
1433
  return error;
1434
1434
}
1452
1452
  int fd;
1453
1453
  char temp_file_path[FN_REFLEN];
1454
1454
 
1455
 
  if ((fd= create_temp_file(temp_file_path, NULL,
 
1455
  if ((fd= internal::create_temp_file(temp_file_path, NULL,
1456
1456
                            "tmp", MYF(MY_WME))) < 0)
1457
1457
    die("Failed to create temporary file for ds");
1458
1458
 
1459
1459
  /* Write ds to temporary file and set file pos to beginning*/
1460
 
  if (my_write(fd, (unsigned char *) ds->c_str(), ds->length(),
 
1460
  if (internal::my_write(fd, (unsigned char *) ds->c_str(), ds->length(),
1461
1461
               MYF(MY_FNABP | MY_WME)) ||
1462
1462
      lseek(fd, 0, SEEK_SET) == MY_FILEPOS_ERROR)
1463
1463
  {
1464
 
    my_close(fd, MYF(0));
 
1464
    internal::my_close(fd, MYF(0));
1465
1465
    /* Remove the temporary file */
1466
 
    my_delete(temp_file_path, MYF(0));
 
1466
    internal::my_delete(temp_file_path, MYF(0));
1467
1467
    die("Failed to write file '%s'", temp_file_path);
1468
1468
  }
1469
1469
 
1470
1470
  error= compare_files2(fd, fname);
1471
1471
 
1472
 
  my_close(fd, MYF(0));
 
1472
  internal::my_close(fd, MYF(0));
1473
1473
  /* Remove the temporary file */
1474
 
  my_delete(temp_file_path, MYF(0));
 
1474
  internal::my_delete(temp_file_path, MYF(0));
1475
1475
 
1476
1476
  return(error);
1477
1477
}
1513
1513
    */
1514
1514
    char reject_file[FN_REFLEN];
1515
1515
    size_t reject_length;
1516
 
    dirname_part(reject_file, result_file_name, &reject_length);
 
1516
    internal::dirname_part(reject_file, result_file_name, &reject_length);
1517
1517
 
1518
1518
    if (access(reject_file, W_OK) == 0)
1519
1519
    {
1520
1520
      /* Result file directory is writable, save reject file there */
1521
 
      fn_format(reject_file, result_file_name, NULL,
 
1521
      internal::fn_format(reject_file, result_file_name, NULL,
1522
1522
                ".reject", MY_REPLACE_EXT);
1523
1523
    }
1524
1524
    else
1525
1525
    {
1526
1526
      /* Put reject file in opt_logdir */
1527
 
      fn_format(reject_file, result_file_name, opt_logdir,
 
1527
      internal::fn_format(reject_file, result_file_name, opt_logdir,
1528
1528
                ".reject", MY_REPLACE_DIR | MY_REPLACE_EXT);
1529
1529
    }
1530
1530
    str_to_file(reject_file, ds->c_str(), ds->length());
1565
1565
  if (string_cmp(ds, fname.c_str()))
1566
1566
  {
1567
1567
    char reason[FN_REFLEN];
1568
 
    fn_format(reason, fname.c_str(), "", "", MY_REPLACE_EXT | MY_REPLACE_DIR);
 
1568
    internal::fn_format(reason, fname.c_str(), "", "", MY_REPLACE_EXT | MY_REPLACE_DIR);
1569
1569
    abort_not_supported_test("Test requires: '%s'", reason);
1570
1570
  }
1571
1571
  return;
2145
2145
{
2146
2146
  char buff[FN_REFLEN];
2147
2147
 
2148
 
  if (!test_if_hard_path(name))
 
2148
  if (!internal::test_if_hard_path(name))
2149
2149
  {
2150
2150
    sprintf(buff,"%s%s",opt_basedir,name);
2151
2151
    name=buff;
2152
2152
  }
2153
 
  fn_format(buff, name, "", "", MY_UNPACK_FILENAME);
 
2153
  internal::fn_format(buff, name, "", "", MY_UNPACK_FILENAME);
2154
2154
 
2155
2155
  if (cur_file == file_stack_end)
2156
2156
    die("Source directives are nesting too deep");
2469
2469
                     rm_args, sizeof(rm_args)/sizeof(struct command_arg),
2470
2470
                     ' ');
2471
2471
 
2472
 
  error= my_delete(ds_filename.c_str(), MYF(0)) != 0;
 
2472
  error= internal::my_delete(ds_filename.c_str(), MYF(0)) != 0;
2473
2473
  handle_command_error(command, error);
2474
2474
  return;
2475
2475
}
2503
2503
                     sizeof(copy_file_args)/sizeof(struct command_arg),
2504
2504
                     ' ');
2505
2505
 
2506
 
  error= (my_copy(ds_from_file.c_str(), ds_to_file.c_str(),
 
2506
  error= (internal::my_copy(ds_from_file.c_str(), ds_to_file.c_str(),
2507
2507
                  MYF(MY_DONT_OVERWRITE_FILE)) != 0);
2508
2508
  handle_command_error(command, error);
2509
2509
  return;
2601
2601
                     mkdir_args, sizeof(mkdir_args)/sizeof(struct command_arg),
2602
2602
                     ' ');
2603
2603
 
2604
 
  error= mkdir(ds_dirname.c_str(), (0777 & my_umask_dir)) != 0;
 
2604
  error= mkdir(ds_dirname.c_str(), (0777 & internal::my_umask_dir)) != 0;
2605
2605
  handle_command_error(command, error);
2606
2606
  return;
2607
2607
}
2992
2992
  read_until_delimiter(&ds_script, &ds_delimiter);
2993
2993
 
2994
2994
  /* Create temporary file name */
2995
 
  if ((fd= create_temp_file(temp_file_path, getenv("MYSQLTEST_VARDIR"),
 
2995
  if ((fd= internal::create_temp_file(temp_file_path, getenv("MYSQLTEST_VARDIR"),
2996
2996
                            "tmp", MYF(MY_WME))) < 0)
2997
2997
    die("Failed to create temporary file for perl command");
2998
 
  my_close(fd, MYF(0));
 
2998
  internal::my_close(fd, MYF(0));
2999
2999
 
3000
3000
  str_to_file(temp_file_path, ds_script.c_str(), ds_script.length());
3001
3001
 
3015
3015
  error= pclose(res_file);
3016
3016
 
3017
3017
  /* Remove the temporary file */
3018
 
  my_delete(temp_file_path, MYF(0));
 
3018
  internal::my_delete(temp_file_path, MYF(0));
3019
3019
 
3020
3020
  handle_command_error(command, WEXITSTATUS(error));
3021
3021
  return;
3315
3315
  if (!*p)
3316
3316
    die("Missing argument to %.*s", command->first_word_len, command->query);
3317
3317
  sleep_start= p;
3318
 
  /* Check that arg starts with a digit, not handled by my_strtod */
 
3318
  /* Check that arg starts with a digit, not handled by internal::my_strtod */
3319
3319
  if (!my_isdigit(charset_info, *sleep_start))
3320
3320
    die("Invalid argument to %.*s \"%s\"", command->first_word_len,
3321
3321
        command->query,command->first_argument);
3884
3884
    if (*ds_sock.c_str() != FN_LIBCHAR)
3885
3885
    {
3886
3886
      char buff[FN_REFLEN];
3887
 
      fn_format(buff, ds_sock.c_str(), TMPDIR, "", 0);
 
3887
      internal::fn_format(buff, ds_sock.c_str(), TMPDIR, "", 0);
3888
3888
      ds_sock.clear();
3889
3889
      ds_sock.append(buff);
3890
3890
    }
4649
4649
 
4650
4650
static void print_version(void)
4651
4651
{
4652
 
  printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",my_progname,MTEST_VERSION,
 
4652
  printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,MTEST_VERSION,
4653
4653
         drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
4654
4654
}
4655
4655
 
4660
4660
  printf("Drizzle version modified by Brian, Jay, Monty Taylor, PatG and Stewart\n");
4661
4661
  printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
4662
4662
  printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n");
4663
 
  printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname);
 
4663
  printf("Usage: %s [OPTIONS] [database] < test_file\n", internal::my_progname);
4664
4664
  my_print_help(my_long_options);
4665
4665
  printf("  --no-defaults       Don't read default options from any options file.\n");
4666
4666
  my_print_variables(my_long_options);
4678
4678
  case 'x':
4679
4679
  {
4680
4680
    char buff[FN_REFLEN];
4681
 
    if (!test_if_hard_path(argument))
 
4681
    if (!internal::test_if_hard_path(argument))
4682
4682
    {
4683
4683
      sprintf(buff,"%s%s",opt_basedir,argument);
4684
4684
      argument= buff;
4685
4685
    }
4686
 
    fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
 
4686
    internal::fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4687
4687
    assert(cur_file == file_stack && cur_file->file == 0);
4688
4688
    if (!(cur_file->file= fopen(buff, "r")))
4689
4689
      die("Could not open '%s' for reading: errno = %d", buff, errno);
4695
4695
  case 'm':
4696
4696
  {
4697
4697
    static char buff[FN_REFLEN];
4698
 
    if (!test_if_hard_path(argument))
 
4698
    if (!internal::test_if_hard_path(argument))
4699
4699
    {
4700
4700
      sprintf(buff,"%s%s",opt_basedir,argument);
4701
4701
      argument= buff;
4702
4702
    }
4703
 
    fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
 
4703
    internal::fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4704
4704
    timer_file= buff;
4705
4705
    unlink(timer_file);       /* Ignore error, may not exist */
4706
4706
    break;
4760
4760
 
4761
4761
static int parse_args(int argc, char **argv)
4762
4762
{
4763
 
  load_defaults("drizzle",load_default_groups,&argc,&argv);
 
4763
  internal::load_defaults("drizzle",load_default_groups,&argc,&argv);
4764
4764
  default_argv= argv;
4765
4765
 
4766
4766
  if ((handle_options(&argc, &argv, my_long_options, get_one_option)))
4795
4795
  int fd;
4796
4796
  char buff[FN_REFLEN];
4797
4797
  int flags= O_WRONLY | O_CREAT;
4798
 
  if (!test_if_hard_path(fname))
 
4798
  if (!internal::test_if_hard_path(fname))
4799
4799
  {
4800
4800
    sprintf(buff,"%s%s",opt_basedir,fname);
4801
4801
    fname= buff;
4802
4802
  }
4803
 
  fn_format(buff, fname, "", "", MY_UNPACK_FILENAME);
 
4803
  internal::fn_format(buff, fname, "", "", MY_UNPACK_FILENAME);
4804
4804
 
4805
4805
  if (!append)
4806
4806
    flags|= O_TRUNC;
4807
 
  if ((fd= my_open(buff, flags,
 
4807
  if ((fd= internal::my_open(buff, flags,
4808
4808
                   MYF(MY_WME | MY_FFNF))) < 0)
4809
4809
    die("Could not open '%s' for writing: errno = %d", buff, errno);
4810
4810
  if (append && lseek(fd, 0, SEEK_END) == MY_FILEPOS_ERROR)
4811
4811
    die("Could not find end of file '%s': errno = %d", buff, errno);
4812
 
  if (my_write(fd, (unsigned char*)str, size, MYF(MY_WME|MY_FNABP)))
 
4812
  if (internal::my_write(fd, (unsigned char*)str, size, MYF(MY_WME|MY_FNABP)))
4813
4813
    die("write failed");
4814
 
  my_close(fd, MYF(0));
 
4814
  internal::my_close(fd, MYF(0));
4815
4815
}
4816
4816
 
4817
4817
/*
4833
4833
void dump_result_to_log_file(const char *buf, int size)
4834
4834
{
4835
4835
  char log_file[FN_REFLEN];
4836
 
  str_to_file(fn_format(log_file, result_file_name, opt_logdir, ".log",
 
4836
  str_to_file(internal::fn_format(log_file, result_file_name, opt_logdir, ".log",
4837
4837
                        *opt_logdir ? MY_REPLACE_DIR | MY_REPLACE_EXT :
4838
4838
                        MY_REPLACE_EXT),
4839
4839
              buf, size);
4844
4844
void dump_progress(void)
4845
4845
{
4846
4846
  char progress_file[FN_REFLEN];
4847
 
  str_to_file(fn_format(progress_file, result_file_name,
 
4847
  str_to_file(internal::fn_format(progress_file, result_file_name,
4848
4848
                        opt_logdir, ".progress",
4849
4849
                        *opt_logdir ? MY_REPLACE_DIR | MY_REPLACE_EXT :
4850
4850
                        MY_REPLACE_EXT),
4855
4855
{
4856
4856
  char warn_file[FN_REFLEN];
4857
4857
 
4858
 
  str_to_file(fn_format(warn_file, result_file_name, opt_logdir, ".warnings",
 
4858
  str_to_file(internal::fn_format(warn_file, result_file_name, opt_logdir, ".warnings",
4859
4859
                        *opt_logdir ? MY_REPLACE_DIR | MY_REPLACE_EXT :
4860
4860
                        MY_REPLACE_EXT),
4861
4861
              ds_warning_messages.c_str(), ds_warning_messages.length());
6039
6039
 
6040
6040
uint64_t timer_now(void)
6041
6041
{
6042
 
  return my_micro_time() / 1000;
 
6042
#if defined(HAVE_GETHRTIME)
 
6043
  return gethrtime()/1000/1000;
 
6044
#else
 
6045
  uint64_t newtime;
 
6046
  struct timeval t;
 
6047
  /*
 
6048
    The following loop is here because gettimeofday may fail on some systems
 
6049
  */
 
6050
  while (gettimeofday(&t, NULL) != 0)
 
6051
  {}
 
6052
  newtime= (uint64_t)t.tv_sec * 1000000 + t.tv_usec;
 
6053
  return newtime/1000;
 
6054
#endif  /* defined(HAVE_GETHRTIME) */
6043
6055
}
6044
6056
 
6045
6057