-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 <[email protected]>
- Loading branch information
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |