-
Notifications
You must be signed in to change notification settings - Fork 0
/
once_locally
executable file
·105 lines (83 loc) · 2.77 KB
/
once_locally
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
# Copyright (c) 2020 Matt Windsor and contributors
#
# This file is part of c4-scripts.
# Licenced under the MIT licence; see `LICENSE`.
# Expects to be run in an ACT working directory.
# Runs all of the various single-shot binaries of c4t in a pipeline, outputting to ./tester_test.
# TODO(@MattWindsor91): make this parametric and more robust.
set -euo pipefail
SCRIPTDIR="${SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"}"
readonly SCRIPTDIR
# shellcheck source=act_bash/args.sh
source "${SCRIPTDIR}/act_bash/args.sh"
# shellcheck source=act_bash/log.sh
source "${SCRIPTDIR}/act_bash/log.sh"
# shellcheck source=act_bash/naming.sh
source "${SCRIPTDIR}/act_bash/naming.sh"
## Variables ##
# The name of the output directory.
# If empty, we use a temporary directory.
OUTPUT_DIR=""
# The ID of the machine to run.
MACHINE="localhost"
# The number of times to fuzz.
# If 0, don't fuzz.
FUZZ="0"
# Whether or not verbose logging is enabled.
VERBOSE="false"
## Functions ##
# Prints the script's usage and exits.
usage() {
echo "usage: $0 [-d DIR] [-f CYCLES] [-m MACHINE] [-${ACT_STANDARD_FLAGS}] FILES..." >&2
echo
echo "-d: directory to use for outputting intermediate files"
echo "-f: number of cycles to fuzz each subject (0 = don't fuzz)"
echo "-m: ID of machine to use"
act::standard_usage
exit 1
}
# Fuzzes if FUZZ is non-zero; else, passes stdin through unchanged.
maybe_fuzz() {
if [[ "${FUZZ}" == 0 ]]; then
cat "$1"
else
act::log "Fuzzing %d time(s).\n" "${FUZZ}"
c4t-fuzz -d "${OUTPUT_DIR}/fuzz" -k "${FUZZ}" -n "-1" "$1"
fi
}
# Runs the c4t pipeline.
run() {
local plan="${OUTPUT_DIR}/plan.orig.json"
local pplan="${OUTPUT_DIR}/plan.perturbed.json"
local fplan="${OUTPUT_DIR}/plan.fuzzed.json"
local lplan="${OUTPUT_DIR}/plan.lifted.json"
local oplan="${OUTPUT_DIR}/plan.out.json"
c4t-plan -m "${MACHINE}" "$@" > "${plan}"
c4t-perturb "${plan}" > "${pplan}"
maybe_fuzz "${pplan}" > "${fplan}"
c4t-lift -d "${OUTPUT_DIR}/lift" "${fplan}" > "${lplan}"
c4t-invoke -d "${OUTPUT_DIR}/compile" "${lplan}" > "${oplan}"
c4t-analyse -CPS "${oplan}"
}
# The main function.
main() {
while getopts "d:f:m:qvx?h" a; do
case "${a}" in
d) OUTPUT_DIR="${OPTARG}" ;;
f) FUZZ="${OPTARG}" ;;
m) MACHINE="${OPTARG}" ;;
*) act::parse_standard_args "${a}" "${OPTARG:-}" ;;
esac
done
# VERBOSE etc. are used indirectly by various library functions.
# shellcheck disable=SC2034
readonly VERBOSE FUZZ MACHINE
shift $((OPTIND-1))
if [[ $# -lt 1 ]]; then act::arg_error "need at least one file argument"; fi
if [[ ${FUZZ} -lt 0 ]]; then act::arg_error "count must be a non-negative integer"; fi
if [[ -z ${OUTPUT_DIR} ]]; then act::setup_temp_output_dir; fi
readonly OUTPUT_DIR
run "$@"
}
main "$@"