~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/archive_test.c

code clean move Item_func_num1 and Item_func_connection_id to functions directory

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 <mysys/my_getopt.h>
25
22
 
26
23
#if TIME_WITH_SYS_TIME
27
24
# include <sys/time.h>
32
29
# else
33
30
#  include <time.h>
34
31
# endif
35
 
#endif
 
32
#endif  
 
33
 
 
34
#define ARCHIVE_ROW_HEADER_SIZE 4
36
35
 
37
36
#define COMMENT_STRING "Your bases"
38
37
#define FRM_STRING "My bases"
55
54
 
56
55
int main(int argc, char *argv[])
57
56
{
58
 
  unsigned int method;
 
57
  az_method method;
59
58
  unsigned int x;
60
59
 
61
60
  if (argc > 2)
62
61
    return 0;
63
62
 
64
 
  drizzled::internal::my_init();
 
63
  my_init();
 
64
 
65
65
  MY_INIT(argv[0]);
66
66
 
67
67
  for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++)
71
71
 
72
72
    printf("Testing %d\n", (int)method);
73
73
    gettimeofday(&start_time, NULL);
74
 
    small_test((az_method)method);
 
74
    small_test(method);
75
75
    gettimeofday(&end_time, NULL);
76
76
    timing= timedif(end_time, start_time);
77
77
    printf("\tTime took %ld.%03ld seconds\n\n", timing / 1000, timing % 1000);
91
91
 
92
92
      printf("Testing %"PRIu64" bytes with (%d)\n", row_lengths[x], (int)method);
93
93
      gettimeofday(&start_time, NULL);
94
 
      size_test(row_lengths[x], row_numbers[x], (az_method)method);
 
94
      size_test(row_lengths[x], row_numbers[x], method);
95
95
      gettimeofday(&end_time, NULL);
96
96
      timing= timedif(end_time, start_time);
97
97
      printf("\tTime took %ld.%03ld seconds\n\n", timing / 1000, timing % 1000);
98
98
    }
99
99
  }
100
100
 
101
 
  drizzled::internal::my_end();
 
101
  my_end(0);
102
102
 
103
103
  return 0;
104
104
}
117
117
 
118
118
  unlink(TEST_FILENAME);
119
119
 
120
 
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR,
 
120
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR|O_BINARY,
121
121
                    method)))
122
122
  {
123
123
    printf("Could not create test file\n");
124
124
    return 0;
125
125
  }
126
126
 
127
 
  azwrite_comment(&writer_handle, (char *)COMMENT_STRING,
 
127
  azwrite_comment(&writer_handle, (char *)COMMENT_STRING, 
128
128
                  (unsigned int)strlen(COMMENT_STRING));
129
129
  azread_comment(&writer_handle, comment_str);
130
130
  assert(!memcmp(COMMENT_STRING, comment_str,
131
131
                strlen(COMMENT_STRING)));
132
132
 
133
 
  azwrite_frm(&writer_handle, (char *)FRM_STRING,
 
133
  azwrite_frm(&writer_handle, (char *)FRM_STRING, 
134
134
                  (unsigned int)strlen(FRM_STRING));
135
135
  azread_frm(&writer_handle, comment_str);
136
136
  assert(!memcmp(FRM_STRING, comment_str,
137
137
                strlen(FRM_STRING)));
138
138
 
139
139
 
140
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
 
140
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
141
141
                    method)))
142
142
  {
143
143
    printf("Could not open test file\n");
184
184
 
185
185
  azclose(&reader_handle);
186
186
 
187
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
 
187
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
188
188
                    method)))
189
189
  {
190
190
    printf("Could not open test file\n");
239
239
    assert(!memcmp(reader_handle.row_ptr, test_string, ret));
240
240
  }
241
241
 
242
 
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_RDWR, method)))
 
242
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_RDWR|O_BINARY, method)))
243
243
  {
244
244
    printf("Could not open file (%s) for appending\n", TEST_FILENAME);
245
245
    return 0;
282
282
  return 0;
283
283
}
284
284
 
285
 
int size_test(uint64_t length, uint64_t rows_to_test_for,
 
285
int size_test(uint64_t length, uint64_t rows_to_test_for, 
286
286
              az_method method)
287
287
{
288
288
  azio_stream writer_handle, reader_handle;
293
293
  int error;
294
294
  int x;
295
295
 
296
 
  if (!(ret= azopen(&writer_handle, TEST_FILENAME,
297
 
                    O_CREAT|O_RDWR|O_TRUNC,
 
296
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, 
 
297
                    O_CREAT|O_RDWR|O_TRUNC|O_BINARY,
298
298
                    method)))
299
299
  {
300
300
    printf("Could not create test file\n");
301
301
    exit(1);
302
302
  }
303
303
 
304
 
  for (count= 0, write_length= 0; write_length < length ;
 
304
  for (count= 0, write_length= 0; write_length < length ; 
305
305
       write_length+= ret)
306
306
  {
307
307
    count++;
319
319
  assert(write_length == count * BUFFER_LEN); /* Number of rows time BUFFER_LEN */
320
320
  azflush(&writer_handle,  Z_SYNC_FLUSH);
321
321
 
322
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
 
322
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
323
323
                    method)))
324
324
  {
325
325
    printf("Could not open test file\n");
329
329
  /* We do a double loop to test speed */
330
330
  for (x= 0, read_length= 0; x < 2; x++, read_length= 0)
331
331
  {
332
 
    uint64_t read_count;
 
332
    uint64_t count;
333
333
 
334
334
    azread_init(&reader_handle);
335
 
    for (read_count= 0; read_count < writer_handle.rows; read_count++)
 
335
    for (count= 0; count < writer_handle.rows; count++)
336
336
    {
337
337
      ret= azread_row(&reader_handle, &error);
338
338
      read_length+= ret;
359
359
long int timedif(struct timeval a, struct timeval b)
360
360
{
361
361
    register int us, s;
362
 
 
 
362
 
363
363
    us = a.tv_usec - b.tv_usec;
364
364
    us /= 1000;
365
365
    s = a.tv_sec - b.tv_sec;