[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH 3/3] tests: LIOv2-Testfälle, die konvertiertes ext2 brauchen



+ tests: Jetzt, nachdem cdi/fs und damit auch ext2 nach LIOv2
  konvertiert ist, können auch die entsprechenden Testfälle gemergt
  werden.

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 tests/lostio/002.c       |  188 ++++++++++++++++++++++++++++++++++++++++++
 tests/lostio/003.c       |  205 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/lostio/Makefile    |   10 ++-
 tests/lostio/run_test.sh |   18 ++++
 4 files changed, 419 insertions(+), 2 deletions(-)
 create mode 100644 tests/lostio/002.c
 create mode 100644 tests/lostio/003.c

diff --git a/tests/lostio/002.c b/tests/lostio/002.c
new file mode 100644
index 0000000..a987481
--- /dev/null
+++ b/tests/lostio/002.c
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 2011 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Kevin Wolf.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <syscall.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ports.h>
+#include <services.h>
+#include <errno.h>
+
+static const char* test_name;
+
+static void __attribute__((noreturn)) quit_qemu(void)
+{
+    request_ports(0xb000, 8);
+    outw(0xb004, 0x2000);
+
+    /* Wird nie erreicht */
+    while(1) {
+        asm volatile("ud2");
+    }
+}
+
+static void _test_assert(bool expr, const char* text, int line)
+{
+    if (!expr) {
+        printf("* FAIL %s: %s [" __FILE__ ":%d]\n", test_name, text, line);
+        quit_qemu();
+    }
+}
+
+#define test_assert(x) \
+    _test_assert((x), #x, __LINE__)
+
+static void rw(lio_stream_t s, int64_t offset, size_t size, void* buf,
+    void *rbuf, bool write)
+{
+    int ret;
+
+    if (write) {
+        ret = lio_pwrite(s, offset, size, buf);
+        test_assert(ret == size);
+    } else {
+        ret = lio_pread(s, offset, size, rbuf);
+        printf("read: %llx + %x:'%d [%llx...]\n",
+            offset, size, ret, *(uint64_t*)rbuf);
+        test_assert(ret == size);
+        test_assert(memcmp(buf, rbuf, size) == 0);
+
+    }
+}
+
+static void test_1_2_rw(bool write, const char* _test_name)
+{
+    lio_resource_t tmp_root;
+    lio_resource_t tmp_file;
+    lio_stream_t s;
+    uint8_t* buf = malloc(512 * 1024);
+    uint8_t* rbuf = malloc(512 * 1024);
+    int ret;
+    int i;
+
+    test_name = _test_name;
+    printf("start %s\n", test_name);
+
+    /* Testdatei anlegen und öffnen */
+    if (write) {
+        tmp_root = lio_resource("ata:/ata00|ext2:/", false);
+        test_assert(tmp_root >= 0);
+
+        tmp_file = lio_mkfile(tmp_root, "test");
+        test_assert(tmp_file >= 0);
+    } else {
+        tmp_file = lio_resource("ata:/ata00|ext2:/test", false);
+        test_assert(tmp_file >= 0);
+    }
+    printf("have res\n");
+
+    s = lio_open(tmp_file, LIO_READ | LIO_WRITE);
+    test_assert(s >= 0);
+
+    printf("starte rw...\n");
+    /* Puffer befuellen */
+    for (i = 0; i < 512 * 1024; i++) {
+        buf[i] = (19 + i) % 43;
+    }
+
+    /* 1. Durchlauf */
+    for (i = 0; i < 16; i++) {
+        rw(s,
+            384 + i * 1536 * 1024,
+            512 * 1024,
+            buf, rbuf, write);
+    }
+
+    /* 2. Durchlauf */
+    for (i = 0; i < 16; i++) {
+        rw(s,
+            384 + 1024 * 1024 + i * 1536 * 1024,
+            512 * 1024,
+            buf, rbuf, write);
+    }
+
+    /* 3. Durchlauf */
+    for (i = 0; i < 16; i++) {
+        rw(s,
+            384 + 512 * 1024 + i * 1536 * 1024,
+            512 * 1024,
+            buf, rbuf, write);
+    }
+
+    /* FIXME lio_sync_all() sollte das erledigen. Tut's aber nicht. */
+    ret = lio_sync(s);
+    test_assert(ret >= 0);
+
+    ret = lio_close(s);
+    test_assert(ret >= 0);
+
+    ret = lio_sync_all();
+    test_assert(ret >= 0);
+
+    free(buf);
+    free(rbuf);
+
+    printf("* PASS %s\n", test_name);
+}
+
+static void test1(void)
+{
+    test_1_2_rw(true, "ext2: Ganz viel write");
+}
+
+static void test2(void)
+{
+    test_1_2_rw(false, "ext2: Ganz viel read nach Reboot");
+}
+
+int main(int argc, char* argv[])
+{
+    if (argc < 2) {
+        printf("* ERROR Zu wenige Parameter\n");
+        quit_qemu();
+    }
+
+    servmgr_need("ata");
+    servmgr_need("ext2");
+
+    switch (atoi(argv[1])) {
+        case 1:
+            test1();
+            break;
+        case 2:
+            test2();
+            break;
+
+        default:
+            printf("* ERROR Unbekannter Testfall\n");
+            break;
+    }
+
+    quit_qemu();
+}
diff --git a/tests/lostio/003.c b/tests/lostio/003.c
new file mode 100644
index 0000000..00e5922
--- /dev/null
+++ b/tests/lostio/003.c
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2011 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Kevin Wolf.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "testlib.h"
+
+#include <syscall.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ports.h>
+#include <services.h>
+#include <errno.h>
+
+const char* test_name;
+
+static void rw(lio_stream_t s, int64_t offset, size_t size, void* buf,
+    void *rbuf, bool write)
+{
+    int ret;
+
+    if (write) {
+        ret = lio_pwrite(s, offset, size, buf);
+        printf("write: %llx + %x: %d\n", offset, size, ret);
+        test_assert(ret == size);
+    } else {
+        ret = lio_pread(s, offset, size, rbuf);
+        printf("read: %llx + %x:'%d [%llx..., expected %llx...]\n",
+            offset, size, ret, *(uint64_t*)rbuf, *(uint64_t*)buf);
+        test_assert(ret == size);
+        test_assert(memcmp(buf, rbuf, size) == 0);
+
+    }
+}
+
+static void test_2_3_rw(bool write, const char* _test_name)
+{
+    lio_resource_t tmp_root;
+    lio_resource_t tmp_file;
+    lio_stream_t s;
+    uint8_t* buf = malloc(512 * 1024);
+    uint8_t* rbuf = malloc(512 * 1024);
+    int ret;
+    int i;
+
+    test_name = _test_name;
+    printf("start %s\n", test_name);
+
+    /* Testdatei anlegen und öffnen */
+    if (write) {
+        tmp_root = lio_resource("ata:/ata00|ext2:/inner.ext2|ext2:/", false);
+        test_assert(tmp_root >= 0);
+
+        tmp_file = lio_mkfile(tmp_root, "test");
+        test_assert(tmp_file >= 0);
+    } else {
+        tmp_file = lio_resource("ata:/ata00|ext2:/inner.ext2|ext2:/test", false);
+        test_assert(tmp_file >= 0);
+    }
+    printf("have res\n");
+
+    s = lio_open(tmp_file, LIO_READ | LIO_WRITE);
+    test_assert(s >= 0);
+
+    printf("starte rw...\n");
+    /* Puffer befuellen */
+    for (i = 0; i < 512 * 1024; i++) {
+        buf[i] = (19 + i) % 43;
+    }
+
+    /* 1. Durchlauf */
+    for (i = 0; i < 16; i++) {
+        rw(s,
+            384 + i * 1536 * 1024,
+            512 * 1024,
+            buf, rbuf, write);
+    }
+
+    /* 2. Durchlauf */
+    for (i = 0; i < 16; i++) {
+        rw(s,
+            384 + 1024 * 1024 + i * 1536 * 1024,
+            512 * 1024,
+            buf, rbuf, write);
+    }
+
+    /* 3. Durchlauf */
+    for (i = 0; i < 16; i++) {
+        rw(s,
+            384 + 512 * 1024 + i * 1536 * 1024,
+            512 * 1024,
+            buf, rbuf, write);
+    }
+
+    /* FIXME lio_sync_all() sollte das erledigen. Tut's aber nicht. */
+    ret = lio_sync(s);
+    test_assert(ret >= 0);
+
+    ret = lio_close(s);
+    test_assert(ret >= 0);
+
+    ret = lio_sync_all();
+    test_assert(ret >= 0);
+
+    free(buf);
+    free(rbuf);
+
+    printf("* PASS %s\n", test_name);
+}
+
+
+static void test1(void)
+{
+    lio_resource_t file;
+    lio_stream_t s;
+    int ret;
+
+    uint8_t* buf = malloc(1024);
+    char text[] = "Ein Testtext zum Texten des Tests und zum Testen "
+                  "des Texts.";
+
+    test_name = "Geschachteltes ext2: Einfaches Lesen";
+
+    file = lio_resource("ata:/ata00|ext2:/inner.ext2|ext2:/test.txt", false);
+    test_assert(file >= 0);
+
+    s = lio_open(file, LIO_READ);
+    test_assert(s >= 0);
+
+    ret = lio_pread(s, 0, 1024, buf);
+    test_assert(ret == sizeof(text));
+    test_assert(memcmp(buf, text, sizeof(text) - 1) == 0);
+
+    ret = lio_close(s);
+    test_assert(ret >= 0);
+
+    ret = lio_pread(s, 0, 1024, buf);
+    test_assert(ret == -EBADF);
+
+    free(buf);
+    printf("* PASS %s\n", test_name);
+}
+
+static void test2(void)
+{
+    test_2_3_rw(true, "Geschachteltes ext2: Ganz viel write");
+}
+
+static void test3(void)
+{
+    test_2_3_rw(false, "Geschachteltes ext2: Ganz viel read nach Reboot");
+}
+
+int main(int argc, char* argv[])
+{
+    if (argc < 2) {
+        printf("* ERROR Zu wenige Parameter\n");
+        quit_qemu();
+    }
+
+    servmgr_need("ata");
+    servmgr_need("ext2");
+
+    switch (atoi(argv[1])) {
+        case 1:
+            test1();
+            break;
+        case 2:
+            test2();
+            break;
+        case 3:
+            test3();
+            break;
+
+        default:
+            printf("* ERROR Unbekannter Testfall\n");
+            break;
+    }
+
+    quit_qemu();
+}
diff --git a/tests/lostio/Makefile b/tests/lostio/Makefile
index 8a4536a..03f4d13 100644
--- a/tests/lostio/Makefile
+++ b/tests/lostio/Makefile
@@ -6,17 +6,23 @@ QEMU=$(QEMU_BINARY)
 
 LIBGCC=$(shell $(CC) -print-libgcc-file-name)
 
-CFLAGS=-I ../../src/include -I../../src/modules/include -I ../../src/include/arch/i386 -I../../src/modules/include/arch/i386
+CFLAGS=-I ../include -I ../../src/include -I../../src/modules/include -I ../../src/include/arch/i386 -I../../src/modules/include/arch/i386
 LDFLAGS=-T ../../src/modules/user-i386.ld --start-group ../../src/lib/library.a ../../src/modules/lib/library.a ../../src/modules/lib/crt0.o $(LIBGCC) --end-group
 
 export QEMU
 
-qemu: 001
+qemu: 001 002 003
 	@./run_test.sh
 
 001: 001.o
 	@$(LD) $^ $(LDFLAGS) -o $@
 
+002: 002.o
+	@$(LD) $^ $(LDFLAGS) -o $@
+
+003: 003.o ../lib/testlib.o
+	@$(LD) $^ $(LDFLAGS) -o $@
+
 %.o: %.c
 	@$(CC) $(CFLAGS) -o $@ $^
 
diff --git a/tests/lostio/run_test.sh b/tests/lostio/run_test.sh
index 1add91f..3bbb00c 100755
--- a/tests/lostio/run_test.sh
+++ b/tests/lostio/run_test.sh
@@ -34,3 +34,21 @@ run_test 001 7
 run_test 001 8
 run_test 001 9
 run_test 001 10
+
+dd if=/dev/zero of=scratch.img bs=1M count=32
+mke2fs -Fq scratch.img
+
+run_test 002 1
+run_test 002 2
+
+dd if=/dev/zero of=scratch.img bs=1M count=32
+mke2fs -Fq scratch.img
+dd if=/dev/zero of=inner.ext2 bs=1M count=28
+mke2fs -Fq inner.ext2
+echo "Ein Testtext zum Texten des Tests und zum Testen des Texts." > test.txt
+debugfs -wR "write test.txt test.txt" inner.ext2
+debugfs -wR "write inner.ext2 inner.ext2" scratch.img
+
+run_test 003 1
+run_test 003 2
+run_test 003 3
-- 
1.7.7