datatest.gms : Driver for datalib tests of all sorts

Description

 


Category : GAMS Data Utilities library


Main file : datatest.gms   includes :  datatest.gms

$TITLE 'Driver for datalib tests of all sorts'

$eolcom //
$version 1

$set SLASH     \
$if %system.filesys% == UNIX $set SLASH /
$if not set PREFIX $set PREFIX %system.buildcode%

$if not set FAIL $set ALL all_data.gms
$if     set FAIL $set ALL all_data.tmp
$if not set FAIL $set FAIL failures_data.gms

$set GAMSlo %GAMS.lo%
$if %GAMS.ide% == 1 $set GAMSlo 2

$set FLAGS lo=%GAMSlo%
$if %DEMOSIZE% == 1 $set FLAGS --DEMOSIZE=1 %FLAGS%

$hidden When adding models we need to update this file at a few
$hidden spots:
$hidden   1. Add the model name (in order) to the set m
$hidden   2. Consider if the model should be in ignore(m), i.e. not
$hidden      run as part of datatest
$hidden   3. Consider if the model should be in winOnly(m), i.e. not
$hidden      run if we are not on Windows
set m   'model names in alphabetic order' /
A
B
C
CheckListbox               'Multiple ask popups for entering values through listboxes or checklistboxes'
CHP                        'Optimize combined heat and power generation in Excel, using vba API (gamsx and opt) and GDXXRW'
CHP2                       'Optimize combined heat and power generation in Excel, using vba API (gamsx, opt and gdx)'
Combobox                   'Multiple ask popups for entering values through comboboxes'
CompTimeWriteTrnsportGDX   'Writes data to GDX file during compile time'
csv2gdx1                   'Test gdxdump and csv2gdx'
D
dBASE                      'Reads a dBASE table from United Nations Statistics Division'
DBTimestamp1               'Retrieve data from database once each day'
DBTimestamp2               'Retrieves data from database once each day'
Distances1                 'Single-valued tables'
Distances2                 'Single-valued tables'
E
embeddedSort               'Sorting of numerical data using the embedded code facility'
embeddedSplit              'Splitting of labels using the embedded code facility'
embeddedMultiInstance      'Handling multiple instances of the embedded code facility at once'
Excel                      'Reads data from Excel through ODBC'
ExecTimeReadTrnsportGDX    'Reads data from a GDX file during execution time'
F
Fileopenbox                'Ask popup for opening a file'
Filesavebox                'Ask popup for saving a file'
G
GDXCOPYExample19           'Copies a GDX file to a compressed format for version 6'
GDXDIFFExample16           'Compares two GDX files and writes the difference to a third GDX file'
GDXDUMPExample15           'Generates first a GDX file and then lists symbols in the GDX file'
GDXExecute_unloadExample4  'Writes data to GDX file during execution time'
GDXINExample1              'Illustrates use of demand data from an external source in compile phase'
GDXINExample2              'Illustrates use of demand and market data from an external source in compile phase'
GDXINExample3              'Lists all the symbols in Trnsport.gdx in the listing file in compile phase'
GDXMERGEExample17          'Merges a number of GDX files into one'
gdxmrw_ext01_init          'Extended use of GDXMRW'
gdxmrw_intro01_init        'Introduction to data transfer between Matlab and GAMS'
gdxmrw_intro02_init        'Introduction to calling GAMS from Matlab'
gdxmrw_irgdx01_init        'Reading data from a indexed GDX file with IRGDX'
gdxmrw_iwgdx01_init        'Writing data into a indexed GDX file with IWGDX'
gdxmrw_qp1                 'Portfolio Analysis with Matlab & GAMS'
gdxmrw_qp1_starter         'Portfolio Analysis with Matlab & GAMS (starter)'
gdxmrw_qp2                 'Portfolio Analysis with Matlab & GAMS'
gdxmrw_qp2_starter         'Portfolio Analysis with Matlab & GAMS (starter)'
gdxmrw_qp3                 'QP solver M-file using GAMS and GDXMRW'
gdxmrw_rgdx01_init         'Reading data from a GDX file into a structure with RGDX'
gdxmrw_tr1                 'Transport LP with non-indexed GDX data interface'
gdxmrw_tr2                 'Transport LP with indexed GDX data interface'
gdxmrw_tr3                 'LP with data from GDXMRW - canonical LP form'
gdxmrw_tr4                 'LP with sets and params from GDXMRW - no UELs'
gdxmrw_tr5                 'LP with sets and params from GDXMRW - nice UELs'
gdxmrw_wgdx01_init         'Writing structured data into a GDX file with WGDX'
GDXMRWPlotting01           'Packages GDXMRW data plotting examples'
GDXMRWShowJac1             'Visualize model Jacobian in Matlab'
GDXRANKExample18           'Sorts a parameter, creates a sorted version and verifies that the sort works correctly'
GDXViewerExample           'Illustrates conversion of GDX data into different formats'
GDXXRW_AUTOOPEN            'Tests that gdxxrw calls the auto_open macro facility'
GDXXRWExample10            'Reads a number of parameters and sets using the index option from an MS Excel file and writes it to a GDX file'
GDXXRWExample11a           'Generates a GDX file and writes it to an MS Excel file at compile time'
GDXXRWExample11b           'Generates a GDX file and writes it to an MS Excel file at execution time'
GDXXRWExample12            'Illustrates the use of merge and clear option'
GDXXRWExample13            'Reads a table from an MS Excel file, manipulates data and writes it to first a GDX file and then to the MS Excel file'
GDXXRWExample14            'This example illustrates reading from and writing to an MS Excel file using a modified version of trnsport.gms'
GDXXRWExample15            'Write spreadsheet using a filter'
GDXXRWExample16            'Write spreadsheet using text and hyperlinks'
GDXXRWExample5             'Reads a two dimensional parameter from an MS Excel file and writes it to a GDX file'
GDXXRWExample6             'Reads a two dimensional parameter from an MS Excel file and writes it to a GDX file'
GDXXRWExample7             'Reads a four dimensional parameter from an MS Excel file and writes it to a GDX file'
GDXXRWExample8             'Reads a parameter with special values from an MS Excel file and writes it to a GDX file'
GDXXRWExample9             "Reads a set using 'values' option from an MS Excel file and writes it to a GDX file"
H
I
IndexMapping1              'Index mapping in GAMS code'
IndexMapping2              'Index mapping in MS Access'
IndexMapping3              'Index mapping in GAMS code'
IndexMapping4              'Index mapping in MS Access'
invert1                    'Matrix inversion via R'
invert2                    'Matrix inversion via Matlab'
J
K
L
Loadpoint                  'Illustrates use of "execute_loadpoint" command'
M
MDB2GDX1                   'Creates a GDX file in execution time and displays it in GDXVIEWER'
MDB2GDX2                   'Creates a GDX file in compile time'
MDB2GMS                    'Runs MDB2GMS interactively'
MDBSr5                     'Sequence of GAMS models using save/restart facility'
MultipleAsk                'Multiple ask popups for entering various data types'
N
O
P
PopulateV                  'Creates MS Access database'
Portfolio                  'Determines an efficient frontier in Excel, using the GDX DLL (vba API) and the GAMS executable'
Q
R
RadioButton                'Multiple ask popups for entering values through radio buttons'
readdata                   'Read data from .inc, .xls, .mdb and .csv file'
ReadMultiDimPar            'Reads a multidimensional parameter'
ReadMultiRange             'Reads a multi-area range and does post processing to eliminate invalid entries'
ReadSet                    'Reads set data'
ReadTrnsportData1          'Reads set data and the table of the transportation model in several calls'
ReadTrnsportData2          'Reads set data and the table of the transportation model in one call'
S
SalesProfitDB1             'Single-valued tables'
SalesProfitDB2c            'Use of UNION to read multi-data column tables'
SalesProfitDB2m            'Use of UNION to read multi-data column tables'
SalesProfitDB3             'Multiple queries in one call'
SalesProfitDB4             'Multiple queries in one call'
SalesProfitDB5             'Use of UNION to read multi-data column tables'
SalesProfitDB6             'Multiple queries in one call'
SalesProfitDB7             'Multiple queries in one call'
Samurai                    'Solve a Samurai Sudoku in Excel, using the GDX DLL (vba API) and the GAMS executable'
Samurai2                   'Solve a Samurai Sudoku in Excel, using the GDX and GAMSX DLL (vba API)'
Savepoint                  'Saves solution to a log or GDX file'
SingleAsk                  'Single ask popup for entering an integer value'
SpawnGAMSAccess            'Spawn GAMS from Access'
SpawnGAMSExcel             'Spawn an arbitrary GAMS model from Excel'
SQL2GDX1                   'Creates a GDX file in execution time and displays it in GDXVIEWER'
SQL2GDX2                   'Creates a GDX file in compile time'
SQL2GMS                    'Runs SQL2GMS interactively'
SQLServer                  'Test timeouts against SQL Server'
SQLSr5                     'Sequence of GAMS models using save/restart facility'
Sudoku                     'Solve a Sudoku in Excel, using the GDX DLL (vba API) and the GAMS executable'
T
Text                       'Reads table from a text file using the ODBC Text Driver'
tompivot                   'Little GAMS Program from Tom Rutherford that Illustrates Report Generation with Excel'
transxls                   'Solve classical transportation problem in Excel, using vba API (gamsx, opt and gdx)'
triobal                    'Tommasino-Rao Input Output Balance Software'
TrnsxcllStarter            'Trnsxcll: Excel Spreadsheet in Charge of GAMS'
tsvngdx                    'Integrate gdxdiff with TortoiseSVN'
U
V
W
Wiring                     'Use of wiring option to read multi-data column tables'
X
Y
Z
     /

letters(m) / a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z /

$if not set TEST $goto alltest
SET runtests(m) / %TEST% /;
$if errorfree $goto TEST_OK
$clearerror
$log The test model(s) specified (--TEST=%TEST%) are not all valid
$abort

$label alltest
SET runtests(m);
runtests(m)$(not letters(m)) = yes;
$label TEST_OK

Set ignore(m)  /
  CheckListbox     'model shows only the use of listbox and checklistbox'
  CHP              'model opens interactive spreadsheet in excel'
  CHP2             'model opens interactive spreadsheet in excel'
  Combobox         'model shows only the use of combobox'
  Fileopenbox      'model shows only the use of fileopenbox'
  Filesavebox      'model shows only the use of filesavebox'
  GDXViewerExample 'model shows only the use of the GDX viewer'
  gdxmrw_ext01_init     'example requires Matlab'
  gdxmrw_intro01_init   'example requires Matlab'
  gdxmrw_intro02_init   'example requires Matlab'
  gdxmrw_irgdx01_init   'example requires Matlab'
  gdxmrw_iwgdx01_init   'example requires Matlab'
  gdxmrw_qp1            'example requires Matlab'
  gdxmrw_qp1_starter    'example requires Matlab'
  gdxmrw_qp2            'example requires Matlab'
  gdxmrw_qp2_starter    'example requires Matlab'
  gdxmrw_qp3            'example requires Matlab'
  gdxmrw_rgdx01_init    'example requires Matlab'
  gdxmrw_tr1            'example requires Matlab'
  gdxmrw_tr2            'example requires Matlab'
  gdxmrw_tr3            'example requires Matlab'
  gdxmrw_tr4            'example requires Matlab'
  gdxmrw_tr5            'example requires Matlab'
  gdxmrw_wgdx01_init    'example requires Matlab'
  GDXMRWPlotting01 'model just a placeholder for GDXMRW examples, requires Matlab'
  GDXMRWShowJac1   'model requires Matlab'
  invert1          'example requires R'
  invert2          'example requires Matlab'
  MDB2GDX1         'model has a gdx viewer call'
  MDB2GMS          'model has an ask call'
  MultipleAsk      'model has several ask calls'
  PopulateV        'model has an Access call'
  Portfolio        'model opens interactive spreadsheet'
  RadioButton      'model has two ask calls'
  SalesProfitDB4   'model has a gdx viewer call'
  SalesProfitDB7   'model has a gdx viewer call'
  Samurai          'model opens interactive spreadsheet'
  Samurai2         'model opens interactive spreadsheet'
  SingleAsk        'model has an ask call'
  SpawnGAMSAccess  'model opens interactive spreadsheet'
  SpawnGAMSExcel   'model opens interactive spreadsheet'
  SQL2GDX1         'model has a gdx viewer call'
  SQL2GMS          'model has an ask call'
  SQLServer        'model has an SQL server call'
  Sudoku           'model opens interactive spreadsheet'
  transxls         'model opens interactive spreadsheet'
  triobal          'model opens interactive spreadsheet'
  tsvngdx          'model needs two gdx files as input and uses WinMerge'
  TrnsxcllStarter  'model opens interactive spreadsheet'
  /;

Set WinOnly(m)  /
  SingleAsk,    MultipleAsk,
  RadioButton,  CheckListbox,   Combobox,       Fileopenbox,    Filesavebox,
  GDXXRW_AUTOOPEN
  GDXXRWExample5  *GDXXRWExample10,
  GDXXRWExample11a,GDXXRWExample11b,
  GDXXRWExample12 *GDXXRWExample16,
  Distances1,   Distances2,
  SalesProfitDB1,SalesProfitDB2c,SalesProfitDB2m,SalesProfitDB3*SalesProfitDB7,
  DBTimestamp1, DBTimestamp2,
  IndexMapping1*IndexMapping4,
  MDB2GMS,      MDBSr5,         MDB2GDX1,       MDB2GDX2,
  Wiring,       PopulateV,
  SQL2GMS,      SQLSr5,         SQL2GDX1,       SQL2GDX2,       SQLServer,
  Excel,        Text,           dBASE,          ReadSet,        readdata
  ReadTrnsportData1,ReadTrnsportData2,ReadMultiDimPar,ReadMultiRange,
  GDXViewerExample,
  Sudoku,       Samurai,        Samurai2,       CHP,            CHP2,
  Portfolio,    transxls,       tsvngdx,        tompivot,       TrnsxcllStarter
  /;

$onempty
set mdlstdoutskip(m) 'skips for stdout check' /
  GDXDUMPExample15   'demonstrates simple use of gdxdump, writes to stdout'
/;
set mdlstderrskip(m) 'skips for stderr check' /
/;
$offempty

$if %system.filesys% == UNIX ignore(WinOnly) = yes;

scalar
  rc     / 0 /
  tot    / 0 /,
  err    / 0 /,
  stderr / 0 /,
  stdout / 0 /,
  cnt    / 0 /;

file oneTest  / 'onetest.gms' /         //Getting test from testlib and executing test
     stdTest  / 'stdtest.gms' /         //Checking if stderr and stdout are empty
     allTests / '%ALL%'  /
     ferr / '%FAIL%' /
     rmme / 'rmme.gms'  /
     log  / ''          /
     fx;

$if %ALL% == all_data.gms putclose allTests '* These are the tests we ran' /;
$if %FAIL% == failures_data.gms putclose ferr '* These are the tests that failed' /;

putclose rmme '* Delete all directories of tests without problems' /;
allTests.ap = 1;
ferr.ap = 1;
rmme.ap = 1;

$if not set DIRNAME $set DIRNAME "'%PREFIX%_data_' m.tl:0 "

loop(runtests(m)$(not ignore(m)),
  cnt = cnt + 1;
  tot = tot + 1;
  put_utility fx 'shell' / 'rm -rf ' %DIRNAME%;
  put_utility fx 'shell' / 'mkdir ' %DIRNAME%;
  put oneTest
     '$call datalib -q ' m.tl:0
   / '$if errorlevel 1 $abort'
   / '$call =gams ' m.tl:0 ' %FLAGS%';
  putclose oneTest
   / '$if errorlevel 1 $set err 1'
   / '$if set err scalar err /%err%/'
   / "$if %err% == 1 $abort 'Problem'";
  put_utility fx 'log' / 'Calling ' m.tl:0;
  put_utility fx 'shell' / 'mv -f onetest.gms ' %DIRNAME% ' && cd ' %DIRNAME% ' && gams onetest lo=%GAMS.lo% --err=0 gdx=..%SLASH%err > stdout.txt 2>stderr.txt'; rc=1; execute_load 'err' rc=err;
  putclose stdTest                                                                                          //Checking if stderr and stdout are empty
     '$call =test -s ' %DIRNAME% '%SLASH%stderr.txt'
   / '$if errorlevel 1 $set stderr 0'
   / '$if set stderr scalar stderr /%stderr%/'
   / '$call =test -s ' %DIRNAME% '%SLASH%stdout.txt'
   / '$if errorlevel 1 $set stdout 0'
   / '$if set stdout scalar stdout /%stdout%/'
  execute 'gams stdtest.gms lo=2 --stderr=1 --stdout=1 gdx=std'; stderr=1; stdout=1; execute_load 'std' stderr,stdout;
  put allTests;
  put '$call =gams datatest %FLAGS% --fail=failures_data.tmp --test=' m.tl:0 ' ';
  if {rc,     put '--ftrace=1 '};
  if {stderr and not mdlstderrskip(m), put '--fstderr=1 '};
  if {stdout and not mdlstdoutskip(m), put '--fstdout=1 '};
  putclose allTests '--dir='%DIRNAME% /;
  if {(rc or (stderr and not mdlstderrskip(m)) or (stdout) and not mdlstdoutskip(m)),
    err = err + 1;
    put ferr;                                                                                         // failure_data.gms
    put '$call =gams datatest %FLAGS% --fail=failures_data.tmp --test=' m.tl:0 ' ';                   // --fail defines alternative failures file
    if {rc,     put '--ftrace=1 '};                                                                   // execution error
    if {stderr and not mdlstderrskip(m), put '--fstderr=1 '};                                      // writing to standard error
    if {stdout and not mdlstdoutskip(m), put '--fstdout=1 '};                                      // writing to standard output
    putclose ferr '--dir='%DIRNAME% /;                                                        // name of kept directory
  else
    putclose rmme '$call rm -rf ' %DIRNAME% /;
  };
  if(cnt=5,
    execute "=gams rmme lo=0";
    cnt = 0;
    execute "echo '* Delete all directories of tests without problems' > rmme.gms";
  );
);

execute "=gams rmme lo=0";

putclose oneTest '*Total tests: ', tot:0:0, '  Failed tests: ', err:0:0 ;
$if %FAIL% == failures_data.gms execute 'cat onetest.gms >> %FAIL%'

execute 'rm -f rmme.* err.gdx std.gdx onetest.gms stdtest.*';

put log;
if {(err > 0),
  put 'There were errors: ', err:0:0, ' out of ',
       tot:0:0, ' tests failed.' /;
  put 'See the file failures_data.gms to reproduce the failed runs'/;
  put 'You have some failures. See failures_data.gms for details.';
else
  put 'Congratulations!  All ', tot:0:0, ' tests passed.'/;
};

put 'See the file %ALL%.gms to reproduce all the runs'/;