From f1ccc0a5b2cd35c4d19b84f6f6dcc35ae99996f3 Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Wed, 1 Jul 2020 22:18:23 +0100 Subject: [PATCH 1/9] create gh actions --- .github/workflows/rust.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..3c13d1b --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,22 @@ +name: Rust + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose From cfb73c3f2197927078be88c650fc6795523e19f2 Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Wed, 1 Jul 2020 22:40:46 +0100 Subject: [PATCH 2/9] Update rust.yml --- .github/workflows/rust.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 3c13d1b..35573b2 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -10,13 +10,20 @@ env: CARGO_TERM_COLOR: always jobs: - build: + test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - run: rustup component add clippy rustfmt + - name: Check fmt + run: cargo fmt -- --check + - uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-features - name: Build - run: cargo build --verbose + run: cargo build - name: Run tests - run: cargo test --verbose + run: cargo test From 0f67c4c07ad3462d4f5554b687fbf5dc40f868ee Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Thu, 2 Jul 2020 09:11:54 +0100 Subject: [PATCH 3/9] Create grcov.yml --- .github/action-rs/grcov.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/action-rs/grcov.yml diff --git a/.github/action-rs/grcov.yml b/.github/action-rs/grcov.yml new file mode 100644 index 0000000..d8ce523 --- /dev/null +++ b/.github/action-rs/grcov.yml @@ -0,0 +1,14 @@ +branch: true +ignore-not-existing: true +llvm: true +filter: covered +output-type: lcov +output-path: ./lcov.info +prefix-dir: /home/user/build/ +ignore: + - "/*" + - "C:/*" + - "../*" +path-mapping: + - "/path1" + - "/path2" From 9635781e23fe1ff3ef44a364cdb10ebda7df111e Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Thu, 2 Jul 2020 09:12:05 +0100 Subject: [PATCH 4/9] Update rust.yml --- .github/workflows/rust.yml | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 35573b2..7b8239b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,9 +11,7 @@ env: jobs: test: - runs-on: ubuntu-latest - steps: - uses: actions/checkout@v2 - run: rustup component add clippy rustfmt @@ -27,3 +25,30 @@ jobs: run: cargo build - name: Run tests run: cargo test + + coverage: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + - uses: actions-rs/cargo@v1 + with: + command: clean + - uses: actions-rs/cargo@v1 + with: + command: test + args: --all-features --no-fail-fast # Customize args for your own needs + env: + CARGO_INCREMENTAL: '0' + RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' + RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' + - id: coverage + uses: actions-rs/grcov@v0.1 + - name: Coveralls upload + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ${{ steps.coverage.outputs.report }} From cccc294847f4808b3e64f33e2bc894a88d4b6095 Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Thu, 2 Jul 2020 19:54:37 +0100 Subject: [PATCH 5/9] Update rust.yml set meaningful names --- .github/workflows/rust.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7b8239b..216264b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -34,10 +34,12 @@ jobs: with: toolchain: nightly override: true - - uses: actions-rs/cargo@v1 + - name: Cargo clean + uses: actions-rs/cargo@v1 with: command: clean - - uses: actions-rs/cargo@v1 + - name: Cargo test + uses: actions-rs/cargo@v1 with: command: test args: --all-features --no-fail-fast # Customize args for your own needs @@ -45,6 +47,7 @@ jobs: CARGO_INCREMENTAL: '0' RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' + - name: Placeholder (run the example) - id: coverage uses: actions-rs/grcov@v0.1 - name: Coveralls upload From b21759062d4b7cdf9eccfcab521681705c602b5b Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Thu, 2 Jul 2020 19:58:45 +0100 Subject: [PATCH 6/9] Update rust.yml --- .github/workflows/rust.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 216264b..9655744 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -48,6 +48,10 @@ jobs: RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' - name: Placeholder (run the example) + uses: actions-rs/cargo@v1 + with: + command: run + args: --example producer -- # needs a file there - id: coverage uses: actions-rs/grcov@v0.1 - name: Coveralls upload From ab55963fc7cac17b38d715ed3e47467cfa81bd2f Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Thu, 18 Feb 2021 08:38:55 +0000 Subject: [PATCH 7/9] Apply Clippy's recommendation --- src/iter.rs | 9 ++++----- src/lib.rs | 17 +++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/iter.rs b/src/iter.rs index 8633d7d..7b208e7 100755 --- a/src/iter.rs +++ b/src/iter.rs @@ -50,11 +50,10 @@ impl Iterator for PcapIterator { .fill_buf() .and_then(|b| { (if first_block { - parse_header(b) - .and_then(|(u, h)| Ok(Some((b.len() - u.len(), Block::Header(h))))) + parse_header(b).map(|(u, h)| Some((b.len() - u.len(), Block::Header(h)))) } else { parse_record(b, endianness, nano_sec) - .and_then(|(u, r)| Ok(Some((b.len() - u.len(), Block::Record(r))))) + .map(|(u, r)| Some((b.len() - u.len(), Block::Record(r)))) }) .or_else(|e| match e { Err::Incomplete(_) @@ -64,7 +63,7 @@ impl Iterator for PcapIterator { }) }) .unwrap_or(None) - .and_then(|(c, block)| { + .map(|(c, block)| { self.first_block = false; if c != 0 { self.reader.consume(c); @@ -73,7 +72,7 @@ impl Iterator for PcapIterator { self.endianness = h.endianness; self.nano_sec = h.nano_sec; } - Some(block) + block }) } } diff --git a/src/lib.rs b/src/lib.rs index 1e0f44f..0196580 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,7 @@ use nom::{ /// Enumerates all frame format supported by pcap. #[allow(non_camel_case_types)] +#[allow(clippy::upper_case_acronyms)] #[derive(Debug, PartialEq, Copy, Clone)] pub enum LinkType { NULL, @@ -293,12 +294,12 @@ named_args!(parse_header_e(e: Endianness, nsec: bool)
, |val:&LinkType| { *val != LinkType::UNKNOWN } ) >> (Header { - major: major, - minor: minor, - this_zone: this_zone, - sigfigs: sigfigs, - snaplen: snaplen, - network: network, + major, + minor, + this_zone, + sigfigs, + snaplen, + network, nano_sec: nsec, endianness: e }) @@ -326,9 +327,9 @@ named_args!(pub parse_record(e: Endianness, nano_sec: bool), do_parse!( data: take!(incl_len) >> (Record { - ts_sec: ts_sec, + ts_sec, ts_nanosec: if nano_sec {ts_subsec} else {ts_subsec*1000}, - orig_len: orig_len, + orig_len, data: Vec::from(data) }) )); From 9d86d193c56a180d36f740791d4add5440bc1547 Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Thu, 18 Feb 2021 08:50:09 +0000 Subject: [PATCH 8/9] Update rust.yml --- .github/workflows/rust.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9655744..5c9e0a2 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -14,6 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - run: rustup update - run: rustup component add clippy rustfmt - name: Check fmt run: cargo fmt -- --check From 59d083d3630263afdfca8e19892d3898ff6e6bc6 Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Thu, 18 Feb 2021 08:58:23 +0000 Subject: [PATCH 9/9] Update rust.yml --- .github/workflows/rust.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 5c9e0a2..c741afb 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,9 +13,12 @@ jobs: test: runs-on: ubuntu-latest steps: + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + components: clippy, rustfmt + override: true - uses: actions/checkout@v2 - - run: rustup update - - run: rustup component add clippy rustfmt - name: Check fmt run: cargo fmt -- --check - uses: actions-rs/clippy-check@v1