-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add dev_random example This example illustrates how to use the mount option on partitions. * remove device field from the partition config This field was not used at all in the codebase, having it in the config is misleading. Further on, it seems that there is no point in having it: device files can be mounted through the mount option already. Maybe we can eventually build something where for each partition with at least one device mount we run `udevadm wait --settle <device> [<device>]...` in a satellite thread, and we re-mount a device when it pops back. That way we can re-attach a device without restarting the hypervisor. Further discussion in #80 * refine CI, add prettier --------- Co-authored-by: Wanja Zaeske <[email protected]>
- Loading branch information
Showing
9 changed files
with
143 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,53 @@ | ||
name: Run checks | ||
name: Checks | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
nix-checks: | ||
nix-flake-check: | ||
name: Run nix flake check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v3 | ||
- uses: cachix/install-nix-action@v22 | ||
with: | ||
github_access_token: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: cachix/cachix-action@v12 | ||
with: | ||
name: dlr-ft | ||
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' | ||
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" | ||
- name: Nix Flake Check | ||
run: nix flake check | ||
|
||
impure-checks: | ||
name: Run check ${{ matrix.check }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
check: | ||
- udeps | ||
- treefmt --fail-on-change | ||
- audit --deny warnings | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: cachix/install-nix-action@v22 | ||
with: | ||
github_access_token: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: cachix/cachix-action@v12 | ||
with: | ||
name: dlr-ft | ||
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" | ||
- uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
target/ | ||
key: ${{ runner.os }}-${{ github.job }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
- name: Run check ${{ matrix.check }} | ||
run: nix develop --command ${{ matrix.check }} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,10 @@ | ||
major_frame: 1s | ||
partitions: | ||
- id: 0 | ||
name: partition_0 | ||
duration: 1s | ||
offset: 0ms | ||
period: 1s | ||
image: target/x86_64-unknown-linux-musl/release/dev_random | ||
mounts: | ||
- [/dev/random, /dev/random] |
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,11 @@ | ||
[package] | ||
name = "dev_random" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
a653rs = { workspace = true, features = ["macros"] } | ||
a653rs-linux = { path = "../../partition" } | ||
log.workspace = true |
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,55 @@ | ||
use a653rs::partition; | ||
use a653rs::prelude::PartitionExt; | ||
use a653rs_linux::partition::ApexLogger; | ||
use log::LevelFilter; | ||
|
||
fn main() { | ||
ApexLogger::install_panic_hook(); | ||
ApexLogger::install_logger(LevelFilter::Trace).unwrap(); | ||
|
||
dev_random::Partition.run() | ||
} | ||
|
||
#[partition(a653rs_linux::partition::ApexLinuxPartition)] | ||
mod dev_random { | ||
use log::info; | ||
use std::{fs::*, io::Read}; | ||
|
||
#[start(cold)] | ||
fn cold_start(mut ctx: start::Context) { | ||
// create and start an aperiodic process | ||
ctx.create_process_0().unwrap().start().unwrap(); | ||
} | ||
|
||
// do the same as a cold_start | ||
#[start(warm)] | ||
fn warm_start(ctx: start::Context) { | ||
cold_start(ctx); | ||
} | ||
|
||
// this aperiodic process opens /dev/random and reads some random bytes from it | ||
#[aperiodic( | ||
time_capacity = "Infinite", | ||
stack_size = "8KB", | ||
base_priority = 1, | ||
deadline = "Soft" | ||
)] | ||
fn process_0(_: process_0::Context) { | ||
info!("started process_0"); | ||
|
||
// open the device file and read its metadata | ||
let filename = "/dev/random"; | ||
let mut f = File::open(&filename).expect("no file found"); | ||
let metadata = metadata(&filename).expect("unable to read metadata"); | ||
info!("metadata: {metadata:#?}"); | ||
|
||
// read 16 bytes from the device | ||
let mut buffer = [0u8; 16]; | ||
f.read(&mut buffer).expect("buffer overflow"); | ||
info!("got some randomness: {buffer:?}"); | ||
|
||
info!("terminating this partitiong by setting the operating mode to idle"); | ||
// TODO wait for https://github.com/DLR-FT/a653rs/issues/22 to be fixed | ||
// Hypervisor::set_partition_mode(OperatingMode::Idle); | ||
} | ||
} |
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