mirror of
https://github.com/MariaDB/server.git
synced 2025-01-23 07:14:17 +01:00
908ba5ecf4
All newbrt tests now call toku_brt_init/destroy git-svn-id: file:///svn/toku/tokudb.1032b@8393 c7de825b-a66e-492c-adef-691d508d4ae1
78 lines
1.9 KiB
C
78 lines
1.9 KiB
C
/* Test bread by writing random data and then reading it using bread_backwards() to see if it gives the right answer.
|
|
* See test_1305 for another bread test (testing to see if it can read 1GB files) */
|
|
|
|
#include "test.h"
|
|
#include "toku_portability.h"
|
|
|
|
#include <assert.h>
|
|
#include <fcntl.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "../brttypes.h"
|
|
#include "../bread.h"
|
|
|
|
#define FNAME "bread-test.data"
|
|
|
|
#define RECORDS 2
|
|
|
|
static void
|
|
test (int seed) {
|
|
srandom(seed);
|
|
unlink(FNAME);
|
|
int i;
|
|
char buf[RECORDS][100];
|
|
int sizes[RECORDS];
|
|
int sizesn[RECORDS];
|
|
toku_off_t off = 0;
|
|
{
|
|
int fd = open(FNAME, O_CREAT+O_RDWR+O_BINARY, 0777);
|
|
assert(fd>=0);
|
|
for (i=0; i<RECORDS; i++) {
|
|
sizes[i] = random()%100;
|
|
sizesn[i] = toku_htonl(sizes[i]);
|
|
int j;
|
|
for (j=0; j<sizes[i]; j++) {
|
|
buf[i][j]=(char)random();
|
|
}
|
|
int r = write(fd, buf[i], sizes[i]);
|
|
assert(r==sizes[i]);
|
|
off+=r;
|
|
r = write(fd, &sizesn[i], 4);
|
|
assert(r==4);
|
|
off+=4;
|
|
}
|
|
{ int r=close(fd); assert(r==0); }
|
|
}
|
|
int fd = open(FNAME, O_RDONLY+O_BINARY); assert(fd>=0);
|
|
// Now read it all backward
|
|
BREAD br = create_bread_from_fd_initialize_at(fd, off, 50);
|
|
while (bread_has_more(br)) {
|
|
assert(i>0);
|
|
i--;
|
|
int sizen;
|
|
{ int r = bread_backwards(br, &sizen, 4); assert(r==4); }
|
|
int sizeh=toku_ntohl(sizen);
|
|
assert(sizeh==sizes[i]);
|
|
assert(0<=sizeh && sizeh<100);
|
|
{
|
|
char rbuf[100];
|
|
int r = bread_backwards(br, rbuf,sizeh);
|
|
assert(r==sizeh);
|
|
assert(memcmp(rbuf, &buf[i][0], sizes[i])==0);
|
|
}
|
|
}
|
|
assert(i==0);
|
|
{ int r=close_bread_without_closing_fd(br); assert(r==0); }
|
|
{ int r=close(fd); assert(r==0); }
|
|
unlink(FNAME);
|
|
}
|
|
|
|
int
|
|
test_main (int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) {
|
|
int i;
|
|
for (i=0; i<10; i++) test(i);
|
|
return 0;
|
|
}
|