! Tests the SYSTEM command
!
! Version: $Id: test_system.mm,v 1.11 2015/12/22 16:48:20 ntn Exp $
!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  invoke use=nxm.sys.lib.Native.getUse() canUseNativeIO=use.contains("|IO|")
  ! test_disk requires Native code to run
  if canUseNativeIO then
    call test_disk
  else
    info "skipping disk statistics test since Native code is not enabled."
  endif

  ! FUNC: MONITOR/MEMORY & MONITOR/THREADS are tested under %test_profiler

if interAct then
! TODO write test cases for other functions:
! 1. THREADS (requires interactive verification of output)
! 2. TOP (does NOT work under Windows, also interactive)

!JC4: Disabled interactive test since it was confusing.
!  set my3000file "temp_test_system"
!  set defaultStat "DISK"
!  pipe init
!    panel/msgid=MAIN/setup/controls=gc
!    system/pause=2.0 defaultStat file=my3000file
!    list/poll=2.0 my3000file
!
!    gcontrol label macro "MACRO"
!    gcontrol menu main "Exit with Status = " "PASS,FAIL" "PASS" /tleft
!    set gc.main.itemColors {PASS=GREEN,FAIL=RED}
!    set instructions "todo: write test instructions here..."
!    gcontrol text idtext "Instructions" "^instructions" 24 8 /title
!
!    gcontrol choice "STATTYPE" "Statistic Type" reg.SYSTEM.statsList defaultStat
!  pipe off
endif

endmacro

!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: Interactive tests" msg.data eqss "PASS"
    pipe stop
  endif
return

!******************************************************************************!
! test FUNC=DISK (statistics)
! Currently requires Native code
!******************************************************************************!
procedure test_disk
  if baseline then
    aux/store
    ! to test BUG 2233 (AUX.9 must be "ramd:..." ICE RamDisk )
    set haveRamdAUX9 test(aux.9,eqss,"ramd:")
    if haveRamdAUX9 isTrue then
      aux ,, +9
    else
      info "Unable to test BUG 2233, no 'ramd:..' at AUX=9"
    endif

    sedit opt.path index SELECT "ICE"
    if index ge 0 then
      ! to test BUG 2233 (need to remove ICE option tree from path)
      res origPath opt.path
      path remove ICE
    endif
  endif

  set testfile3000 "ram:temp_test_system"
  info "!!!!! It is ok to see a warning below for 'Unable to get disk statistics for path=ramd:...' !!!!!"
  system func="DISK" table=diskstats file=testfile3000

  sedit aux.read readAuxSize nelem "|"
  assert/text="^reg.main.name: disk statistics output Table results exists" diskstats rexists
  assert/text="^reg.main.name: disk statistics output Table size == ^readAuxSize (Read Aux Size)" readAuxSize eq diskstats.getsize

  assert/text="^reg.main.name: disk statistics output file exists" testfile3000 fexists
  status testfile3000 type=type size=size numberSubRecords=numSubRec
  assert/text="^reg.main.name: disk statistics output file is type 3000" type eq 3000
  assert/text="^reg.main.name: disk statistics output file size > 0" size gt 0
  assert/text="^reg.main.name: disk statistics output file numSubRecords == ^readAuxSize (Read Aux Size)" numSubRec eq ^readAuxSize

  if baseline then
    aux/restore
    if origPath rexists then
      path set ^origPath
    endif
  endif
return
