From e5a98843b486dc460dc909f2d593e73b412540e1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 25 Sep 2017 13:55:48 -0700 Subject: [PATCH] Assert that diassembly is "small" There's a lot of trickery in this crate which expands to a lot of code, so in addition to asserting that we find the right instruction, let's assert we find a small function as well (as these should all be just one or so instructions anyway). --- library/stdarch/assert-instr/src/lib.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/library/stdarch/assert-instr/src/lib.rs b/library/stdarch/assert-instr/src/lib.rs index 092f25e6a5aa..df1336b2f7c1 100644 --- a/library/stdarch/assert-instr/src/lib.rs +++ b/library/stdarch/assert-instr/src/lib.rs @@ -256,17 +256,25 @@ pub fn assert(fnptr: usize, fnname: &str, expected: &str) { // Look for `expected` as the first part of any instruction in this // function, returning if we do indeed find it. + let mut found = false; for instr in function.instrs.iter() { // Gets the first instruction, e.g. tzcntl in tzcntl %rax,%rax if let Some(part) = instr.parts.get(0) { // Truncates the instruction with the length of the expected // instruction: tzcntl => tzcnt and compares that. if part.starts_with(expected) { - return + found = true; + break } } } + let probably_only_one_instruction = function.instrs.len() < 20; + + if found && probably_only_one_instruction { + return + } + // Help debug by printing out the found disassembly, and then panic as we // didn't find the instruction. println!("disassembly for {}: ", sym.as_ref().unwrap()); @@ -277,5 +285,10 @@ pub fn assert(fnptr: usize, fnname: &str, expected: &str) { } println!(""); } - panic!("failed to find instruction `{}` in the disassembly", expected); + + if !found { + panic!("failed to find instruction `{}` in the disassembly", expected); + } else if !probably_only_one_instruction { + panic!("too many instructions in the disassembly"); + } }