dirs01.gms : Test search and processing of gamslice.txt and gamsconfig.yaml in user space

Description

This test places a bad license file below the working directory and sets enviornment variables
APPDATA (Windows), HOME (MacOS), and XDG_DATA_HOME (other Unix) to instruct the GAMS user data
location routines to pick up the license.

A similar test is done with good and bad gamsconfig.yaml to test the user configuration of GAMS
via gamsconfig.yaml files.

The test setup is complicated since the environment variables take effect at the start of GAMS
we cannot control this while GAMS is running. So this test script calls two more scripts (dirtest1
and dirtest2) which again call some GAMS scripts.

Contributors: Michael Bussieck, April 2020


Small Model of Type : GAMS


Category : GAMS Test library


Main file : dirs01.gms

$TITLE 'Test search and processing of gamslice.txt and gamsconfig.yaml in user space' (dirs01,SEQ=820)

$ontext
This test places a bad license file below the working directory and sets enviornment variables
APPDATA (Windows), HOME (MacOS), and XDG_DATA_HOME (other Unix) to instruct the GAMS user data 
location routines to pick up the license.

A similar test is done with good and bad gamsconfig.yaml to test the user configuration of GAMS
via gamsconfig.yaml files.

The test setup is complicated since the environment variables take effect at the start of GAMS
we cannot control this while GAMS is running. So this test script calls two more scripts (dirtest1 
and dirtest2) which again call some GAMS scripts.

Contributors: Michael Bussieck, April 2020
$offtext


* Do not run with GAMS Version prior to 31.0
$if not gamsversion 310 $exit

* For some calls an error is expected
$offCheckErrorLevel

* YAML file with bad syntax
$onEcho > 1.yaml
commandLineParameters:
  - eolCom:
      value: '//'
        maxVersion: 31
$offEcho
* YAML file with environment variable
$onEcho > 2.yaml
environmentVariables:
  - MYGAMSVAR:
      value: 1967
$offEcho
$onEchoV > checkev1.gms
$if not %sysEnv.MYGAMSVAR%==1967 $abort Expect system environment variable to be set to 1967. We actually have %sysEnv.MYGAMSVAR%
$offEcho
$onEchoV > checkev2.gms
$if %sysEnv.MYGAMSVAR%==1967 $abort Expect system environment variable not to be set to 1967.
$offEcho

$onEcho > 3.yaml
commandLineParameters:
  - --MYGAMSVAR:
      value: 1967
$offEcho
$onEchoV > checkdd1.gms
$if not %MYGAMSVAR%==1967 $abort Expect double dash variable to be set to 1967. We actually have %MYGAMSVAR%
$offEcho
$onEchoV > checkdd2.gms
$if %MYGAMSVAR%==1967 $abort Expect double dash variable not to be set to 1967.
$offEcho

$onEcho > 4.yaml
commandLineParameters:
  - LP:
      value: bdmlpd
$offEcho
$onEchoV > checkclp1.gms
$if not %gams.LP%==bdmlpd $abort Expect CLP LP to be set to bdmlpd. We actually have %gams.LP%
$offEcho
$onEchoV > checkclp2.gms
$if %gams.LP%==bdmlpd $abort Expect CLP LP not to be set to bdmlpd.
$offEcho

$ifThen %system.filesys%==UNIX
$  set sn gmsgenus.run
$  set en gmsgenux.out
$  set ln libcpxcclib64.so
$else
$  set sn gmsgennt.cmd
$  set en gmsgennx.exe
$  set ln cpxcclib64.dll
$endif
$if %system.platform%==WIN $set ln cpxcclib.dll
$if %system.platform%==DEX $set ln libcpxcclib64.dylib
$onEcho > 5.yaml
solverConfig:
- mycplex:
    fileType: 1011
    dictType: 5
    licCodes: CPCL
    defaultOkFlag: True
    hiddenFlag: False
    defName: optcplex.def
    scriptName: %sn%
    executableName: %en%
    library:
      libName: %ln%
      auditCode: cpx
      solverInterfaceType: 1
      threadSafeIndic: True
    modelTypes:
    - MIP
    - LP
$offEcho

$onechoV > dirtest1.gms
$set mkdir mkdir
$if %system.fileSys%==UNIX $set mkdir mkdir -p

*
* Create data directory
*
$ifThen %system.filesys%==UNIX
$  set userDataDir "%system.userDataDir%"
$else
$  set userDataDir "%sysEnv.APPDATA%GAMS\"
$endif
$if not dExist "%userDataDir%" $call %mkdir% "%userDataDir%"

*
* Check if we access a bad license in the userDataDir
*
$echo Bad License File > "%userDataDir%gamslice.txt"
$call.checkErrorLevel gamslib -q 1
$call gams trnsport lo 2 license "%userDataDir%gamslice.txt"
$ifE errorLevel<>7  $abort 'expected license failure (explicit)'
$call gams trnsport lo 2
$ifE errorLevel<>7  $abort 'expected license failure (implicit)'
$if     %system.filesys%==UNIX $call rm -rf "%userDataDir%"
$if not %system.filesys%==UNIX $call del /Q /S "%userDataDir%" > nul
$offecho

$ifThen %system.filesys%==UNIX
$  if     %system.platform%==DEX $call HOME=`pwd` gams dirtest1 lo=2
$  if not %system.platform%==DEX $call XDG_DATA_HOME=`pwd`/GAMS gams dirtest1 lo=2
$  ifE errorLevel<>0 $abort Failed dirtest1. Inspect dirtest1.lst/log 
$else
$  ifThen.Windows not exist "%system.userDataDir%gamslice.txt"
$    set APPDATA "%sysenv.APPDATA%"
$    setenv APPDATA "%gams.workDir%"
$    call gams dirtest1 lo=2
$    ifE errorLevel<>0 $abort Failed dirtest1. Inspect dirtest1.lst/log 
$    setenv APPDATA "%APPDATA%"
$  endif.Windows
$endIf

$onechoV > dirtest2.gms
$set mkdir mkdir
$if %system.fileSys%==UNIX $set mkdir mkdir -p

*
* Create config directory
*
$ifThen %system.filesys%==UNIX
$  set userConfigDir "%system.userConfigDir%"
$else
$  set userConfigDir "%sysEnv.LOCALAPPDATA%GAMS\"
$endif
$if not dExist "%userConfigDir%" $call %mkdir% "%userConfigDir%"

*
* Check if we complain if we access a badly formatted gamsconfig.yaml
*
$call.checkErrorLevel cp -f 1.yaml "%userConfigDir%gamsconfig.yaml"
$call.checkErrorLevel gamslib -q 1
$call gams trnsport lo 3 a=c > trnsport.log
$call.checkErrorLevel grep "Error: System problems in yaml_parser_parse:" trnsport.log > %system.nullFile%

*
* Check if we get an environment variable from gamsconfig.yaml
*
$call.checkErrorLevel cp -f 2.yaml "%userConfigDir%gamsconfig.yaml"
$call.checkErrorLevel gams checkev1 lo=3 > checkev1.log
*
* Check if version filtering works
*
$eval prevRelease %system.GamsRelease%-1
$echo '      maxVersion: %prevRelease%' >> "%userConfigDir%gamsconfig.yaml"
$call.checkErrorLevel gams checkev2 lo=3 > checkev.log

*
* Check if we get an double dash variable from gamsconfig.yaml
*
$call.checkErrorLevel cp -f 3.yaml "%userConfigDir%gamsconfig.yaml"
$call.checkErrorLevel gams checkdd1 lo=3 > checkdd1.log
*
* Check if version filtering works
*
$eval prevRelease %system.GamsRelease%-1
$echo '      maxVersion: %prevRelease%' >> "%userConfigDir%gamsconfig.yaml"
$call.checkErrorLevel gams checkdd2 lo=3 > checkdd2.log

*
* Check if we get regular CLP from gamsconfig.yaml
*
$call.checkErrorLevel cp -f 4.yaml "%userConfigDir%gamsconfig.yaml"
$call.checkErrorLevel gams checkclp1 lo=3 > checkclp1.log
*
* Check if version filtering works
*
$eval prevRelease %system.GamsRelease%-1
$echo '      maxVersion: %prevRelease%' >> "%userConfigDir%gamsconfig.yaml"
$call.checkErrorLevel gams checkclp2 lo=3 > checkclp2.log

*
* Check if we get MYCPLEX as solver from gamsconfig.yaml
*
$call.checkErrorLevel cp -f 5.yaml "%userConfigDir%gamsconfig.yaml"
$call.checkErrorLevel gamslib -q 1
$call.checkErrorLevel gams trnsport lo 3 lp=mycplex > trnsport.log
$call.checkErrorLevel grep "Executing MYCPLEX" trnsport.log > %system.nullFile%
*
* Check if version filtering works
*
$eval nextRelease %system.GamsRelease%+1
$echo '    minVersion: %nextRelease%' >> "%userConfigDir%gamsconfig.yaml"
$call gams trnsport lo 3 lp=mycplex > trnsport.log
$call.checkErrorLevel grep "Unknown solver name for LP=mycplex" trnsport.log > %system.nullFile%
$if     %system.filesys%==UNIX $call rm -rf "%userConfigDir%"
$if not %system.filesys%==UNIX $call del /Q /S "%userConfigDir%" > nul
$offecho

$ifThen %system.filesys%==UNIX
$  if     %system.platform%==DEX $call HOME=`pwd` gams dirtest2 lo=2
$  if not %system.platform%==DEX $call XDG_CONFIG_HOME=`pwd`/GAMS gams dirtest2 lo=2
$  ifE errorLevel<>0 $abort Failed dirtest2. Inspect dirtest2.lst/log 
$else
$  set LOCALAPPDATA "%sysenv.LOCALAPPDATA%"
$  setenv LOCALAPPDATA "%gams.workDir%"
$  call gams dirtest2 lo=2
$  ifE errorLevel<>0 $abort Failed dirtest2. Inspect dirtest2.lst/log 
$  setenv LOCALAPPDATA "%LOCALAPPDATA%"
$endIf