Skip to content

ABM Test Failure in test-cpp-gcc-openmp CI Job #1422

@julianlitz

Description

@julianlitz

Bug description

Summary
The TestMobilityRules.hospital test in the ABM module fails in the test-cpp-gcc-openmp CI job. This happens very rarely (0.1% of the ./memilio-test runs). Enable OpenMP.

Error Output

[ RUN      ] TestMobilityRules.hospital
[warning] Using RNG with seeds: 2224242119, 3829650121, 3420097603, 3118483604, 4246163161, 2108093968.
/home/runner/work/memilio/memilio/cpp/tests/test_abm_mobility_rules.cpp:496: Failure
Expected equality of these values:
mio::abm::go_to_hospital(rng_car, p_car, t, dt, mio::abm::Parameters(num_age_groups))
   Which is: 4-byte object <05-00 00-00>
mio::abm::LocationType::Home
   Which is: 4-byte object <00-00 00-00>
[  FAILED  ] TestMobilityRules.hospital (0 ms)

Test Code Snippet

TEST_F(TestMobilityRules, hospital)
{
    mio::abm::Location home(mio::abm::LocationType::Home, 0, num_age_groups);
    auto t  = mio::abm::TimePoint(12346);
    auto dt = mio::abm::hours(1);
    auto p_inf =
        make_test_person(this->get_rng(), home, age_group_15_to_34, mio::abm::InfectionState::InfectedSevere, t);
    auto rng_inf = mio::abm::PersonalRandomNumberGenerator(p_inf);

    EXPECT_EQ(mio::abm::go_to_hospital(rng_inf, p_inf, t, dt, mio::abm::Parameters(num_age_groups)),
              mio::abm::LocationType::Hospital);

    auto p_car =
        make_test_person(this->get_rng(), home, age_group_15_to_34, mio::abm::InfectionState::InfectedSymptoms);
    auto rng_car = mio::abm::PersonalRandomNumberGenerator(p_car);

    EXPECT_EQ(mio::abm::go_to_hospital(rng_car, p_car, t, dt, mio::abm::Parameters(num_age_groups)),
              mio::abm::LocationType::Home);
}

Recreate the error with this run script:
cpp/scripts/run_tests_n_times.sh

#!/usr/bin/env bash
# run_tests_n_times.sh
# Usage:
#   ./run_tests_n_times.sh [N] [command...]
# Examples:
#   ./run_tests_n_times.sh 1000 ./../build/bin/memilio-test
#   ./run_tests_n_times.sh    ./../build/bin/memilio-test   # runs 1000 times by default

set -u
# default runs
DEFAULT_RUNS=1000

# parse arguments
if [[ $# -eq 0 ]]; then
  RUNS=$DEFAULT_RUNS
  CMD="./../build/bin/memilio-test"
else
  # if first arg is a number, use as runs
  if [[ $1 =~ ^[0-9]+$ ]]; then
    RUNS=$1
    shift
    if [[ $# -ge 1 ]]; then
      CMD="$*"
    else
      CMD="./../build/bin/memilio-test"
    fi
  else
    RUNS=$DEFAULT_RUNS
    CMD="$*"
  fi
fi

echo "Will run command: $CMD"
echo "Number of runs: $RUNS"
echo

failures=0
successes=0
LOG_FAILS="failed_runs.log"
: > "$LOG_FAILS"   # truncate log file

for i in $(seq 1 "$RUNS"); do
  printf "\n=== Run %d / %d ===\n" "$i" "$RUNS"
  # run command, capture output and exit code
  output=$($CMD 2>&1)
  rc=$?

  # show a short tail of the output so you see immediate feedback
  echo "$output" | tail -n 20

  # Decide if this run failed:
  # - non-zero exit code OR output contains "FAILED" / "failed"
  if [[ $rc -ne 0 ]] || echo "$output" | grep -qiE '(^|\W)(FAILED|failed)(\W|$)'; then
    echo "-> Result: FAILED (exit code: $rc)"
    failures=$((failures + 1))
    {
      printf "\n----- Run %d (exit code %d) -----\n" "$i" "$rc"
      echo "$output"
    } >> "$LOG_FAILS"
  else
    echo "-> Result: OK"
    successes=$((successes + 1))
  fi
done

echo
echo "========================================"
echo "Done: $RUNS runs completed."
echo "Successes: $successes"
echo "Failures:  $failures"
echo "Detailed failed runs (if any): $LOG_FAILS"
echo "========================================"

# optional desktop notification if notify-send is available
if command -v notify-send >/dev/null 2>&1; then
  notify-send "Test runs completed" "Runs: $RUNS — Success: $successes — Failures: $failures"
fi

# exit non-zero if any failures (useful for CI)
if [[ $failures -gt 0 ]]; then
  exit 1
else
  exit 0
fi

Version

Linux

To reproduce

Bug appeared in the CI of #1421.

Relevant log output

Add any relevant information, e.g. used compiler, screenshots.

Checklist

  • Attached labels, especially loc:: or model:: labels.
  • Linked to project

Metadata

Metadata

Assignees

No one assigned

    Labels

    class::bugBugs found in the software

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions