#!/bin/sh
#
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.

#
# Common configuration data for system tests, to be sourced into
# other shell scripts.
#

# For specific stuff (currently kill HUP -> rdnc reload in notify)
CYGWIN=1

# Find the top of the BIND9 tree.
TOP=${SYSTEMTESTTOP:=.}/../../..

# Make it absolute so that it continues to work after we cd.
TOP=`cd $TOP && pwd`

# Visual Studio build configurations are Release and Debug
VSCONF=Debug

# Default algorithm for testing
DEFAULT_ALGORITHM=ECDSAP256SHA256
DEFAULT_ALGORITHM_NUMBER=13
DEFAULT_BITS=256

# must be different from DEFAULT_ALGORITHM
ALTERNATIVE_ALGORITHM=RSASHA256
ALTERNATIVE_ALGORITHM_NUMBER=8
ALTERNATIVE_BITS=1280

ARPANAME=$TOP/Build/$VSCONF/arpaname@EXEEXT@
CDS=$TOP/Build/$VSCONF/dnssec-cds@EXEEXT@
CHECKCONF=$TOP/Build/$VSCONF/named-checkconf@EXEEXT@
CHECKDS="$PYTHON `cygpath -w $TOP/bin/python/dnssec-checkds.py`"
CHECKZONE=$TOP/Build/$VSCONF/named-checkzone@EXEEXT@
COVERAGE="$PYTHON `cygpath -w $TOP/bin/python/dnssec-coverage.py`"
DDNSCONFGEN=$TOP/Build/$VSCONF/ddns-confgen@EXEEXT@
DELV=$TOP/Build/$VSCONF/delv@EXEEXT@
DIG=$TOP/Build/$VSCONF/dig@EXEEXT@
DNSTAPREAD=$TOP/Build/$VSCONF/dnstap-read@EXEEXT@
DSFROMKEY=$TOP/Build/$VSCONF/dnssec-dsfromkey@EXEEXT@
FEATURETEST=$TOP/Build/$VSCONF/feature-test@EXEEXT@
FSTRM_CAPTURE=@FSTRM_CAPTURE@
IMPORTKEY=$TOP/Build/$VSCONF/dnssec-importkey@EXEEXT@
JOURNALPRINT=$TOP/Build/$VSCONF/named-journalprint@EXEEXT@
KEYFRLAB=$TOP/Build/$VSCONF/dnssec-keyfromlabel@EXEEXT@
KEYGEN=$TOP/Build/$VSCONF/dnssec-keygen@EXEEXT@
KEYMGR="$PYTHON `cygpath -w $TOP/bin/python/dnssec-keymgr.py`"
MDIG=$TOP/Build/$VSCONF/mdig@EXEEXT@
NAMED=$TOP/Build/$VSCONF/named@EXEEXT@
NSEC3HASH=$TOP/Build/$VSCONF/nsec3hash@EXEEXT@
NSLOOKUP=$TOP/Build/$VSCONF/nslookup@EXEEXT@
NSUPDATE=$TOP/Build/$VSCONF/nsupdate@EXEEXT@
NZD2NZF=$TOP/Build/$VSCONF/named-nzd2nzf@EXEEXT@
PK11DEL="$TOP/Build/$VSCONF/pkcs11-destroy@EXEEXT@ -s ${SLOT:-0} -p ${HSMPIN:-1234} -w 0"
PK11GEN="$TOP/Build/$VSCONF/pkcs11-keygen@EXEEXT@ -q -s ${SLOT:-0} -p ${HSMPIN:-1234}"
PK11LIST="$TOP/Build/$VSCONF/pkcs11-list@EXEEXT@ -s ${SLOT:-0} -p ${HSMPIN:-1234}"
RESOLVE=$TOP/lib/samples/resolve
REVOKE=$TOP/Build/$VSCONF/dnssec-revoke@EXEEXT@
RNDC=$TOP/Build/$VSCONF/rndc@EXEEXT@
RNDCCONFGEN=$TOP/Build/$VSCONF/rndc-confgen@EXEEXT@
RRCHECKER=$TOP/Build/$VSCONF/named-rrchecker@EXEEXT@
SAMPLEUPDATE=$TOP/Build/$VSCONF/update@EXEEXT@
SETTIME=$TOP/Build/$VSCONF/dnssec-settime@EXEEXT@
SIGNER=$TOP/Build/$VSCONF/dnssec-signzone@EXEEXT@
TSIGKEYGEN=$TOP/Build/$VSCONF/tsig-keygen@EXEEXT@
VERIFY=$TOP/Build/$VSCONF/dnssec-verify@EXEEXT@

# to port WIRETEST=$TOP/Build/$VSCONF/wire_test@EXEEXT@
WIRETEST=

BIGKEY=$TOP/Build/$VSCONF/bigkey@EXEEXT@
GENCHECK=$TOP/Build/$VSCONF/gencheck@EXEEXT@
KEYCREATE=$TOP/Build/$VSCONF/keycreate@EXEEXT@
KEYDELETE=$TOP/Build/$VSCONF/keydelete@EXEEXT@
MAKEJOURNAL=$TOP/Build/$VSCONF/makejournal@EXEEXT@
PIPEQUERIES=$TOP/Build/$VSCONF/pipequeries@EXEEXT@
# to port SAMPLEUPDATE=$TOP/lib/samples/sample-update

# we don't want a KRB5_CONFIG setting breaking the tests
KRB5_CONFIG=NUL

# The "stress" test is not run by default since it creates enough
# load on the machine to make it unusable to other users.
# The "dialup", "delzone", and "dupsigs" tests are also not run by
# default because they take a very long time to complete.
#
# List of tests that use ports 5300 and 9953.  For this reason, these must
# be run sequentially.
SEQUENTIALDIRS="ecdsa eddsa @PKCS11_TEST@ tkey"

# List of tests that use unique ports (other than 5300 and 9953). These
# tests can be run in parallel.
#
# XXX: Note that tests are not currently run in parallel on Windows, so it
# isn't strictly necessary to maintain these as separate lists in this file,
# but using the same variable names as in conf.sh.in may simplify keeping the
# lists in sync.
#
# XXX: removed logfileconfig as it doesn't currently work on windows.
PARALLELDIRS="acl additional addzone allow-query auth autosign \
	builtin cacheclean case catz cds chain \
	checkconf checknames checkzone \
	@CHECKDS@ @COVERAGE@ @KEYMGR@ \
	cookie database digdelv dlv dlz dlzexternal \
	dns64 dnssec @DNSTAP@ dscp dsdigest dyndb \
	ednscompliance emptyzones \
	fetchlimit filter-aaaa formerr forward \
	geoip glue idna inline integrity ixfr keepalive \
	legacy limits masterfile masterformat metadata mirror mkeys \
	names notify nslookup nsupdate nzd2nzf \
	padding pending pipelined qmin \
	reclimit redirect resolver rndc rootkeysentinel rpz rpzrecurse \
	rrchecker rrl rrsetorder rsabigexponent runtime \
	serve-stale sfcache smartsign sortlist \
	spf staticstub statistics statschannel stub synthfromdnssec \
	tcp tools tsig tsiggss ttl \
	unknown upforwd verify views wildcard \
	xfer xferquota zero zonechecks"

SUBDIRS="$SEQUENTIALDIRS $PARALLELDIRS"

#Things that are different on Windows
KILL="/bin/kill -f"
DIFF="diff --strip-trailing-cr"
DOS2UNIX=dos2unix
# No trailing period
TP=

# Configure is launched from native environment, but tests are run in Cygwin -
# so any detection is unreliable.
SHELL="/bin/bash -o igncr"
CURL=/usr/bin/curl
XMLLINT=/usr/bin/xmllint
PERL=/usr/bin/perl

#
# PsSuspend is part of PSTools and can be downloaded from
# https://download.sysinternals.com/files/PSTools.zip
#
PSSUSPEND=@PSSUSPEND@

PYTHON=@PYTHON@

#
# Determine if we support various optional features.
#
HAVEXMLSTATS=@XMLSTATS@
HAVEJSONSTATS=@JSONSTATS@
ZLIB=@ZLIB@
NZD=@NZD_TOOLS@

# copy_setports - Copy Configuration File and Replace Ports
# Unfortunately it has to be different on Windows.
#
# Convenience function to copy a configuration file, replacing the tokens
# QUERYPORT, CONTROLPORT and EXTRAPORT[1-8] with the values of the equivalent
# environment variables. (These values are set by "run.sh", which calls the
# scripts invoking this function.)
#
# Usage:
#   copy_setports infile outfile

copy_setports() {
    # The indirect method of handling the substitution of the PORT variables
    # (defining "atsign" then substituting for it in the "sed" statement) is
    # required because to prevent the "Configure" script (in the the
    # bin9/win32utils directory) replacing the the <at>PORT<at> substitution
    # tokens when it processes this file and produces conf.sh.
    atsign="@"
    sed -e "s/${atsign}PORT${atsign}/${PORT}/g" \
        -e "s/${atsign}EXTRAPORT1${atsign}/${EXTRAPORT1}/g" \
        -e "s/${atsign}EXTRAPORT2${atsign}/${EXTRAPORT2}/g" \
        -e "s/${atsign}EXTRAPORT3${atsign}/${EXTRAPORT3}/g" \
        -e "s/${atsign}EXTRAPORT4${atsign}/${EXTRAPORT4}/g" \
        -e "s/${atsign}EXTRAPORT5${atsign}/${EXTRAPORT5}/g" \
        -e "s/${atsign}EXTRAPORT6${atsign}/${EXTRAPORT6}/g" \
        -e "s/${atsign}EXTRAPORT7${atsign}/${EXTRAPORT7}/g" \
        -e "s/${atsign}EXTRAPORT8${atsign}/${EXTRAPORT8}/g" \
        -e "s/${atsign}CONTROLPORT${atsign}/${CONTROLPORT}/g" \
	-e "s/${atsign}DEFAULT_ALGORITHM${atsign}/${DEFAULT_ALGORITHM}/g" \
	-e "s/${atsign}DEFAULT_ALGORITHM_NUMBER${atsign}/${DEFAULT_ALGORITHM_NUMBER}/g" \
	-e "s/${atsign}DEFAULT_BITS${atsign}/${DEFAULT_BITS}/g" \
	-e "s/${atsign}ALTERNATIVE_ALGORITHM${atsign}/${ALTERNATIVE_ALGORITHM}/g" \
	-e "s/${atsign}ALTERNATIVE_ALGORITHM_NUMBER${atsign}/${ALTERNATIVE_ALGORITHM_NUMBER}/g" \
	-e "s/${atsign}ALTERNATIVE_BITS${atsign}/${ALTERNATIVE_BITS}/g" \
	$1 > $2
}

# The rest is shared between Windows and Unices
. $TOP/bin/tests/system/conf.sh.common
