Skip to content

Commit 8c562bf

Browse files
committed
Add integration test
1 parent 2911952 commit 8c562bf

File tree

5 files changed

+143
-4
lines changed

5 files changed

+143
-4
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
contents: write
3737
env:
3838
default-branch: ${{ format('refs/heads/{0}', github.event.repository.default_branch) }}
39-
RUSTDOCFLAGS: -D rustdoc::broken_intra_doc_links
39+
RUSTDOCFLAGS: -D rustdoc::broken_intra_doc_links -D missing-docs
4040
steps:
4141
- uses: actions/checkout@v4
4242
- uses: dtolnay/rust-toolchain@nightly

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# axconfig-gen
22

3-
A TOML-based configuration generator for ArceOS.
3+
A TOML-based configuration generator for [ArceOS](https://github.com/arceos-org/arceos).
44

55
## Usage
66

@@ -11,14 +11,15 @@ Options:
1111
-s, --spec <SPEC> Path to the config specification file
1212
-c, --oldconfig <OLDCONFIG> Path to the old config file
1313
-o, --output <OUTPUT> Path to the output config file
14+
-f, --fmt <FMT> The output format [default: toml] [possible values: toml, rust]
1415
-h, --help Print help
1516
-V, --version Print version
1617
```
1718

1819
For example, to generate a config file `.axconfig.toml` from the config specifications distributed in `a.toml` and `b.toml`, you can run:
1920

2021
```sh
21-
axconfig-gen -s a.toml -s b.toml -o .axconfig.toml
22+
axconfig-gen -s a.toml -s b.toml -o .axconfig.toml -f toml
2223
```
2324

2425
See [defconfig.toml](example_configs/defconfig.toml) for an example of a config specification file.

example_configs/output.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/// Architecture identifier.
2+
pub const ARCH: &str = "x86_64";
3+
/// Platform identifier.
4+
pub const PLAT: &str = "x86_64-qemu-q35";
5+
/// Number of CPUs
6+
pub const SMP: usize = 1;
7+
8+
///
9+
/// Device specifications
10+
///
11+
mod device {
12+
/// MMIO regions with format (`base_paddr`, `size`).
13+
pub const MMIO_REGIONS: &[(usize, usize)] = &[
14+
(0xb000_0000, 0x1000_0000),
15+
(0xfe00_0000, 0xc0_0000),
16+
(0xfec0_0000, 0x1000),
17+
(0xfed0_0000, 0x1000),
18+
(0xfee0_0000, 0x1000),
19+
];
20+
/// End PCI bus number.
21+
pub const PCI_BUS_END: usize = 0;
22+
/// Base physical address of the PCIe ECAM space (should read from ACPI 'MCFG' table).
23+
pub const PCI_ECAM_BASE: usize = 0;
24+
/// PCI device memory ranges (not used on x86).
25+
pub const PCI_RANGES: &[(usize, usize)] = &[];
26+
/// VirtIO MMIO regions with format (`base_paddr`, `size`).
27+
pub const VIRTIO_MMIO_REGIONS: &[(usize, usize)] = &[];
28+
}
29+
30+
///
31+
/// Kernel configs
32+
///
33+
mod kernel {
34+
/// Stack size of each task.
35+
pub const TASK_STACK_SIZE: usize = 0;
36+
/// Number of timer ticks per second (Hz). A timer tick may contain several timer
37+
/// interrupts.
38+
pub const TICKS_PER_SEC: usize = 0;
39+
}
40+
41+
///
42+
/// Platform configs
43+
///
44+
mod platform {
45+
/// Kernel address space base.
46+
pub const KERNEL_ASPACE_BASE: usize = 0xffff_ff80_0000_0000;
47+
/// Kernel address space size.
48+
pub const KERNEL_ASPACE_SIZE: usize = 0x0000_007f_ffff_f000;
49+
/// Base physical address of the kernel image.
50+
pub const KERNEL_BASE_PADDR: usize = 0x20_0000;
51+
/// Base virtual address of the kernel image.
52+
pub const KERNEL_BASE_VADDR: usize = 0xffff_ff80_0020_0000;
53+
/// Offset of bus address and phys address. some boards, the bus address is
54+
/// different from the physical address.
55+
pub const PHYS_BUS_OFFSET: usize = 0;
56+
/// Base address of the whole physical memory.
57+
pub const PHYS_MEMORY_BASE: usize = 0;
58+
/// Size of the whole physical memory.
59+
pub const PHYS_MEMORY_SIZE: usize = 0x800_0000;
60+
/// Linear mapping offset, for quick conversions between physical and virtual
61+
/// addresses.
62+
pub const PHYS_VIRT_OFFSET: usize = 0xffff_ff80_0000_0000;
63+
/// Timer interrupt frequencyin Hz.
64+
pub const TIMER_FREQUENCY: usize = 0;
65+
}

example_configs/output.toml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Architecture identifier.
2+
arch = "x86_64"
3+
# Platform identifier.
4+
plat = "x86_64-qemu-q35"
5+
# Number of CPUs
6+
smp = 1
7+
8+
#
9+
# Device specifications
10+
#
11+
[device]
12+
# MMIO regions with format (`base_paddr`, `size`).
13+
mmio-regions = [
14+
["0xb000_0000", "0x1000_0000"],
15+
["0xfe00_0000", "0xc0_0000"],
16+
["0xfec0_0000", "0x1000"],
17+
["0xfed0_0000", "0x1000"],
18+
["0xfee0_0000", "0x1000"]
19+
]
20+
# End PCI bus number.
21+
pci-bus-end = 0
22+
# Base physical address of the PCIe ECAM space (should read from ACPI 'MCFG' table).
23+
pci-ecam-base = 0
24+
# PCI device memory ranges (not used on x86).
25+
pci-ranges = []
26+
# VirtIO MMIO regions with format (`base_paddr`, `size`).
27+
virtio-mmio-regions = []
28+
29+
#
30+
# Kernel configs
31+
#
32+
[kernel]
33+
# Stack size of each task.
34+
task-stack-size = 0
35+
# Number of timer ticks per second (Hz). A timer tick may contain several timer
36+
# interrupts.
37+
ticks-per-sec = 0
38+
39+
#
40+
# Platform configs
41+
#
42+
[platform]
43+
# Kernel address space base.
44+
kernel-aspace-base = "0xffff_ff80_0000_0000"
45+
# Kernel address space size.
46+
kernel-aspace-size = "0x0000_007f_ffff_f000"
47+
# Base physical address of the kernel image.
48+
kernel-base-paddr = 0x20_0000
49+
# Base virtual address of the kernel image.
50+
kernel-base-vaddr = "0xffff_ff80_0020_0000"
51+
# Offset of bus address and phys address. some boards, the bus address is
52+
# different from the physical address.
53+
phys-bus-offset = 0
54+
# Base address of the whole physical memory.
55+
phys-memory-base = 0
56+
# Size of the whole physical memory.
57+
phys-memory-size = 0x800_0000
58+
# Linear mapping offset, for quick conversions between physical and virtual
59+
# addresses.
60+
phys-virt-offset = "0xffff_ff80_0000_0000"
61+
# Timer interrupt frequencyin Hz.
62+
timer-frequency = 0

src/tests.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{ConfigErr, ConfigResult, ConfigType, ConfigValue};
1+
use crate::{Config, ConfigErr, ConfigResult, ConfigType, ConfigValue, OutputFormat};
22

33
fn check_type_infer(value: &str, expect_ty: &str) -> ConfigResult<()> {
44
let value = ConfigValue::new(value)?;
@@ -177,3 +177,14 @@ fn test_to_rust() {
177177
assert_eq!(ty.to_rust_type(), "&[&[(usize, &[&str], usize)]]");
178178
assert_eq!(value.to_rust_value(&ty, 0).unwrap(), rust);
179179
}
180+
181+
#[test]
182+
fn integration_test() -> std::io::Result<()> {
183+
let spec = std::fs::read_to_string("example_configs/defconfig.toml")?;
184+
let toml = std::fs::read_to_string("example_configs/output.toml")?;
185+
let rust = std::fs::read_to_string("example_configs/output.rs")?;
186+
let cfg = Config::from_toml(&spec).unwrap();
187+
assert_eq!(cfg.dump(OutputFormat::Toml).unwrap(), toml);
188+
assert_eq!(cfg.dump(OutputFormat::Rust).unwrap(), rust);
189+
Ok(())
190+
}

0 commit comments

Comments
 (0)