blob: daf03729d8dd8134cbac3b9aa794f4d424751225 [file] [edit]
#!/bin/bash
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -euo pipefail
# This script checks the content of a fake_resultstore dump file
# to verify that it contains multiple FAILED invocations (recursive ninja).
DUMP_FILE=""
JQ_BIN=""
while [[ "$#" -gt 0 ]]; do
case $1 in
--dump_file) DUMP_FILE="$2"; shift ;;
--jq) JQ_BIN="$2"; shift ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
if [[ -z "${DUMP_FILE}" || -z "${JQ_BIN}" ]]; then
echo "Usage: $0 --dump_file <path> --jq <path>"
exit 1
fi
if [ ! -s "${DUMP_FILE}" ]; then
echo "FAIL: ResultStore dump file '${DUMP_FILE}' does not exist or is empty." >&2
exit 1
fi
echo "--- RS DUMP CONTENT ---"
cat "${DUMP_FILE}"
echo "--- END RS DUMP CONTENT ---"
# 1. Count logical invocations (should be at least 2).
NUM_INVOCATIONS=$("${JQ_BIN}" -r '.create_inv_reqs | length' "${DUMP_FILE}")
if [[ "${NUM_INVOCATIONS}" -lt 2 ]]; then
echo "FAIL: Expected at least 2 logical RS invocations (outer + inner), found ${NUM_INVOCATIONS}." >&2
exit 1
fi
echo "Found ${NUM_INVOCATIONS} RS invocations."
# 2. Check for failure statuses in final_state.
# An inner failure should cascade to the outer one, so both should be FAILED.
# Use grep -c for robust line-by-line counting of FAILED/CANCELLED statuses.
num_failures=$("${JQ_BIN}" -r '.final_state.invocations[] | .status_attributes.status' "${DUMP_FILE}" | grep -E -c "^(FAILED|FAILED_TO_BUILD|CANCELLED)$") || num_failures=0
echo "Found ${num_failures} FAILED/CANCELLED statuses in final_state."
if [[ "${num_failures}" -ge 2 ]]; then
echo "PASS: Recursive Ninja ResultStore dump validation successful (found ${num_failures} FAILED/CANCELLED statuses)."
exit 0
else
echo "FAIL: Expected at least 2 FAILED/CANCELLED statuses in final_state, but found: ${STATUSES}" >&2
exit 1
fi