Skip to content

Commit

Permalink
Merge pull request #857 from andrewdavidmackenzie/pigg_289
Browse files Browse the repository at this point in the history
pigg_289
  • Loading branch information
andrewdavidmackenzie authored Feb 20, 2025
2 parents f07fd23 + f4ac557 commit bec4d0a
Show file tree
Hide file tree
Showing 16 changed files with 315 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ jobs:
if: runner.os != 'Windows'
run: |
grcov . --binary-path target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "/*" -o lcov.info
lcov --ignore-errors unused --ignore-errors unsupported --ignore-errors inconsistent --ignore-errors empty,empty --remove lcov.info -o lcov.info --erase-functions "(?=^.*fmt).+"
lcov --remove lcov.info 'target/debug/build/**' 'target/release/build/**' '/usr*' '**/errors.rs' '**/build.rs' '*tests/*' --ignore-errors unused,unused --ignore-errors unsupported --ignore-errors inconsistent --ignore-errors empty,empty -o lcov.info --erase-functions "(?=^.*fmt).+"
- name: UploadCoverage
if: runner.os != 'Windows'
Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
# we specify bash to get pipefail; it guards against the `curl` command
# failing. otherwise `sh` won't catch that `curl` returned non-0
shell: bash
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.24.0/cargo-dist-installer.sh | sh"
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.28.0/cargo-dist-installer.sh | sh"
- name: Cache dist
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -107,6 +107,7 @@ jobs:
# - N "local" tasks that build each platform's binaries and platform-specific installers
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
runs-on: ${{ matrix.runner }}
container: ${{ matrix.container && matrix.container.image || null }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
Expand All @@ -117,13 +118,20 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Rust non-interactively if not already installed
if: ${{ matrix.container }}
run: |
if ! command -v cargo > /dev/null 2>&1; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
fi
- name: "Install armv7 and aarch64 Linkers"
if: "runner.os == 'Linux'"
run: |
sudo apt install gcc-aarch64-linux-gnu
sudo apt install gcc-arm-linux-gnueabihf
- name: Install dist
run: ${{ matrix.install_dist }}
run: ${{ matrix.install_dist.run }}
# Get the dist-manifest
- name: Fetch local artifacts
uses: actions/download-artifact@v4
Expand All @@ -148,7 +156,7 @@ jobs:
run: |
# Parse out what we just built and upload it to scratch storage
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
dist print-upload-files-from-manifest --manifest dist-manifest.json >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ target/
*.pdb

.vscode
.idea
.idea
*.profraw
coverage.info
2 changes: 2 additions & 0 deletions Cargo.lock

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

19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,21 @@ web-run: web-build
.PHONY: usb
usb:
@echo "Echo your root password at the prompt to copy udev rules for piggui to the system folder for them"
sudo cp 70.pigg.rules /etc/udev/rules.d/
sudo cp 70.pigg.rules /etc/udev/rules.d/

.PHONY: clean-start
clean-start:
@find . -name "*.profraw" | xargs rm -rf {}

.PHONY: coverage
coverage: clean-start
@echo "coverage<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
@RUSTFLAGS="-C instrument-coverage" LLVM_PROFILE_FILE="pigg-%p-%m.profraw" cargo build
cargo test
@echo "Gathering coverage information"
@grcov . --binary-path target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "/*" -o coverage.info
@lcov --remove coverage.info 'target/debug/build/**' 'target/release/build/**' '**/errors.rs' '**/build.rs' '*tests/*' --ignore-errors unused,unused --ignore-errors unsupported --ignore-errors inconsistent --ignore-errors empty,empty -o coverage.info --erase-functions "(?=^.*fmt).+"
@find . -name "*.profraw" | xargs rm -f
@echo "Generating coverage report"
@genhtml -o target/coverage --quiet coverage.info
@echo "View coverage report using 'open target/coverage/index.html'"
2 changes: 1 addition & 1 deletion dist-workspace.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = ["cargo:."]
# Config for 'dist'
[dist]
# The preferred dist version to use in CI (Cargo.toml SemVer syntax)
cargo-dist-version = "0.24.0"
cargo-dist-version = "0.28.0"
# CI backends to support
ci = "github"
# The installers to generate for each app
Expand Down
4 changes: 4 additions & 0 deletions piggui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ iced = { version = "0.13.1", default-features = false, features = ["tokio", "tin
[target.'cfg(not(any(all(target_arch = "aarch64", target_os = "linux"), target_arch = "arm" )))'.dependencies]
iced = { version = "0.13.1", default-features = false, features = ["tokio", "wgpu"] }

[dev-dependencies] # For tests
pignet = { path = "../pignet", features = ["iroh", "tcp", "discovery", "usb"] }
sysinfo = { version = "0.33" }

[package.metadata.cargo-all-features]
skip_optional_dependencies = true

Expand Down
4 changes: 2 additions & 2 deletions piggui/tests/iroh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ fn connect_via_iroh() {

wait_for_stdout(&mut piggui, "Connected to hardware").expect("Did not get connected message");

kill(piggui);
kill(piglet);
kill(&mut piggui);
kill(&mut piglet);
}
4 changes: 2 additions & 2 deletions piggui/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod support;
fn version_number() {
let mut child = support::run("piggui", vec!["--version".into()], None);
let line = wait_for_stdout(&mut child, "piggui").expect("Failed to get expected output");
kill(child);
kill(&mut child);
let version = line.split(' ').nth(1).unwrap().trim();
assert_eq!(version, env!("CARGO_PKG_VERSION"));
}
Expand All @@ -22,5 +22,5 @@ fn help() {
"'piggui' - Pi GPIO GUI for interacting with Raspberry Pi GPIO Hardware",
)
.expect("Failed to get expected output");
kill(child);
kill(&mut child);
}
45 changes: 44 additions & 1 deletion piggui/tests/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::net::IpAddr;
use std::path::PathBuf;
use std::process::{Child, Command, Stdio};
use std::str::FromStr;
use sysinfo::System;

pub fn run(binary: &str, options: Vec<String>, config: Option<PathBuf>) -> Child {
let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
Expand Down Expand Up @@ -49,13 +50,55 @@ pub fn run(binary: &str, options: Vec<String>, config: Option<PathBuf>) -> Child
.expect("Failed to spawn command")
}

pub fn kill(mut child: Child) {
#[allow(dead_code)] // for piggui
pub fn build(binary: &str) {
let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let workspace_dir = crate_dir
.parent()
.expect("Could not get workspace directory");
let mut command = Command::new(env!("CARGO"));

let args = vec![
"build".to_string(),
"--bin".to_string(),
binary.to_string(),
"--".into(),
];

println!("Running Command: cargo {}", args.join(" "));

// Build the binary and wait until it ends
command
.args(args)
.current_dir(workspace_dir)
// .env("@RUSTFLAGS", "-Cinstrument-coverage")
// .env("LLVM_PROFILE_FILE", "pigg-%p-%m.profraw")
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::inherit())
.spawn()
.unwrap()
.wait_with_output()
.unwrap();
}

pub fn kill(child: &mut Child) {
child.kill().expect("Failed to kill child process");

// wait for the process to be removed
child.wait().expect("Failed to wait until child exited");
}

#[allow(dead_code)] // for piggui
/// Kill all instances of a process based on it's name
pub fn kill_all(process_name: &str) {
let s = System::new_all();
for process in s.processes_by_exact_name(process_name.as_ref()) {
process.kill();
process.wait();
}
}

fn wait_for<R: BufRead>(token: &str, reader: &mut R) -> Option<String> {
let mut line = String::new();

Expand Down
4 changes: 2 additions & 2 deletions piggui/tests/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ fn connect_via_ip() {

wait_for_stdout(&mut piggui, "Connected to hardware").expect("Did not get connected message");

kill(piggui);
kill(piglet);
kill(&mut piggui);
kill(&mut piglet);
}
5 changes: 3 additions & 2 deletions piglet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ anyhow = { version = "1", default-features = false, features = ["std"] }
futures = { version = "0.3.31", default-features = false }
tokio = { version = "1.43", default-features = false, features = ["time", "rt", "rt-multi-thread", "macros"] }
log = { version = "0.4.25", default-features = false }
sysinfo = { version = "0.33.1", default-features = false, features = ["system"] }
sysinfo = { version = "0.33", default-features = false, features = ["system"] }
service-manager = { version = "0.7.1", default-features = false }
clap = { version = "4.5.30", default-features = false, features = ["std", "help", "error-context"] }
# for config serialization to/from file
Expand All @@ -60,7 +60,8 @@ serial_test = "3.1.1"

[dev-dependencies]
# For tests
pignet = { version = "0.6", path = "../pignet" }
pignet = { path = "../pignet", features = ["iroh", "tcp", "discovery", "usb"] }
sysinfo = { version = "0.33" }

[package.metadata.cargo-all-features]
skip_optional_dependencies = true
Expand Down
Loading

0 comments on commit bec4d0a

Please sign in to comment.