cpplib00.gms : Test build of CPP library

Description

Test that the CPP library is buildable and that, once built, it
passes some simple tests.

Contributor: Steve

  if BUILDLIB not set, take a hint from quality.gms

     GHOST not set

  At this point, BUILDLIB is either NO or YES


Small Model of Type : GAMS


Category : GAMS Test library


Main file : cpplib00.gms

$Title Test build of CPP library (CPPLIB00,SEQ=657)

$ontext
Test that the CPP library is buildable and that, once built, it
passes some simple tests.

Contributor: Steve
$offtext
$ondollar

$ifthen NOT set BUILDLIB
* if BUILDLIB not set, take a hint from quality.gms
$  if set noComp  $set BUILDLIB NO
$endif

$ifthen NOT set BUILDLIB
$  escape &
$  ifthen.xx %sysenv.GHOST% == %&sysenv.GHOST%&
*    GHOST not set
$    set BUILDLIB NO
$  else.xx
$    set BUILDLIB YES
$    if %sysenv.GHOST% == XPTESTER            $set BUILDLIB NO
$    if %sysenv.GHOST% == Win8                $set BUILDLIB NO
$  endif.xx
$  escape %
$endif
$if NOT %BUILDLIB% == NO  $set BUILDLIB YES

* At this point, BUILDLIB is either NO or YES
$ifthen.bld  %BUILDLIB% == YES

$  ifthen.unzip exist cppcclib.cpp
$    log File cppcclib.cpp exists already: not unzipping cppsource.zip
$  else.unzip
$    call gmsunzip -o cppsource.zip
$  endif.unzip

$  ifthen %system.buildcode% == AIX
$    call rm -f libexample64.so
$    log Building CPP library for platform AIX
$    call xlC_r -q64 -o libexample64.so -G -brtl -bnoentry -b64 -bernotok -bexpall cppcclib.cpp cppcclibql.c -lm
$    ifthen.AIX NOT exist libexample64.so
$      log Example shared library libexample64.so not found: the build failed
$      abort Could not create example shared library for AIX
$    endif.AIX
$    funclibin myLib ./libexample64.so

$  elseif %system.buildcode% == DEG
$    call rm -f libexample64.dylib
$    log Building CPP library for platform DEG
$    call g++ -fPIC -fvisibility=hidden -dynamiclib -shared -m64 -Wall -o libexample64.dylib cppcclib.cpp cppcclibql.c -lm -ldl -lstdc++
$    ifthen.DEG NOT exist libexample64.dylib
$      log Example shared library libexample64.dylib not found: the build failed
$      abort Could not create example shared library for DEG
$    endif.DEG
$    funclibin myLib ./libexample64.dylib

$  elseif %system.buildcode% == LEG
$    call rm -f libexample64.so
$    log Building CPP library for platform LEG
$    call g++ -fPIC -nostartfiles -shared -Wl,-Bsymbolic -pthread -Wall -o libexample64.so cppcclib.cpp cppcclibql.c -m64 -lm -ldl -lstdc++
$    ifthen.LEG NOT exist libexample64.so
$      log Example shared library libexample64.so not found: the build failed
$      abort Could not create example shared library for LEG
$    endif.LEG
$    funclibin myLib ./libexample64.so

$  elseif %system.buildcode% == SIG
$    call rm -f libexample64.so
$    log Building CPP library for platform SIG
$    call g++ -fPIC -nostartfiles -shared -Wl,-Bsymbolic -pthread -Wall -o libexample64.so cppcclib.cpp cppcclibql.c -m64 -lm -ldl -lstdc++
$    ifthen.SIG NOT exist libexample64.so
$      log Example shared library libexample64.so not found: the build failed
$      abort Could not create example shared library for SIG
$    endif.SIG
$    funclibin myLib ./libexample64.so

$  elseif %system.buildcode% == SOX
$    call rm -f libexample64.so
$    log Building CPP library for platform SOX
$    call CC -xO5 -KPIC -G -Bsymbolic -o libexample64.so cppcclib.cpp cppcclibql.c -m64 -mt -lCrun -lrt -lm -ldl -lc
$    ifthen.SOX NOT exist libexample64.so
$      log Example shared library libexample64.so not found: the build failed
$      abort Could not create example shared library for SOX
$    endif.SOX
$    funclibin myLib ./libexample64.so

$  elseif %system.buildcode% == VS8
$    call rm -f example.dll
$    log Building CPP library for platform VS8
$    call cl.exe -nologo -O2 -EHsc -GR -D_CRT_DISABLE_PERFCRIT_LOCKS -D_CRT_SECURE_NO_WARNINGS -W3 -LD -Feexample.dll cppcclib.cpp cppcclibql.c -link -def:cppcclib.def
$    ifthen.VS8 NOT exist example.dll
$      log Example shared library example.dll not found: the build failed
$      abort Could not create example shared library for VS8
$    endif.VS8
$    funclibin myLib ./example.dll

$  elseif %system.buildcode% == WEI
$    call rm -f example64.dll
$    log Building CPP library for platform WEI
$    call icl.exe -nologo -O3 -D_CRT_DISABLE_PERFCRIT_LOCKS -D_CRT_SECURE_NO_WARNINGS -LD -Feexample64.dll cppcclib.cpp cppcclibql.c -link -nodefaultlib:libc.lib
$    ifthen.WEI NOT exist example64.dll
$      log Example shared library example64.dll not found: the build failed
$      abort Could not create example shared library for WEI
$    endif.WEI
$    funclibin myLib ./example64.dll

$  else
$    log No branch taken: test implementation is incomplete
$    abort No build commands found for platform %system.buildcode%: aborting

$  endif

$else.bld

$  if %system.buildcode% == AIX    $funclibin myLib  libcppcclib64.so
$  if %system.buildcode% == DEG    $funclibin myLib  libcppcclib64.dylib
$  if %system.buildcode% == LEG    $funclibin myLib  libcppcclib64.so
$  if %system.buildcode% == SIG    $funclibin myLib  libcppcclib64.so
$  if %system.buildcode% == SOX    $funclibin myLib  libcppcclib64.so
$  if %system.buildcode% == VS8    $funclibin myLib  cppcclib.dll
$  if %system.buildcode% == WEI    $funclibin myLib  cppcclib64.dll

$endif.bld

$if not errorfree $abort Error initializing extrinsic library myLib: aborting

function cdf1  'CDF of univariate normal' / myLib.cdfUVN /;

sets
  i / i1 * i5 /
  k / want, got /
  ;
parameter
  x(i) /
   i1  -50
   i2  -1
   i3  eps
   i4  1
   i5  50
  /,
  f_(i) /
   i1  eps
   i2  .1586552539314570
   i3  .5
   i4  .8413447460685429
   i5  1.0
  /,
  g_(i) /
   i1  eps
   i2  .2419707245191433
   i3  .3989422804014327
   i4  .2419707245191433
   i5  eps
  /,
  h_(i) /
   i1  eps
   i2   0.241970724519143
   i3  0
   i4  -0.241970724519143
   i5  eps
  /,
  v(i), d(i);

v(i) = cdf1(x(i)) + eps;
d(i) = abs(v(i)-f_(i));
abort$[smax{i, d(i)} > 1e-14] 'bad function values', d, v, f_;

v(i) = cdf1.grad(x(i)) + eps;
d(i) = abs(v(i)-g_(i));
abort$[smax{i, d(i)} > 1e-14] 'bad gradient values', d, v, g_;

v(i) = cdf1.hess(x(i)) + eps;
d(i) = abs(v(i)-h_(i));
abort$[smax{i, d(i)} > 1e-13] 'bad Hessian values', d, v, h_;

$log CPP Library test passed for platform %system.buildcode%