Skip to content

Commit

Permalink
ci: deny warnings and add more checks
Browse files Browse the repository at this point in the history
  • Loading branch information
y86-dev committed Apr 20, 2024
1 parent 3367b99 commit 45a64ee
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 38 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ jobs:
toolchain: ${{ matrix.toolchain }}
components: clippy
- name: cargo clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
run: cargo clippy -- -D warnings
doc:
runs-on: ubuntu-latest
name: nightly / doc
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/nostd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ jobs:
run: rustup target add ${{ matrix.target }}
- name: cargo check
run: cargo check --target ${{ matrix.target }} --no-default-features
env:
RUSTFLAGS: "-Dwarnings"
18 changes: 14 additions & 4 deletions .github/workflows/safety.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,24 @@ jobs:
run: cargo test --lib --tests --all-features --target x86_64-unknown-linux-gnu
env:
ASAN_OPTIONS: "detect_odr_violation=0:detect_leaks=0"
RUSTFLAGS: "--cfg NO_UI_TESTS --cfg NO_ALLOC_FAIL_TESTS -Z sanitizer=address"
RUSTFLAGS: "--cfg NO_UI_TESTS --cfg NO_ALLOC_FAIL_TESTS -Z sanitizer=address -Dwarnings"
- name: cargo test -Zsanitizer=leak
if: always()
run: cargo test --all-features --target x86_64-unknown-linux-gnu
env:
LSAN_OPTIONS: "suppressions=lsan-suppressions.txt"
RUSTFLAGS: "--cfg NO_UI_TESTS --cfg NO_ALLOC_FAIL_TESTS -Z sanitizer=leak"
RUSTFLAGS: "--cfg NO_UI_TESTS --cfg NO_ALLOC_FAIL_TESTS -Z sanitizer=leak -Dwarnings"
miri:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
flags: [
"",
"-Zmiri-tree-borrows",
"-Zmiri-strict-provenance",
"-Zmiri-tree-borrows -Zmiri-strict-provenance"
]
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -48,10 +57,11 @@ jobs:
with:
toolchain: ${{ env.NIGHTLY }}
components: miri
- name: cargo miri test
- name: ${{ matrix.flags }} cargo miri test
run: cargo miri test
env:
MIRIFLAGS: ""
RUSTFLAGS: "-Dwarnings"
MIRIFLAGS: ${{ matrix.flags }}
# loom:
# runs-on: ubuntu-latest
# steps:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
run: cargo generate-lockfile
- name: cargo test --locked
run: cargo test --locked --all-features --all-targets
env:
RUSTFLAGS: "-Dwarnings"
# https://twitter.com/alcuadrado/status/1571291687837732873
update:
runs-on: ubuntu-latest
Expand All @@ -46,4 +48,4 @@ jobs:
- name: cargo test
run: cargo test --locked --all-features --all-targets
env:
RUSTFLAGS: -D deprecated
RUSTFLAGS: -Ddeprecated -Dwarnings
8 changes: 7 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ jobs:
# https://twitter.com/jonhoo/status/1571290371124260865
- name: cargo test --locked
run: cargo test --locked --all-features --all-targets
env:
RUSTFLAGS: "-Dwarnings"
# https://github.com/rust-lang/cargo/issues/6669
- name: cargo test --doc
run: cargo test --locked --all-features --doc
env:
RUSTFLAGS: "-Dwarnings"
os-check:
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} / nightly
Expand All @@ -53,4 +57,6 @@ jobs:
if: hashFiles('Cargo.lock') == ''
run: cargo generate-lockfile
- name: cargo test
run: cargo test --locked --all-features --all-targets
run: cargo test --locked --all-features --all-targets
env:
RUSTFLAGS: "-Dwarnings"
26 changes: 3 additions & 23 deletions tests/alloc_fail.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
#![feature(allocator_api)]

use core::alloc::AllocError;
use pinned_init::*;
use std::sync::Arc;

#[path = "./ring_buf.rs"]
mod ring_buf;
use ring_buf::*;

#[cfg(all(not(miri), not(NO_ALLOC_FAIL_TESTS), not(target_os = "macos")))]
#[test]
fn too_big_pinned() {
// should be too big with current hardware.
assert!(matches!(
Box::pin_init(RingBuffer::<u8, { 1024 * 1024 * 1024 * 1024 }>::new()),
Err(AllocError)
));
// should be too big with current hardware.
assert!(matches!(
Arc::pin_init(RingBuffer::<u8, { 1024 * 1024 * 1024 * 1024 }>::new()),
Err(AllocError)
));
}

#[cfg(all(not(miri), not(NO_ALLOC_FAIL_TESTS), not(target_os = "macos")))]
#[test]
fn too_big_in_place() {
use core::alloc::AllocError;
use pinned_init::*;
use std::sync::Arc;
// should be too big with current hardware.
assert!(matches!(
Box::init(zeroed::<[u8; 1024 * 1024 * 1024 * 1024]>()),
Expand Down
24 changes: 20 additions & 4 deletions tests/ring_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ use core::{
use pinned_init::*;
use std::sync::Arc;

#[path = "../examples/mutex.rs"]
mod mutex;
use mutex::*;

#[pin_data(PinnedDrop)]
pub struct RingBuffer<T, const SIZE: usize> {
buffer: [MaybeUninit<T>; SIZE],
Expand Down Expand Up @@ -239,6 +235,7 @@ fn with_failing_inner() {
assert_eq!(buf.as_mut().pop(), None);
}

#[cfg_attr(miri, allow(dead_code))]
#[derive(Debug)]
struct BigStruct {
buf: [u8; 1024 * 1024],
Expand All @@ -263,6 +260,10 @@ fn big_struct() {
#[cfg(not(miri))]
#[test]
fn with_big_struct() {
#[path = "../examples/mutex.rs"]
mod mutex;
use mutex::*;

let buf = Arc::pin_init(CMutex::new(RingBuffer::<BigStruct, 64>::new())).unwrap();
let mut buf = buf.lock();
for _ in 0..63 {
Expand All @@ -285,3 +286,18 @@ fn with_big_struct() {
assert!(matches!(buf.as_mut().pop_no_stack(), Some(_)));
}
}

#[cfg(all(not(miri), not(NO_ALLOC_FAIL_TESTS), not(target_os = "macos")))]
#[test]
fn too_big_pinned() {
// should be too big with current hardware.
assert!(matches!(
Box::pin_init(RingBuffer::<u8, { 1024 * 1024 * 1024 * 1024 }>::new()),
Err(AllocError)
));
// should be too big with current hardware.
assert!(matches!(
Arc::pin_init(RingBuffer::<u8, { 1024 * 1024 * 1024 * 1024 }>::new()),
Err(AllocError)
));
}
6 changes: 4 additions & 2 deletions tests/ui.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#[cfg_attr(not(any(miri, NO_UI_TESTS)), test)]
#[cfg(not(any(miri, NO_UI_TESTS)))]
#[test]
fn compile_fail() {
let test_cases = trybuild::TestCases::new();
test_cases.compile_fail("tests/ui/compile-fail/pinned_drop/*.rs");
Expand All @@ -7,7 +8,8 @@ fn compile_fail() {
test_cases.compile_fail("tests/ui/compile-fail/zeroable/*.rs");
}

#[cfg_attr(not(any(miri, NO_UI_TESTS)), test)]
#[cfg(not(any(miri, NO_UI_TESTS)))]
#[test]
fn expand() {
macrotest::expand("tests/ui/expand/*.rs");
}

0 comments on commit 45a64ee

Please sign in to comment.