From patchwork Fri Aug 23 16:21:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172124 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp886303ily; Fri, 23 Aug 2019 09:22:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzfFig2SRm86Tidft7ynU9lIY1eYS827fTqGdHNEvMDFEMKPc2JmlUgG9aa/d4AhPPvVT2D X-Received: by 2002:ae9:e118:: with SMTP id g24mr4895249qkm.378.1566577362632; Fri, 23 Aug 2019 09:22:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577362; cv=none; d=google.com; s=arc-20160816; b=f2SJhouKRzYvhfsxfjBdFRSywxd2e+c+PkMs8pwuA3Qa07F0HqJpgs2Hplb9oKyX93 ZPP+LB6CkIV+GD9WI2vhCeq3Jfmvxr5tp0f/L9sqaLIh6GMBUa39fhGj2PZsEPmJXZMi dz9qfzbz+yzO4OuIUh7IvZmwNPccFJQVSkLP9xKwLExQ7IDBFpMnEwcuSmjhupzHRdpd XNTw8KpMgtNeUs1jH+Sz4noFjWP11eZdAdNjHWRifRIJXvHLGSTuC2Km5qtTpDzwbfd3 csji0hbxvA25CW1DOvsiNd57zTVTit1FCL73LjXXZI60Wioy3hnBvh7aPrlr7pLJ9gG/ cwNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=9+OOeBSZ4nvRKdUERdgyMf+CDN8VvXsDiaJzWqqqhWY=; b=gcjTg8twViKc7/+UcIHp2sIgSVX3D+1pvYvSIai6W3oMcYnwrax7F9vBq07uL3IIBA rZJ482JbrKipjE6Evas8zq8Umz7C8kXEcldgvFVaMSXcI2aSz6NqcR4GbcEhi5kcefqq 8KEfAB81lVGB453acWtRZ8/7ctOGEygXR3XuoWh2xD1LT2fawLXAX8jcEXBIIP4jep4/ fzLYVaptbTxtrcrd2puXsM4wNq2ePzN5drlfih5QYLgTYuCxDgLSwt90oAyRENXtXjlS s1rt5M0ITAFvGXCcgSoCokLFIV8xRHknj/jnu2TgHhGA2nXMYwYbS7apeBh1KzsZ97Uz l8Tw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id g17si2100895qkl.306.2019.08.23.09.22.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:42 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 60CD01E2029; Fri, 23 Aug 2019 16:22:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A6A3BA8F; Fri, 23 Aug 2019 16:22:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id F12ED180BAA2; Fri, 23 Aug 2019 16:22:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGMDeC006098 for ; Fri, 23 Aug 2019 12:22:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6275460605; Fri, 23 Aug 2019 16:22:13 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3BDE60872; Fri, 23 Aug 2019 16:22:12 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:21:59 -0400 Message-Id: <91200df1c0012490e08a68101b1ec4c362dee6b8.1566576129.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 15/16] tests: mock execv/execve X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Fri, 23 Aug 2019 16:22:41 +0000 (UTC) From: Marc-André Lureau Learn to override the paths to the program to execute (vhost-user helpers are executed to check for runtime capabilities). Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson --- tests/virfilewrapper.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/virfilewrapper.c b/tests/virfilewrapper.c index 160cd571e0..3d3f319f2c 100644 --- a/tests/virfilewrapper.c +++ b/tests/virfilewrapper.c @@ -44,6 +44,8 @@ static FILE *(*real_fopen)(const char *path, const char *mode); static int (*real_access)(const char *path, int mode); static int (*real_mkdir)(const char *path, mode_t mode); static DIR *(*real_opendir)(const char *path); +static int (*real_execv)(const char *path, char *const argv[]); +static int (*real_execve)(const char *path, char *const argv[], char *const envp[]); static void init_syms(void) { @@ -55,6 +57,8 @@ static void init_syms(void) VIR_MOCK_REAL_INIT(mkdir); VIR_MOCK_REAL_INIT(open); VIR_MOCK_REAL_INIT(opendir); + VIR_MOCK_REAL_INIT(execv); + VIR_MOCK_REAL_INIT(execve); } @@ -191,4 +195,22 @@ DIR *opendir(const char *path) return real_opendir(newpath ? newpath : path); } +int execv(const char *path, char *const argv[]) +{ + VIR_AUTOFREE(char *) newpath = NULL; + + PATH_OVERRIDE(newpath, path); + + return real_execv(newpath ? newpath : path, argv); +} + +int execve(const char *path, char *const argv[], char *const envp[]) +{ + VIR_AUTOFREE(char *) newpath = NULL; + + PATH_OVERRIDE(newpath, path); + + return real_execve(newpath ? newpath : path, argv, envp); +} + #endif