From patchwork Thu Jun 21 06:25:21 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: 139454 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp1674868lji; Wed, 20 Jun 2018 23:32:00 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIKtD/J49kp3BGKu9F6T8C8nETeja6y44L2ZXlsI2Lu2fYm97Y03CwX8hQJRuf62UAAKDws X-Received: by 2002:ae9:dfc2:: with SMTP id t185-v6mr20387634qkf.274.1529562720862; Wed, 20 Jun 2018 23:32:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529562720; cv=none; d=google.com; s=arc-20160816; b=L5+rLEW1v1ItseMwOLIbrMUiH5EkZ5J7sMYNBgyrjEj3aCMiIRoWipGLb1yi/KCUIh dvfVxCe7oIBDQYYx7yyOah84wjuahiq7kG9Z0VczBsISMT7l1/lR7a3UVzNbwlwTpyVb VHG/B15VwIP7LMurqZi6Lhc+jiVOd/OwsZ6ef8HF0/WsTW0ZGwHZym2KdmbTX8Or5cHv Y8SwZLQhA3aEQuLlkR1jlTzyY1Ft4Ktf3R2CenxMwM08Dc22LNQ8znWzF2Acju9f9Cq0 2v2/ROTrqOIdPLOCTzCzHopLIIOMNAMhILb0v2wRW/mofqORkZpsroKJ3+0ddYZLLzZ3 eIyw== 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=iyMPC5qeIHfVKNTV56V8VzLOm4Bthf39+ya7CFC9P4M=; b=1AiN6f7KSoGicFoSnLdVTKbXdvGkBCPpLLJM8tmTYmuFUjbNfJcTgCIJElXaXlBA81 O9Xt/fph1Bfy8BreswwuO8KgwXKFh6ZEStFhmNc0YF0tdAAJdYOtYX/5qX9wNk9pRufX 0pWid2SEH3ipFyM7dPnrn45WF7dMj18Uq2A7eGXlsylbHHcblV7P0jdbOolMkTNqR8h7 SV7tbFN59v9ICFsPGfURLpxwY2rntv8ii46HRcJYjSN0Mh8+AMIQhJLrlL5oXQgTBr88 D39id4brEIME6G9USeu64Dgwo/BuQr5+T/ex3dGmroWqY1kbtYC3vHqTbzJZGnFU1iSt ynVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=a3iNLI2n; 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 k33-v6si2932641qta.311.2018.06.20.23.32.00 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Jun 2018 23:32: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=a3iNLI2n; 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]:53262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVt8S-0004YL-5q for patch@linaro.org; Thu, 21 Jun 2018 02:32:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53118) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVt2v-0000y1-MU for qemu-devel@nongnu.org; Thu, 21 Jun 2018 02:26:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVt2u-0000ey-L1 for qemu-devel@nongnu.org; Thu, 21 Jun 2018 02:26:17 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:50596) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fVt2u-0000eG-BR for qemu-devel@nongnu.org; Thu, 21 Jun 2018 02:26:16 -0400 Received: by mail-wm0-x241.google.com with SMTP id e16-v6so3126899wmd.0 for ; Wed, 20 Jun 2018 23:26:16 -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=iyMPC5qeIHfVKNTV56V8VzLOm4Bthf39+ya7CFC9P4M=; b=a3iNLI2nsPDq1Mr87CFHpsgym+NF5bi4ttzD5ATAsoM2Uk4NcitnlquEKiuc0zWDD0 /Ol2rHobMxr15guZc2ce08f4zv14vPy7K8hM9LaOA4yt/yeyYWwj06j6MGLNYOdmplN8 jo5EGbliNrjz/TbEf8RCxUClFWdhKerf2dmwU= 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=iyMPC5qeIHfVKNTV56V8VzLOm4Bthf39+ya7CFC9P4M=; b=b+IwuIEpAeBDPfSb5CzWiiYe/Qh/qn0QsEQnfc0nhCA+j/iF51eZxl0fs8JqVm+fv8 FIqpPm+4daK3wn+BxNJBPQiyUeUFRgGQjTDxTCfgjkm8x5CFRCA9y5HqVPj3K3dv2U8+ gu78pkyyuFF1MFOmlU5YYhmZYGdl2+ajTldQoxeKn4ghWs0Azzo8EDmXfT4drO2Xm/pf 2BdhimHwFRdFLfg8PIhRiNRaoQcf/u299FGZHJ0mN8IMOlwAqHii+koiaeNwujWXfYvE yrJQnjoWPnrtuIRKoxJwUKfLH1WsdgYEZinDOI02GGi/Xx3Iv72E94qOvaM/ZRQv2KUF VFbw== X-Gm-Message-State: APt69E11I27dj98M40UmbYldrvrPUBZ/OuPzTaW1rnpKZqeB8twqYWNv hIQslgzVWdRLcuDxUg9wSccOhA== X-Received: by 2002:a1c:228b:: with SMTP id i133-v6mr4127521wmi.92.1529562375312; Wed, 20 Jun 2018 23:26:15 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id t13-v6sm6721555wro.62.2018.06.20.23.26.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Jun 2018 23:26:11 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 5C92E3E0B02; Thu, 21 Jun 2018 07:26:06 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Thu, 21 Jun 2018 07:25:21 +0100 Message-Id: <20180621062605.941-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180621062605.941-1-alex.bennee@linaro.org> References: <20180621062605.941-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] [PULL v2 13/57] 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: agraf@suse.de, =?utf-8?q?Alex_Benn=C3=A9e?= , richard.henderson@linaro.org, qemu-devel@nongnu.org, f4bug@amsat.org, cota@braap.org, famz@redhat.com, aurelien@aurel32.net 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. Ideally test directory creation should be common functionally across all TCG tests but this could complicate an already huge patch series so we mark it as a TODO for next time. Signed-off-by: Alex Bennée -- 2.17.1 diff --git a/tests/tcg/multiarch/linux-test.c b/tests/tcg/multiarch/linux-test.c index 6f2c531474..e80eccc0ce 100644 --- a/tests/tcg/multiarch/linux-test.c +++ b/tests/tcg/multiarch/linux-test.c @@ -40,9 +40,8 @@ #include #include #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 +84,16 @@ static void test_file(void) struct iovec vecs[2]; DIR *dir; struct dirent *de; + /* TODO: make common tempdir creation for tcg tests */ + 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); + assert(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 +159,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 +181,7 @@ static void test_file(void) error("stat mode"); /* getdents */ - dir = opendir(TESTPATH); + dir = opendir(tmpdir); if (!dir) error("opendir"); len = 0; @@ -207,7 +203,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 +260,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 +268,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 +276,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 +288,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 +308,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);