From patchwork Fri Jun 15 19:46:23 2018 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: 138793 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp1276485lji; Fri, 15 Jun 2018 13:19:01 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI6NfqJRC10vqBGEENIXWMYPtO8Ut+X8lJG6kKIMCYX1Vl8eb8RREWgx8fXAxlITcOOBVou X-Received: by 2002:ac8:285d:: with SMTP id 29-v6mr2953519qtr.61.1529093940918; Fri, 15 Jun 2018 13:19:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529093940; cv=none; d=google.com; s=arc-20160816; b=u4W6hlVsBakBIOCiRYMZsL0rhdRdh5hE4tj2JOYRvvTNmVHtg9uygWbDkglnBu3TRj jDXUB2ciFwkQ+U/zcFPUZR7Sd5gb4Jitd4/xxeRxZx2ZGwj7QnjbIwyeMh+hJoVHLX4D 3mXgjox5n/JhfG3QvdIoXGVf4SjIZpsHN5RXm8Vn5hjk++HA5hihfU0Kzi2Who2BrsEx 3URzSK8QeIhruFKpDEc8+3cov9j6G0Y18m0OpmLbAZYjeQykTt95NOPJK6F6MrR2anYM xF5LLz8d0G8AUVhq9q2rm4uPf0WVaBAhbWxAaZDQhecq5wWm7vbIRtDN8/GLxF+R+/Ko tIdQ== 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=NZI74Jhqax7meTdDkfET6dVRSJrBruMzq87HFfwt/zw=; b=Dw3V2rcad+gL46ABU9IQK8upZuanoZ5hHZxzlVtrn9zgnUvP1zkrT10RFyHJlP6qGi 4oxwPKNmtY5d5ZhI1ox+Wkk0HtWIdWhxJZsmlt6r1V26DdJystegw+LMZkXnGzHqr0Uy 6tmYZ87IBuu8MAVZkNwL0Lz573nX6f65SvLzfPd3Lv1B11D2bCG3LByRjA4oZQZ0Y0rt P9H6WD2dvgOUFoodRT6LU28x4K5ukBvBilYVMnQ2MwaLwq9lSVbdWmenCVE7D0MWUOZa /n6NgVThjB7HEKvKRHbzLxVXBHTnGFwFMX/jEnDrkMcgPNf7HymYg7pidUXL5Q04+eYq zntw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ixcysVZl; 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 c45-v6si1922447qvc.60.2018.06.15.13.19.00 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 15 Jun 2018 13:19:00 -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 header.s=google header.b=ixcysVZl; 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]:49147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTvBU-0002fY-BR for patch@linaro.org; Fri, 15 Jun 2018 16:19:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTugo-0002Zn-SR for qemu-devel@nongnu.org; Fri, 15 Jun 2018 15:47:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fTugn-0005SQ-PE for qemu-devel@nongnu.org; Fri, 15 Jun 2018 15:47:18 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:55161) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fTugn-0005QG-G7 for qemu-devel@nongnu.org; Fri, 15 Jun 2018 15:47:17 -0400 Received: by mail-wm0-x241.google.com with SMTP id o13-v6so5155375wmf.4 for ; Fri, 15 Jun 2018 12:47:17 -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=NZI74Jhqax7meTdDkfET6dVRSJrBruMzq87HFfwt/zw=; b=ixcysVZlT2xx6wqiW+1y559SjqgtMmF103qNemeumBk1gsb7RKBCXc+91fvTKwJ1Yq 2plWlbhZUDc8qSYterSMU3CG2+bmwG8bHqUT2uwhJ62cVkpGvBm3w9rM45GrSVa41n+O Q6JYODgSEmQeDur5MitlfxHHyS0sPxSlPNMIc= 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=NZI74Jhqax7meTdDkfET6dVRSJrBruMzq87HFfwt/zw=; b=cgdyaaQOq0pXPR3/k1OI2RjjOHDhGptAfuyU7qQzD1evKoOcrVtFwLiEtmAWnowEF/ LjbvcAZN384W7PAB9uJPp6FU+Cu7ExvpNg0JmUhXHA9gjL7++onb4RA32JQqUBg+Icqp B9oWb+7+bAgolP/3qwWXX3L6d7xmNsAWMl420HKnAciC6oChC82f01iBr+s2SZNlPkWC 8Y5RGGNV+gNAucMGzCvCCgg7lThsibS8kbKlBv5wBR27JrDzpofDCt5tqn5tg+uB3KGG TH0VoudAUdoD0e+XdHWM6+Kr1gGuXyS4SV51jqU5+kuUiK7tm1CLDz0p+5O6fHzsx4iy pITA== X-Gm-Message-State: APt69E0qxQ4Dfv4vg4iPpu8crzeVBFmTLEFABJue/oA6Iuky6zjvuvX5 UKD4+x+wqx422IOuKEQPagWDDw== X-Received: by 2002:a1c:5c82:: with SMTP id q124-v6mr2343723wmb.24.1529092036345; Fri, 15 Jun 2018 12:47:16 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id n12-v6sm7451889wrp.69.2018.06.15.12.47.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Jun 2018 12:47:12 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 6C0243E0AB4; Fri, 15 Jun 2018 20:47:06 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: cota@braap.org, famz@redhat.com, berrange@redhat.com, f4bug@amsat.org, richard.henderson@linaro.org, balrogg@gmail.com, aurelien@aurel32.net, agraf@suse.de, peter.maydell@linaro.org Date: Fri, 15 Jun 2018 20:46:23 +0100 Message-Id: <20180615194705.28019-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180615194705.28019-1-alex.bennee@linaro.org> References: <20180615194705.28019-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::241 Subject: [Qemu-devel] [PATCH v7 12/54] tests/tcg/multiarch: don't hard code paths/ports for linux-test 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" The fixed path and ports get in the way of running our tests and builds in parallel. Instead of using TESTPATH we use mkdtemp() and instead of a fixed port we allow the kernel to assign one and query it afterwards. Signed-off-by: Alex Bennée --- tests/tcg/multiarch/linux-test.c | 37 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 18 deletions(-) -- 2.17.1 diff --git a/tests/tcg/multiarch/linux-test.c b/tests/tcg/multiarch/linux-test.c index 6f2c531474..3f73b96420 100644 --- a/tests/tcg/multiarch/linux-test.c +++ b/tests/tcg/multiarch/linux-test.c @@ -41,8 +41,6 @@ #include #include -#define TESTPATH "/tmp/linux-test.tmp" -#define TESTPORT 7654 #define STACK_SIZE 16384 static void error1(const char *filename, int line, const char *fmt, ...) @@ -85,19 +83,15 @@ static void test_file(void) struct iovec vecs[2]; DIR *dir; struct dirent *de; + char template[] = "/tmp/linux-test-XXXXXX"; + char *tmpdir = mkdtemp(template); - /* clean up, just in case */ - unlink(TESTPATH "/file1"); - unlink(TESTPATH "/file2"); - unlink(TESTPATH "/file3"); - rmdir(TESTPATH); + chk_error(strlen(tmpdir)); if (getcwd(cur_dir, sizeof(cur_dir)) == NULL) error("getcwd"); - chk_error(mkdir(TESTPATH, 0755)); - - chk_error(chdir(TESTPATH)); + chk_error(chdir(tmpdir)); /* open/read/write/close/readv/writev/lseek */ @@ -163,7 +157,7 @@ static void test_file(void) st.st_mtime != 1000) error("stat time"); - chk_error(stat(TESTPATH, &st)); + chk_error(stat(tmpdir, &st)); if (!S_ISDIR(st.st_mode)) error("stat mode"); @@ -185,7 +179,7 @@ static void test_file(void) error("stat mode"); /* getdents */ - dir = opendir(TESTPATH); + dir = opendir(tmpdir); if (!dir) error("opendir"); len = 0; @@ -207,7 +201,7 @@ static void test_file(void) chk_error(unlink("file3")); chk_error(unlink("file2")); chk_error(chdir(cur_dir)); - chk_error(rmdir(TESTPATH)); + chk_error(rmdir(tmpdir)); } static void test_fork(void) @@ -264,7 +258,7 @@ static int server_socket(void) chk_error(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val))); sockaddr.sin_family = AF_INET; - sockaddr.sin_port = htons(TESTPORT); + sockaddr.sin_port = htons(0); /* choose random ephemeral port) */ sockaddr.sin_addr.s_addr = 0; chk_error(bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr))); chk_error(listen(fd, 0)); @@ -272,7 +266,7 @@ static int server_socket(void) } -static int client_socket(void) +static int client_socket(uint16_t port) { int fd; struct sockaddr_in sockaddr; @@ -280,7 +274,7 @@ static int client_socket(void) /* server socket */ fd = chk_error(socket(PF_INET, SOCK_STREAM, 0)); sockaddr.sin_family = AF_INET; - sockaddr.sin_port = htons(TESTPORT); + sockaddr.sin_port = htons(port); inet_aton("127.0.0.1", &sockaddr.sin_addr); chk_error(connect(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr))); return fd; @@ -292,10 +286,17 @@ static void test_socket(void) { int server_fd, client_fd, fd, pid, ret, val; struct sockaddr_in sockaddr; - socklen_t len; + struct sockaddr_in server_addr; + socklen_t len, socklen; + uint16_t server_port; char buf[512]; server_fd = server_socket(); + /* find out what port we got */ + socklen = sizeof(server_addr); + ret = getsockname(server_fd, &server_addr, &socklen); + chk_error(ret); + server_port = ntohs(server_addr.sin_port); /* test a few socket options */ len = sizeof(val); @@ -305,7 +306,7 @@ static void test_socket(void) pid = chk_error(fork()); if (pid == 0) { - client_fd = client_socket(); + client_fd = client_socket(server_port); send(client_fd, socket_msg, sizeof(socket_msg), 0); close(client_fd); exit(0);