5477409477
* add testcase for load read/write git-svn-id: svn+ssh://en.codiert.org/home/staff/ben/dev/misc.svn/projects/fpgafs@360 766a2236-cff9-0310-b0c0-a81a5f92509a
76 lines
1.5 KiB
C
76 lines
1.5 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <errno.h>
|
|
|
|
static char src[] = { 0x12, 0x34, 0x56, 0x78, 0x90};
|
|
static char des[] = { 0x0, 0x0, 0x0, 0x0, 0x0};
|
|
|
|
/*
|
|
* LOAD WRITE/READ TEST
|
|
*/
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
int fd, res, i;
|
|
char *str, *dir, *tmp;
|
|
|
|
if (argc < 2) {
|
|
printf("USAGE: %.20 <fpgafs-mountpoint>\n", argv[0]);
|
|
return -1;
|
|
}
|
|
|
|
dir=malloc(sizeof(argv[1]) + 10);
|
|
str=malloc(sizeof(argv[1]) + 15);
|
|
sprintf(dir, "%s/bla", argv[1]);
|
|
sprintf(str, "%s/bla/load", argv[1]);
|
|
|
|
if (mkdir(dir, 0777) == -1) {
|
|
printf("ERROR-1: %s\n", strerror(errno));
|
|
return -1;
|
|
}
|
|
printf("created: %s\n", dir);
|
|
|
|
if ((fd = open(str, O_WRONLY, 0)) == -1) {
|
|
printf("ERROR-2: %s\n", strerror(errno));
|
|
return -1;
|
|
}
|
|
printf("opened: %s\n", str);
|
|
|
|
if ((res=write(fd, src, sizeof(src))) == -1) {
|
|
printf("ERROR-3: %s\n", strerror(errno));
|
|
return -1;
|
|
}
|
|
printf("written (%d): ", res);
|
|
for (i=0; i < sizeof(src); i++)
|
|
printf("0x%x ", src[i]);
|
|
printf("\n");
|
|
close(fd);
|
|
|
|
if ((fd = open(str, O_RDONLY, 0)) == -1) {
|
|
printf("ERROR-4: %s\n", strerror(errno));
|
|
return -1;
|
|
}
|
|
printf("opened: %s\n", str);
|
|
|
|
if ((res=read(fd, des, sizeof(des))) == -1) {
|
|
printf("ERROR-5: %s\n", strerror(errno));
|
|
return -1;
|
|
}
|
|
printf("read (%d): ", res);
|
|
for (i=0; i < sizeof(des); i++)
|
|
printf("0x%x ", des[i]);
|
|
printf("\n");
|
|
close(fd);
|
|
|
|
if (rmdir(dir) == -1) {
|
|
printf("ERROR-6: %s\n", strerror(errno));
|
|
return -1;
|
|
}
|
|
printf("removed: %s\n", dir);
|
|
|
|
return 0;
|
|
}
|