[fs][v9fs] Add an example test for VirtIO 9p filesystem
Add a simple test to validate the filesystem APIs that connect the LK filesystem layer and the virtualIO 9p devices. The test does the same as `app/tests/v9p_tests.c` to mount the littlekernel codebase folder as the `/v9p` on the LK filesystem. Then it tries to read the `LICENSE` file under the codebase and show the first 1024 bytes of the file. For example: ``` starting internet servers starting app shell entering main console loop ] v9fs_tests 0x80017060: 2f 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20 |/*. * Copyright 0x80017070: 28 63 29 20 32 30 30 38 2d 32 30 31 35 20 54 72 |(c) 2008-2015 Tr 0x80017080: 61 76 69 73 20 47 65 69 73 65 6c 62 72 65 63 68 |avis Geiselbrech 0x80017090: 74 0a 20 2a 0a 20 2a 20 50 65 72 6d 69 73 73 69 |t. *. * Permissi 0x800170a0: 6f 6e 20 69 73 20 68 65 72 65 62 79 20 67 72 61 |on is hereby gra ... ``` Signed-off-by: Cody Wong <codycswong@google.com>
This commit is contained in:
committed by
Travis Geiselbrecht
parent
7ed757b144
commit
7cda17edfc
@@ -20,6 +20,7 @@ int clock_tests(int argc, const console_cmd_args *argv);
|
||||
int printf_tests(int argc, const console_cmd_args *argv);
|
||||
int printf_tests_float(int argc, const console_cmd_args *argv);
|
||||
int v9p_tests(int argc, const console_cmd_args *argv);
|
||||
int v9fs_tests(int argc, const console_cmd_args *argv);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ MODULE_SRCS := \
|
||||
$(LOCAL_DIR)/thread_tests.c \
|
||||
$(LOCAL_DIR)/port_tests.c \
|
||||
$(LOCAL_DIR)/v9p_tests.c \
|
||||
$(LOCAL_DIR)/v9fs_tests.c \
|
||||
|
||||
MODULE_FLOAT_SRCS := \
|
||||
$(LOCAL_DIR)/benchmarks.c \
|
||||
|
||||
@@ -23,4 +23,5 @@ STATIC_COMMAND("fibo", "threaded fibonacci", &fibo)
|
||||
STATIC_COMMAND("spinner", "create a spinning thread", &spinner)
|
||||
STATIC_COMMAND("cbuf_tests", "test lib/cbuf", &cbuf_tests)
|
||||
STATIC_COMMAND("v9p_tests", "test dev/virtio/9p", &v9p_tests)
|
||||
STATIC_COMMAND("v9fs_tests", "test lib/fs/9p", &v9fs_tests)
|
||||
STATIC_COMMAND_END(tests);
|
||||
|
||||
72
app/tests/v9fs_tests.c
Normal file
72
app/tests/v9fs_tests.c
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Cody Wong
|
||||
*
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
#include <app/tests.h>
|
||||
#include <lk/err.h>
|
||||
#include <lk/debug.h>
|
||||
|
||||
#define _LOGF(fmt, args...) \
|
||||
printf("[%s:%d] " fmt, __PRETTY_FUNCTION__, __LINE__, ##args)
|
||||
#define LOGF(x...) _LOGF(x)
|
||||
|
||||
#if WITH_DEV_VIRTIO_9P
|
||||
#include <lib/fs.h>
|
||||
|
||||
#define V9FS_MOUNT_POINT "/v9p"
|
||||
#define V9FS_NAME "9p"
|
||||
#define V9P_BDEV_NAME "v9p0"
|
||||
|
||||
#define BUF_SIZE 1024
|
||||
|
||||
int v9fs_tests(int argc, const console_cmd_args *argv) {
|
||||
status_t status;
|
||||
ssize_t readbytes;
|
||||
filehandle *handle;
|
||||
char buf[BUF_SIZE];
|
||||
|
||||
status = fs_mount(V9FS_MOUNT_POINT, V9FS_NAME, V9P_BDEV_NAME);
|
||||
if (status != NO_ERROR) {
|
||||
LOGF("failed to mount v9p bdev (%s) onto mount point (%s): %d\n",
|
||||
V9P_BDEV_NAME, V9FS_MOUNT_POINT, status);
|
||||
return status;
|
||||
}
|
||||
|
||||
status = fs_open_file(V9FS_MOUNT_POINT "/LICENSE", &handle);
|
||||
if (status != NO_ERROR) {
|
||||
LOGF("failed to open the target file: %d\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
readbytes = fs_read_file(handle, buf, 0, BUF_SIZE);
|
||||
if (readbytes < 0) {
|
||||
LOGF("failed to read the target file: %ld\n", readbytes);
|
||||
return status;
|
||||
}
|
||||
|
||||
hexdump8(buf, BUF_SIZE);
|
||||
|
||||
status = fs_close_file(handle);
|
||||
if (status != NO_ERROR) {
|
||||
LOGF("failed to close the target file: %d\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
status = fs_unmount(V9FS_MOUNT_POINT);
|
||||
if (status != NO_ERROR) {
|
||||
LOGF("failed to unmount v9p on mount point (%s): %d\n",
|
||||
V9FS_MOUNT_POINT, status);
|
||||
return status;
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
#else
|
||||
int v9fs_tests(int argc, const console_cmd_args *argv) {
|
||||
LOGF("platform didn't have dev/virtio/9p supported\n");
|
||||
return ERR_NOT_SUPPORTED;
|
||||
}
|
||||
#endif // WITH_DEV_VIRTIO_9P
|
||||
Reference in New Issue
Block a user