Skip to content

Commit

Permalink
lilos-watch: initial draft.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbiffle committed May 5, 2024
1 parent 3b31f5c commit 862a63b
Show file tree
Hide file tree
Showing 12 changed files with 494 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"handoff",
"semaphore",
"rwlock",
"watch",
"examples/*/*",
"testsuite",
"testsuite/stm32f3",
Expand All @@ -29,6 +30,7 @@ lilos-testsuite = { path = "testsuite" }
lilos-handoff = { path = "handoff" }
lilos-semaphore = { path = "semaphore" }
lilos-rwlock = { path = "rwlock" }
lilos-watch = { path = "watch" }

# External
cfg-if = "1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ for k in ${!MODES[@]}; do
popd > /dev/null
done

DIRS="handoff semaphore rwlock list testsuite/stm32f4 testsuite/stm32g0 testsuite/stm32f3 testsuite/lm3s6965 examples/*/*/"
DIRS="handoff semaphore rwlock list watch testsuite/stm32f4 testsuite/stm32g0 testsuite/stm32f3 testsuite/lm3s6965 examples/*/*/"

for d in $DIRS; do
if [[ $d == *memory.x ]]; then
Expand Down
2 changes: 1 addition & 1 deletion clippy-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -euo pipefail

DIRS="os list handoff semaphore rwlock testsuite/stm32f4 testsuite/stm32g0 testsuite/stm32f3 examples/*/*/"
DIRS="os list handoff semaphore rwlock watch testsuite/stm32f4 testsuite/stm32g0 testsuite/stm32f3 examples/*/*/"

for d in $DIRS; do
echo "---- clipping in $d"
Expand Down
2 changes: 1 addition & 1 deletion doc-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -euo pipefail

DIRS="os list handoff semaphore rwlock"
DIRS="os list handoff semaphore rwlock watch"

for d in $DIRS; do
echo "---- testing doc generation in $d"
Expand Down
2 changes: 1 addition & 1 deletion msrv-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euo pipefail

jq --version

DIRS="os list handoff semaphore rwlock testsuite/stm32f4 testsuite/stm32g0 testsuite/stm32f3 examples/*/*/"
DIRS="os list handoff semaphore rwlock watch testsuite/stm32f4 testsuite/stm32g0 testsuite/stm32f3 examples/*/*/"

for d in $DIRS; do
pushd $d > /dev/null
Expand Down
4 changes: 3 additions & 1 deletion testsuite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ repository.workspace = true
rust-version.workspace = true

[features]
default = ["handoff", "semaphore", "rwlock"]
default = ["handoff", "semaphore", "rwlock", "watch"]
handoff = ["dep:lilos-handoff"]
semaphore = ["dep:lilos-semaphore"]
rwlock = ["dep:lilos-rwlock"]
watch = ["dep:lilos-watch"]

[package.metadata.docs.rs]
default-target = "thumbv7em-none-eabihf"
Expand All @@ -30,6 +31,7 @@ lilos-semaphore = { workspace = true, optional = true }
lilos-rwlock = { workspace = true, optional = true }
panic-semihosting.workspace = true
lilos-list.workspace = true
lilos-watch = { workspace = true, optional = true }

[lib]
test = false
Expand Down
7 changes: 7 additions & 0 deletions testsuite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ mod handoff;
mod semaphore;
#[cfg(feature = "rwlock")]
mod rwlock;
#[cfg(feature = "watch")]
mod watch;

use core::convert::Infallible;
use core::pin::pin;
Expand Down Expand Up @@ -162,6 +164,11 @@ async fn task_coordinator() -> Infallible {
rwlock::test_blocking,
#[cfg(feature = "rwlock")]
rwlock::test_fairness,

#[cfg(feature = "watch")]
watch::test_receive_only,
#[cfg(feature = "watch")]
watch::test_send_receive,
}
};

Expand Down
40 changes: 40 additions & 0 deletions testsuite/src/watch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use core::pin::pin;

use lilos_watch::Watch;

use crate::{poll_and_assert_not_ready, poll_and_assert_ready};

pub async fn test_receive_only() {
let w = Watch::new(123_u32);

let mut receiver = w.subscribe();

receiver.glimpse(|&value| assert_eq!(value, 123_u32));

{
let mut change_fut = pin!(receiver.changed());
poll_and_assert_not_ready!(change_fut.as_mut());
poll_and_assert_not_ready!(change_fut.as_mut());
}

receiver.mark_as_unseen();

{
let mut change_fut = pin!(receiver.changed());
poll_and_assert_ready!(change_fut.as_mut());
}
}

pub async fn test_send_receive() {
let w = Watch::new(123_u32);

let sender = w.sender();
let mut receiver = w.subscribe();

poll_and_assert_not_ready!(pin!(receiver.changed()));

sender.send(456_u32);

poll_and_assert_ready!(pin!(receiver.changed()));
receiver.glimpse(|&value| assert_eq!(value, 456_u32));
}
2 changes: 2 additions & 0 deletions watch/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = "thumbv7em-none-eabihf"
14 changes: 14 additions & 0 deletions watch/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "lilos-watch"
version = "0.1.0"
edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true

[dependencies]
lilos.workspace = true

[lib]
test = false
bench = false
Loading

0 comments on commit 862a63b

Please sign in to comment.