#!/bin/sh
# PCP QA Test No. 903
# Exercise fetch profile handling in a multithreaded environment.
#
# Copyright (c) 2019 Ken McDonell.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

_cleanup()
{
    cd $here
    $sudo rm -rf $tmp $tmp.*
}

status=1	# failure is the default!
$sudo rm -rf $tmp $tmp.* $seq.full
trap "_cleanup; exit \$status" 0 1 2 3 15

# real QA test starts here
for src in "-h localhost" "-a tmparch/bigbin" -L
do
    echo | tee -a $here/$seq.full
    echo "=== $src ===" | tee -a $here/$seq.full
    [ "$src" = "-L" ] && echo "Note: expect errors with -L"
    src/multithread13 -i -v $src -s 100 5 >$tmp.out 2>$tmp.err
    cat $tmp.err $tmp.out >>$here/$seq.full
    cat $tmp.err $tmp.out
    for o in /tmp/mt13out.*
    do
	echo "--- $o ---" >>$here/$seq.full
	cat $o >>$here/$seq.full
	grep -E -v 'include|exclude| numpmid=1 ' <$o \
	| sed -e 's/^\[[0-4]]/[x]/' \
	| LC_COLLATE=posix sort
    done
done

# success, all done
status=0
exit
