blob: e3ae01550ff6f701b9f9ba3a4092ac799d54214a [file] [log] [blame]
Simon Butcheref50c0d2016-01-26 22:15:11 +00001#!/bin/sh
2
3# This script splits the data test files containing the test cases into
4# individual files (one test case per file) suitable for use with afl
5# (American Fuzzy Lop). http://lcamtuf.coredump.cx/afl/
6#
7# Usage: generate-afl-tests.sh <test data file path>
8# <test data file path> - should be the path to one of the test suite files
9# such as 'test_suite_mpi.data'
Bence Szépkúti700ee442020-05-26 00:33:31 +020010#
11# Copyright (C) 2016, Arm Limited, All Rights Reserved
Bence Szépkútic7da1fe2020-05-26 01:54:15 +020012# SPDX-License-Identifier: Apache-2.0
13#
14# Licensed under the Apache License, Version 2.0 (the "License"); you may
15# not use this file except in compliance with the License.
16# You may obtain a copy of the License at
17#
18# http://www.apache.org/licenses/LICENSE-2.0
19#
20# Unless required by applicable law or agreed to in writing, software
21# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23# See the License for the specific language governing permissions and
24# limitations under the License.
Bence Szépkúti700ee442020-05-26 00:33:31 +020025#
26# This file is part of Mbed TLS (https://tls.mbed.org)
Simon Butcheref50c0d2016-01-26 22:15:11 +000027
28# Abort on errors
29set -e
30
31if [ -z $1 ]
32then
33 echo " [!] No test file specified" >&2
34 echo "Usage: $0 <test data file>" >&2
35 exit 1
36fi
37
38SRC_FILEPATH=$(dirname $1)/$(basename $1)
39TESTSUITE=$(basename $1 .data)
40
41THIS_DIR=$(basename $PWD)
42
43if [ -d ../library -a -d ../include -a -d ../tests -a $THIS_DIR == "tests" ];
44then :;
45else
46 echo " [!] Must be run from mbed TLS tests directory" >&2
47 exit 1
48fi
49
50DEST_TESTCASE_DIR=$TESTSUITE-afl-tests
51DEST_OUTPUT_DIR=$TESTSUITE-afl-out
52
53echo " [+] Creating output directories" >&2
54
55if [ -e $DEST_OUTPUT_DIR/* ];
56then :
57 echo " [!] Test output files already exist." >&2
58 exit 1
59else
60 mkdir -p $DEST_OUTPUT_DIR
61fi
62
63if [ -e $DEST_TESTCASE_DIR/* ];
64then :
65 echo " [!] Test output files already exist." >&2
66else
67 mkdir -p $DEST_TESTCASE_DIR
68fi
69
70echo " [+] Creating test cases" >&2
71cd $DEST_TESTCASE_DIR
72
73split -p '^\s*$' ../$SRC_FILEPATH
74
75for f in *;
76do
77 # Strip out any blank lines (no trim on OS X)
78 sed '/^\s*$/d' $f >testcase_$f
79 rm $f
80done
81
82cd ..
83
84echo " [+] Test cases in $DEST_TESTCASE_DIR" >&2
85