use super::*;
#[test]
fn test_f036_ptx_has_zero_page_detection() {
let kernel = Lz4WarpCompressKernel::new(100);
let ptx = kernel.emit_ptx();
assert!(
ptx.contains("or.b32"),
"Missing OR operations for zero detection"
);
assert!(
ptx.contains("L_write_zero_size"),
"Missing zero-size output path"
);
assert!(
ptx.contains("L_after_size_write"),
"Missing size write merge label"
);
}
#[test]
fn test_f037_ptx_warp_reduction() {
let kernel = Lz4WarpCompressKernel::new(100);
let ptx = kernel.emit_ptx();
let bar_count = ptx.matches("bar.sync").count();
assert!(
bar_count >= 3,
"Should have at least 3 barrier syncs, found {}",
bar_count
);
}
#[test]
fn test_f038_zero_page_compressed_size() {
let kernel = Lz4WarpCompressKernel::new(100);
let ptx = kernel.emit_ptx();
assert!(
ptx.contains("20"),
"Should reference compressed zero page size"
);
}
#[test]
fn test_f039_page_id_calculation() {
let kernel = Lz4WarpCompressKernel::new(100);
let ptx = kernel.emit_ptx();
assert!(ptx.contains("%ctaid.x"), "Missing blockIdx.x access");
assert!(ptx.contains("%tid.x"), "Missing threadIdx.x access");
}
#[test]
fn test_f040_lane_id_masking() {
let kernel = Lz4WarpCompressKernel::new(100);
let ptx = kernel.emit_ptx();
assert!(ptx.contains("and.b32"), "Missing lane ID masking");
}
#[test]
fn test_f041_shared_memory_allocation() {
let kernel = Lz4WarpCompressKernel::new(100);
let smem = kernel.shared_memory_bytes();
let min_required = 4 * (PAGE_SIZE as usize + LZ4_HASH_SIZE as usize * 2);
assert!(
smem >= min_required,
"Shared memory {} < required {}",
smem,
min_required
);
}
#[test]
fn test_f042_bounds_check_present() {
let kernel = Lz4WarpCompressKernel::new(100);
let ptx = kernel.emit_ptx();
assert!(
ptx.contains("setp.lt"),
"Missing bounds check comparison (setp.lt)"
);
assert!(ptx.contains("L_exit"), "Missing exit label for OOB pages");
}
#[test]
fn test_f043_cooperative_load() {
let kernel = Lz4WarpCompressKernel::new(100);
let ptx = kernel.emit_ptx();
let ld_count = ptx.matches("ld.global.u32").count();
assert!(
ld_count >= 32,
"Should have many global loads, found {}",
ld_count
);
}
#[test]
fn test_f044_leader_thread_writes_size() {
let kernel = Lz4WarpCompressKernel::new(100);
let ptx = kernel.emit_ptx();
assert!(ptx.contains("setp.eq"), "Missing leader thread check");
assert!(
ptx.contains("L_not_leader"),
"Missing non-leader skip label"
);
}
#[test]
fn test_f045_output_size_write() {
let kernel = Lz4WarpCompressKernel::new(100);
let ptx = kernel.emit_ptx();
assert!(ptx.contains("st.global.u32"), "Missing size output store");
}
#[test]
fn test_f048_shared_memory_reduction() {
let kernel = Lz4WarpCompressKernel::new(100);
let ptx = kernel.emit_ptx();
let wgsl = kernel.emit_wgsl();
assert!(
ptx.contains("st.u32"),
"PTX missing generic store for reduction"
);
assert!(
ptx.contains("ld.u32"),
"PTX missing generic load for reduction"
);
assert!(
ptx.contains(".shared"),
"PTX missing shared memory declaration"
);
assert!(
ptx.contains("cvta.shared"),
"PTX missing cvta for shared->generic"
);
assert!(
wgsl.contains("smem[reduction_idx]"),
"WGSL missing shared memory reduction"
);
}
#[test]
fn test_f049_page_data_integrity() {
let kernel = Lz4WarpCompressKernel::new(100);
let ptx = kernel.emit_ptx();
let global_loads = ptx.matches("ld.global.u32").count();
let global_stores = ptx.matches("st.global.u32").count();
assert!(global_loads >= 32, "Need at least 32 global loads for 4KB");
assert!(
global_stores >= 32,
"Need at least 32 global stores for 4KB"
);
}
#[test]
fn test_f050_kernel_determinism() {
let k1 = Lz4WarpCompressKernel::new(100);
let k2 = Lz4WarpCompressKernel::new(100);
let wgsl1 = k1.emit_wgsl();
let wgsl2 = k2.emit_wgsl();
assert_eq!(wgsl1, wgsl2, "WGSL should be deterministic");
let ptx1 = k1.emit_ptx();
let ptx2 = k2.emit_ptx();
let instr_count_1 = ptx1
.lines()
.filter(|l| l.trim().starts_with(|c: char| c.is_alphabetic()))
.count();
let instr_count_2 = ptx2
.lines()
.filter(|l| l.trim().starts_with(|c: char| c.is_alphabetic()))
.count();
assert_eq!(
instr_count_1, instr_count_2,
"PTX instruction count should match"
);
assert_eq!(
ptx1.matches("L_exit").count(),
ptx2.matches("L_exit").count()
);
assert_eq!(
ptx1.matches("L_not_leader").count(),
ptx2.matches("L_not_leader").count()
);
}