From patchwork Tue Feb 11 15:31:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 24470 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AD92C206FF for ; Tue, 11 Feb 2014 15:31:37 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id u16sf1393009iet.8 for ; Tue, 11 Feb 2014 07:31:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=U1MCgNA/nZ+vttpXfO6B1+vK/0rPBoV4ciGg/LjOq3c=; b=BdDqpO+UKvJrfTGcdzahqrRtVOA8mYVs8RF0ml2XazYdPrBTYjWiiKoCypYJIAaL30 o4W40jLnboFGiQxIoz6n1LXT4f3T3KrpM0PNLKC+Uhtyq+Wa03gbYM7G8R6dfY399D25 lnb8PzFhEVdHi205U9SQvJksr2ORYyIqFqy79K5iggshXuKDg6dt016Ph1CO+AaoCwSy bU23YWZatnjv2nZBhoVJ8DfdWsHxXJcWRaIRmq2PDfOh5iyuChfKXArW0+LCsxErVURl w0+pEupcKUKJbvJBsDjaxk5Qgf/7YsAMKLc3NhZgJvmwEVkli0IPNBNE7g2PNCF5DjL1 MRHA== X-Gm-Message-State: ALoCoQk1kG+bnLpL5+5xOsM8M2NDXFmpsbhwaYr8v4oZrmR4QqAj9QddBHdpi17t62QtJCI0U6ex X-Received: by 10.50.153.69 with SMTP id ve5mr3225igb.7.1392132696909; Tue, 11 Feb 2014 07:31:36 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.34.76 with SMTP id k70ls2435584qgk.30.gmail; Tue, 11 Feb 2014 07:31:36 -0800 (PST) X-Received: by 10.52.185.196 with SMTP id fe4mr5519826vdc.27.1392132696756; Tue, 11 Feb 2014 07:31:36 -0800 (PST) Received: from mail-vb0-f53.google.com (mail-vb0-f53.google.com [209.85.212.53]) by mx.google.com with ESMTPS id x7si6035508vel.38.2014.02.11.07.31.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Feb 2014 07:31:36 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.53 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.53; Received: by mail-vb0-f53.google.com with SMTP id p17so5865338vbe.40 for ; Tue, 11 Feb 2014 07:31:36 -0800 (PST) X-Received: by 10.52.22.105 with SMTP id c9mr71536vdf.57.1392132696614; Tue, 11 Feb 2014 07:31:36 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp254811vcz; Tue, 11 Feb 2014 07:31:35 -0800 (PST) X-Received: by 10.14.126.9 with SMTP id a9mr3944345eei.95.1392132694603; Tue, 11 Feb 2014 07:31:34 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id x7si32916636eef.30.2014.02.11.07.31.30 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 11 Feb 2014 07:31:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WDFJ1-0004rV-Vz; Tue, 11 Feb 2014 15:31:27 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Richard Henderson Subject: [RFC] translate-all.c: add hack for coverage testing Date: Tue, 11 Feb 2014 15:31:27 +0000 Message-Id: <1392132687-18664-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.53 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Actually this barely even rises to the level of an RFC, but since I'm not entirely sure how or if it might be possible to turn this into upstreamable code I thought I might as well send it out as-is in case anybody else finds it useful. The basic idea is that you build the linux-user binary and run it on something (anything). Instead of actually running code we instead just loop round feeding every possible instruction pattern to the decoder. This lets us catch: * "can't happen" assertions in the wrong place * TCG temp leaks * insns which generate too many TCG ops Obvious deficiencies here: * no UI for specifying that you want to test a smaller part of the instruction space * an assumption that instructions are fixed-length 32 bits * cheesily hardwired in You can do a complete sweep of an entire 32-bit instruction encoding space within a couple of hours. thanks -- PMM --- translate-all.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/translate-all.c b/translate-all.c index 543e1ff..716f501 100644 --- a/translate-all.c +++ b/translate-all.c @@ -195,6 +195,53 @@ int cpu_gen_code(CPUArchState *env, TranslationBlock *tb, int *gen_code_size_ptr return 0; } +#if 1 +static void cpu_exercise_decoder(CPUArchState *env, TranslationBlock *tb) +{ + fprintf(stderr, "Test mode, exercising decoder\n"); + uint32_t insn = 0; + int maxops = 0, numops; + uint32_t insnbuf[1]; + + /* Force the decoder to do just one instruction at a time */ + singlestep = 1; + + for (;;) { + /* ARM A64 specific hack: just skip all the unallocateds */ + if (insn && !(insn & (3 << 27))) { + insn++; + continue; + } + + if (!(insn & 0xffff)) { + fprintf(stderr, "%x", insn >> 28); + } + + tb->pc = h2g_nocheck(&insnbuf); + insnbuf[0] = insn; + + tcg_func_start(&tcg_ctx); + gen_intermediate_code(env, tb); + + numops = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; + if (numops > maxops) { + maxops = numops; + fprintf(stderr, "\nNew worst case TCG ops: %d (insn %08x)\n", + numops, insn); + } + + insn++; + if (insn == 0) { + break; + } + } + + fprintf(stderr, "\nExercising complete. Worst case TCG ops: %d\n", maxops); + + exit(0); +} +#endif + /* The cpu state corresponding to 'searched_pc' is restored. */ static int cpu_restore_state_from_tb(TranslationBlock *tb, CPUArchState *env, @@ -966,6 +1013,10 @@ TranslationBlock *tb_gen_code(CPUArchState *env, tb->cs_base = cs_base; tb->flags = flags; tb->cflags = cflags; +#if 1 + cpu_exercise_decoder(env, tb); + exit(0); +#endif cpu_gen_code(env, tb, &code_gen_size); tcg_ctx.code_gen_ptr = (void *)(((uintptr_t)tcg_ctx.code_gen_ptr + code_gen_size + CODE_GEN_ALIGN - 1) & ~(CODE_GEN_ALIGN - 1));