#!/bin/bash
#PBS -N wct-doctest-sigproc
#PBS -A neutrinoGPU::debug2
#PBS -q debug
#PBS -l select=1
#PBS -l walltime=00:20:00
#PBS -l filesystems=flare:home
#PBS -j oe
#PBS -o /lus/flare/projects/neutrinoGPU/yuhw/aurora-build-logs/doctest-sigproc-i34.out
# Issue 34: run the sigproc doctest runner (incl. doctest_roi_refinement.cxx) inside the SL7 image,
# after build-wct-lwc.pbs STAGES=wct.  Gates: the runner and the deployed lib are from this commit.
#   qsub -W depend=afterok:<build job> doctest-sigproc.pbs
set -u
Y=/lus/flare/projects/neutrinoGPU/yuhw
S=$Y/wire-cell-toolkit-ai-helper/issues/29-aurora-production/scripts
export Y
echo "=== START $(date) on $(hostname) job ${PBS_JOBID%%.*}"
cd $Y/wire-cell-toolkit
echo "HEAD $(git rev-parse --short HEAD); built from $(cat $Y/aurora-build-logs/wct-build-commit.txt | cut -c1-8)"
$S/in-aurora-sl7.sh bash -c "
  B=build/sigproc
  ls -l --time-style=+%F_%T \$B/wcdoctest-sigproc \$B/libWireCellSigProc.so $Y/opt/lib/libWireCellSigProc.so
  # opt's copy is patchelf-stripped (RPATH), so compare .text, not the whole file
  t1=\$(objcopy -O binary --only-section=.text \$B/libWireCellSigProc.so /dev/stdout | md5sum | cut -c1-32)
  t2=\$(objcopy -O binary --only-section=.text $Y/opt/lib/libWireCellSigProc.so /dev/stdout | md5sum | cut -c1-32)
  echo deployed_text_eq_build=\$([ \"\$t1\" = \"\$t2\" ] && echo yes || echo NO) \$t1
  echo '--- new test registered?'
  \$B/wcdoctest-sigproc --list-test-cases 2>&1 | grep -i -E 'roi_refinement|stale'
  echo '--- the issue-34 test'
  \$B/wcdoctest-sigproc --test-case='*stale*' 2>&1 | tail -6
  echo ROI_TEST_RC=\${PIPESTATUS[0]}
  echo '--- whole sigproc doctest suite'
  \$B/wcdoctest-sigproc 2>&1 | tail -6
  echo SIGPROC_SUITE_RC=\${PIPESTATUS[0]}
" 2>&1 | grep -v '^INFO'
echo "=== END $(date)"
