target_dec_fate.sh 2.5 KB

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