Skip to content
Snippets Groups Projects
Commit 029becda authored by Dor Laor's avatar Dor Laor
Browse files

Add a virtio block test.

With virtio we must use dynamic allocation for the correctness of
virt_to_phys
parent 329a8e1b
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@
/tests/tst-getcwd.so: ../../external/glibc-testsuite/build/debug/io/tst-getcwd.so
/tests/tst-clock.so: ../../external/glibc-testsuite/build/debug/rt/tst-clock.so
/tests/tst-ramdisk.so: ./tests/tst-ramdisk.so
/tests/tst-ramdisk.so: ./tests/tst-vblk.so
/java/Hello.class: ./tests/hello/Hello.class
/java.so: java/java.so
/java/RunJar.class: java/RunJar.class
......
......@@ -65,7 +65,7 @@ autodepend = -MD -MT $@ -MP
do-sys-includes = $(foreach inc, $(sys-includes), -isystem $(inc))
tests := tests/tst-pthread.so tests/tst-ramdisk.so tests/hello/Hello.class
tests += tests/bench/bench.jar
tests += tests/tst-vblk.so tests/bench/bench.jar
tests/hello/Hello.class: javabase=tests/hello
......@@ -73,6 +73,7 @@ java/RunJar.class: javabase=java
tests/tst-pthread.so: tests/tst-pthread.o
tests/tst-ramdisk.so: tests/tst-ramdisk.o
tests/tst-vblk.so: tests/tst-vblk.o
all: loader.img loader.bin
......
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define BUF_SIZE 4096
int main(int argc, char **argv)
{
int fd;
char *wbuf,*rbuf;
// malloc is used since virt_to_phys doesn't work
// on stack addresses and virtio needs that
wbuf = malloc(BUF_SIZE);
rbuf = malloc(BUF_SIZE);
fd = open("/dev/vblk0", O_RDWR);
if (fd < 0) {
perror("open");
return 1;
}
memset(wbuf, 0xab, BUF_SIZE);
if (pwrite(fd, wbuf, BUF_SIZE, 0) != BUF_SIZE) {
perror("pwrite");
return 1;
}
memset(rbuf, 0, BUF_SIZE);
if (pread(fd, rbuf, BUF_SIZE, 0) != BUF_SIZE) {
perror("pwrite");
return 1;
}
if (memcmp(wbuf, wbuf, BUF_SIZE) != 0) {
fprintf(stderr, "read error\n");
return 1;
}
close(fd);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment