<commit_before>#!/bin/bash
##
## @brief Test tpsprio, tpgprio - test launcher
##
## @file run.sh
##
## -----------------------------------------------------------------------------
## Enduro/X Middleware Platform for Distributed Transaction Processing
## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
## Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved.
## This software is released under one of the following licenses:
## AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
## See LICENSE file for full text.
## -----------------------------------------------------------------------------
## AGPL license:
## 
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU Affero General Public License, version 3 as published
## by the Free Software Foundation;
##
## This program is distributed in the hope that it will be useful, but WITHOUT ANY
## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
## PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
## for more details.
##
## You should have received a copy of the GNU Affero General Public License along 
## with this program; if not, write to the Free Software Foundation, Inc., 
## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
## -----------------------------------------------------------------------------
## A commercial use license is available from Mavimax, Ltd
## <EMAIL>
## -----------------------------------------------------------------------------
##

export TESTNAME="test085_prio"

PWD=`pwd`
if [ `echo $PWD | grep $TESTNAME ` ]; then
    # Do nothing 
    echo > /dev/null
else
    # started from parent folder
    pushd .
    echo "Doing cd"
    cd $TESTNAME
fi;

. ../testenv.sh

export TESTDIR="$NDRX_APPHOME/atmitest/$TESTNAME"
export PATH=$PATH:$TESTDIR
export NDRX_ULOG=$TESTDIR
export NDRX_TOUT=30
export NDRX_SILENT=Y

#
# Domain 1 - here client will live
#
set_dom1() {
    echo "Setting domain 1"
    . ../dom1.sh
    export NDRX_CONFIG=$TESTDIR/ndrxconfig-dom1.xml
    export NDRX_DMNLOG=$TESTDIR/ndrxd-dom1.log
    export NDRX_LOG=$TESTDIR/ndrx-dom1.log
    export NDRX_DEBUG_CONF=$TESTDIR/debug-dom1.conf
}



#
# Generic exit function
#
function go_out {
    echo "Test exiting with: $1"
    
    set_dom1;
    xadmin stop -y
    xadmin down -y



    # If some alive stuff left...
    xadmin killall atmiclt85

    popd 2>/dev/null
    exit $1
}

rm *.log
# Any bridges that are live must be killed!
xadmin killall tpbridge

set_dom1;
xadmin down -y
xadmin start -y || go_out 1

xadmin psc
xadmin ppm
echo "Running off client"

set_dom1;
(./atmiclt85 2>&1) > ./atmiclt-dom1.log
#(valgrind --leak-check=full --log-file="v.out" -v ./atmiclt85 2>&1) > ./atmiclt-dom1.log

RET=$?

if [[ "X$RET" != "X0" ]]; then
    go_out $RET
fi


# if poller is epoll very that priority actually works

POLLER=`xadmin poller`

if [[ "$POLLER" == "epoll" || "$POLLER" == "kqueue" ]]; then

    xadmin psc

    echo "*** Default is lower"
    export NDRX_BENCH_FILE="bench.def.log"
    export NDRX_BENCH_CONFIGNAME="results"
    exbenchcl -n5 -P  -t20 -b "{\"T_LONG_FLD\":5}" -f T_CARRAY_FLD -S1024 &
    BENCHPIDDEF_PID=$!

    # event this is started later, it shall fill take a priority over...
    export NDRX_BENCH_FILE="bench.70.log"
    export NDRX_BENCH_CONFIGNAME="results"
    exbenchcl -n5 -P  -t20 -b "{\"T_LONG_FLD\":5}" -f T_CARRAY_FLD -S1024 -p 70 &
    BENCHPID70_PID=$!

    # wait for pids...
    wait $BENCHPIDDEF_PID
    wait $BENCHPID70_PID

    RESDEF=`cat bench.def.log | grep results | awk '{print $3}'`
    RES70=`cat bench.70.log | grep results | awk '{print $3}'`

    echo "[$RESDEF] vs [$RES70]"

    if [[ "X$RESDEF" == "X" || "X$RES70" == "X" ]]; then
        echo "Missing results"
        go_out 1
    fi

    if [[ "$RESDEF" -ge "$RES70" ]]; then
        echo "Priority does not work prio DEF processed $RESDEF (shall be <) prio 70 processed $RES70 (1)"
        go_out 1
    fi

    rm bench.def.log
    rm bench.70.log

    echo "*** Default is higher"
    xadmin stop -y
    export NDRX_CONFIG=$TESTDIR/ndrxconfig-dom1_svcprio.xml
    xadmin start -y

    export NDRX_BENCH_FILE="bench.def.log"
    export NDRX_BENCH_CONFIGNAME="results"
    exbenchcl -n5 -P  -t20 -b "{\"T_LONG_FLD\":5}" -f T_CARRAY_FLD -S1024 &
    BENCHPIDDEF_PID=$!

    # event this is started later, it shall fill take a priority over...
    export NDRX_BENCH_FILE="bench.70.log"
    export NDRX_BENCH_CONFIGNAME="results"
    exbenchcl -n5 -P  -t20 -b "{\"T_LONG_FLD\":5}" -f T_CARRAY_FLD -S1024 -p 70 &
    BENCHPID70_PID=$!

    # wait for pids...
    wait $BENCHPIDDEF_PID
    wait $BENCHPID70_PID

    RESDEF=`cat bench.def.log | grep results | awk '{print $3}'`
    RES70=`cat bench.70.log | grep results | awk '{print $3}'`

    echo "[$RESDEF] vs [$RES70]"<commit_msg>Fixes for prio testing<commit_after>#!/bin/bash
##
## @brief Test tpsprio, tpgprio - test launcher
##
## @file run.sh
##
## -----------------------------------------------------------------------------
## Enduro/X Middleware Platform for Distributed Transaction Processing
## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
## Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved.
## This software is released under one of the following licenses:
## AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
## See LICENSE file for full text.
## -----------------------------------------------------------------------------
## AGPL license:
## 
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU Affero General Public License, version 3 as published
## by the Free Software Foundation;
##
## This program is distributed in the hope that it will be useful, but WITHOUT ANY
## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
## PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
## for more details.
##
## You should have received a copy of the GNU Affero General Public License along 
## with this program; if not, write to the Free Software Foundation, Inc., 
## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
## -----------------------------------------------------------------------------
## A commercial use license is available from Mavimax, Ltd
## <EMAIL>
## -----------------------------------------------------------------------------
##

export TESTNAME="test085_prio"

PWD=`pwd`
if [ `echo $PWD | grep $TESTNAME ` ]; then
    # Do nothing 
    echo > /dev/null
else
    # started from parent folder
    pushd .
    echo "Doing cd"
    cd $TESTNAME
fi;

. ../testenv.sh

export TESTDIR="$NDRX_APPHOME/atmitest/$TESTNAME"
export PATH=$PATH:$TESTDIR
export NDRX_ULOG=$TESTDIR
export NDRX_TOUT=30
export NDRX_SILENT=Y

#
# Domain 1 - here client will live
#
set_dom1() {
    echo "Setting domain 1"
    . ../dom1.sh
    export NDRX_CONFIG=$TESTDIR/ndrxconfig-dom1.xml
    export NDRX_DMNLOG=$TESTDIR/ndrxd-dom1.log
    export NDRX_LOG=$TESTDIR/ndrx-dom1.log
    export NDRX_DEBUG_CONF=$TESTDIR/debug-dom1.conf
}



#
# Generic exit function
#
function go_out {
    echo "Test exiting with: $1"
    
    set_dom1;
    xadmin stop -y
    xadmin down -y



    # If some alive stuff left...
    xadmin killall atmiclt85

    popd 2>/dev/null
    exit $1
}

rm *.log
# Any bridges that are live must be killed!
xadmin killall tpbridge

set_dom1;
xadmin down -y
xadmin start -y || go_out 1

xadmin psc
xadmin ppm
echo "Running off client"

set_dom1;
(./atmiclt85 2>&1) > ./atmiclt-dom1.log
#(valgrind --leak-check=full --log-file="v.out" -v ./atmiclt85 2>&1) > ./atmiclt-dom1.log

RET=$?

if [[ "X$RET" != "X0" ]]; then
    go_out $RET
fi


# if poller is epoll very that priority actually works

POLLER=`xadmin poller`

if [[ "$POLLER" == "epoll" || "$POLLER" == "kqueue" ]]; then

    xadmin psc

    echo ">>> Benchmark the system, to check is test applicable"
    echo ">>>> Single process performance..."
    export NDRX_BENCH_FILE="perf1.log"
    export NDRX_BENCH_CONFIGNAME="results"
    exbenchcl -n1 -P  -t20 -b "{\"T_LONG_FLD\":5}" -f T_CARRAY_FLD -S1024

    echo ">>>> MT process performance..."
    export NDRX_BENCH_FILE="perf2.log"
    export NDRX_BENCH_CONFIGNAME="results"
    exbenchcl -n2 -P  -t20 -b "{\"T_LONG_FLD\":5}" -f T_CARRAY_FLD -S1024

    PERF1=`cat perf1.log | grep results | awk '{print $3}'`
    PERF2=`cat perf2.log | grep results | awk '{print $3}'`

    echo "Results: 1 x thread [$PERF1] 2 x thread [$PERF2]"

    # if MT is not faster than 20% of the single thread, then test cannot be run
    # i.e. we have 1x cpu, and due to scheduler, threads may be fully processed.
    # without any priority.
    let "PERF1 = PERF1 + (PERF1 / 4)"

    if [ $PERF2 -lt $PERF1 ]; then
        echo "Cannot continue - system too slow ($PERF2 < $PERF1) (increase vcpu count?)"
        go_out 0
    fi

    echo ">>> Default is lower"
    export NDRX_BENCH_FILE="bench.def.log"
    export NDRX_BENCH_CONFIGNAME="results"
    exbenchcl -n5 -P  -t20 -b "{\"T_LONG_FLD\":5}" -f T_CARRAY_FLD -S1024 &
    BENCHPIDDEF_PID=$!

    # event this is started later, it shall fill take a priority over...
    export NDRX_BENCH_FILE="bench.70.log"
    export NDRX_BENCH_CONFIGNAME="results"
    exbenchcl -n5 -P  -t20 -b "{\"T_LONG_FLD\":5}" -f T_CARRAY_FLD -S1024 -p 70 &
    BENCHPID70_PID=$!

    # wait for pids...
    wait $BENCHPIDDEF_PID
    wait $BENCHPID70_PID

    RESDEF=`cat bench.def.log | grep results | awk '{print $3}'`
    RES70=`cat bench.70.log | grep results | awk '{print $3}'`

    echo "[$RESDEF] vs [$RES70]"

    if [[ "X$RESDEF" == "X" || "X$RES70" == "X" ]]; then
        echo "Missing results"
        go_out 1
    fi

    if [[ "$RESDEF" -ge "$RES70" ]]; then
        echo "Priority does not work prio DEF processed $RESDEF (shall be <) prio 70 processed $RES70 (1)"
        go_out 1
    fi

    rm bench.def.log
    rm bench.70.log

    echo ">>> Default is higher"
    xadmin stop -y
    export NDRX_CONFIG=$TESTDIR/ndrxconfig-dom1_svcprio.xml
    xadmin start -y

    export NDRX_BENCH_FILE="bench.def.log"
    export NDRX_BENCH_CONFIGNAME="results"
    exbenchcl -n5 -P  -t20 -b "{\"T_LONG_FLD\":5}" -f T_CARRAY_FLD -S1024 &
    BENCHPIDDEF_PID=$!

    # event this is started later, it shall fill take a priority over...
    export NDRX_BENCH_FILE="bench.70.log"
    export NDRX_BENCH_CONFIGNAME="results"
    exbenchcl -n5 -P  -t20 -b "{\"T_LONG_FLD\":5}" -f T_CARRAY_FLD -S1024 -p 70 &
    BENCHPID70_PID=$!

    # wait for pids...
    wait $BENCHPIDDEF_PID
    wait $BENCHPID70_PID

    RESDEF=`cat bench.def.log | grep results | awk '{print $3}'`
    RES70=`cat bench.70.log | grep results | awk '{print $3}'`

    echo "[$RESDEF] vs [$RES70]"
{'fraction_non_alphanumeric': 0.17380097578937678, 'fraction_numerical': 0.03001012611617417, 'mean_word_length': 2.509043927648579, 'pattern_counts': {'":': 10, '<': 8, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6246560', 'n_tokens_mistral': 4021, 'n_tokens_neox': 3680, 'n_words': 1174}