1#!/bin/bash -eu
2# Copyright 2019 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# This script returns the result of state_assumption_external.sh on every even
7# iteration, and PROBLEM_STATUS on every odd_iteration
8
9PROBLEM_STATUS=127
10
11tmp_dir=$(pwd)/afdo_test_tmp
12
13count_file="${tmp_dir}/.count"
14if [[ -f "${count_file}" ]]; then
15  num_call=$(cat "${count_file}")
16else
17  num_call=0
18fi
19
20local_count_file=${tmp_dir}/.local_count
21if [[ -f "${local_count_file}" ]]; then
22  local_count=$(cat "${local_count_file}")
23else
24  local_count=0
25fi
26
27echo -n $(( ${local_count}+1 )) > "${local_count_file}"
28
29# Don't want to fail on performance checks hence local_count >= 2
30# but following that, want to fail every other check
31if [[ ${local_count} -ge 2 ]] && [[ $(( ${num_call}%2 )) -ne 0 ]]; then
32  echo -n $(( ${num_call}+1 )) > "${count_file}"
33  exit "${PROBLEM_STATUS}"
34fi
35
36# script just needs any second argument to write profs to .second_run_*
37$(pwd)/state_assumption_external.sh "$1" 'second_run'
38exit $?
39