From patchwork Mon May 14 21:58:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 8964 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp625749jad; Mon, 14 May 2018 14:59:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrXHCtKlA6rzXU5ke53WHy1g6DugETWJz9cnq7J1sPy/zOuCIgM4Ua5AsfiW8QOdYUkkIij X-Received: by 2002:a1c:f70b:: with SMTP id v11-v6mr5987719wmh.77.1526335153760; Mon, 14 May 2018 14:59:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526335153; cv=none; d=google.com; s=arc-20160816; b=omefnXobW42qewdvZy/EhdAdGwTbMNFFDTxcfM71FzwfIKE3YR7me9YdGb+YCdXPp+ 9uSrAHiZfwFgbC/0gqtHQYmgD5QhlsPmmCVLL9x8UZwjjWtypL4q/nQsve9zP2bgV0nZ 0LPPJaMOr11ZO1qFr4pBOU6QPR4NyUtLUK0vHiE9mts0JiNDnfZHAmUZWg5Kz6JhzlkO J/B6HFOy+wfeg6NSdxIIrH6+cnPRYtoGIwRzdl10hb/EBnNFG2B49BjqZO29auxIlty8 VJJYXjEe67wXgAPFeJsq4A1TCBnWok1gCl1qzF+Vf7GW01odPpdyOIdoIIgatwwgBz8I Aocw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=/Cl1ZeL9SRoCWrQmxVN9OEQOsWY5h5gDSUt5dpeQLyE=; b=0pctAwkKv7TD/MCBJXlwuZ5CikqIsOZxWGcBubwhq6k23ozEBib7EeYftazuG2Sj6n 831PzmPJBkB7ihiITrTTPrkLclM/IvW5ootydMNfQUEr7TY78cJ410w9V1s4c0faMmgb +4GWofMRkm6dXuBDFazDq2g+U5qbkjzYOOC2l4LHvxqMPxUde/2ic2CqK39EyU+aOJtc c2CJQL0XrEsYZl6r5VSAW/KQcEU0dMkUVX2kuyrgY1YprvXdtGrVJDEeSI8s0/5z5RDK BXNhQWgAkkBB5Jt17lxCzjuFc8AAJ9/gkwD5I+44Tlnj+095GCTypBrZNARAtMNP0X6W rtzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=Zzt7TsAN; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id l75-v6si5940956wmd.75.2018.05.14.14.59.13; Mon, 14 May 2018 14:59:13 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=Zzt7TsAN; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 10C04689C18; Tue, 15 May 2018 00:58:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f181.google.com (mail-wr0-f181.google.com [209.85.128.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E04236883E8 for ; Tue, 15 May 2018 00:58:27 +0300 (EEST) Received: by mail-wr0-f181.google.com with SMTP id v5-v6so13872206wrf.9 for ; Mon, 14 May 2018 14:59:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=Ng2+/A0EyTIBYJNAkyx02OBRBx5Vo7ZEc2gC3l9LwHU=; b=Zzt7TsANpt5883dE5QqX6iOefqsn8XCxSwFPa9f5PWVMegFoG8glwcVbijRSakuFIA hKIvCmLa5BgCbCoEcdajo8twzSlMpSeuIbuwpfTmdpFztpfuj97JwpC2aZY4JFkE2Xe6 Doj88r9HJWTagHtkAlEdWnZ8vXMFjChphxWM/m//CBV9XoawTTGbvmiRBzmeyn5W1dxA hBhdbI6Z+CLxIMr7qbYy9oCShlNu9ltFAwno+Qk6chy2IVIIWUVMIZrKg+j+XZFIo3gh 5LaZAyd4ovJDPkrkTiv30498njfJ4wa2Us5Hb98XirMgIwrhWce20AKLMxCbcg3JoOE2 3P4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Ng2+/A0EyTIBYJNAkyx02OBRBx5Vo7ZEc2gC3l9LwHU=; b=PlA8TJwD9jR48jWnNT5jqpSw8uuvq/aBEKK+8U18rLgMYeqxIhcogwmkDFl/DSoFCK kY/dg4KlRoo/vvDDsMuyha0zRwlGAz9TKzRNHOVTkzwnCd27ivp+SpG0pSSlYn5ARLfT xDNGgDg2o91eRGkEzIzWz8MXi1F5bvlv4ZbmDatpbtkCGk7Duj9ZJh1/UiNfNF4F3aUn G3hRzF3F/viEbAXJRRYeradwcEhsxSQqwdf/kIwGk5DBCxzuxZF8zmBEgX5JlfmWaoVr eYlj+c/GAi2QYeWx2jyRwYvi26Lf6VwZs1CTugZe3rcjJsqQYbpwyMgDjyvCXGQm30Rk Hitw== X-Gm-Message-State: ALKqPweFGJ0/SmaV1M5GBQaO6fbmV4/Z+mc2FmHFChCSmu6l9vTJJGhl KRf4T73UGtUKBwHIzE9DjPZ/H9BN X-Received: by 2002:adf:b611:: with SMTP id f17-v6mr8955306wre.139.1526335145145; Mon, 14 May 2018 14:59:05 -0700 (PDT) Received: from rywe.jkqxz.net (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id 123-v6sm10348180wmt.19.2018.05.14.14.59.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 May 2018 14:59:04 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 14 May 2018 22:58:58 +0100 Message-Id: <20180514215858.11461-3-sw@jkqxz.net> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180514215858.11461-1-sw@jkqxz.net> References: <20180514215858.11461-1-sw@jkqxz.net> Subject: [FFmpeg-devel] [PATCH 3/3] hwcontext: Add test for device creation and derivation X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This uses any devices it can find on the host system - on a system with no hardware device support or in builds with no support included it will do nothing and pass. --- libavutil/Makefile | 1 + libavutil/tests/hwdevice.c | 234 +++++++++++++++++++++++++++++++++++++++++++++ tests/fate/libavutil.mak | 4 + tests/ref/fate/hwdevice | 1 + 4 files changed, 240 insertions(+) create mode 100644 libavutil/tests/hwdevice.c create mode 100644 tests/ref/fate/hwdevice diff --git a/libavutil/Makefile b/libavutil/Makefile index 4fe470748c..d0632f16a6 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -206,6 +206,7 @@ TESTPROGS = adler32 \ fifo \ hash \ hmac \ + hwdevice \ integer \ imgutils \ lfg \ diff --git a/libavutil/tests/hwdevice.c b/libavutil/tests/hwdevice.c new file mode 100644 index 0000000000..a14c4be8a4 --- /dev/null +++ b/libavutil/tests/hwdevice.c @@ -0,0 +1,234 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "libavutil/hwcontext.h" + +static int test_derivation(AVBufferRef *src_ref, const char *src_name) +{ + enum AVHWDeviceType derived_type; + const char *derived_name; + AVBufferRef *derived_ref, *back_ref; + AVHWDeviceContext *src_dev, *derived_dev; + int err; + + src_dev = (AVHWDeviceContext*)src_ref->data; + + derived_type = AV_HWDEVICE_TYPE_NONE; + while (1) { + derived_type = av_hwdevice_iterate_types(derived_type); + if (derived_type == AV_HWDEVICE_TYPE_NONE) + break; + + derived_name = av_hwdevice_get_type_name(derived_type); + + err = av_hwdevice_ctx_create_derived(&derived_ref, derived_type, + src_ref, 0); + if (err < 0) { + fprintf(stderr, "Unable to derive %s -> %s: %d.\n", + src_name, derived_name, err); + continue; + } + + derived_dev = (AVHWDeviceContext*)derived_ref->data; + if (derived_dev->type != derived_type) { + printf("Device derived as type %d has type %d.\n", + derived_type, derived_dev->type); + goto fail; + } + + if (derived_type == src_dev->type) { + if (derived_dev != src_dev) { + printf("Derivation of %s from itself succeeded but did " + "not return the same device.\n", src_name); + goto fail; + } + av_buffer_unref(&derived_ref); + continue; + } + + err = av_hwdevice_ctx_create_derived(&back_ref, src_dev->type, + derived_ref, 0); + if (err < 0) { + printf("Derivation %s to %s succeeded, but derivation back " + "again failed: %d.\n", src_name, derived_name, err); + goto fail; + } + + if (back_ref->data != src_ref->data) { + printf("Derivation %s to %s succeeded, but derivation back " + "again did not return the original device.\n", + src_name, derived_name); + goto fail; + } + + fprintf(stderr, "Successfully tested derivation %s -> %s.\n", + src_name, derived_name); + + av_buffer_unref(&derived_ref); + av_buffer_unref(&back_ref); + } + + return 0; + +fail: + av_buffer_unref(&derived_ref); + av_buffer_unref(&back_ref); + return -1; +} + +static int test_device(enum AVHWDeviceType type, const char *name, + const char *device, AVDictionary *opts, int flags) +{ + AVBufferRef *ref; + AVHWDeviceContext *dev; + int err; + + err = av_hwdevice_ctx_create(&ref, type, device, opts, flags); + if (err < 0) { + fprintf(stderr, "Failed to create %s device: %d.\n", name, err); + return 1; + } + + dev = (AVHWDeviceContext*)ref->data; + if (dev->type != type) { + printf("Device created as type %d has type %d.\n", + type, dev->type); + return -1; + } + + fprintf(stderr, "Device type %s successfully created.\n", name); + + err = test_derivation(ref, name); + + av_buffer_unref(&ref); + + return err; +} + +static const struct { + enum AVHWDeviceType type; + const char *possible_devices[5]; +} test_devices[] = { + { AV_HWDEVICE_TYPE_CUDA, + { "0", "1", "2" } }, + { AV_HWDEVICE_TYPE_DRM, + { "/dev/dri/card0", "/dev/dri/card1", + "/dev/dri/renderD128", "/dev/dri/renderD129" } }, + { AV_HWDEVICE_TYPE_DXVA2, + { "0", "1", "2" } }, + { AV_HWDEVICE_TYPE_D3D11VA, + { "0", "1", "2" } }, + { AV_HWDEVICE_TYPE_OPENCL, + { "0.0", "0.1", "1.0", "1.1" } }, + { AV_HWDEVICE_TYPE_VAAPI, + { "/dev/dri/renderD128", "/dev/dri/renderD129", ":0" } }, +}; + +static int test_device_type(enum AVHWDeviceType type) +{ + enum AVHWDeviceType check; + const char *name; + int i, j, found, err; + + name = av_hwdevice_get_type_name(type); + if (!name) { + printf("No name available for device type %d.\n", type); + return -1; + } + + check = av_hwdevice_find_type_by_name(name); + if (check != type) { + printf("Type %d maps to name %s maps to type %d.\n", + type, name, check); + return -1; + } + + found = 0; + + err = test_device(type, name, NULL, NULL, 0); + if (err < 0) { + printf("Test failed for %s with default options.\n", name); + return -1; + } + if (err == 0) { + fprintf(stderr, "Test passed for %s with default options.\n", + name); + ++found; + } + + for (i = 0; i < FF_ARRAY_ELEMS(test_devices); i++) { + if (test_devices[i].type != type) + continue; + + for (j = 0; test_devices[i].possible_devices[j]; j++) { + err = test_device(type, name, + test_devices[i].possible_devices[j], + NULL, 0); + if (err < 0) { + printf("Test failed for %s with device %s.\n", + name, test_devices[i].possible_devices[j]); + return -1; + } + if (err == 0) { + fprintf(stderr, "Test passed for %s with device %s.\n", + name, test_devices[i].possible_devices[j]); + ++found; + } + } + } + + return !found; +} + +int main(void) +{ + enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE; + int pass, fail, skip, err; + + pass = fail = skip = 0; + while (1) { + type = av_hwdevice_iterate_types(type); + if (type == AV_HWDEVICE_TYPE_NONE) + break; + + err = test_device_type(type); + if (err == 0) + ++pass; + else if (err < 0) + ++fail; + else + ++skip; + } + + fprintf(stderr, "Attempted to test %d device types: " + "%d passed, %d failed, %d skipped.\n", + pass + fail + skip, pass, fail, skip); + + if (fail > 0) { + printf("Failed (%d passed, %d failed, %d skipped).\n", + pass, fail, skip); + return 1; + } else { + // This can't contain any more detail because the output would + // differ depending on system and configure options. + printf("Passed.\n"); + return 0; + } +} diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak index 9b32d880f5..f5e0cfdd1b 100644 --- a/tests/fate/libavutil.mak +++ b/tests/fate/libavutil.mak @@ -86,6 +86,10 @@ FATE_LIBAVUTIL += fate-hmac fate-hmac: libavutil/tests/hmac$(EXESUF) fate-hmac: CMD = run libavutil/tests/hmac +FATE_LIBAVUTIL += fate-hwdevice +fate-hwdevice: libavutil/tests/hwdevice$(EXESUF) +fate-hwdevice: CMD = run libavutil/tests/hwdevice + FATE_LIBAVUTIL += fate-imgutils fate-imgutils: libavutil/tests/imgutils$(EXESUF) fate-imgutils: CMD = run libavutil/tests/imgutils diff --git a/tests/ref/fate/hwdevice b/tests/ref/fate/hwdevice new file mode 100644 index 0000000000..02876925f0 --- /dev/null +++ b/tests/ref/fate/hwdevice @@ -0,0 +1 @@ +Passed.