1#!/usr/bin/env bash
2
3# Copyright 2017 The Fuchsia Authors
4#
5# Use of this source code is governed by a MIT-style
6# license that can be found in the LICENSE file or at
7# https://opensource.org/licenses/MIT
8
9# Build Zircon with entropy collection tests enabled.
10#
11# This script internally calls `scripts/make-parallel`, but it passes through
12# some extra arguments to the build.
13#
14# Invocation mostly matches `make`, i.e.:
15#
16#     scripts/entropy-test/make-parallel <target>
17#
18# The exception to this is the '-l' flag. If passed, this script strips it out,
19# and uses the '-l' argument as the length of entropy test to run (this is used
20# to set ENTROPY_COLLECTOR_TEST_MAXLEN). That means you can't pass the '-l' flag
21# through to `make` (used to set a max load average for parallel builds). Oh
22# well.
23
24set -e -u
25CDPATH=
26ZIRCONDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"
27
28function HELP {
29    echo "$0 [options] <project>" >&2
30    echo >&2
31    echo "    <project> : zircon project, e.g. x86" >&2
32    echo >&2
33    echo "Options:" >&2
34    echo "    -l <len>  : value to pass to ENTROPY_COLLECTOR_TEST_MAXLEN" >&2
35    echo "              : (default: 1048576; no suffixes like '1M' allowed)" >&2
36    exit 1
37}
38
39LENGTH=1048576
40PASSTHOUGH_ARGS=()
41
42while [[ $# -gt 0 ]]; do
43    case "$1" in
44        -l)
45            if [[ $# -lt 2 ]]; then echo "-l missing len" >&2; HELP; fi
46            LENGTH="$2"
47            shift 2
48            ;;
49        *)
50            PASSTHOUGH_ARGS+=("$1")
51            shift
52            ;;
53    esac
54done
55
56DEFINES="ENABLE_ENTROPY_COLLECTOR_TEST=1 ENTROPY_COLLECTOR_TEST_MAXLEN=$LENGTH"
57
58cd "$ZIRCONDIR"
59exec scripts/make-parallel "${PASSTHOUGH_ARGS[@]}" EXTERNAL_DEFINES="$DEFINES"
60