Skip to content

Commit

Permalink
enhancement(shadows): Remove state from persisted shadow (#54)
Browse files Browse the repository at this point in the history
* Remove the bound on PAL Error type being Copy

* Change PersistedShadow to not contain the actual state, but rather read it from storage on every get, and write it on every change. This saves quite a bit of stack for larger shadow states

* Update CI to use nightly and remove codecov

* Update pfx credentials for integration test to new format used by openssl3
  • Loading branch information
MathiasKoch authored Sep 12, 2023
1 parent edeb11e commit f4b1dbc
Show file tree
Hide file tree
Showing 13 changed files with 386 additions and 352 deletions.
14 changes: 0 additions & 14 deletions .github/workflows/audit.yml

This file was deleted.

176 changes: 13 additions & 163 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,205 +19,55 @@ jobs:
access_token: ${{ secrets.GITHUB_TOKEN }}

test:
name: Test
name: Build & Test
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: thumbv7m-none-eabi
override: true

uses: actions/checkout@v3
- uses: dsherret/rust-toolchain-file@v1
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --all --target thumbv7m-none-eabi --features ${{ env.ALL_FEATURES }}
args: --all --target thumbv7em-none-eabihf --features ${{ env.ALL_FEATURES }}

- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: --lib --features "ota_mqtt_data,log"
grcov:
name: Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
target: x86_64-unknown-linux-gnu
override: true

- name: Install grcov
uses: actions-rs/cargo@v1
# uses: actions-rs/[email protected]
with:
# crate: grcov
# version: latest
# use-tool-cache: true
command: install
args: --locked grcov --git https://github.com/mozilla/grcov

- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: --lib --no-fail-fast --features "ota_mqtt_data,ota_http_data,log"
env:
CARGO_INCREMENTAL: "0"
RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=unwind -Zpanic_abort_tests"
RUSTDOCFLAGS: "-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=unwind -Zpanic_abort_tests"

- name: Generate coverage data
id: grcov
# uses: actions-rs/[email protected]
run: |
grcov target/debug/ \
--branch \
--llvm \
--source-dir . \
--output-file lcov.info \
--ignore='/**' \
--ignore='C:/**' \
--ignore='../**' \
--ignore-not-existing \
--excl-line "#\\[derive\\(" \
--excl-br-line "(#\\[derive\\()|(debug_assert)" \
--excl-start "#\\[cfg\\(test\\)\\]" \
--excl-br-start "#\\[cfg\\(test\\)\\]" \
--commit-sha ${{ github.sha }} \
--service-job-id ${{ github.job }} \
--service-name "GitHub Actions" \
--service-number ${{ github.run_id }}
- name: Upload coverage as artifact
uses: actions/upload-artifact@v2
with:
name: lcov.info
# path: ${{ steps.grcov.outputs.report }}
path: lcov.info

- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v1
with:
# file: ${{ steps.grcov.outputs.report }}
file: lcov.info
fail_ci_if_error: true

rustfmt:
name: rustfmt
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: rustfmt

- name: Run rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check --verbose

# tomlfmt:
# name: tomlfmt
# runs-on: ubuntu-latest
# steps:
# - name: Checkout source code
# uses: actions/checkout@v2

# - name: Install Rust
# uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: nightly
# override: true

# - name: Install tomlfmt
# uses: actions-rs/[email protected]
# with:
# crate: cargo-tomlfmt
# version: latest
# use-tool-cache: true

# - name: Run Tomlfmt
# uses: actions-rs/cargo@v1
# with:
# command: tomlfmt
# args: --dryrun
uses: actions/checkout@v3
- uses: dsherret/rust-toolchain-file@v1
- name: Rustfmt
run: cargo fmt -- --check

clippy:
name: clippy
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: clippy

uses: actions/checkout@v3
- uses: dsherret/rust-toolchain-file@v1
- name: Run clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: -- ${{ env.CLIPPY_PARAMS }}
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2
with:
persist-credentials: false

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true

- name: Build documentation
uses: actions-rs/cargo@v1
with:
command: doc
args: --verbose --no-deps --features ${{ env.ALL_FEATURES }}

integration-test:
name: Integration Tests
runs-on: ubuntu-latest
needs: ['test', 'rustfmt', 'clippy']
steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: x86_64-unknown-linux-gnu
override: true
uses: actions/checkout@v3
- uses: dsherret/rust-toolchain-file@v1
- name: Create OTA Job
run: |
./scripts/create_ota.sh
Expand Down
7 changes: 7 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[toolchain]
channel = "nightly-2023-06-28"
components = [ "rust-src", "rustfmt", "llvm-tools-preview", "clippy" ]
targets = [
"x86_64-unknown-linux-gnu",
"thumbv7em-none-eabihf"
]
5 changes: 4 additions & 1 deletion scripts/register.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ SECRETS_DIR=$(dirname $0)/../tests/secrets

PUBLIC_KEY=$(openssl ec -in $SECRETS_DIR/sign_public.pem -pubin -text -noout 2>/dev/null | awk 'NR>2 && NR<8 {gsub(/ /,""); gsub(/:/, ""); print $0}' | tr -d '\n' | awk '{ gsub(/\r/, ""); print substr($0,3)}' | xxd -r -p | base64 -w0 -)

aws lambda invoke --function-name "ms-device-provisioner-register" --output text --cli-binary-format raw-in-base64-out --payload '{"uuid": "rustot-provision", "public_key": "'$PUBLIC_KEY'", "device_type": "fbduo", "hardware_version": "test"}' response.json >/dev/null
API_KEY_ID="wxghvqsvp8"
API_KEY=`aws apigateway get-api-key --api-key $API_KEY_ID --include-value --query value --output text`

curl -X POST -L -H "Content-Type: application/json" -H "x-api-key: $API_KEY" -d '{"uuid": "rustot-provision", "public_key": "'$PUBLIC_KEY'", "device_type": "fbduo", "hardware_version": "test"}' register.blackbird.online -o response.json

# Store files to `$SECRETS_DIR/claim_certificate.pem.crt` & `$SECRETS_DIR/claim_private.pem.key`
jq -r '.certificateId' response.json > $SECRETS_DIR/claim_certificate.id
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

// This mod MUST go first, so that the others see its macros.
pub(crate) mod fmt;
Expand Down
2 changes: 1 addition & 1 deletion src/ota/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl From<mqttrust::MqttError> for OtaError {
}
}

impl<E: Copy> From<OtaPalError<E>> for OtaError {
impl<E> From<OtaPalError<E>> for OtaError {
fn from(_e: OtaPalError<E>) -> Self {
Self::Pal
}
Expand Down
15 changes: 10 additions & 5 deletions src/ota/pal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ use core::str::FromStr;
use super::encoding::FileContext;
use super::state::ImageStateReason;

#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum ImageState<E: Copy> {
pub enum ImageState<E> {
Unknown,
Aborted(ImageStateReason<E>),
Rejected(ImageStateReason<E>),
Accepted,
Testing(ImageStateReason<E>),
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum OtaPalError<E: Copy> {
pub enum OtaPalError<E> {
SignatureCheckFailed,
FileWriteFailed,
FileTooLarge,
Expand All @@ -31,6 +30,12 @@ pub enum OtaPalError<E: Copy> {
Custom(E),
}

impl<E> From<E> for OtaPalError<E> {
fn from(value: E) -> Self {
Self::Custom(value)
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum PalImageState {
Expand Down Expand Up @@ -142,7 +147,7 @@ impl core::cmp::Ord for Version {
}
/// Platform abstraction layer for OTA jobs
pub trait OtaPal {
type Error: Copy;
type Error;

/// OTA abort.
///
Expand Down
Loading

0 comments on commit f4b1dbc

Please sign in to comment.