1
/* Copyright (C) 2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
27
#if TIME_WITH_SYS_TIME
28
# include <sys/time.h>
32
# include <sys/time.h>
38
#include <boost/scoped_ptr.hpp>
40
#define COMMENT_STRING "Your bases"
41
#define FRM_STRING "My bases"
42
#define TEST_FILENAME "test.az"
43
#define TEST_STRING_INIT "YOU don't know about me without you have read a book by the name of The Adventures of Tom Sawyer; but that ain't no matter. That book was made by Mr. Mark Twain, and he told the truth, mainly. There was things which he stretched, but mainly he told the truth. That is nothing. I never seen anybody but lied one time or another, without it was Aunt Polly, or the widow, or maybe Mary. Aunt Polly--Tom's Aunt Polly, she is--and Mary, and the Widow Douglas is all told about in that book, which is mostly a true book, with some stretchers, as I said before. Now the way that the book winds up is this: Tom and me found the money that the robbers hid in the cave, and it made us rich. We got six thousand dollars apiece--all gold. It was an awful sight of money when it was piled up. Well, Judge Thatcher he took it and put it out at interest, and it fetched us a dollar a day apiece all the year round --more than a body could tell what to do with. The Widow Douglas she took me for her son, and allowed she would..."
44
#define TEST_LOOP_NUM 100
46
#define BUFFER_LEN 1024
48
char test_string[BUFFER_LEN];
50
uint64_t row_lengths[]= {536870912LL, 2147483648LL, 4294967296LL, 8589934592LL};
51
uint64_t row_numbers[]= {524288LL, 2097152LL, 4194304LL, 8388608LL};
54
int size_test(uint64_t length, uint64_t rows_to_test_for, az_method method);
55
int small_test(az_method method);
56
long int timedif(struct timeval a, struct timeval b);
59
int main(int argc, char *argv[])
67
drizzled::internal::my_init();
70
for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++)
72
struct timeval start_time, end_time;
75
printf("Testing %d\n", (int)method);
76
gettimeofday(&start_time, NULL);
77
small_test((az_method)method);
78
gettimeofday(&end_time, NULL);
79
timing= timedif(end_time, start_time);
80
printf("\tTime took %ld.%03ld seconds\n\n", timing / 1000, timing % 1000);
86
/* Start size tests */
87
printf("About to run .5/2/4/8 gig tests now, you may want to hit CTRL-C\n");
88
for (x= 0; x < 4; x++) /* 4 is the current size of the array we use */
90
for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++)
92
struct timeval start_time, end_time;
95
printf("Testing %"PRIu64" bytes with (%d)\n", row_lengths[x], (int)method);
96
gettimeofday(&start_time, NULL);
97
size_test(row_lengths[x], row_numbers[x], (az_method)method);
98
gettimeofday(&end_time, NULL);
99
timing= timedif(end_time, start_time);
100
printf("\tTime took %ld.%03ld seconds\n\n", timing / 1000, timing % 1000);
104
drizzled::internal::my_end();
109
int small_test(az_method method)
112
char comment_str[10];
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();
122
memcpy(test_string, TEST_STRING_INIT, 1024);
124
unlink(TEST_FILENAME);
126
if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR,
129
printf("Could not create test file\n");
133
azwrite_comment(&writer_handle, (char *)COMMENT_STRING,
134
(unsigned int)strlen(COMMENT_STRING));
135
azread_comment(&writer_handle, comment_str);
136
assert(!memcmp(COMMENT_STRING, comment_str,
137
strlen(COMMENT_STRING)));
139
azwrite_frm(&writer_handle, (char *)FRM_STRING,
140
(unsigned int)strlen(FRM_STRING));
141
azread_frm(&writer_handle, comment_str);
142
assert(!memcmp(FRM_STRING, comment_str,
143
strlen(FRM_STRING)));
146
if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
149
printf("Could not open test file\n");
153
assert(reader_handle.rows == 0);
154
assert(reader_handle.auto_increment == 0);
155
assert(reader_handle.check_point == 0);
156
assert(reader_handle.forced_flushes == 0);
157
assert(reader_handle.dirty == AZ_STATE_DIRTY);
159
for (x= 0; x < TEST_LOOP_NUM; x++)
161
ret= azwrite_row(&writer_handle, test_string, BUFFER_LEN);
162
assert(ret == BUFFER_LEN);
165
azflush(&writer_handle, Z_SYNC_FLUSH);
167
azread_comment(&writer_handle, comment_str);
168
assert(!memcmp(COMMENT_STRING, comment_str,
169
strlen(COMMENT_STRING)));
171
/* Lets test that our internal stats are good */
172
assert(writer_handle.rows == TEST_LOOP_NUM);
174
/* Reader needs to be flushed to make sure it is up to date */
175
azflush(&reader_handle, Z_SYNC_FLUSH);
176
assert(reader_handle.rows == TEST_LOOP_NUM);
177
assert(reader_handle.auto_increment == 0);
178
assert(reader_handle.check_point == 1269);
179
assert(reader_handle.forced_flushes == 1);
180
assert(reader_handle.comment_length == 10);
181
assert(reader_handle.dirty == AZ_STATE_SAVED);
183
writer_handle.auto_increment= 4;
184
azflush(&writer_handle, Z_SYNC_FLUSH);
185
assert(writer_handle.rows == TEST_LOOP_NUM);
186
assert(writer_handle.auto_increment == 4);
187
assert(writer_handle.check_point == 1269);
188
assert(writer_handle.forced_flushes == 2);
189
assert(writer_handle.dirty == AZ_STATE_SAVED);
191
azclose(&reader_handle);
193
if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
196
printf("Could not open test file\n");
201
/* Read the original data */
202
azread_init(&reader_handle);
203
for (x= 0; x < writer_handle.rows; x++)
205
ret= azread_row(&reader_handle, &error);
207
assert(ret == BUFFER_LEN);
208
assert(!memcmp(reader_handle.row_ptr, test_string, ret));
210
assert(writer_handle.rows == TEST_LOOP_NUM);
213
/* Test here for falling off the planet */
215
/* Final Write before closing */
216
ret= azwrite_row(&writer_handle, test_string, BUFFER_LEN);
217
assert(ret == BUFFER_LEN);
219
/* We don't use FINISH, but I want to have it tested */
220
azflush(&writer_handle, Z_FINISH);
222
assert(writer_handle.rows == TEST_LOOP_NUM+1);
224
/* Read final write */
225
azread_init(&reader_handle);
226
for (x= 0; x < writer_handle.rows; x++)
228
ret= azread_row(&reader_handle, &error);
229
assert(ret == BUFFER_LEN);
231
assert(!memcmp(reader_handle.row_ptr, test_string, ret));
235
azclose(&writer_handle);
238
/* Rewind and full test */
239
azread_init(&reader_handle);
240
for (x= 0; x < writer_handle.rows; x++)
242
ret= azread_row(&reader_handle, &error);
243
assert(ret == BUFFER_LEN);
245
assert(!memcmp(reader_handle.row_ptr, test_string, ret));
248
if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_RDWR, method)))
250
printf("Could not open file (%s) for appending\n", TEST_FILENAME);
253
ret= azwrite_row(&writer_handle, test_string, BUFFER_LEN);
254
assert(ret == BUFFER_LEN);
255
azflush(&writer_handle, Z_SYNC_FLUSH);
256
azflush(&reader_handle, Z_SYNC_FLUSH);
258
/* Rewind and full test */
259
azread_init(&reader_handle);
260
for (x= 0; x < writer_handle.rows; x++)
262
ret= azread_row(&reader_handle, &error);
264
assert(ret == BUFFER_LEN);
265
assert(!memcmp(reader_handle.row_ptr, test_string, ret));
268
/* Reader needs to be flushed to make sure it is up to date */
269
azflush(&reader_handle, Z_SYNC_FLUSH);
270
assert(reader_handle.rows == 102);
271
assert(reader_handle.auto_increment == 4);
272
assert(reader_handle.check_point == 1829);
273
assert(reader_handle.forced_flushes == 4);
274
assert(reader_handle.dirty == AZ_STATE_SAVED);
276
azflush(&writer_handle, Z_SYNC_FLUSH);
277
assert(writer_handle.rows == reader_handle.rows);
278
assert(writer_handle.auto_increment == reader_handle.auto_increment);
279
assert(writer_handle.check_point == reader_handle.check_point);
280
/* This is +1 because we do a flush right before we read */
281
assert(writer_handle.forced_flushes == reader_handle.forced_flushes + 1);
282
assert(writer_handle.dirty == reader_handle.dirty);
284
azclose(&writer_handle);
285
azclose(&reader_handle);
286
unlink(TEST_FILENAME);
291
int size_test(uint64_t length, uint64_t rows_to_test_for,
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;
305
if (!(ret= azopen(&writer_handle, TEST_FILENAME,
306
O_CREAT|O_RDWR|O_TRUNC,
309
printf("Could not create test file\n");
313
for (count= 0, write_length= 0; write_length < length ;
317
ret= azwrite_row(&writer_handle, test_string, BUFFER_LEN);
318
if (ret != BUFFER_LEN)
320
printf("Size %u\n", ret);
321
assert(ret != BUFFER_LEN);
323
if ((write_length % 14031) == 0)
325
azflush(&writer_handle, Z_SYNC_FLUSH);
328
assert(write_length == count * BUFFER_LEN); /* Number of rows time BUFFER_LEN */
329
azflush(&writer_handle, Z_SYNC_FLUSH);
331
if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
334
printf("Could not open test file\n");
338
/* We do a double loop to test speed */
339
for (x= 0, read_length= 0; x < 2; x++, read_length= 0)
343
azread_init(&reader_handle);
344
for (read_count= 0; read_count < writer_handle.rows; read_count++)
346
ret= azread_row(&reader_handle, &error);
348
assert(!memcmp(reader_handle.row_ptr, test_string, ret));
349
if (ret != BUFFER_LEN)
351
printf("Size %u\n", ret);
352
assert(ret != BUFFER_LEN);
355
azread_init(&reader_handle);
357
assert(read_length == write_length);
358
assert(writer_handle.rows == rows_to_test_for);
360
azclose(&writer_handle);
361
azclose(&reader_handle);
363
unlink(TEST_FILENAME);
368
long int timedif(struct timeval a, struct timeval b)
372
us = a.tv_usec - b.tv_usec;
374
s = a.tv_sec - b.tv_sec;