#!/bin/bash

. $TEST_ROOT_DIR/run-test-common

set -x

# This test case is to test CPPEvalClient works with the same setup of users. 
# For that purpose, the test needs to create the pre-trained model in the Examples directories as expected by CPPEvalExtendedClient.
# These files are removed by Jenkins during workspace cleanup.

# The eval test uses some pretrained models which are not part of the CNTK repository itself
# We use the dataset from an external location specified using an environment variable
if [[ -z "$CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY" || ! -d "$CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY" ]]; then
  echo This test uses external data that is not part of the CNTK repository. Environment variable CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY must be set to point to the external test data location.
  exit 1
fi

if [ "$OS" == "Windows_NT" ]; then
  TestDataDir=`cygpath -au $CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY`
else
  TestDataDir=$CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY
fi

ATISDir=$TEST_ROOT_DIR/../../Examples/LanguageUnderstanding/ATIS/BrainScript
DataDir=$ATISDir/../Data
OutputDir=$ATISDir/work
ConfigDir=$ATISDir

# Train model for evaluation
DeleteModelsAfterTest=0
[ -f $ConfigDir/ATIS.cntk ] || exit 1
cntkrun ATIS.cntk "stderr=- command=Train Train=[SGD=[maxEpochs=1]]" || exit $?

if [ "$OS" == "Windows_NT" ]; then
  $TEST_BIN_DIR/CPPEvalExtendedClientTest.exe
else
  $TEST_BIN_DIR/cppevalextendedclient
fi
ExitCode=$?

[ -d $ATISDir/work ] && rm -rf $ATISDir/work

exit $ExitCode