1cabdff1aSopenharmony_ci#!/bin/sh
2cabdff1aSopenharmony_ci#
3cabdff1aSopenharmony_ci# * Copyright (C) 2018 Michael Niedermayer (michaelni@gmx.at)
4cabdff1aSopenharmony_ci# *
5cabdff1aSopenharmony_ci# * This file is part of FFmpeg.
6cabdff1aSopenharmony_ci# *
7cabdff1aSopenharmony_ci# * FFmpeg is free software; you can redistribute it and/or modify
8cabdff1aSopenharmony_ci# * it under the terms of the GNU General Public License as published by
9cabdff1aSopenharmony_ci# * the Free Software Foundation; either version 2 of the License, or
10cabdff1aSopenharmony_ci# * (at your option) any later version.
11cabdff1aSopenharmony_ci# *
12cabdff1aSopenharmony_ci# * FFmpeg is distributed in the hope that it will be useful,
13cabdff1aSopenharmony_ci# * but WITHOUT ANY WARRANTY; without even the implied warranty of
14cabdff1aSopenharmony_ci# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15cabdff1aSopenharmony_ci# * GNU General Public License for more details.
16cabdff1aSopenharmony_ci# *
17cabdff1aSopenharmony_ci# * You should have received a copy of the GNU General Public License
18cabdff1aSopenharmony_ci# * along with FFmpeg; if not, write to the Free Software
19cabdff1aSopenharmony_ci# * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20cabdff1aSopenharmony_ci
21cabdff1aSopenharmony_ciset -e
22cabdff1aSopenharmony_ci
23cabdff1aSopenharmony_ciLC_ALL=C
24cabdff1aSopenharmony_ciexport LC_ALL
25cabdff1aSopenharmony_ci
26cabdff1aSopenharmony_ciLIST=target_dec_fate.list
27cabdff1aSopenharmony_ci
28cabdff1aSopenharmony_cishow_help(){
29cabdff1aSopenharmony_ci    cat <<EOF
30cabdff1aSopenharmony_ciUsage: ./target_dec_fate.sh <directory> [<test to run>]
31cabdff1aSopenharmony_ci
32cabdff1aSopenharmony_cidirectory       the directory into which sample files will be downloaded
33cabdff1aSopenharmony_citest to run     the number of the issue to test
34cabdff1aSopenharmony_ciNote, some test samples may not yet be available to the public, also this
35cabdff1aSopenharmony_ciscript will not download samples which are already in the directory. So you
36cabdff1aSopenharmony_cimay want to preserve its content between runs.
37cabdff1aSopenharmony_ciEOF
38cabdff1aSopenharmony_ci    exit 0
39cabdff1aSopenharmony_ci}
40cabdff1aSopenharmony_ci
41cabdff1aSopenharmony_citest -z "$1"  && show_help
42cabdff1aSopenharmony_citest ! -d "$1"  && echo $1 is not an accessable directory && show_help
43cabdff1aSopenharmony_citest ! -f target_dec_fate.sh && echo $0 Must be run from its location && show_help
44cabdff1aSopenharmony_cigrep 'CONFIG_OSSFUZZ 0' ../config.h && echo not configured for ossfuzz && show_help
45cabdff1aSopenharmony_ci
46cabdff1aSopenharmony_ci#Download testcases
47cabdff1aSopenharmony_ciwhile read -r LINE; do
48cabdff1aSopenharmony_ci    ISSUE_NUM=`echo $LINE | sed 's#/.*##'`
49cabdff1aSopenharmony_ci    FILE_ID=`echo $LINE | sed 's#.*/clusterfuzz-testcase[a-zA-Z0-9_-]*-\([0-9]*\).*#\1#'`
50cabdff1aSopenharmony_ci    FILE=`echo $LINE | sed 's# .*##'`
51cabdff1aSopenharmony_ci    if test -f "$1/$FILE" ; then
52cabdff1aSopenharmony_ci        echo exists       $FILE
53cabdff1aSopenharmony_ci    elif echo "$ISSUE_NUM" | grep '#' >/dev/null ; then
54cabdff1aSopenharmony_ci        echo disabled     $FILE
55cabdff1aSopenharmony_ci    else
56cabdff1aSopenharmony_ci        echo downloading  $FILE
57cabdff1aSopenharmony_ci        mkdir -p "$1/$ISSUE_NUM"
58cabdff1aSopenharmony_ci        wget -O "$1/$FILE" "https://oss-fuzz.com/download?testcase_id=$FILE_ID" || rm "$1/$FILE"
59cabdff1aSopenharmony_ci    fi
60cabdff1aSopenharmony_cidone < "$LIST"
61cabdff1aSopenharmony_ci
62cabdff1aSopenharmony_ci#Find which fuzzers we need to build
63cabdff1aSopenharmony_ciTOOLS=
64cabdff1aSopenharmony_ciwhile read -r LINE; do
65cabdff1aSopenharmony_ci    TOOL_ID=`echo $LINE | sed 's#[^ ]* ##'`
66cabdff1aSopenharmony_ci    TOOLS="$TOOLS tools/$TOOL_ID"
67cabdff1aSopenharmony_cidone < "$LIST"
68cabdff1aSopenharmony_ci
69cabdff1aSopenharmony_cicd ..
70cabdff1aSopenharmony_ci#Build fuzzers
71cabdff1aSopenharmony_cimake -j4 $TOOLS
72cabdff1aSopenharmony_ci
73cabdff1aSopenharmony_ci#Run testcases
74cabdff1aSopenharmony_ciwhile read -r LINE; do
75cabdff1aSopenharmony_ci    TOOL_ID=`echo $LINE | sed 's#[^ ]* ##'`
76cabdff1aSopenharmony_ci    FILE=`echo $LINE | sed 's# .*##'`
77cabdff1aSopenharmony_ci    if ! test -f "$1/$FILE" ; then
78cabdff1aSopenharmony_ci        continue
79cabdff1aSopenharmony_ci    fi
80cabdff1aSopenharmony_ci    tools/$TOOL_ID $1/$FILE
81cabdff1aSopenharmony_cidone < "tools/$LIST"
82cabdff1aSopenharmony_ci
83cabdff1aSopenharmony_ciecho OK
84