~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/archive_test.c

  • Committer: Jim Winstead
  • Date: 2008-07-19 02:56:45 UTC
  • mto: (202.1.8 codestyle)
  • mto: This revision was merged to the branch mainline in revision 207.
  • Revision ID: jimw@mysql.com-20080719025645-w2pwytebgzusjzjb
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
Temporarily disables tab-completion in the drizzle client until an appropriate
autoconf check can be added/enabled.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
 
#include <config.h>
17
16
#include "azio.h"
18
17
#include <string.h>
19
18
#include <assert.h>
20
19
#include <stdio.h>
21
20
#include <string.h>
22
 
#include <fcntl.h>
23
 
#include <unistd.h>
24
 
#include <cstdlib>
25
 
#include <memory>
26
 
 
27
 
#if TIME_WITH_SYS_TIME
28
 
# include <sys/time.h>
29
 
# include <time.h>
30
 
#else
31
 
# if HAVE_SYS_TIME_H
32
 
#  include <sys/time.h>
33
 
# else
34
 
#  include <time.h>
35
 
# endif
36
 
#endif
37
 
 
38
 
#include <boost/scoped_ptr.hpp>
 
21
#include <my_getopt.h>
 
22
#include <drizzle_version.h>
 
23
 
 
24
#define ARCHIVE_ROW_HEADER_SIZE 4
39
25
 
40
26
#define COMMENT_STRING "Your bases"
41
27
#define FRM_STRING "My bases"
47
33
 
48
34
char test_string[BUFFER_LEN];
49
35
 
50
 
uint64_t row_lengths[]= {536870912LL, 2147483648LL, 4294967296LL, 8589934592LL};
51
 
uint64_t row_numbers[]= {524288LL, 2097152LL, 4194304LL, 8388608LL};
 
36
unsigned long long row_lengths[]= {536870912LL, 2147483648LL, 4294967296LL, 8589934592LL};
 
37
unsigned long long row_numbers[]= {524288LL, 2097152LL, 4194304LL, 8388608LL};
52
38
 
53
39
/* prototypes */
54
 
int size_test(uint64_t length, uint64_t rows_to_test_for, az_method method);
 
40
int size_test(unsigned long long length, unsigned long long rows_to_test_for, az_method method);
55
41
int small_test(az_method method);
56
42
long int timedif(struct timeval a, struct timeval b);
57
43
 
58
44
 
59
45
int main(int argc, char *argv[])
60
46
{
61
 
  unsigned int method;
 
47
  az_method method;
62
48
  unsigned int x;
63
49
 
64
50
  if (argc > 2)
65
51
    return 0;
66
52
 
67
 
  drizzled::internal::my_init();
 
53
  my_init();
 
54
 
68
55
  MY_INIT(argv[0]);
69
56
 
70
57
  for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++)
74
61
 
75
62
    printf("Testing %d\n", (int)method);
76
63
    gettimeofday(&start_time, NULL);
77
 
    small_test((az_method)method);
 
64
    small_test(method);
78
65
    gettimeofday(&end_time, NULL);
79
66
    timing= timedif(end_time, start_time);
80
67
    printf("\tTime took %ld.%03ld seconds\n\n", timing / 1000, timing % 1000);
92
79
      struct timeval start_time, end_time;
93
80
      long int timing;
94
81
 
95
 
      printf("Testing %"PRIu64" bytes with (%d)\n", row_lengths[x], (int)method);
 
82
      printf("Testing %llu bytes with (%d)\n", row_lengths[x], (int)method);
96
83
      gettimeofday(&start_time, NULL);
97
 
      size_test(row_lengths[x], row_numbers[x], (az_method)method);
 
84
      size_test(row_lengths[x], row_numbers[x], method);
98
85
      gettimeofday(&end_time, NULL);
99
86
      timing= timedif(end_time, start_time);
100
87
      printf("\tTime took %ld.%03ld seconds\n\n", timing / 1000, timing % 1000);
101
88
    }
102
89
  }
103
90
 
104
 
  drizzled::internal::my_end();
 
91
  my_end(0);
105
92
 
106
93
  return 0;
107
94
}
114
101
  int error;
115
102
  unsigned int x;
116
103
  int written_rows= 0;
117
 
  boost::scoped_ptr<azio_stream> writer_handle_ap(new azio_stream);
118
 
  boost::scoped_ptr<azio_stream> reader_handle_ap(new azio_stream);
119
 
  azio_stream &writer_handle= *writer_handle_ap.get();
120
 
  azio_stream &reader_handle= *reader_handle_ap.get();
 
104
  azio_stream writer_handle, reader_handle;
121
105
 
122
106
  memcpy(test_string, TEST_STRING_INIT, 1024);
123
107
 
124
108
  unlink(TEST_FILENAME);
125
109
 
126
 
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR,
 
110
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR|O_BINARY,
127
111
                    method)))
128
112
  {
129
113
    printf("Could not create test file\n");
130
114
    return 0;
131
115
  }
132
116
 
133
 
  azwrite_comment(&writer_handle, (char *)COMMENT_STRING,
 
117
  azwrite_comment(&writer_handle, (char *)COMMENT_STRING, 
134
118
                  (unsigned int)strlen(COMMENT_STRING));
135
119
  azread_comment(&writer_handle, comment_str);
136
120
  assert(!memcmp(COMMENT_STRING, comment_str,
137
121
                strlen(COMMENT_STRING)));
138
122
 
139
 
  azwrite_frm(&writer_handle, (char *)FRM_STRING,
 
123
  azwrite_frm(&writer_handle, (char *)FRM_STRING, 
140
124
                  (unsigned int)strlen(FRM_STRING));
141
125
  azread_frm(&writer_handle, comment_str);
142
126
  assert(!memcmp(FRM_STRING, comment_str,
143
127
                strlen(FRM_STRING)));
144
128
 
145
129
 
146
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
 
130
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
147
131
                    method)))
148
132
  {
149
133
    printf("Could not open test file\n");
190
174
 
191
175
  azclose(&reader_handle);
192
176
 
193
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
 
177
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
194
178
                    method)))
195
179
  {
196
180
    printf("Could not open test file\n");
245
229
    assert(!memcmp(reader_handle.row_ptr, test_string, ret));
246
230
  }
247
231
 
248
 
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_RDWR, method)))
 
232
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_RDWR|O_BINARY, method)))
249
233
  {
250
234
    printf("Could not open file (%s) for appending\n", TEST_FILENAME);
251
235
    return 0;
288
272
  return 0;
289
273
}
290
274
 
291
 
int size_test(uint64_t length, uint64_t rows_to_test_for,
 
275
int size_test(unsigned long long length, unsigned long long rows_to_test_for, 
292
276
              az_method method)
293
277
{
294
 
  boost::scoped_ptr<azio_stream> writer_handle_ap(new azio_stream);
295
 
  boost::scoped_ptr<azio_stream> reader_handle_ap(new azio_stream);
296
 
  azio_stream &writer_handle= *writer_handle_ap.get();
297
 
  azio_stream &reader_handle= *reader_handle_ap.get();
298
 
  uint64_t write_length;
299
 
  uint64_t read_length;
300
 
  uint64_t count;
 
278
  azio_stream writer_handle, reader_handle;
 
279
  unsigned long long write_length;
 
280
  unsigned long long read_length;
 
281
  unsigned long long count;
301
282
  unsigned int ret;
302
283
  int error;
303
284
  int x;
304
285
 
305
 
  if (!(ret= azopen(&writer_handle, TEST_FILENAME,
306
 
                    O_CREAT|O_RDWR|O_TRUNC,
 
286
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, 
 
287
                    O_CREAT|O_RDWR|O_TRUNC|O_BINARY,
307
288
                    method)))
308
289
  {
309
290
    printf("Could not create test file\n");
310
291
    exit(1);
311
292
  }
312
293
 
313
 
  for (count= 0, write_length= 0; write_length < length ;
 
294
  for (count= 0, write_length= 0; write_length < length ; 
314
295
       write_length+= ret)
315
296
  {
316
297
    count++;
328
309
  assert(write_length == count * BUFFER_LEN); /* Number of rows time BUFFER_LEN */
329
310
  azflush(&writer_handle,  Z_SYNC_FLUSH);
330
311
 
331
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
 
312
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
332
313
                    method)))
333
314
  {
334
315
    printf("Could not open test file\n");
338
319
  /* We do a double loop to test speed */
339
320
  for (x= 0, read_length= 0; x < 2; x++, read_length= 0)
340
321
  {
341
 
    uint64_t read_count;
 
322
    unsigned long long count;
342
323
 
343
324
    azread_init(&reader_handle);
344
 
    for (read_count= 0; read_count < writer_handle.rows; read_count++)
 
325
    for (count= 0; count < writer_handle.rows; count++)
345
326
    {
346
327
      ret= azread_row(&reader_handle, &error);
347
328
      read_length+= ret;
368
349
long int timedif(struct timeval a, struct timeval b)
369
350
{
370
351
    register int us, s;
371
 
 
 
352
 
372
353
    us = a.tv_usec - b.tv_usec;
373
354
    us /= 1000;
374
355
    s = a.tv_sec - b.tv_sec;