Skip to content

Commit

Permalink
Merge pull request #5 from kevinheavey/ci-checks
Browse files Browse the repository at this point in the history
add CI checks
  • Loading branch information
kevinheavey authored Jul 29, 2024
2 parents 60545a7 + 2883e40 commit d9450e1
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 7 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Rust CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
cargo-fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt
- name: Check Formatting
run: cargo fmt -- --check

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Clippy Lint
run: RUSTFLAGS="-D warnings" cargo clippy --tests

clippy-native-cpu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Clippy Lint
run: RUSTFLAGS="-D warnings -C target-cpu=native" cargo clippy --tests

clippy-all-features:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Clippy Lint
run: RUSTFLAGS="-D warnings" cargo clippy --all-features --tests

tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Run tests
run: cargo test

tests-native-cpu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Run tests
run: RUSTFLAGS='-C target-cpu=native' cargo test -F std

tests-miri-big-endian:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install Miri
run: |
rustup toolchain install nightly --component miri
rustup override set nightly
cargo miri setup
- name: Run tests
run: cargo +nightly miri test --target s390x-unknown-linux-gnu -F std
4 changes: 2 additions & 2 deletions crates/five8/src/avx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,14 @@ mod tests {
for i in 0..90 {
in_.0[16 * (i / 10) + (i % 10)] = i as u8 + 1;
}
let in_ptr = in_.0.as_ptr() as *const u8;
let in_ptr = in_.0.as_ptr();
let a = wuc_ld(in_ptr);
let b = wuc_ld(unsafe { in_ptr.offset(32) });
let c = wuc_ld(unsafe { in_ptr.offset(64) });
let d = wuc_ld(unsafe { in_ptr.offset(96) });
let e = wuc_ld(unsafe { in_ptr.offset(128) });
let (out0, out1, out2) = ten_per_slot_down_64(a, b, c, d, e);
let out_ptr = out.0.as_mut_ptr() as *mut u8;
let out_ptr = out.0.as_mut_ptr();
wuc_st(out_ptr, out0);
wuc_st(unsafe { out_ptr.offset(32) }, out1);
wuc_st(unsafe { out_ptr.offset(64) }, out2);
Expand Down
7 changes: 6 additions & 1 deletion crates/five8/src/decode.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::missing_transmute_annotations)]
#[cfg(target_feature = "avx2")]
use core::mem::transmute;

Expand Down Expand Up @@ -277,7 +278,9 @@ fn truncate_and_swap_u64s_registers<
mod tests {
#[cfg(target_feature = "avx2")]
use core::arch::x86_64::{_mm256_shuffle_epi32, _mm256_unpacklo_epi64};
#[cfg(not(miri))]
use prop::array::uniform32;
#[cfg(not(miri))]
use proptest::prelude::*;

use super::*;
Expand Down Expand Up @@ -355,7 +358,7 @@ mod tests {
49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 0, 1, 0, 0, 0, 0, 0, 127,
];
let mut out = [0u8; 32];
let err = decode_32(&encoded, &mut out).unwrap_err();
let err = decode_32(encoded, &mut out).unwrap_err();
assert_eq!(err, DecodeError::InvalidChar(0));
}

Expand Down Expand Up @@ -468,6 +471,7 @@ mod tests {
println!("out3: {out3:?}");
}

#[cfg(not(miri))]
proptest! {
#[test]
fn proptest_decode_32(key in uniform32(0u8..)) {
Expand All @@ -481,6 +485,7 @@ mod tests {
}
}

#[cfg(not(miri))]
proptest! {
#[test]
fn proptest_decode_64(first_half in uniform32(0u8..), second_half in uniform32(0u8..)) {
Expand Down
12 changes: 8 additions & 4 deletions crates/five8/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ fn intermediate_to_base58_32(
)
}
#[cfg(target_feature = "avx2")]
intermediate_to_base58_32_avx(&intermediate, in_leading_0s, out)
intermediate_to_base58_32_avx(intermediate, in_leading_0s, out)
}

#[inline(always)]
Expand Down Expand Up @@ -822,7 +822,9 @@ mod tests {
#[cfg(target_feature = "avx2")]
use core::array::from_fn;
use five8_core::{BASE58_ENCODED_32_MAX_LEN, BASE58_ENCODED_64_MAX_LEN};
#[cfg(not(miri))]
use prop::array::uniform32;
#[cfg(not(miri))]
use proptest::prelude::*;

use super::*;
Expand All @@ -843,7 +845,7 @@ mod tests {
expected_len: u8,
encoded: &str,
) {
assert_eq!(&encode_32_to_string(&bytes, len, buf), encoded);
assert_eq!(&encode_32_to_string(bytes, len, buf), encoded);
assert_eq!(*len, expected_len);
let mut decoded = [0u8; 32];
decode_32(encoded.as_bytes(), &mut decoded).unwrap();
Expand All @@ -857,7 +859,7 @@ mod tests {
expected_len: u8,
encoded: &str,
) {
assert_eq!(&encode_64_to_string(&bytes, len, buf), encoded);
assert_eq!(&encode_64_to_string(bytes, len, buf), encoded);
assert_eq!(*len, expected_len);
let mut decoded = [0u8; 64];
decode_64(encoded.as_bytes(), &mut decoded).unwrap();
Expand All @@ -869,7 +871,7 @@ mod tests {
len: &mut u8,
buf: &mut [u8; BASE58_ENCODED_64_MAX_LEN],
) -> String {
encode_64(&bytes, Some(len), buf);
encode_64(bytes, Some(len), buf);
buf[..*len as usize].iter().map(|c| *c as char).collect()
}

Expand Down Expand Up @@ -1017,6 +1019,7 @@ mod tests {
);
}

#[cfg(not(miri))]
proptest! {
#[test]
fn proptest_encode_32(key in uniform32(0u8..)) {
Expand All @@ -1028,6 +1031,7 @@ mod tests {
}
}

#[cfg(not(miri))]
proptest! {
#[test]
fn proptest_encode_64(first_half in uniform32(0u8..), second_half in uniform32(0u8..)) {
Expand Down
8 changes: 8 additions & 0 deletions crates/five8_const/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,20 @@ const fn truncate_and_swap_u64s_const<const BINARY_SZ: usize, const N: usize>(
// 4 5 6 7 12 13 14 15 20 21 22 23 etc
let binary_u8_idx = i * 8;
let out_idx = i * 4;
#[cfg(target_endian = "little")]
unsafe {
out[out_idx] = *binary_u8.add(binary_u8_idx + 3);
out[out_idx + 1] = *binary_u8.add(binary_u8_idx + 2);
out[out_idx + 2] = *binary_u8.add(binary_u8_idx + 1);
out[out_idx + 3] = *binary_u8.add(binary_u8_idx);
}
#[cfg(target_endian = "big")]
unsafe {
out[out_idx] = *binary_u8.add(binary_u8_idx + 4);
out[out_idx + 1] = *binary_u8.add(binary_u8_idx + 5);
out[out_idx + 2] = *binary_u8.add(binary_u8_idx + 6);
out[out_idx + 3] = *binary_u8.add(binary_u8_idx + 7);
}
i += 1
}
out
Expand Down

0 comments on commit d9450e1

Please sign in to comment.