llam 0.1.2

Safe, Go-style Rust bindings for the LLAM runtime
use llam::sys;
use std::mem::{align_of, offset_of, size_of};

#[test]
fn abi_reported_struct_sizes_match_rust_layout() {
    let mut info = unsafe { std::mem::zeroed::<sys::llam_abi_info_t>() };
    let rc = unsafe { sys::llam_abi_get_info(&mut info, size_of::<sys::llam_abi_info_t>()) };
    assert_eq!(rc, 0);
    assert_eq!(info.abi_major, sys::LLAM_ABI_VERSION_MAJOR);
    assert_eq!(info.abi_minor, sys::LLAM_ABI_VERSION_MINOR);
    assert_eq!(info.struct_size, size_of::<sys::llam_abi_info_t>());
    assert_eq!(
        info.runtime_opts_size,
        size_of::<sys::llam_runtime_opts_t>()
    );
    assert_eq!(info.spawn_opts_size, size_of::<sys::llam_spawn_opts_t>());
    assert_eq!(
        info.runtime_stats_size,
        size_of::<sys::llam_runtime_stats_t>()
    );
}

#[test]
fn public_struct_layout_is_c_abi_sane() {
    assert_eq!(align_of::<sys::llam_spawn_opts_t>(), align_of::<u64>());
    assert_eq!(offset_of!(sys::llam_spawn_opts_t, task_class), 0);
    assert_eq!(offset_of!(sys::llam_spawn_opts_t, stack_class), 4);
    assert_eq!(offset_of!(sys::llam_spawn_opts_t, flags), 8);
    assert_eq!(offset_of!(sys::llam_spawn_opts_t, deadline_ns), 16);

    assert_eq!(align_of::<sys::llam_runtime_opts_t>(), align_of::<u64>());
    assert_eq!(offset_of!(sys::llam_runtime_opts_t, deterministic), 0);
    assert_eq!(offset_of!(sys::llam_runtime_opts_t, forced_yield_every), 4);
    assert_eq!(offset_of!(sys::llam_runtime_opts_t, experimental_flags), 8);
    assert_eq!(offset_of!(sys::llam_runtime_opts_t, idle_spin_ns), 16);
    assert_eq!(
        offset_of!(sys::llam_runtime_opts_t, idle_spin_max_iters),
        24
    );
    assert_eq!(offset_of!(sys::llam_runtime_opts_t, sqpoll_cpu), 28);
    assert_eq!(offset_of!(sys::llam_runtime_opts_t, profile), 32);

    assert_eq!(offset_of!(sys::llam_select_op_t, kind), 0);
    assert!(offset_of!(sys::llam_select_op_t, channel) >= 8);
    assert!(
        size_of::<sys::llam_runtime_stats_t>()
            >= offset_of!(sys::llam_runtime_stats_t, yield_direct_fail_push) + size_of::<u64>()
    );
}

#[test]
fn fd_sentinel_matches_platform_contract() {
    assert!(sys::fd_is_invalid(sys::LLAM_INVALID_FD));
    #[cfg(not(windows))]
    assert_eq!(sys::LLAM_INVALID_FD, -1);
}