From patchwork Mon May 3 10:34:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedaa X-Patchwork-Id: 27564 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a10:399:0:0:0:0 with SMTP id 25csp118581pxh; Mon, 3 May 2021 03:34:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4ZdZ56rWlshysvaRuxiFgvbKRQR7/t29F3oUYbm6V/w+Gp4FpKkahfoIrAIZ/7/358MPg X-Received: by 2002:aa7:d7cf:: with SMTP id e15mr7970950eds.109.1620038097053; Mon, 03 May 2021 03:34:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620038097; cv=none; d=google.com; s=arc-20160816; b=e6T8e0EnsX8TPg77X8c5MTSJB66bbe/dRCBFvdrN97RVbl82/L3L31HrwUa21nfDrc 5OpvPsQu4+DBoL7HEX8hVw6+HlhtGm0W6zmQjYL2Jg8X5ZtV9HhPMWxxT6ukZneDgsqd FDYJq+/eYQbIvTVSX1rsMo/TEnynDrwKhlP6MJt18qNnpra9Ube8W2qX2x8e7oKv83Po neJJFK5KKGP5FerFkhc38CDjyQk2x/YkUMRTJ0vUNBXk5Ylhubxa2pE44K2+r7nKlUwd Y8UyWTGydE4dgB2F0p7bSYz7vGxIOKpbFEv2kLm5P7wD/OiMnb1VKZzbpW4oEbMovPf3 wNoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=5P7y275RWSjU3PZ8npcnC3DIGvcjWeEqqvI+jAnl2xE=; b=j2y2oCKsUM5yMI/VBz1Rt+Y3jHMmAtivP6zs5CVTQO4bOnz47nq3/m8zYZO2HteEYz 86MeN34cBM1rtJDF/JHSenU2D1OiXJuUiP7K+XHtFPx4/YXs+54UoUd5smH6EqtXFLqy bD/DN/902VXgBOjPKliEfNXeIeRgSqj9jkUKQj7fDVLagMUjuPsSFWAUNtfg6gbDwl42 qvT9rUMxcc/mA3BjoGgrPnbVas67MIT1d5dKDnvrK3OBuknlL7PLuh8iK8w8L2yjvelf EEkbw06mFadfapuk1ysv5fr7ot2DbZzUP7ovrC+Hhd3afjdnM+VL+ZBTz2/E1fFPwo+z PRbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@riseup.net header.s=squak header.b=ManyaP8a; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=riseup.net Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m16si8106794eds.603.2021.05.03.03.34.56; Mon, 03 May 2021 03:34:57 -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=@riseup.net header.s=squak header.b=ManyaP8a; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=riseup.net Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8497A687F43; Mon, 3 May 2021 13:34:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A8DD36807AA for ; Mon, 3 May 2021 13:34:45 +0300 (EEST) Received: from fews1.riseup.net (fews1-pn.riseup.net [10.0.1.83]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "Sectigo RSA Domain Validation Secure Server CA" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4FYfVX1WxgzDq9w for ; Mon, 3 May 2021 03:34:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1620038084; bh=SpQRJzNtd+ahpqJ5I1cVVNv81nvi/UolTRH8Talf2Os=; h=From:To:Subject:Date:From; b=ManyaP8apIMqEKvlEiRz6/57e0Y4ox1pA3LQSgAY5ulBxFzr3nutdqQJIoJ3e91VO NfLI2hAFX1uF+UiJvsZEwb2EtqmxAx2OQ2TKSLgh69RC1pJyZvDiZlDzmLtkpwUUUt 07kyDhH09E35FagfnxPH8AXMHih0rYiGfYYeLDlI= X-Riseup-User-ID: 846A19B94227801818ED4BC9506B0EB11470AF417DFC51A9561D5A7A3A82F264 Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews1.riseup.net (Postfix) with ESMTPSA id 4FYfVW1LVrz5vND for ; Mon, 3 May 2021 03:34:42 -0700 (PDT) From: Vedaa To: ffmpeg-devel@ffmpeg.org Date: Mon, 3 May 2021 16:04:28 +0530 Message-Id: <20210503103428.839392-1-vedaa@riseup.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] fate/integer.c: Connect test to fuzzer X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: /u5500dAI/Ns Hi, I am applying for GSoC '21. I have attempted to connect fate-integer to the fuzzer by using a header file with the test function to ensure code reusability. However, the linker is unable to link the function definiton. What changes should I make to properly link the function? --- Makefile | 2 ++ libavutil/tests/integer.c | 36 ++++++++++++++++++------------------ libavutil/tests/integer.h | 26 ++++++++++++++++++++++++++ tools/Makefile | 3 +++ tools/target_int_fuzzer.c | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 18 deletions(-) create mode 100644 libavutil/tests/integer.h create mode 100644 tools/target_int_fuzzer.c diff --git a/Makefile b/Makefile index 7e9d8b08c3..416fc9b3e0 100644 --- a/Makefile +++ b/Makefile @@ -62,6 +62,8 @@ tools/target_dem_fuzzer$(EXESUF): tools/target_dem_fuzzer.o $(FF_DEP_LIBS) tools/target_io_dem_fuzzer$(EXESUF): tools/target_io_dem_fuzzer.o $(FF_DEP_LIBS) $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS) $(FF_EXTRALIBS) $(LIBFUZZER_PATH) +target_int_fuzzer$(EXESUF): tools/target_int_fuzzer.o $(FF_DEP_LIBS) + $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS) $(FF_EXTRALIBS) $(LIBFUZZER_PATH) tools/enum_options$(EXESUF): ELIBS = $(FF_EXTRALIBS) tools/enum_options$(EXESUF): $(FF_DEP_LIBS) diff --git a/libavutil/tests/integer.c b/libavutil/tests/integer.c index d2c8f2a903..644518485c 100644 --- a/libavutil/tests/integer.c +++ b/libavutil/tests/integer.c @@ -18,31 +18,31 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include +#include "libavutil/tests/integer.h" -#include "libavutil/avassert.h" -#include "libavutil/integer.h" -#include "libavutil/intmath.h" +void TestInteger(int64_t a, int64_t b) { + AVInteger ai= av_int2i(a); + AVInteger bi= av_int2i(b); + + av_assert0(av_i2int(ai) == a); + av_assert0(av_i2int(bi) == b); + av_assert0(av_i2int(av_add_i(ai,bi)) == a+b); + av_assert0(av_i2int(av_sub_i(ai,bi)) == a-b); + av_assert0(av_i2int(av_mul_i(ai,bi)) == a*b); + av_assert0(av_i2int(av_shr_i(ai, 9)) == a>>9); + av_assert0(av_i2int(av_shr_i(ai,-9)) == a<<9); + av_assert0(av_i2int(av_shr_i(ai, 17)) == a>>17); + av_assert0(av_i2int(av_shr_i(ai,-17)) == a<<17); + av_assert0(av_log2_i(ai) == av_log2(a)); + av_assert0(av_i2int(av_div_i(ai,bi)) == a/b); +} int main(void){ int64_t a,b; for(a=7; a<256*256*256; a+=13215){ for(b=3; b<256*256*256; b+=27118){ - AVInteger ai= av_int2i(a); - AVInteger bi= av_int2i(b); - - av_assert0(av_i2int(ai) == a); - av_assert0(av_i2int(bi) == b); - av_assert0(av_i2int(av_add_i(ai,bi)) == a+b); - av_assert0(av_i2int(av_sub_i(ai,bi)) == a-b); - av_assert0(av_i2int(av_mul_i(ai,bi)) == a*b); - av_assert0(av_i2int(av_shr_i(ai, 9)) == a>>9); - av_assert0(av_i2int(av_shr_i(ai,-9)) == a<<9); - av_assert0(av_i2int(av_shr_i(ai, 17)) == a>>17); - av_assert0(av_i2int(av_shr_i(ai,-17)) == a<<17); - av_assert0(av_log2_i(ai) == av_log2(a)); - av_assert0(av_i2int(av_div_i(ai,bi)) == a/b); + TestInteger(a,b); } } return 0; diff --git a/libavutil/tests/integer.h b/libavutil/tests/integer.h new file mode 100644 index 0000000000..97f15862a3 --- /dev/null +++ b/libavutil/tests/integer.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2004 Michael Niedermayer + * + * 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/avassert.h" +#include "libavutil/integer.h" +#include "libavutil/intmath.h" + +void TestInteger(int64_t a, int64_t b); diff --git a/tools/Makefile b/tools/Makefile index 82baa8eadb..fde7f08984 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -17,6 +17,9 @@ tools/target_dem_fuzzer.o: tools/target_dem_fuzzer.c tools/target_io_dem_fuzzer.o: tools/target_dem_fuzzer.c $(COMPILE_C) -DIO_FLAT=0 +tools/target_int_fuzzer.o: tools/target_int_fuzzer.c + $(COMPILE_C) + OUTDIRS += tools clean:: diff --git a/tools/target_int_fuzzer.c b/tools/target_int_fuzzer.c new file mode 100644 index 0000000000..f6edabe06b --- /dev/null +++ b/tools/target_int_fuzzer.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2004 Michael Niedermayer + * + * 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 + +int LLVMFuzzerTestOneInput( const uint8_t *data, size_t size ) { + if (size < 2 * sizeof(int64_t)) + return 1; + + int64_t a,b; + memcpy(&a,data,sizeof(int64_t)); + memcpy(&b,&(data[sizeof(int64_t)]),sizeof(int64_t)); + TestInteger(a,b); + return 0; +}