From patchwork Fri Jun 2 16:08:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 101286 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp477138qge; Fri, 2 Jun 2017 09:15:18 -0700 (PDT) X-Received: by 10.237.60.77 with SMTP id u13mr10228483qte.18.1496420118104; Fri, 02 Jun 2017 09:15:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496420118; cv=none; d=google.com; s=arc-20160816; b=ZSrWYni5b0Zttqyym7biBHBw/oPXgw+j91F42Or8uit0eHPdpekXrKllaPtHAFX23o AKywu+AWhmH7CwUQgg/yBeIpFEUwXdxIg5afA5Fn5N0d6NfTNoRkjjXUea0d9PezeDgy b9jjVVVAhVsNYRUoLEQp7aVpbQ939c1HmbpMngkRWSBMit6UhTfeyHxs+LtrIeFKXrZw B0tqtf0Yl9WtFy4yhiNk5suU9qWN+d1/Lu71amFmT8jbvF2iLqtc2aaUsG40eSQjhghb TyBqfjn3fI1Xkzs4c79rkFQDSKipVS3wTXd43jE+euOXo4MHVuKmhLyuRnudSkqbQWfi 4ceg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=Ro1ytADxnG64aJjlX9UADcYFs9uHSdXlpYSXxFKZhRw=; b=UgPawh4bw1XyGBGNTV4t7nMxPBqsyAQkntkfgrHlsfiPACjHY36t2ZV+EC8G6svNXZ JkyZ52L3bhIrLzZzJxvOJ3Ckula66RmYMkXDOf3A4Mg5A8HrdMRXV5fCHIfHQ//62b+f 39KB9/GNMEGv5wQbm0IMFpbal+i4P7qr0By20ZN4vRodn3xuFOKHGwTXzYxB9HQ2pCI9 6LxecHXiqZmataE97u2ECQ4Wcho+jArao/M3gARBIlb8J12ZLNKtDFqPrA9GW+LDKMHV EmiiS2TuWhryuylqUaKFOsSkqCCj5DmG56TCUOUYMRm3MvmneqY/O9gF+p8w2hGYc3mz dGxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id f14si23824857qta.315.2017.06.02.09.15.17 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 02 Jun 2017 09:15:18 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGpEJ-0003ch-EC for patch@linaro.org; Fri, 02 Jun 2017 12:15:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54504) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGp82-000631-5J for qemu-devel@nongnu.org; Fri, 02 Jun 2017 12:08:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGp80-00053O-PV for qemu-devel@nongnu.org; Fri, 02 Jun 2017 12:08:46 -0400 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:34836) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGp80-00052s-GR for qemu-devel@nongnu.org; Fri, 02 Jun 2017 12:08:44 -0400 Received: by mail-wm0-x234.google.com with SMTP id b84so29301844wmh.0 for ; Fri, 02 Jun 2017 09:08:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ro1ytADxnG64aJjlX9UADcYFs9uHSdXlpYSXxFKZhRw=; b=RKnpbbT6/VK/XTLsZ6nXCo1vFx+kJgO3Bvcef+/5Gavekx50oSvhKyeRB3FIDZRfmb GQYqB2zB76QYHkDjWF+tgQaHJ9ie5oZgmmspl0DjNY7SPIHh3XQraoOFIEeujIS/jaWy toj7m9nVK+4D5e2vSFzAWelXfIzhz/qsUaiDw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ro1ytADxnG64aJjlX9UADcYFs9uHSdXlpYSXxFKZhRw=; b=c1h4fPxk+PB5RkWvDCfCMAPV9QoUY9l7tO/U08y6GaO6Oi1vxqztrJHjWaXY3HB0CB yW7ohu5wRP8j7jARYibCU4olj+kFZCw4Qt8rgxihCm/XZQNTea30rRBboOsG4+78Ws9S 3eUbE65nAsyqntwEy/2GA/X1VxzYZlZwWW8qlXFCK5ZN1SWZ9F5FeYa5KwipMdrVqJdR KVH6TygBhUXkNXsRoSp5eDx8cvnNztFs91dsF91+XQnyPkUGJvfu0iOXYTyiL4PVGc2B l313nC3ecCTbjaUzFpROT+ts8HHsa9omWIQQS06X60u+Mu6kgxPLGrXDPS+rST3HanjI pOag== X-Gm-Message-State: AODbwcAYtlb73FbDwfkP1CKGt3uW/b28d9cDd1gZp2aDfgy7e/xtIdQh wHa2WQvFeKkdODKr X-Received: by 10.28.211.5 with SMTP id k5mr42073wmg.11.1496419723532; Fri, 02 Jun 2017 09:08:43 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id n92sm22903763wrb.62.2017.06.02.09.08.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2017 09:08:39 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id AA5C13E0422; Fri, 2 Jun 2017 17:08:54 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Fri, 2 Jun 2017 17:08:45 +0100 Message-Id: <20170602160848.4913-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170602160848.4913-1-alex.bennee@linaro.org> References: <20170602160848.4913-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::234 Subject: [Qemu-devel] [RISU PATCH v4 07/10] risu: add simple trace and replay support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This adds a very dumb and easily breakable trace and replay support. In --master mode the various risu ops trigger a write of register/memory state into a binary file which can be played back to an apprentice. Currently there is no validation of the image source so feeding the wrong image will fail straight away. The trace files will get very big for any appreciable sized test file and this will be addressed in later patches. Signed-off-by: Alex Bennée --- v4 - fix formatting mess - abort() instead of reporting de-sync - don't fake return for compiler v3 - fix options parsing - re-factored so no need for copy & paste v2 - moved read/write functions into main risu.c - cleaned up formatting - report more in apprentice --trace mode --- risu.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 84 insertions(+), 13 deletions(-) -- 2.13.0 diff --git a/risu.c b/risu.c index 22571cd..137cbbf 100644 --- a/risu.c +++ b/risu.c @@ -31,6 +31,7 @@ void *memblock = 0; int apprentice_socket, master_socket; +int trace_file = 0; sigjmp_buf jmpbuf; @@ -40,10 +41,12 @@ int test_fp_exc = 0; long executed_tests = 0; void report_test_status(void *pc) { - executed_tests += 1; - if (executed_tests % 100 == 0) { - fprintf(stderr,"Executed %ld test instructions (pc=%p)\r", - executed_tests, pc); + if (ismaster || trace_file) { + executed_tests += 1; + if (executed_tests % 100 == 0) { + fprintf(stderr,"Executed %ld test instructions (pc=%p)\r", + executed_tests, pc); + } } } @@ -54,6 +57,12 @@ int read_sock(void *ptr, size_t bytes) return recv_data_pkt(master_socket, ptr, bytes); } +int write_trace(void *ptr, size_t bytes) +{ + size_t res = write(trace_file, ptr, bytes); + return (res == bytes) ? 0 : 1; +} + void respond_sock(int r) { send_response_byte(master_socket, r); @@ -66,9 +75,36 @@ int write_sock(void *ptr, size_t bytes) return send_data_pkt(apprentice_socket, ptr, bytes); } +int read_trace(void *ptr, size_t bytes) +{ + size_t res = read(trace_file, ptr, bytes); + return (res == bytes) ? 0 : 1; +} + +void respond_trace(int r) +{ + switch (r) { + case 0: /* test ok */ + case 1: /* end of test */ + break; + default: + /* should not get here */ + abort(); + break; + } +} + void master_sigill(int sig, siginfo_t *si, void *uc) { - switch (recv_and_compare_register_info(read_sock, respond_sock, uc)) + int r; + + if (trace_file) { + r = send_register_info(write_trace, uc); + } else { + r = recv_and_compare_register_info(read_sock, respond_sock, uc); + } + + switch (r) { case 0: /* match OK */ @@ -82,7 +118,15 @@ void master_sigill(int sig, siginfo_t *si, void *uc) void apprentice_sigill(int sig, siginfo_t *si, void *uc) { - switch (send_register_info(write_sock, uc)) + int r; + + if (trace_file) { + r = recv_and_compare_register_info(read_trace, respond_trace, uc); + } else { + r = send_register_info(write_sock, uc); + } + + switch (r) { case 0: /* match OK */ @@ -94,6 +138,9 @@ void apprentice_sigill(int sig, siginfo_t *si, void *uc) exit(0); default: /* mismatch */ + if (trace_file) { + report_match_status(); + } exit(1); } } @@ -155,7 +202,13 @@ int master(int sock) { if (sigsetjmp(jmpbuf, 1)) { - return report_match_status(); + if (trace_file) { + close(trace_file); + fprintf(stderr,"\nDone...\n"); + return 0; + } else { + return report_match_status(); + } } master_socket = sock; set_sigill_handler(&master_sigill); @@ -184,6 +237,7 @@ void usage (void) fprintf(stderr, "between master and apprentice risu processes.\n\n"); fprintf(stderr, "Options:\n"); fprintf(stderr, " --master Be the master (server)\n"); + fprintf(stderr, " -t, --trace=FILE Record/playback trace file\n"); fprintf(stderr, " -h, --host=HOST Specify master host machine (apprentice only)\n"); fprintf(stderr, " -p, --port=PORT Specify the port to connect to/listen on (default 9191)\n"); } @@ -194,6 +248,7 @@ int main(int argc, char **argv) uint16_t port = 9191; char *hostname = "localhost"; char *imgfile; + char *trace_fn = NULL; int sock; // TODO clean this up later @@ -204,13 +259,14 @@ int main(int argc, char **argv) { { "help", no_argument, 0, '?'}, { "master", no_argument, &ismaster, 1 }, + { "trace", required_argument, 0, 't' }, { "host", required_argument, 0, 'h' }, { "port", required_argument, 0, 'p' }, { "test-fp-exc", no_argument, &test_fp_exc, 1 }, { 0,0,0,0 } }; int optidx = 0; - int c = getopt_long(argc, argv, "h:p:", longopts, &optidx); + int c = getopt_long(argc, argv, "h:p:t:", longopts, &optidx); if (c == -1) { break; @@ -223,6 +279,11 @@ int main(int argc, char **argv) /* flag set by getopt_long, do nothing */ break; } + case 't': + { + trace_fn = optarg; + break; + } case 'h': { hostname = optarg; @@ -253,17 +314,27 @@ int main(int argc, char **argv) } load_image(imgfile); - + if (ismaster) { - fprintf(stderr, "master port %d\n", port); - sock = master_connect(port); + if (trace_fn) + { + trace_file = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU); + } else { + fprintf(stderr, "master port %d\n", port); + sock = master_connect(port); + } return master(sock); } else { - fprintf(stderr, "apprentice host %s port %d\n", hostname, port); - sock = apprentice_connect(hostname, port); + if (trace_fn) + { + trace_file = open(trace_fn, O_RDONLY); + } else { + fprintf(stderr, "apprentice host %s port %d\n", hostname, port); + sock = apprentice_connect(hostname, port); + } return apprentice(sock); } }