From: Eric Bollengier Date: Wed, 30 Jul 2008 15:48:37 +0000 (+0000) Subject: ebl Add accurate disk tests X-Git-Tag: Release-3.0.0~1102 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8fc9cf0ef4d8f2ac36e79184ee31f2bcefe5741d;p=bacula%2Fbacula ebl Add accurate disk tests git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@7454 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/patches/testing/justdisk.c b/bacula/patches/testing/justdisk.c new file mode 100644 index 0000000000..1acee29417 --- /dev/null +++ b/bacula/patches/testing/justdisk.c @@ -0,0 +1,182 @@ +/* + * This file is used to test simple I/O operation for accurate mode + * + * + * 1) Loading + * fseek() ? + * fwrite() + * + * 2) Fetch + Update + * fseek(pos1) + * fread() + * fseek(pos1) + * fwrite() + * + * 3) Read all + * fseek() + * fread() + * + */ + +/* +g++ -g -Wall -I../../src -I../../src/lib -L../../src/lib justdisk.c -lbac -lpthread -lssl -D_TEST_OPEN + */ + +#include +#include +#include +#include +#include +#include "bacula.h" + +typedef struct { + int path; + int filename; + int mtime; + int ctime; + int seen; +} AccurateElt; + +#define NB_ELT 50000000 + +typedef struct { + char *buf; + rblink *link; +} MY; + +static int my_cmp(void *item1, void *item2) +{ + MY *elt1, *elt2; + elt1 = (MY *) item1; + elt2 = (MY *) item2; + printf("cmp(%s, %s)\n", elt1->buf, elt2->buf); + return strcmp(elt1->buf, elt2->buf); +} + +rblist *load_rb(const char *file) +{ + FILE *fp; + char buffer[1024]; + MY *res; + rblist *lst; + lst = New(rblist(res, res->link)); + + fp = fopen(file, "r"); + if (!fp) { + return NULL; + } + while (fgets(buffer, sizeof(buffer), fp)) { + if (*buffer) { + int len = strlen(buffer); + if (len > 0) { + buffer[len-1]=0; /* zap \n */ + } + MY *buf = (MY *)malloc(sizeof(MY)); + memset(buf, 0, sizeof(MY)); + buf->buf = bstrdup(buffer); + res = (MY *)lst->insert(buf, my_cmp); + if (res != buf) { + free(buf->buf); + free(buf); + } + } + } + fclose(fp); + + return lst; +} + +#ifdef _TEST_OPEN +int main() +{ + int fd; + int i; + AccurateElt elt; + char *start_heap = (char *)sbrk(0); + + rblist *rb_file = load_rb("files"); + rblist *rb_path = load_rb("path"); + + char *etc = (char *)rb_path->search((void *)"/etc/", my_cmp); + + printf("%p\n", etc); + + fd = open("testfile", O_CREAT | O_RDWR, 0600); + if (fd<0) { + perror("E: Can't open testfile "); + return(1); + } + + memset(&elt, 0, sizeof(elt)); + + /* 1) Loading */ + for (i=0; i