~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/archive_test.c

  • Committer: Monty Taylor
  • Date: 2008-07-11 15:23:55 UTC
  • mto: (77.6.1 glibclient-merge)
  • mto: This revision was merged to the branch mainline in revision 134.
  • Revision ID: monty@inaugust.com-20080711152355-o92cod4mg0u9ck03
More const-correctness.

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>
 
21
#include <my_getopt.h>
 
22
#include <drizzle_version.h>
25
23
 
26
 
#if TIME_WITH_SYS_TIME
27
 
# include <sys/time.h>
28
 
# include <time.h>
29
 
#else
30
 
# if HAVE_SYS_TIME_H
31
 
#  include <sys/time.h>
32
 
# else
33
 
#  include <time.h>
34
 
# endif
35
 
#endif
 
24
#define ARCHIVE_ROW_HEADER_SIZE 4
36
25
 
37
26
#define COMMENT_STRING "Your bases"
38
27
#define FRM_STRING "My bases"
44
33
 
45
34
char test_string[BUFFER_LEN];
46
35
 
47
 
uint64_t row_lengths[]= {536870912LL, 2147483648LL, 4294967296LL, 8589934592LL};
48
 
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};
49
38
 
50
39
/* prototypes */
51
 
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);
52
41
int small_test(az_method method);
53
42
long int timedif(struct timeval a, struct timeval b);
54
43
 
55
44
 
56
45
int main(int argc, char *argv[])
57
46
{
58
 
  unsigned int method;
 
47
  az_method method;
59
48
  unsigned int x;
60
49
 
61
50
  if (argc > 2)
62
51
    return 0;
63
52
 
64
 
  drizzled::internal::my_init();
 
53
  my_init();
 
54
 
65
55
  MY_INIT(argv[0]);
66
56
 
67
57
  for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++)
71
61
 
72
62
    printf("Testing %d\n", (int)method);
73
63
    gettimeofday(&start_time, NULL);
74
 
    small_test((az_method)method);
 
64
    small_test(method);
75
65
    gettimeofday(&end_time, NULL);
76
66
    timing= timedif(end_time, start_time);
77
67
    printf("\tTime took %ld.%03ld seconds\n\n", timing / 1000, timing % 1000);
89
79
      struct timeval start_time, end_time;
90
80
      long int timing;
91
81
 
92
 
      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);
93
83
      gettimeofday(&start_time, NULL);
94
 
      size_test(row_lengths[x], row_numbers[x], (az_method)method);
 
84
      size_test(row_lengths[x], row_numbers[x], method);
95
85
      gettimeofday(&end_time, NULL);
96
86
      timing= timedif(end_time, start_time);
97
87
      printf("\tTime took %ld.%03ld seconds\n\n", timing / 1000, timing % 1000);
98
88
    }
99
89
  }
100
90
 
101
 
  drizzled::internal::my_end();
 
91
  my_end(0);
102
92
 
103
93
  return 0;
104
94
}
117
107
 
118
108
  unlink(TEST_FILENAME);
119
109
 
120
 
  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,
121
111
                    method)))
122
112
  {
123
113
    printf("Could not create test file\n");
124
114
    return 0;
125
115
  }
126
116
 
127
 
  azwrite_comment(&writer_handle, (char *)COMMENT_STRING,
 
117
  azwrite_comment(&writer_handle, (char *)COMMENT_STRING, 
128
118
                  (unsigned int)strlen(COMMENT_STRING));
129
119
  azread_comment(&writer_handle, comment_str);
130
120
  assert(!memcmp(COMMENT_STRING, comment_str,
131
121
                strlen(COMMENT_STRING)));
132
122
 
133
 
  azwrite_frm(&writer_handle, (char *)FRM_STRING,
 
123
  azwrite_frm(&writer_handle, (char *)FRM_STRING, 
134
124
                  (unsigned int)strlen(FRM_STRING));
135
125
  azread_frm(&writer_handle, comment_str);
136
126
  assert(!memcmp(FRM_STRING, comment_str,
137
127
                strlen(FRM_STRING)));
138
128
 
139
129
 
140
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
 
130
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
141
131
                    method)))
142
132
  {
143
133
    printf("Could not open test file\n");
184
174
 
185
175
  azclose(&reader_handle);
186
176
 
187
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
 
177
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
188
178
                    method)))
189
179
  {
190
180
    printf("Could not open test file\n");
239
229
    assert(!memcmp(reader_handle.row_ptr, test_string, ret));
240
230
  }
241
231
 
242
 
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_RDWR, method)))
 
232
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_RDWR|O_BINARY, method)))
243
233
  {
244
234
    printf("Could not open file (%s) for appending\n", TEST_FILENAME);
245
235
    return 0;
282
272
  return 0;
283
273
}
284
274
 
285
 
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, 
286
276
              az_method method)
287
277
{
288
278
  azio_stream writer_handle, reader_handle;
289
 
  uint64_t write_length;
290
 
  uint64_t read_length;
291
 
  uint64_t count;
 
279
  unsigned long long write_length;
 
280
  unsigned long long read_length;
 
281
  unsigned long long count;
292
282
  unsigned int ret;
293
283
  int error;
294
284
  int x;
295
285
 
296
 
  if (!(ret= azopen(&writer_handle, TEST_FILENAME,
297
 
                    O_CREAT|O_RDWR|O_TRUNC,
 
286
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, 
 
287
                    O_CREAT|O_RDWR|O_TRUNC|O_BINARY,
298
288
                    method)))
299
289
  {
300
290
    printf("Could not create test file\n");
301
291
    exit(1);
302
292
  }
303
293
 
304
 
  for (count= 0, write_length= 0; write_length < length ;
 
294
  for (count= 0, write_length= 0; write_length < length ; 
305
295
       write_length+= ret)
306
296
  {
307
297
    count++;
319
309
  assert(write_length == count * BUFFER_LEN); /* Number of rows time BUFFER_LEN */
320
310
  azflush(&writer_handle,  Z_SYNC_FLUSH);
321
311
 
322
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
 
312
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
323
313
                    method)))
324
314
  {
325
315
    printf("Could not open test file\n");
329
319
  /* We do a double loop to test speed */
330
320
  for (x= 0, read_length= 0; x < 2; x++, read_length= 0)
331
321
  {
332
 
    uint64_t read_count;
 
322
    unsigned long long count;
333
323
 
334
324
    azread_init(&reader_handle);
335
 
    for (read_count= 0; read_count < writer_handle.rows; read_count++)
 
325
    for (count= 0; count < writer_handle.rows; count++)
336
326
    {
337
327
      ret= azread_row(&reader_handle, &error);
338
328
      read_length+= ret;
359
349
long int timedif(struct timeval a, struct timeval b)
360
350
{
361
351
    register int us, s;
362
 
 
 
352
 
363
353
    us = a.tv_usec - b.tv_usec;
364
354
    us /= 1000;
365
355
    s = a.tv_sec - b.tv_sec;