blob: 6cd3f61408ffdb3d467d53fe5124ec2988d531f1 [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útib7246ad2020-05-26 00:33:31 +020010#
11# Copyright (C) 2016, Arm Limited, All Rights Reserved
12#
13# This file is part of Mbed TLS (https://tls.mbed.org)
Simon Butcheref50c0d2016-01-26 22:15:11 +000014
15# Abort on errors
16set -e
17
18if [ -z $1 ]
19then
20 echo " [!] No test file specified" >&2
21 echo "Usage: $0 <test data file>" >&2
22 exit 1
23fi
24
25SRC_FILEPATH=$(dirname $1)/$(basename $1)
26TESTSUITE=$(basename $1 .data)
27
28THIS_DIR=$(basename $PWD)
29
30if [ -d ../library -a -d ../include -a -d ../tests -a $THIS_DIR == "tests" ];
31then :;
32else
33 echo " [!] Must be run from mbed TLS tests directory" >&2
34 exit 1
35fi
36
37DEST_TESTCASE_DIR=$TESTSUITE-afl-tests
38DEST_OUTPUT_DIR=$TESTSUITE-afl-out
39
40echo " [+] Creating output directories" >&2
41
42if [ -e $DEST_OUTPUT_DIR/* ];
43then :
44 echo " [!] Test output files already exist." >&2
45 exit 1
46else
47 mkdir -p $DEST_OUTPUT_DIR
48fi
49
50if [ -e $DEST_TESTCASE_DIR/* ];
51then :
52 echo " [!] Test output files already exist." >&2
53else
54 mkdir -p $DEST_TESTCASE_DIR
55fi
56
57echo " [+] Creating test cases" >&2
58cd $DEST_TESTCASE_DIR
59
60split -p '^\s*$' ../$SRC_FILEPATH
61
62for f in *;
63do
64 # Strip out any blank lines (no trim on OS X)
65 sed '/^\s*$/d' $f >testcase_$f
66 rm $f
67done
68
69cd ..
70
71echo " [+] Test cases in $DEST_TESTCASE_DIR" >&2
72