1#!/bin/bash -eu
2# Copyright 2020 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16################################################################################
17
18./autogen.sh
19./configure \
20    --enable-fuzzing \
21    FUZZING_LIBS="${LIB_FUZZING_ENGINE} -lc++" \
22    LIBEVENT_LIBS="-Wl,-Bstatic -levent -Wl,-Bdynamic" \
23    LIBTINFO_LIBS="-Wl,-Bstatic -ltinfo -Wl,-Bdynamic"
24
25make -j"$(nproc)" check
26find "${SRC}/tmux/fuzz/" -name '*-fuzzer' -exec cp -v '{}' "${OUT}"/ \;
27find "${SRC}/tmux/fuzz/" -name '*-fuzzer.options' -exec cp -v '{}' "${OUT}"/ \;
28find "${SRC}/tmux/fuzz/" -name '*-fuzzer.dict' -exec cp -v '{}' "${OUT}"/ \;
29
30MAXLEN=$(grep -Po 'max_len\s+=\s+\K\d+' "${OUT}/input-fuzzer.options")
31mkdir "${WORK}/fuzzing_corpus"
32cd "${WORK}/fuzzing_corpus"
33bash "${SRC}/tmux/tools/24-bit-color.sh" | \
34    split -a4 -db$MAXLEN - 24-bit-color.out.
35perl "${SRC}/tmux/tools/256colors.pl" | \
36    split -a4 -db$MAXLEN - 256colors.out.
37cat "${SRC}/tmux/tools/UTF-8-demo.txt" | \
38    split -a4 -db$MAXLEN - UTF-8-demo.txt.
39cat "${SRC}/tmux-fuzzing-corpus/alacritty"/* | \
40    split -a4 -db$MAXLEN - alacritty.
41cat "${SRC}/tmux-fuzzing-corpus/esctest"/* | \
42    split -a4 -db$MAXLEN - esctest.
43cat "${SRC}/tmux-fuzzing-corpus/iterm2"/* | \
44    split -a5 -db$MAXLEN - iterm2.
45zip -q -j -r "${OUT}/input-fuzzer_seed_corpus.zip" \
46    "${WORK}/fuzzing_corpus/"
47