~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/archive_test.c

  • Committer: Monty Taylor
  • Date: 2008-08-22 04:35:12 UTC
  • mto: (365.1.2 drizzle)
  • mto: This revision was merged to the branch mainline in revision 368.
  • Revision ID: monty@inaugust.com-20080822043512-3vafw99x3vv97d39
INT32_MAX stuff.

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