update test program

This commit is contained in:
root 2011-03-23 21:32:51 +00:00
parent 9245824a65
commit 46b296ff92
2 changed files with 48 additions and 16 deletions

9
test/Makefile Normal file
View File

@ -0,0 +1,9 @@
CFLAGS = -Wall
SRCS = load_rw.c
OBJS = $(SRCS:%.c=%.o)
load_rw: ${OBJS}
${CC} -o $@ $^
clean:
rm *.o load_rw

View File

@ -20,6 +20,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
@ -33,58 +34,80 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int fd, res, i; int fd, res, i;
char *str, *dir, *tmp; char *str, *drv, *dir;
if (argc < 2) { if (argc < 2) {
printf("USAGE: %.20 <fpgafs-mountpoint>\n", argv[0]); printf("USAGE: %20s <fpgafs-mountpoint>\n", argv[0]);
return -1; return -1;
} }
dir=malloc(sizeof(argv[1]) + 10); dir=malloc(sizeof(argv[1]) + 10);
str=malloc(sizeof(argv[1]) + 15); str=malloc(sizeof(argv[1]) + 15);
drv=malloc(sizeof(argv[1]) + 15);
sprintf(dir, "%s/bla", argv[1]); sprintf(dir, "%s/bla", argv[1]);
sprintf(drv, "%s/bla/lldrv", argv[1]);
sprintf(str, "%s/bla/load", argv[1]); sprintf(str, "%s/bla/load", argv[1]);
if (mkdir(dir, 0777) == -1) { /* create context */
printf("ERROR-1: %s\n", strerror(errno)); if (mkdir(dir, 0777) < 0) {
printf("ERROR-%d\n", __LINE__);
return -1; return -1;
} }
printf("created: %s\n", dir); printf("created: %s\n", dir);
if ((fd = open(str, O_WRONLY, 0)) == -1) { /* set low level driver */
printf("ERROR-2: %s\n", strerror(errno)); if ((fd = open(drv, O_WRONLY, 0)) < 0) {
printf("ERROR-%d: %d\n", __LINE__, fd);
return -1; return -1;
} }
printf("opened: %s\n", str); printf("opened: %s\n", drv);
if ((res=write(fd, src, sizeof(src))) == -1) { if ((res=write(fd, "dbg", sizeof("dbg"))) < 0) {
printf("ERROR-3: %s\n", strerror(errno)); printf("ERROR-%d: %d\n", __LINE__, res);
goto out;
}
close(fd);
printf("set low level driver: %d\n", res);
/* load image */
if ((fd = open(str, O_WRONLY, 0)) < 0) {
printf("ERROR-%d: %d\n", __LINE__, fd);
return -1; return -1;
} }
printf("opened: %s\n", str);fflush(stdout);
if ((res=write(fd, src, sizeof(src))) < 0) {
printf("ERROR-%d: %d\n", __LINE__, res);
goto out;
}
printf("written (%d): ", res); printf("written (%d): ", res);
for (i=0; i < sizeof(src); i++) for (i=0; i < sizeof(src); i++)
printf("0x%x ", src[i]); printf("0x%x ", src[i]);
printf("\n"); printf("\n");
close(fd); close(fd);
if ((fd = open(str, O_RDONLY, 0)) == -1) { /* read image */
printf("ERROR-4: %s\n", strerror(errno)); if ((fd = open(str, O_RDONLY, 0)) < 0) {
printf("ERROR-%d: %d\n", __LINE__, fd);
return -1; return -1;
} }
printf("opened: %s\n", str); printf("opened: %s\n", str);
if ((res=read(fd, des, sizeof(des))) == -1) { if ((res=read(fd, des, sizeof(des))) < 0) {
printf("ERROR-5: %s\n", strerror(errno)); printf("ERROR-%d: %d\n", __LINE__, res);
return -1; goto out;
} }
printf("read (%d): ", res); printf("read (%d): ", res);
for (i=0; i < sizeof(des); i++) for (i=0; i < sizeof(des); i++)
printf("0x%x ", des[i]); printf("0x%x ", des[i]);
printf("\n"); printf("\n");
out:
close(fd); close(fd);
if (rmdir(dir) == -1) { /* destroy context */
printf("ERROR-6: %s\n", strerror(errno)); if (rmdir(dir) < 0) {
printf("ERROR-%d\n", __LINE__);
return -1; return -1;
} }
printf("removed: %s\n", dir); printf("removed: %s\n", dir);