Skip to content

Commit c38404f

Browse files
authored
fix: tests on avx512 host (#35)
1 parent c08a045 commit c38404f

File tree

8 files changed

+21
-9
lines changed

8 files changed

+21
-9
lines changed

.github/workflows/CI.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ jobs:
4343
env:
4444
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4545
- name: Run tests
46-
run: cargo test
46+
run: |
47+
cargo clippy --all-targets --all-features -- -D warnings
48+
cargo fmt --all -- --check
49+
cargo test
4750
4851
miri:
4952
runs-on: ${{ matrix.os }}
@@ -111,7 +114,7 @@ jobs:
111114
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112115

113116
- name: Test with ASAN
114-
run: cargo test --tests --target x86_64-unknown-linux-gnu
117+
run: cargo test --tests --target x86_64-unknown-linux-gnu --features asan
115118
env:
116119
RUST_TARGET: x86_64-unknown-linux-gnu
117120
RUST_BACKTRACE: 1

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ path = "examples/escape.rs"
1818

1919
[features]
2020
codspeed = ["criterion2/codspeed"]
21+
asan = [] # for ASAN
2122

2223
[[bench]]
2324
name = "escape"

src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,16 @@ mod tests {
521521
for i in 0u8..32 {
522522
let s = String::from_utf8(vec![i]).unwrap();
523523
let result = escape(&s);
524-
let expected = serde_json::to_string(&s).unwrap();
525-
assert_eq!(result, expected, "Failed for byte 0x{:02x}", i);
524+
let expected = String::from_utf8(QUOTE_TAB[i as usize].1.to_vec())
525+
.unwrap()
526+
.trim_end_matches('\0')
527+
.to_string();
528+
assert_eq!(
529+
result,
530+
format!("\"{}\"", expected),
531+
"Failed for byte 0x{:02x}",
532+
i
533+
);
526534
}
527535
}
528536

src/simd/avx2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ pub unsafe fn format_string(value: &str, dst: &mut [u8]) -> usize {
232232
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
233233
Simd256u::loadu(placeholder[..].as_ptr())
234234
} else {
235-
#[cfg(any(debug_assertions, miri))]
235+
#[cfg(any(debug_assertions, miri, feature = "asan"))]
236236
{
237237
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
238238
Simd256u::loadu(placeholder[..].as_ptr())

src/simd/avx512.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ pub unsafe fn format_string(value: &str, dst: &mut [u8]) -> usize {
225225
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
226226
Simd512u::loadu(placeholder[..].as_ptr())
227227
} else {
228-
#[cfg(any(debug_assertions, miri))]
228+
#[cfg(any(debug_assertions, miri, feature = "asan"))]
229229
{
230230
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
231231
Simd512u::loadu(placeholder[..].as_ptr())

src/simd/neon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ pub unsafe fn format_string(value: &str, dst: &mut [u8]) -> usize {
233233
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
234234
Simd128u::loadu(placeholder[..].as_ptr())
235235
} else {
236-
#[cfg(any(debug_assertions, miri))]
236+
#[cfg(any(debug_assertions, miri, feature = "asan"))]
237237
{
238238
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
239239
Simd128u::loadu(placeholder[..].as_ptr())

src/simd/sse2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ pub unsafe fn format_string(value: &str, dst: &mut [u8]) -> usize {
229229
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
230230
Simd128u::loadu(placeholder[..].as_ptr())
231231
} else {
232-
#[cfg(any(debug_assertions, miri))]
232+
#[cfg(any(debug_assertions, miri, feature = "asan"))]
233233
{
234234
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
235235
Simd128u::loadu(placeholder[..].as_ptr())

src/simd/v128.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub fn format_string(value: &str, dst: &mut [u8]) -> usize {
161161
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
162162
Simd128u::loadu(placeholder[..].as_ptr())
163163
} else {
164-
#[cfg(any(debug_assertions, miri))]
164+
#[cfg(any(debug_assertions, miri, feature = "asan"))]
165165
{
166166
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
167167
Simd128u::loadu(placeholder[..].as_ptr())

0 commit comments

Comments
 (0)