Path: blob/main/tests/all/native_debug/simulate.rs
2450 views
use super::dump::{DwarfDumpSection, get_dwarfdump};1use super::obj::compile_cranelift;2use anyhow::{Result, format_err};3use filecheck::{CheckerBuilder, NO_VARIABLES};4use tempfile::NamedTempFile;5use wat::parse_str;67#[allow(dead_code, reason = "used by conditionally-defined tests below")]8fn check_wat(wat: &str) -> Result<()> {9let wasm = parse_str(wat)?;10let obj_file = NamedTempFile::new()?;11let obj_path = obj_file.path().to_str().unwrap();12compile_cranelift(&wasm, None, None, obj_path)?;13let dump = get_dwarfdump(obj_path, DwarfDumpSection::DebugInfo)?;14let mut builder = CheckerBuilder::new();15builder16.text(wat)17.map_err(|e| format_err!("unable to build checker: {e:?}"))?;18let checker = builder.finish();19let check = checker20.explain(&dump, NO_VARIABLES)21.map_err(|e| format_err!("{e:?}"))?;22assert!(check.0, "didn't pass check {}", check.1);23Ok(())24}2526#[test]27#[ignore]28#[cfg(all(29any(target_os = "linux", target_os = "macos"),30target_pointer_width = "64"31))]32fn test_debug_dwarf_simulate_simple_x86_64() -> Result<()> {33check_wat(34r#"35;; check: DW_TAG_compile_unit36(module37;; check: DW_TAG_subprogram38;; check: DW_AT_name ("wasm-function[0]")39;; check: DW_TAG_formal_parameter40;; check: DW_AT_name ("var0")41;; check: DW_AT_type42;; sameln: "i32"43;; check: DW_TAG_variable44;; check: DW_AT_name ("var1")45;; check: DW_AT_type46;; sameln: "i32"47(func (param i32) (result i32)48(local i32)49local.get 050local.set 151local.get 152)53)"#,54)55}5657#[test]58#[ignore]59#[cfg(all(60any(target_os = "linux", target_os = "macos"),61target_pointer_width = "64"62))]63fn test_debug_dwarf_simulate_with_imports_x86_64() -> Result<()> {64check_wat(65r#"66;; check: DW_TAG_compile_unit67(module68;; check: DW_TAG_subprogram69;; check: DW_AT_name ("func1")70(import "foo" "bar" (func $import1) )71(func $func1 (result i32)72i32.const 173)74)"#,75)76}7778#[test]79#[ignore]80#[cfg(all(81any(target_os = "linux", target_os = "macos"),82target_pointer_width = "64"83))]84fn test_debug_dwarf_simulate_with_invalid_name_x86_64() -> Result<()> {85check_wat(86r#"87;; check: DW_TAG_compile_unit88(module (@name "\00")89;; check: DW_TAG_subprogram90;; check: DW_AT_name ("wasm-function[1]")91(import "foo" "bar" (func $import1) )92(func (@name "\00f") (result i32)93(local (@name "l\00") i32)94i32.const 195)96)"#,97)98}99100101