#!/bin/sh
# PCP QA Test No. 590
# concurrent use of different archives
#
# Copyright (c) 2017 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

_get_libpcp_config
$multi_threaded || _notrun "No libpcp threading support"

if [ $PCP_PLATFORM = openbsd ]
then
    if cc --version 2>&1 | grep clang >/dev/null
    then
        # This is a bad combination ... we're not sure if it is libc
        # on openbsd where fopen() is not thread safe leading to:
	# pmNewContext(archives/ok-foo) -> No such file or directory
        # or our implementation of "thread provate data" that is busted
        # with clang, but as this test passes everywhere else, we've opted
        # to "notrun" it here.
	#
	_notrun "openbsd and clang are not our friends"
    fi
fi

_cleanup()
{
    cd $here
    $sudo rm -rf $tmp $tmp.*
    $sudo rm -f /tmp/thread_?.out
}

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
export PCP_DERIVED_CONFIG=

$sudo rm -f /tmp/thread_?.out
src/multithread12 -a 5 -b 5 -c 5 -d 5 -e 5 -C network.interface.out.packets \
    archives/ok-foo archives/ok-mv-foo archives/multi archives/bozo-20170904 \
    archives/multi_v3

echo
echo "=== Thread A archives/ok-foo ==="
if [ -f /tmp/thread_A.out ]
then
    cat /tmp/thread_A.out
else
    echo "Error: /tmp/thread_A.out not created."
fi

echo
echo "=== Thread B archives/ok-mv-foo ==="
if [ -f /tmp/thread_B.out ]
then
    cat /tmp/thread_B.out
else
    echo "Error: /tmp/thread_B.out not created."
fi

echo
echo "=== Thread C archives/multi ==="
if [ -f /tmp/thread_C.out ]
then
    cat /tmp/thread_C.out
else
    echo "Error: /tmp/thread_C.out not created."
fi

echo
echo "=== Thread D archives/bozo-20170904 ==="
if [ -f /tmp/thread_D.out ]
then
    cat /tmp/thread_D.out
else
    echo "Error: /tmp/thread_D.out not created."
fi

echo
echo "=== Thread E archives/multi_v3 ==="
if [ -f /tmp/thread_E.out ]
then
    cat /tmp/thread_E.out
else
    echo "Error: /tmp/thread_E.out not created."
fi

# success, all done
status=0
exit
