github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/tools/syz-bq.sh (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2024 syzkaller project authors. All rights reserved.
     3  # Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     4  
     5  set -e # exit on any problem
     6  set -o pipefail
     7  
     8  while getopts w:d:t:n:r:b:c: option
     9  do
    10      case "${option}"
    11          in
    12          w)workdir=${OPTARG};;
    13          d)duration=${OPTARG};;
    14          t)to_date=${OPTARG};;
    15          n)namespace=${OPTARG};;
    16          r)repo=${OPTARG};;
    17          b)branch=${OPTARG};;
    18          c)client_name=${OPTARG};;
    19      esac
    20  done
    21  
    22  if [ -z "$workdir" ]
    23  then
    24    echo "-w is requires to specify workdir"
    25    exit
    26  fi
    27  if [ -z "$to_date" ]
    28  then
    29    echo "-t is required to specify to_date"
    30    exit
    31  fi
    32  if [ -z "$duration" ]
    33  then
    34    echo "-d is required to specify duration"
    35    exit
    36  fi
    37  if [ -z "$namespace" ]
    38  then
    39    echo "-n is required to specify namespace"
    40    exit
    41  fi
    42  if [ -z "$repo" ]
    43  then
    44    echo "-r is required to specify the merging repo base"
    45    exit
    46  fi
    47  if [ -z "$branch" ]
    48  then
    49    echo "-b is required to specify the merging branch base"
    50    exit
    51  fi
    52  
    53  echo "Workdir: $workdir"
    54  base_dir="${workdir}repos/linux_kernels"
    55  if [ ! -d $base_dir ]; then
    56    echo "base dir doesn't exist, cloning"
    57    git clone $repo $base_dir
    58  fi
    59  cd $base_dir
    60  remote=$(git remote -v | grep $repo | head -n1 | awk '{print $1;}')
    61  git fetch --tags $remote
    62  git checkout $remote/$branch
    63  cd -
    64  
    65  # get the last merged commit at to_date
    66  # sometimes many commits have same time and are shuffled
    67  base_commit=$(git --git-dir=${base_dir}/.git log --date=iso-local --before ${to_date}T23:59:59 --pretty=format:"%cd %H" -1000 | \
    68    sort -rn | { head -1; cat >/dev/null; } | rev | cut -d' ' -f1 | rev)
    69  if [ -z "$base_commit" ]
    70  then
    71    echo FAILED to get the base merging commit.
    72    exit
    73  fi
    74  echo The latest commit as of $to_date is $base_commit.
    75  
    76  from_date=$(date -d "$to_date - $duration days + 1 day" +%Y-%m-%d)
    77  # every partition covers 1 day
    78  query=$(cat <<-END
    79  SELECT
    80    sum(total_rows) as total_rows,
    81  FROM
    82    syzkaller.syzbot_coverage.INFORMATION_SCHEMA.PARTITIONS
    83  WHERE
    84    table_name = '${namespace}' AND
    85    PARSE_DATE('%Y%m%d', partition_id) >= '${from_date}' AND
    86    PARSE_DATE('%Y%m%d', partition_id) <= '${to_date}';
    87  END
    88  )
    89  
    90  total_rows=$(bq query --format=csv --use_legacy_sql=false "$query" | tail -n +2)
    91  if (( total_rows <= 0 ))
    92  then
    93    echo error: no source rows in bigquery available
    94    exit
    95  else
    96    echo $total_rows rows are available for processing
    97  fi
    98  
    99  go run ./tools/syz-covermerger/ -workdir $workdir \
   100    -repo $repo \
   101    -commit $base_commit \
   102    -to-dashapi https://syzkaller.appspot.com \
   103    -dashboard-client-name $client_name \
   104    -namespace $namespace \
   105    -duration $duration \
   106    -date-to $to_date \
   107    -total-rows $total_rows
   108  
   109  echo Done