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
$  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% == DEG
$    call rm -f libexample64.dylib
$    log Building CPP library for platform DEG
$    call g++ -fPIC -fvisibility=hidden -dynamiclib -shared -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% == DAC
$    call rm -f libexample64.dylib
$    log Building CPP library for platform DAC
$    call clang++ -fPIC -fvisibility=hidden -dynamiclib -shared -Wall -Wno-deprecated -Wno-deprecated-declarations -o libexample64.dylib cppcclib.cpp cppcclibql.c -lm -ldl
$    ifThen.DAC NOT exist libexample64.dylib
$      log Example shared library libexample64.dylib not found: the build failed
$      abort Could not create example shared library for DAC
$    endIf.DAC
$    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% == 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.platform% == DEX    $funcLibIn myLib  libcppcclib64.dylib
$  if %system.platform% == DAX    $funcLibIn myLib  libcppcclib64.dylib
$  if %system.platform% == LEX    $funcLibIn myLib  libcppcclib64.so
$  if %system.platform% == WEX    $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%