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 */
21
#include <my_getopt.h>
22
#include <mysql_version.h>
24
#define ARCHIVE_ROW_HEADER_SIZE 4
26
#define COMMENT_STRING "Your bases"
27
#define FRM_STRING "My bases"
28
#define TEST_FILENAME "test.az"
29
#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..."
30
#define TEST_LOOP_NUM 100
32
#define BUFFER_LEN 1024
34
char test_string[BUFFER_LEN];
36
unsigned long long row_lengths[]= {LL(536870912), LL(2147483648), LL(4294967296), LL(8589934592)};
37
unsigned long long row_numbers[]= {LL(524288), LL(2097152), LL(4194304), LL(8388608)};
40
int size_test(unsigned long long length, unsigned long long rows_to_test_for, az_method method);
41
int small_test(az_method method);
42
long int timedif(struct timeval a, struct timeval b);
45
int main(int argc, char *argv[])
57
for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++)
59
struct timeval start_time, end_time;
62
printf("Testing %d\n", (int)method);
63
gettimeofday(&start_time, NULL);
65
gettimeofday(&end_time, NULL);
66
timing= timedif(end_time, start_time);
67
printf("\tTime took %ld.%03ld seconds\n\n", timing / 1000, timing % 1000);
73
/* Start size tests */
74
printf("About to run .5/2/4/8 gig tests now, you may want to hit CTRL-C\n");
75
for (x= 0; x < 4; x++) /* 4 is the current size of the array we use */
77
for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++)
79
struct timeval start_time, end_time;
82
printf("Testing %llu bytes with (%d)\n", row_lengths[x], (int)method);
83
gettimeofday(&start_time, NULL);
84
size_test(row_lengths[x], row_numbers[x], method);
85
gettimeofday(&end_time, NULL);
86
timing= timedif(end_time, start_time);
87
printf("\tTime took %ld.%03ld seconds\n\n", timing / 1000, timing % 1000);
96
int small_test(az_method method)
104
azio_stream writer_handle, reader_handle;
106
memcpy(test_string, TEST_STRING_INIT, 1024);
108
unlink(TEST_FILENAME);
110
if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR|O_BINARY,
113
printf("Could not create test file\n");
117
azwrite_comment(&writer_handle, (char *)COMMENT_STRING,
118
(unsigned int)strlen(COMMENT_STRING));
119
azread_comment(&writer_handle, comment_str);
120
assert(!memcmp(COMMENT_STRING, comment_str,
121
strlen(COMMENT_STRING)));
123
azwrite_frm(&writer_handle, (char *)FRM_STRING,
124
(unsigned int)strlen(FRM_STRING));
125
azread_frm(&writer_handle, comment_str);
126
assert(!memcmp(FRM_STRING, comment_str,
127
strlen(FRM_STRING)));
130
if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
133
printf("Could not open test file\n");
137
assert(reader_handle.rows == 0);
138
assert(reader_handle.auto_increment == 0);
139
assert(reader_handle.check_point == 0);
140
assert(reader_handle.forced_flushes == 0);
141
assert(reader_handle.dirty == AZ_STATE_DIRTY);
143
for (x= 0; x < TEST_LOOP_NUM; x++)
145
ret= azwrite_row(&writer_handle, test_string, BUFFER_LEN);
146
assert(ret == BUFFER_LEN);
149
azflush(&writer_handle, Z_SYNC_FLUSH);
151
azread_comment(&writer_handle, comment_str);
152
assert(!memcmp(COMMENT_STRING, comment_str,
153
strlen(COMMENT_STRING)));
155
/* Lets test that our internal stats are good */
156
assert(writer_handle.rows == TEST_LOOP_NUM);
158
/* Reader needs to be flushed to make sure it is up to date */
159
azflush(&reader_handle, Z_SYNC_FLUSH);
160
assert(reader_handle.rows == TEST_LOOP_NUM);
161
assert(reader_handle.auto_increment == 0);
162
assert(reader_handle.check_point == 1269);
163
assert(reader_handle.forced_flushes == 1);
164
assert(reader_handle.comment_length == 10);
165
assert(reader_handle.dirty == AZ_STATE_SAVED);
167
writer_handle.auto_increment= 4;
168
azflush(&writer_handle, Z_SYNC_FLUSH);
169
assert(writer_handle.rows == TEST_LOOP_NUM);
170
assert(writer_handle.auto_increment == 4);
171
assert(writer_handle.check_point == 1269);
172
assert(writer_handle.forced_flushes == 2);
173
assert(writer_handle.dirty == AZ_STATE_SAVED);
175
azclose(&reader_handle);
177
if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
180
printf("Could not open test file\n");
185
/* Read the original data */
186
azread_init(&reader_handle);
187
for (x= 0; x < writer_handle.rows; x++)
189
ret= azread_row(&reader_handle, &error);
191
assert(ret == BUFFER_LEN);
192
assert(!memcmp(reader_handle.row_ptr, test_string, ret));
194
assert(writer_handle.rows == TEST_LOOP_NUM);
197
/* Test here for falling off the planet */
199
/* Final Write before closing */
200
ret= azwrite_row(&writer_handle, test_string, BUFFER_LEN);
201
assert(ret == BUFFER_LEN);
203
/* We don't use FINISH, but I want to have it tested */
204
azflush(&writer_handle, Z_FINISH);
206
assert(writer_handle.rows == TEST_LOOP_NUM+1);
208
/* Read final write */
209
azread_init(&reader_handle);
210
for (x= 0; x < writer_handle.rows; x++)
212
ret= azread_row(&reader_handle, &error);
213
assert(ret == BUFFER_LEN);
215
assert(!memcmp(reader_handle.row_ptr, test_string, ret));
219
azclose(&writer_handle);
222
/* Rewind and full test */
223
azread_init(&reader_handle);
224
for (x= 0; x < writer_handle.rows; x++)
226
ret= azread_row(&reader_handle, &error);
227
assert(ret == BUFFER_LEN);
229
assert(!memcmp(reader_handle.row_ptr, test_string, ret));
232
if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_RDWR|O_BINARY, method)))
234
printf("Could not open file (%s) for appending\n", TEST_FILENAME);
237
ret= azwrite_row(&writer_handle, test_string, BUFFER_LEN);
238
assert(ret == BUFFER_LEN);
239
azflush(&writer_handle, Z_SYNC_FLUSH);
240
azflush(&reader_handle, Z_SYNC_FLUSH);
242
/* Rewind and full test */
243
azread_init(&reader_handle);
244
for (x= 0; x < writer_handle.rows; x++)
246
ret= azread_row(&reader_handle, &error);
248
assert(ret == BUFFER_LEN);
249
assert(!memcmp(reader_handle.row_ptr, test_string, ret));
252
/* Reader needs to be flushed to make sure it is up to date */
253
azflush(&reader_handle, Z_SYNC_FLUSH);
254
assert(reader_handle.rows == 102);
255
assert(reader_handle.auto_increment == 4);
256
assert(reader_handle.check_point == 1829);
257
assert(reader_handle.forced_flushes == 4);
258
assert(reader_handle.dirty == AZ_STATE_SAVED);
260
azflush(&writer_handle, Z_SYNC_FLUSH);
261
assert(writer_handle.rows == reader_handle.rows);
262
assert(writer_handle.auto_increment == reader_handle.auto_increment);
263
assert(writer_handle.check_point == reader_handle.check_point);
264
/* This is +1 because we do a flush right before we read */
265
assert(writer_handle.forced_flushes == reader_handle.forced_flushes + 1);
266
assert(writer_handle.dirty == reader_handle.dirty);
268
azclose(&writer_handle);
269
azclose(&reader_handle);
270
unlink(TEST_FILENAME);
275
int size_test(unsigned long long length, unsigned long long rows_to_test_for,
278
azio_stream writer_handle, reader_handle;
279
unsigned long long write_length;
280
unsigned long long read_length;
281
unsigned long long count;
286
if (!(ret= azopen(&writer_handle, TEST_FILENAME,
287
O_CREAT|O_RDWR|O_TRUNC|O_BINARY,
290
printf("Could not create test file\n");
294
for (count= 0, write_length= 0; write_length < length ;
298
ret= azwrite_row(&writer_handle, test_string, BUFFER_LEN);
299
if (ret != BUFFER_LEN)
301
printf("Size %u\n", ret);
302
assert(ret != BUFFER_LEN);
304
if ((write_length % 14031) == 0)
306
azflush(&writer_handle, Z_SYNC_FLUSH);
309
assert(write_length == count * BUFFER_LEN); /* Number of rows time BUFFER_LEN */
310
azflush(&writer_handle, Z_SYNC_FLUSH);
312
if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
315
printf("Could not open test file\n");
319
/* We do a double loop to test speed */
320
for (x= 0, read_length= 0; x < 2; x++, read_length= 0)
322
unsigned long long count;
324
azread_init(&reader_handle);
325
for (count= 0; count < writer_handle.rows; count++)
327
ret= azread_row(&reader_handle, &error);
329
assert(!memcmp(reader_handle.row_ptr, test_string, ret));
330
if (ret != BUFFER_LEN)
332
printf("Size %u\n", ret);
333
assert(ret != BUFFER_LEN);
336
azread_init(&reader_handle);
338
assert(read_length == write_length);
339
assert(writer_handle.rows == rows_to_test_for);
341
azclose(&writer_handle);
342
azclose(&reader_handle);
344
unlink(TEST_FILENAME);
349
long int timedif(struct timeval a, struct timeval b)
353
us = a.tv_usec - b.tv_usec;
355
s = a.tv_sec - b.tv_sec;