From patchwork Tue Jun 26 16:28:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Trimble X-Patchwork-Id: 9513 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:141:0:0:0:0:0 with SMTP id c62-v6csp5567568jad; Tue, 26 Jun 2018 09:35:58 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd52V518FnxO9rNeVZFscbVx/qpKfVJPXH92qCyLEvbxKHC/yuDvgz7peyikHxzEAckd8Eg X-Received: by 2002:a1c:6744:: with SMTP id b65-v6mr2163649wmc.9.1530030958072; Tue, 26 Jun 2018 09:35:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530030958; cv=none; d=google.com; s=arc-20160816; b=CGUkV/1ApeCg+ujrCTV/xY7ap0F26TYlE9SoDk+w/ySSNObPW4AUDvlZ5pf8qygwz9 eGwMHeXPdh6B1uTZtgw+byoa6610YX14JS4y1DWkZcFKSYgfrrtAnma6RlAO8g1hHBi1 uXYJcSpj8yDUPff/cO7heoBSDeicXX/9zOer0z8Fe1N4is5iK1DOPjDXLoZ+2b+3c77s IL1SVzk6INcXPo1ibNCluQDv1FNVrpmWBlJP4Iw+PlMRRT1DZPy6RWMTZxzim7+CSkqZ FdseNTCvJXMB5vvjC/e+QxSaFy+4JuIcQGzXPo94SdtXg7F8A4xcV/jlajieHIanoenx g53Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:in-reply-to:references:mime-version :dkim-signature:delivered-to:arc-authentication-results; bh=NjS7kAUXoKlgpD8wop4/gLiRQMaS5us/o6Ik+eS3k/4=; b=QHdSpS8yiSurUvjMjmIdhicgTesxC6FozCSMViHbck/yx4GTNX10q30osed+8dyvi4 FjvNAzRB/0upIFFDrsTYfEtt4gtE+Eylit0fJHHKBCAJ0sjzZfnaZNevHmEbuS4lxSXB fazkjSUf4ekMXbBzPHiwUcM4Wr4uzQai08Ox5X2Bp46vYwf9BpxhfoHiPDMMyNo0/0hi Ifsv4eEUaQNpbY6mdmbW+vSLBw4ez11htaRWSXJ45DMho7yQetS/Ahyzw6mD+bY51WgL +5xO/x1GFEzj7vUVUUk0DPOMklDjugSPmvn5y2GR1Ddb/JC0OKSOogQx3HtjCkHND0Xo i1wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=MS4zzjVm; 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 n21-v6si1825330wmh.33.2018.06.26.09.35.57; Tue, 26 Jun 2018 09:35:58 -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=@google.com header.s=20161025 header.b=MS4zzjVm; 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 B75B468A4A7; Tue, 26 Jun 2018 19:35:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 57DC968A232 for ; Tue, 26 Jun 2018 19:34:54 +0300 (EEST) Received: by mail-lj1-f196.google.com with SMTP id a6-v6so9299112ljj.7 for ; Tue, 26 Jun 2018 09:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=HhXgpkYbx3sCafLxi9jHETJTHsk5lF0pH52bOE42Hh0=; b=MS4zzjVmfRlUKhbofLU6R85U7rOjAURsyd8jGc3OmjW5pkW9tbj9G61LCqhlDHcgqv DOJyGuHJBfGa8+R+ocUf5C7HUSL9MYBb/2sqRVkj5iZQc3iWQtP0JHNwDZd4/wJWU1gz EDef/ahH4Mmoz+Gdd19oA1tFqAQqvwtuz4nSxXV5oB+Fac0aXy5ZgQr9hdiAaX9hiXQq Q7xNt1NCfMJUixlJ/Y5+RVEgZgZ9BAafB/SSXcjsRPGMUMacghxRF9+MSBPqdvP7hiXo 5/iyZgO5YkjY+saiP86Omy19XaHy9hqbSYs8guxBufmNt3ZsnicOxiDBchp7v6VeZCur V79g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=HhXgpkYbx3sCafLxi9jHETJTHsk5lF0pH52bOE42Hh0=; b=K1v7tqEZt8CbrjdHN7YC1ei2j/sEAT3k3xxCRV/dSgoZTxdTVFHqzIC+kpx3nW7jb0 jpuE79aTUrg7QP/aVFNPiVrsb0KxG26Bw0Y0HVhe7GhNihIyN37TjXkn12AAwHqkNaxq sLwfJCC9Mbsx3KtZoW6+9P6pyU6KN7TO8ECt7TA6gaNahA9ucffFCEN7jSZf2KmPA80j b05kdqQSDTNB52J1G3WyBR2UaIppmQxIuXoB63dPcm3zkGK3n8S66pMlJ2IjGdtRsEod L83BI2nr5NP3mCN/IfxanmGwfuPnXpqSp1tOt8KiL7bmGpRr1fAuyghnsBF66sMZ2qdp eYkQ== X-Gm-Message-State: APt69E1YjwDh/jGeea35XV12x3C4ngeZrHxUTPxl43NyfF3t0mJ4LImh mde6DWzJ4Dk2js6OOJUxg2HF2OD4vFhJdDjON6NXWx1Q X-Received: by 2002:a2e:9809:: with SMTP id a9-v6mr1582726ljj.143.1530030493769; Tue, 26 Jun 2018 09:28:13 -0700 (PDT) MIME-Version: 1.0 References: <20180601195148.251265-1-modmaker@google.com> <20180626003021.GM4859@michaelspb> In-Reply-To: <20180626003021.GM4859@michaelspb> From: Jacob Trimble Date: Tue, 26 Jun 2018 09:28:01 -0700 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH] libavutil/encryption_info: Add unit tests. 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On Mon, Jun 25, 2018 at 5:30 PM Michael Niedermayer wrote: > > On Fri, Jun 01, 2018 at 12:51:48PM -0700, Jacob Trimble wrote: > > Signed-off-by: Jacob Trimble > > --- > > libavutil/Makefile | 1 + > > libavutil/encryption_info.h | 2 +- > > libavutil/tests/.gitignore | 2 + > > libavutil/tests/encryption_info.c | 176 ++++++++++++++++++++++++++++++ > > tests/fate/libavutil.mak | 4 + > > tests/ref/fate/encryption-info | 0 > > 6 files changed, 184 insertions(+), 1 deletion(-) > > create mode 100644 libavutil/tests/encryption_info.c > > create mode 100644 tests/ref/fate/encryption-info > > > > diff --git a/libavutil/Makefile b/libavutil/Makefile > > index d0632f16a6..9ed24cfc82 100644 > > --- a/libavutil/Makefile > > +++ b/libavutil/Makefile > > @@ -200,6 +200,7 @@ TESTPROGS = adler32 \ > > des \ > > dict \ > > display \ > > + encryption_info \ > > error \ > > eval \ > > file \ > > > diff --git a/libavutil/encryption_info.h b/libavutil/encryption_info.h > > index 9140968fde..8fe7ebfe43 100644 > > --- a/libavutil/encryption_info.h > > +++ b/libavutil/encryption_info.h > > @@ -129,7 +129,7 @@ typedef struct AVEncryptionInitInfo { > > * > > * @param subsample_count The number of subsamples. > > * @param key_id_size The number of bytes in the key ID, should be 16. > > - * @param key_id_size The number of bytes in the IV, should be 16. > > + * @param iv_size The number of bytes in the IV, should be 16. > > * > > * @return The new AVEncryptionInfo structure, or NULL on error. > > */ > > How is this related to adding a test ? > I guess it's unrelated, created a separate patch for it. > > > > diff --git a/libavutil/tests/.gitignore b/libavutil/tests/.gitignore > > index 71f75a8ee9..9d90827954 100644 > > --- a/libavutil/tests/.gitignore > > +++ b/libavutil/tests/.gitignore > > @@ -17,6 +17,7 @@ > > /dict > > /display > > /error > > +/encryption_info > > /eval > > /fifo > > /file > > > @@ -24,6 +25,7 @@ > > /hmac > > /hwdevice > > /imgutils > > +/integer > > /lfg > > /lls > > /log > > this also looks unrelated Same. > > > [...] > -- > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB > > Opposition brings concord. Out of discord comes the fairest harmony. > -- Heraclitus > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel From c97e44904020944e469faec18b9c279cb6d89b46 Mon Sep 17 00:00:00 2001 From: Jacob Trimble Date: Fri, 1 Jun 2018 11:38:05 -0700 Subject: [PATCH] libavutil/encryption_info: Add unit tests. Signed-off-by: Jacob Trimble --- libavutil/Makefile | 1 + libavutil/tests/.gitignore | 1 + libavutil/tests/encryption_info.c | 176 ++++++++++++++++++++++++++++++ tests/fate/libavutil.mak | 4 + tests/ref/fate/encryption-info | 0 5 files changed, 182 insertions(+) create mode 100644 libavutil/tests/encryption_info.c create mode 100644 tests/ref/fate/encryption-info diff --git a/libavutil/Makefile b/libavutil/Makefile index d0632f16a6..9ed24cfc82 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -200,6 +200,7 @@ TESTPROGS = adler32 \ des \ dict \ display \ + encryption_info \ error \ eval \ file \ diff --git a/libavutil/tests/.gitignore b/libavutil/tests/.gitignore index 71f75a8ee9..d7de295617 100644 --- a/libavutil/tests/.gitignore +++ b/libavutil/tests/.gitignore @@ -17,6 +17,7 @@ /dict /display /error +/encryption_info /eval /fifo /file diff --git a/libavutil/tests/encryption_info.c b/libavutil/tests/encryption_info.c new file mode 100644 index 0000000000..d489612b7d --- /dev/null +++ b/libavutil/tests/encryption_info.c @@ -0,0 +1,176 @@ +/* + * 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 "libavutil/encryption_info.h" + +#include +#include + +#include "libavutil/avassert.h" + +static const AVSubsampleEncryptionInfo test_subsamples[] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}}; +static const size_t test_subsample_count = sizeof(test_subsamples) / sizeof(test_subsamples[0]); +static const uint8_t test_iv[] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}; +static const uint8_t test_key_id[] = {0x21, 0x22, 0x23, 0x24}; +static const uint8_t test_key_id_2[] = {0x31, 0x32, 0x33, 0x34}; +static const uint8_t test_system_id[] = {0x41, 0x42, 0x43}; +static const uint8_t test_data[] = {0x51, 0x52}; + +static int compare_encryption_info(const AVEncryptionInfo *a, const AVEncryptionInfo *b) { + if (!a || !b || a->scheme != b->scheme || a->crypt_byte_block != b->crypt_byte_block || + a->skip_byte_block != b->skip_byte_block || a->key_id_size != b->key_id_size || + a->iv_size != b->iv_size || a->subsample_count != b->subsample_count) + return 1; + + if (memcmp(a->key_id, b->key_id, a->key_id_size) != 0 || + memcmp(a->iv, b->iv, a->iv_size) != 0 || + memcmp(a->subsamples, b->subsamples, a->subsample_count * sizeof(a->subsamples[0]))) + return 1; + + return 0; +} + +static int compare_encryption_init_info(const AVEncryptionInitInfo *a, const AVEncryptionInitInfo *b) { + if (!a || !b || a->system_id_size != b->system_id_size || + a->num_key_ids != b->num_key_ids || a->key_id_size != b->key_id_size || + a->data_size != b->data_size) + return 1; + + if (memcmp(a->system_id, b->system_id, a->system_id_size) != 0 || + memcmp(a->data, b->data, a->data_size) != 0) + return 1; + + for (uint32_t i = 0; i < a->num_key_ids; i++) { + if (memcmp(a->key_ids[i], b->key_ids[i], a->key_id_size) != 0) + return 1; + } + + if (a->next || b->next) { + if (!a->next || !b->next) + return 1; + if (compare_encryption_init_info(a->next, b->next) != 0) + return 1; + } + + return 0; +} + +static void run_encryption_info_test(void) +{ + AVEncryptionInfo *info, *copy; + uint8_t *side_data; + size_t side_data_size; + + info = av_encryption_info_alloc(test_subsample_count, sizeof(test_key_id), sizeof(test_iv)); + av_assert0(info); + av_assert0(info->key_id); + av_assert0(info->key_id_size == sizeof(test_key_id)); + av_assert0(info->iv); + av_assert0(info->iv_size == sizeof(test_iv)); + av_assert0(info->subsamples); + av_assert0(info->subsample_count == test_subsample_count); + + info->scheme = 1234; + info->crypt_byte_block = 333; + info->skip_byte_block = 444; + memcpy(info->key_id, test_key_id, sizeof(test_key_id)); + memcpy(info->iv, test_iv, sizeof(test_iv)); + memcpy(info->subsamples, test_subsamples, sizeof(test_subsamples)); + + copy = av_encryption_info_clone(info); + av_assert0(copy); + av_assert0(copy != info); + av_assert0(compare_encryption_info(info, copy) == 0); + av_encryption_info_free(copy); + + side_data = av_encryption_info_add_side_data(info, &side_data_size); + av_assert0(side_data); + av_assert0(side_data_size > 0); + + copy = av_encryption_info_get_side_data(side_data, side_data_size); + av_assert0(copy); + av_assert0(copy != info); + av_assert0(compare_encryption_info(info, copy) == 0); + av_encryption_info_free(copy); + av_free(side_data); + + av_encryption_info_free(info); +} + +static AVEncryptionInitInfo *create_init_info(void) +{ + AVEncryptionInitInfo *info; + + info = av_encryption_init_info_alloc(sizeof(test_system_id), 2, sizeof(test_key_id), sizeof(test_data)); + av_assert0(info); + av_assert0(info->system_id); + av_assert0(info->system_id_size == sizeof(test_system_id)); + av_assert0(info->key_ids); + av_assert0(info->num_key_ids == 2); + av_assert0(info->key_id_size == sizeof(test_key_id)); + av_assert0(info->key_ids[0]); + av_assert0(info->key_ids[1]); + av_assert0(info->data); + av_assert0(info->data_size == sizeof(test_data)); + av_assert0(!info->next); + + memcpy(info->system_id, test_system_id, sizeof(test_system_id)); + memcpy(info->key_ids[0], test_key_id, sizeof(test_key_id)); + memcpy(info->key_ids[1], test_key_id_2, sizeof(test_key_id_2)); + memcpy(info->data, test_data, sizeof(test_data)); + + return info; +} + +static void run_encryption_init_info_test(void) +{ + AVEncryptionInitInfo *info, *copy; + uint8_t *side_data; + size_t side_data_size; + + info = create_init_info(); + + side_data = av_encryption_init_info_add_side_data(info, &side_data_size); + av_assert0(side_data); + av_assert0(side_data_size > 0); + copy = av_encryption_init_info_get_side_data(side_data, side_data_size); + av_assert0(copy); + av_assert0(compare_encryption_init_info(info, copy) == 0); + av_encryption_init_info_free(copy); + av_free(side_data); + + // Make the first init info different from the second to test the correct order. + memset(info->system_id, 0, info->system_id_size); + info->next = create_init_info(); + side_data = av_encryption_init_info_add_side_data(info, &side_data_size); + av_assert0(side_data); + copy = av_encryption_init_info_get_side_data(side_data, side_data_size); + av_assert0(copy); + av_assert0(compare_encryption_init_info(info, copy) == 0); + av_encryption_init_info_free(copy); + av_free(side_data); + + av_encryption_init_info_free(info); +} + +int main(int argc, char **argv) +{ + run_encryption_info_test(); + run_encryption_init_info_test(); + return 0; +} diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak index 9b32d880f5..a1d9313c3d 100644 --- a/tests/fate/libavutil.mak +++ b/tests/fate/libavutil.mak @@ -70,6 +70,10 @@ FATE_LIBAVUTIL += fate-dict fate-dict: libavutil/tests/dict$(EXESUF) fate-dict: CMD = run libavutil/tests/dict +FATE_LIBAVUTIL += fate-encryption-info +fate-encryption-info: libavutil/tests/encryption_info$(EXESUF) +fate-encryption-info: CMD = run libavutil/tests/encryption_info + FATE_LIBAVUTIL += fate-eval fate-eval: libavutil/tests/eval$(EXESUF) fate-eval: CMD = run libavutil/tests/eval diff --git a/tests/ref/fate/encryption-info b/tests/ref/fate/encryption-info new file mode 100644 index 0000000000..e69de29bb2 -- 2.18.0.rc2.346.g013aa6912e-goog