150 lines
3.8 KiB
Bash
Executable File
150 lines
3.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eu
|
|
|
|
SUITE="/home/dariodf/Scrivania/MARTE/marte-benchmark-suite"
|
|
|
|
DEFAULT_SOURCE="$SUITE/configurations/generated/S00/smoke_s0_core.marte"
|
|
DEFAULT_OUTPUT="$SUITE/configurations/generated/S01/from_patcher/smoke_s1_timing_from_s00.marte"
|
|
|
|
SOURCE="${1:-$DEFAULT_SOURCE}"
|
|
OUTPUT="${2:-$DEFAULT_OUTPUT}"
|
|
|
|
EXPECTED_SOURCE_SHA256="49a9b48595aab88cd8fd11d1e58ace4ab11d7d0a649e9b143bdc25c8866253d5"
|
|
EXPECTED_OUTPUT_SHA256="1513e1ca72eba56d53079ac7328908f12ddc72772456e2d75bcbacb6465d2427"
|
|
|
|
fail() {
|
|
code="$1"
|
|
shift
|
|
printf "ERRORE: %s\n" "$*" >&2
|
|
exit "$code"
|
|
}
|
|
|
|
if [ ! -f "$SOURCE" ]; then
|
|
fail 2 "configurazione sorgente non trovata: $SOURCE"
|
|
fi
|
|
|
|
SOURCE_SHA256="$(sha256sum "$SOURCE" | awk '{print $1}')"
|
|
|
|
if [ "$SOURCE_SHA256" != "$EXPECTED_SOURCE_SHA256" ]; then
|
|
fail 3 "hash della configurazione sorgente non riconosciuto: $SOURCE_SHA256"
|
|
fi
|
|
|
|
if grep -q 'State1_Thread1_CycleTime' "$SOURCE"; then
|
|
fail 4 "la configurazione sorgente contiene già il segnale S01"
|
|
fi
|
|
|
|
OUTPUT_DIR="$(dirname "$OUTPUT")"
|
|
mkdir -p "$OUTPUT_DIR"
|
|
|
|
if [ -e "$OUTPUT" ]; then
|
|
if [ ! -f "$OUTPUT" ]; then
|
|
fail 5 "il percorso di output esiste ma non è un file regolare: $OUTPUT"
|
|
fi
|
|
|
|
OUTPUT_SHA256="$(sha256sum "$OUTPUT" | awk '{print $1}')"
|
|
|
|
if [ "$OUTPUT_SHA256" = "$EXPECTED_OUTPUT_SHA256" ]; then
|
|
printf "RISULTATO GIÀ PRESENTE E CORRETTO\n"
|
|
printf "Output: %s\n" "$OUTPUT"
|
|
printf "SHA-256: %s\n" "$OUTPUT_SHA256"
|
|
exit 0
|
|
fi
|
|
|
|
fail 6 "il file di output esiste ma ha un contenuto inatteso: $OUTPUT"
|
|
fi
|
|
|
|
TMP="${OUTPUT}.tmp.$$"
|
|
|
|
cleanup() {
|
|
if [ -f "$TMP" ]; then
|
|
rm -f "$TMP"
|
|
fi
|
|
}
|
|
|
|
trap cleanup EXIT HUP INT TERM
|
|
|
|
set +e
|
|
awk '
|
|
BEGIN {
|
|
inGamDisplay = 0
|
|
inInputSignals = 0
|
|
inOutputSignals = 0
|
|
inputInsertions = 0
|
|
outputInsertions = 0
|
|
}
|
|
|
|
{
|
|
if ($0 ~ /^ \+GAMDisplay[[:space:]]*=[[:space:]]*\{[[:space:]]*$/) {
|
|
inGamDisplay = 1
|
|
}
|
|
|
|
if (inGamDisplay &&
|
|
$0 ~ /^ InputSignals[[:space:]]*=[[:space:]]*\{[[:space:]]*$/) {
|
|
inInputSignals = 1
|
|
}
|
|
|
|
if (inGamDisplay &&
|
|
$0 ~ /^ OutputSignals[[:space:]]*=[[:space:]]*\{[[:space:]]*$/) {
|
|
inOutputSignals = 1
|
|
}
|
|
|
|
if (inInputSignals &&
|
|
$0 ~ /^ \}[[:space:]]*$/) {
|
|
print " State1_Thread1_CycleTime = {"
|
|
print " Alias = State1.Thread1_CycleTime"
|
|
print " DataSource = Timings"
|
|
print " Type = uint32"
|
|
print " }"
|
|
inputInsertions++
|
|
inInputSignals = 0
|
|
}
|
|
|
|
if (inOutputSignals &&
|
|
$0 ~ /^ \}[[:space:]]*$/) {
|
|
print " State1_Thread1_CycleTime = {"
|
|
print " DataSource = Display"
|
|
print " Type = uint32"
|
|
print " }"
|
|
print " } "
|
|
outputInsertions++
|
|
inOutputSignals = 0
|
|
next
|
|
}
|
|
|
|
print
|
|
|
|
if (inGamDisplay &&
|
|
$0 ~ /^ \}[[:space:]]*$/) {
|
|
inGamDisplay = 0
|
|
}
|
|
}
|
|
|
|
END {
|
|
if (inputInsertions != 1 || outputInsertions != 1) {
|
|
exit 42
|
|
}
|
|
}
|
|
' "$SOURCE" > "$TMP"
|
|
|
|
AWK_RC=$?
|
|
set -e
|
|
|
|
if [ "$AWK_RC" -ne 0 ]; then
|
|
fail 7 "trasformazione non applicata in modo univoco; codice awk: $AWK_RC"
|
|
fi
|
|
|
|
GENERATED_SHA256="$(sha256sum "$TMP" | awk '{print $1}')"
|
|
|
|
if [ "$GENERATED_SHA256" != "$EXPECTED_OUTPUT_SHA256" ]; then
|
|
fail 8 "output generato differente dalla S01 manuale: $GENERATED_SHA256"
|
|
fi
|
|
|
|
mv "$TMP" "$OUTPUT"
|
|
trap - EXIT HUP INT TERM
|
|
|
|
printf "PATCH S00 -> S01 COMPLETATA\n"
|
|
printf "Sorgente: %s\n" "$SOURCE"
|
|
printf "Output: %s\n" "$OUTPUT"
|
|
printf "SHA-256 sorgente: %s\n" "$SOURCE_SHA256"
|
|
printf "SHA-256 output: %s\n" "$GENERATED_SHA256"
|