~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/archive_test.c

  • Committer: Monty Taylor
  • Date: 2009-03-08 23:45:12 UTC
  • mto: (923.2.1 mordred)
  • mto: This revision was merged to the branch mainline in revision 921.
  • Revision ID: mordred@inaugust.com-20090308234512-tqkygxtu1iaig23s
Removed C99 isnan() usage, which allows us to remove the util/math.{cc,h} workarounds. Yay for standards!

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <string.h>
21
21
#include <mysys/my_getopt.h>
22
22
 
23
 
#define ARCHIVE_ROW_HEADER_SIZE 4
 
23
#if TIME_WITH_SYS_TIME
 
24
# include <sys/time.h>
 
25
# include <time.h>
 
26
#else
 
27
# if HAVE_SYS_TIME_H
 
28
#  include <sys/time.h>
 
29
# else
 
30
#  include <time.h>
 
31
# endif
 
32
#endif
24
33
 
25
34
#define COMMENT_STRING "Your bases"
26
35
#define FRM_STRING "My bases"
32
41
 
33
42
char test_string[BUFFER_LEN];
34
43
 
35
 
unsigned long long row_lengths[]= {536870912LL, 2147483648LL, 4294967296LL, 8589934592LL};
36
 
unsigned long long row_numbers[]= {524288LL, 2097152LL, 4194304LL, 8388608LL};
 
44
uint64_t row_lengths[]= {536870912LL, 2147483648LL, 4294967296LL, 8589934592LL};
 
45
uint64_t row_numbers[]= {524288LL, 2097152LL, 4194304LL, 8388608LL};
37
46
 
38
47
/* prototypes */
39
 
int size_test(unsigned long long length, unsigned long long rows_to_test_for, az_method method);
 
48
int size_test(uint64_t length, uint64_t rows_to_test_for, az_method method);
40
49
int small_test(az_method method);
41
50
long int timedif(struct timeval a, struct timeval b);
42
51
 
78
87
      struct timeval start_time, end_time;
79
88
      long int timing;
80
89
 
81
 
      printf("Testing %llu bytes with (%d)\n", row_lengths[x], (int)method);
 
90
      printf("Testing %"PRIu64" bytes with (%d)\n", row_lengths[x], (int)method);
82
91
      gettimeofday(&start_time, NULL);
83
92
      size_test(row_lengths[x], row_numbers[x], method);
84
93
      gettimeofday(&end_time, NULL);
106
115
 
107
116
  unlink(TEST_FILENAME);
108
117
 
109
 
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR|O_BINARY,
 
118
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR,
110
119
                    method)))
111
120
  {
112
121
    printf("Could not create test file\n");
113
122
    return 0;
114
123
  }
115
124
 
116
 
  azwrite_comment(&writer_handle, (char *)COMMENT_STRING, 
 
125
  azwrite_comment(&writer_handle, (char *)COMMENT_STRING,
117
126
                  (unsigned int)strlen(COMMENT_STRING));
118
127
  azread_comment(&writer_handle, comment_str);
119
128
  assert(!memcmp(COMMENT_STRING, comment_str,
120
129
                strlen(COMMENT_STRING)));
121
130
 
122
 
  azwrite_frm(&writer_handle, (char *)FRM_STRING, 
 
131
  azwrite_frm(&writer_handle, (char *)FRM_STRING,
123
132
                  (unsigned int)strlen(FRM_STRING));
124
133
  azread_frm(&writer_handle, comment_str);
125
134
  assert(!memcmp(FRM_STRING, comment_str,
126
135
                strlen(FRM_STRING)));
127
136
 
128
137
 
129
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
 
138
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
130
139
                    method)))
131
140
  {
132
141
    printf("Could not open test file\n");
173
182
 
174
183
  azclose(&reader_handle);
175
184
 
176
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
 
185
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
177
186
                    method)))
178
187
  {
179
188
    printf("Could not open test file\n");
228
237
    assert(!memcmp(reader_handle.row_ptr, test_string, ret));
229
238
  }
230
239
 
231
 
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_RDWR|O_BINARY, method)))
 
240
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_RDWR, method)))
232
241
  {
233
242
    printf("Could not open file (%s) for appending\n", TEST_FILENAME);
234
243
    return 0;
271
280
  return 0;
272
281
}
273
282
 
274
 
int size_test(unsigned long long length, unsigned long long rows_to_test_for, 
 
283
int size_test(uint64_t length, uint64_t rows_to_test_for,
275
284
              az_method method)
276
285
{
277
286
  azio_stream writer_handle, reader_handle;
278
 
  unsigned long long write_length;
279
 
  unsigned long long read_length;
280
 
  unsigned long long count;
 
287
  uint64_t write_length;
 
288
  uint64_t read_length;
 
289
  uint64_t count;
281
290
  unsigned int ret;
282
291
  int error;
283
292
  int x;
284
293
 
285
 
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, 
286
 
                    O_CREAT|O_RDWR|O_TRUNC|O_BINARY,
 
294
  if (!(ret= azopen(&writer_handle, TEST_FILENAME,
 
295
                    O_CREAT|O_RDWR|O_TRUNC,
287
296
                    method)))
288
297
  {
289
298
    printf("Could not create test file\n");
290
299
    exit(1);
291
300
  }
292
301
 
293
 
  for (count= 0, write_length= 0; write_length < length ; 
 
302
  for (count= 0, write_length= 0; write_length < length ;
294
303
       write_length+= ret)
295
304
  {
296
305
    count++;
308
317
  assert(write_length == count * BUFFER_LEN); /* Number of rows time BUFFER_LEN */
309
318
  azflush(&writer_handle,  Z_SYNC_FLUSH);
310
319
 
311
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
 
320
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
312
321
                    method)))
313
322
  {
314
323
    printf("Could not open test file\n");
318
327
  /* We do a double loop to test speed */
319
328
  for (x= 0, read_length= 0; x < 2; x++, read_length= 0)
320
329
  {
321
 
    unsigned long long count;
 
330
    uint64_t read_count;
322
331
 
323
332
    azread_init(&reader_handle);
324
 
    for (count= 0; count < writer_handle.rows; count++)
 
333
    for (read_count= 0; read_count < writer_handle.rows; read_count++)
325
334
    {
326
335
      ret= azread_row(&reader_handle, &error);
327
336
      read_length+= ret;
348
357
long int timedif(struct timeval a, struct timeval b)
349
358
{
350
359
    register int us, s;
351
 
 
 
360
 
352
361
    us = a.tv_usec - b.tv_usec;
353
362
    us /= 1000;
354
363
    s = a.tv_sec - b.tv_sec;