Polish OSDK documentation

This commit is contained in:
Jianfeng Jiang
2024-05-22 06:04:36 +00:00
committed by Tate, Hongliang Tian
parent 07caaa5b3f
commit 1391ff59f2
20 changed files with 253 additions and 164 deletions

View File

@ -26,11 +26,18 @@ the following tools need to be installed:
- Rust >= 1.75.0
- cargo-binutils
- gcc
- qemu-system-x86_64
- gdb
- grub
- ovmf
- qemu-system-x86_64
- xorriso
The dependencies required for installing Rust and running QEMU can be installed by:
```bash
apt install build-essential curl gdb grub-efi-amd64 grub2-common \
libpixman-1-dev mtools ovmf qemu-system-x86 xorriso
```
About how to install Rust, you can refer to
the [official site](https://www.rust-lang.org/tools/install).
@ -40,12 +47,6 @@ after Rust is installed by
cargo install cargo-binutils
```
Other tools can be installed by
```bash
apt install build-essential grub-efi-amd64 grub2-common \
libpixman-1-dev mtools qemu-system-x86 ovmf xorriso
```
### Install
`cargo-osdk` is published on [crates.io](https://crates.io/),

View File

@ -57,12 +57,6 @@ The kernel
will print `Hello world from the guest kernel!`to the console
and then abort.
There is also a code snippet that demonstrates
how to write kernel mode unit tests.
It follows a similar code pattern as user mode unit tests.
The test module is marked with the `#[cfg(ktest)]` macro,
and each test case is marked with `#[ktest]`.
```rust
{{#include ../../../../osdk/src/commands/new/kernel.template}}
```
@ -71,6 +65,9 @@ and each test case is marked with `#[ktest]`.
The `src/lib.rs` of library project only contains
a simple kernel mode unit test.
It follows a similar code pattern as user mode unit tests.
The test module is marked with the `#[cfg(ktest)]` macro,
and each test case is marked with `#[ktest]`.
```rust
{{#include ../../../../osdk/src/commands/new/lib.template}}
@ -93,19 +90,27 @@ git = "https://github.com/asterinas/asterinas"
branch = "main"
```
OSDK will also exclude the directory
which is used to generate temporary files.
```toml
[workspace]
exclude = ["target/osdk/base"]
```
### `OSDK.toml`
The `OSDK.toml` file is a manifest
that defines the exact behavior of OSDK.
By default, it contains the following contents.
It includes settings on how to start QEMU to run a kernel.
By default, it includes settings on how to start QEMU to run a kernel.
The meaning of each key can be found
in the [manifest documentation](../reference/manifest.md).
Please avoid changing the default settings
unless you know what you are doing.
The default manifest of a kernel project:
```toml
{{#include ../../../../osdk/src/commands/new/lib.OSDK.toml.template}}
{{#include ../../../../osdk/src/commands/new/kernel.OSDK.toml.template}}
```
### `rust-toolchain.toml`

View File

@ -1,4 +1,4 @@
# Testing or Running an OS Project
# Running or Testing an OS Project
OSDK allows for convenient building, running,
and testing of an OS project.
@ -20,6 +20,11 @@ simply type:
cargo osdk build
```
The initial build of an OSDK project
may take a considerable amount of time
as it involves downloading the Rust toolchain used by the framekernel.
However, this is a one-time process.
## Run the project
To launch the kernel with QEMU,
@ -42,6 +47,14 @@ library projects cannot.
## Test the project
Suppose you have created a new library project named `mylib`
which contains a default test case
and you are in the project directory.
```bash
cargo osdk new --lib mylib && cd mylib
```
To run the kernel mode tests, use the following command:
```bash
@ -50,6 +63,9 @@ cargo osdk test
OSDK will run all the kernel mode tests in the crate.
Test cases can be added not only in library projects
but also in kernel projects.
If you want to run a specific test with a given name,
for example, if the test is named `foo`,
use the following command:

View File

@ -17,7 +17,9 @@ touch Cargo.toml
Then, add the following content to `Cargo.toml`:
```toml
{{#include ../../../../osdk/tests/examples_in_book/work_in_workspace_templates/Cargo.toml}}
```
## Creating a kernel project and a library project
@ -25,7 +27,7 @@ The two projects can be created using the following commands:
```bash
cargo osdk new --kernel myos
cargo osdk new mymodule
cargo osdk new mylib
```
The generated directory structure will be as follows:
@ -39,7 +41,7 @@ myworkspace/
│ ├── Cargo.toml
│ └── src/
│ └── lib.rs
└── mymodule/
└── mylib/
├── Cargo.toml
└── src/
└── lib.rs
@ -52,21 +54,27 @@ In addition to the two projects,
OSDK will also generate `OSDK.toml` and `rust-toolchain.toml`
at the root of the workspace.
Next, add the following function to `mymodule/src/lib.rs`.
Next, add the following function to `mylib/src/lib.rs`.
This function will calculate the available memory
after booting:
{{#include ../../../../osdk/tests/examples_in_book/work_in_workspace_templates/mymodule/src/lib.rs}}
```rust
{{#include ../../../../osdk/tests/examples_in_book/work_in_workspace_templates/mylib/src/lib.rs}}
```
Then, add a dependency on `mymodule` to `myos/Cargo.toml`:
Then, add a dependency on `mylib` to `myos/Cargo.toml`:
```toml
{{#include ../../../../osdk/tests/examples_in_book/work_in_workspace_templates/myos/Cargo.toml}}
```
In `myos/src/lib.rs`,
modify the file content as follows.
This main function will call the function from `mymodule`:
This main function will call the function from `mylib`:
```rust
{{#include ../../../../osdk/tests/examples_in_book/work_in_workspace_templates/myos/src/lib.rs}}
```
## Building and Running the kernel
@ -92,9 +100,9 @@ cargo osdk test
If you want to run test cases from a specific crate,
navigate to the crate's folder
and run `cargo osdk test`.
For example, if you want to test `myos`,
For example, if you want to test `mylib`,
use the following command:
```bash
cd myos && cargo osdk test
cd mylib && cargo osdk test
```