From patchwork Mon Jun 13 16:08:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 9173541 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 20D5C60573 for ; Mon, 13 Jun 2016 16:12:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13F7D22473 for ; Mon, 13 Jun 2016 16:12:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 089E72723E; Mon, 13 Jun 2016 16:12:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 49A7922473 for ; Mon, 13 Jun 2016 16:12:45 +0000 (UTC) Received: from localhost ([::1]:57564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCUTj-0006SK-Ko for patchwork-qemu-devel@patchwork.kernel.org; Mon, 13 Jun 2016 12:12:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49373) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCUQ0-0003F5-FM for qemu-devel@nongnu.org; Mon, 13 Jun 2016 12:08:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCUPu-0004Cp-3m for qemu-devel@nongnu.org; Mon, 13 Jun 2016 12:08:51 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:63133 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCUPt-0004CM-V2 for qemu-devel@nongnu.org; Mon, 13 Jun 2016 12:08:46 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5DG8bs7106708 for ; Mon, 13 Jun 2016 12:08:45 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0b-001b2d01.pphosted.com with ESMTP id 23gbjv0e6e-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 13 Jun 2016 12:08:44 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 13 Jun 2016 10:08:44 -0600 Received: from d03dlp01.boulder.ibm.com (9.17.202.177) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 13 Jun 2016 10:08:40 -0600 X-IBM-Helo: d03dlp01.boulder.ibm.com X-IBM-MailFrom: mdroth@linux.vnet.ibm.com X-IBM-RcptTo: peter.maydell@linaro.org; qemu-devel@nongnu.org; marcandre.lureau@redhat.com; mlureau@redhat.com Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id D6C3A1FF004A; Mon, 13 Jun 2016 10:08:23 -0600 (MDT) Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u5DG8dEs38994106; Mon, 13 Jun 2016 09:08:39 -0700 Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AFD5C6E03A; Mon, 13 Jun 2016 10:08:39 -0600 (MDT) Received: from localhost (unknown [9.80.82.190]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP id 726CA6E038; Mon, 13 Jun 2016 10:08:39 -0600 (MDT) MIME-Version: 1.0 To: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , "marcandre lureau" From: Michael Roth In-Reply-To: <198901162.5803520.1465821059076.JavaMail.zimbra@redhat.com> References: <1465820746-25664-1-git-send-email-marcandre.lureau@redhat.com> <198901162.5803520.1465821059076.JavaMail.zimbra@redhat.com> User-Agent: alot/0.3.6 Date: Mon, 13 Jun 2016 11:08:29 -0500 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16061316-0004-0000-0000-00000FAB65C4 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16061316-0005-0000-0000-0000761E47FE Message-Id: <20160613160829.31382.26968@loki> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-06-13_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1606130181 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 Subject: Re: [Qemu-devel] [PATCH] tests: use static qga config file 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: peter maydell , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Quoting Marc-André Lureau (2016-06-13 07:30:59) > Hi > > ----- Original Message ----- > > From: Marc-André Lureau > > > > Do not create a leaking temporary file, but use a static file instead. > > > > Signed-off-by: Marc-André Lureau > > Reported-by: Peter Maydell > > --- > > tests/test-qga-config | 8 ++++++++ > > tests/test-qga.c | 27 ++++----------------------- > > 2 files changed, 12 insertions(+), 23 deletions(-) > > create mode 100644 tests/test-qga-config > > > > diff --git a/tests/test-qga-config b/tests/test-qga-config > > new file mode 100644 > > index 0000000..4bb721a > > --- /dev/null > > +++ b/tests/test-qga-config > > @@ -0,0 +1,8 @@ > > +[general] > > +daemon=false > > +method=virtio-serial > > +path=/path/to/org.qemu.guest_agent.0 > > +pidfile=/var/foo/qemu-ga.pid > > +statedir=/var/state > > +verbose=true > > +blacklist=guest-ping;guest-get-time > > diff --git a/tests/test-qga.c b/tests/test-qga.c > > index 251b201..7d206ec 100644 > > --- a/tests/test-qga.c > > +++ b/tests/test-qga.c > > @@ -691,28 +691,11 @@ static void test_qga_blacklist(gconstpointer data) > > static void test_qga_config(gconstpointer data) > > { > > GError *error = NULL; > > - char *cwd, *cmd, *out, *err, *str, **strv, *conf, **argv = NULL; > > + char *cwd, *cmd, *out, *err, *str, **strv, **argv = NULL; > > char *env[2]; > > - int status, tmp; > > + int status; > > gsize n; > > GKeyFile *kf; > > - const char *qga_config = > > - "[general]\n" > > - "daemon=false\n" > > - "method=virtio-serial\n" > > - "path=/path/to/org.qemu.guest_agent.0\n" > > - "pidfile=/var/foo/qemu-ga.pid\n" > > - "statedir=/var/state\n" > > - "verbose=true\n" > > - "blacklist=guest-ping;guest-get-time\n"; > > - > > - tmp = g_file_open_tmp(NULL, &conf, &error); > > - g_assert_no_error(error); > > - g_assert_cmpint(tmp, >=, 0); > > - g_assert_cmpstr(conf, !=, ""); > > - > > - g_file_set_contents(conf, qga_config, -1, &error); > > - g_assert_no_error(error); > > > > cwd = g_get_current_dir(); > > cmd = g_strdup_printf("%s%cqemu-ga -D", > > @@ -720,7 +703,8 @@ static void test_qga_config(gconstpointer data) > > g_shell_parse_argv(cmd, NULL, &argv, &error); > > g_assert_no_error(error); > > > > - env[0] = g_strdup_printf("QGA_CONF=%s", conf); > > + env[0] = g_strdup_printf("QGA_CONF=%s%ctests%ctest-qga-config", > > + cwd, G_DIR_SEPARATOR, G_DIR_SEPARATOR); > > Actually instead of cwd here, it would be nice to have srcdir or testdir. There is g_test_build_filename() in glib 2.38, not sure what we should do without it. Ideas? Maybe just via environment variables? We seem to do the same with MALLOC_PERTURB_ already (though there's probably less options there), and it's consistent with how we control QGA_TEST_SIDE_EFFECTING currently. Also, if we default to cwd things should still work for running the test executable directly. g_test_build_filename seems to do similar under the covers as well, though it is a bit more tedious to have to add to every test target we want access environment variables in. Would be nice if tests/Makefile.include could do it automatically via common dependencies, but I'm not sure if that's doable. > > > env[1] = NULL; > > g_spawn_sync(NULL, argv, env, 0, > > NULL, NULL, &out, &err, &status, &error); > > @@ -775,11 +759,8 @@ static void test_qga_config(gconstpointer data) > > > > g_free(out); > > g_free(err); > > - g_free(conf); > > g_free(env[0]); > > g_key_file_free(kf); > > - > > - close(tmp); > > } > > > > static void test_qga_fsfreeze_status(gconstpointer fix) > > -- > > 2.7.4 > > > > > --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -660,6 +662,7 @@ $(patsubst %, check-%, $(check-unit-y)): check-%: % $(if $(CONFIG_GCOV),@rm -f *.gcda */*.gcda */*/*.gcda */*/*/*.gcda,) $(call quiet-command, \ MALLOC_PERTURB_=$${MALLOC_PERTURB_:-$$((RANDOM % 255 + 1))} \ + QEMU_TEST_SRC_PATH=$(SRC_PATH)/tests \ gtester $(GTESTER_OPTIONS) -m=$(SPEED) $*,"GTESTER $*") $(if $(CONFIG_GCOV),@for f in $(gcov-files-$(subst tests/,,$*)-y) $(gcov-files-generic-y); do \ echo Gcov report for $$f:;\