home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.pdx.edu / 2014.02.ftp.ee.pdx.edu.tar / ftp.ee.pdx.edu / pub / users / Harry / Blitz / version-1-0 / OSProject / p6 / TestProgram1.c < prev    next >
Text File  |  2006-05-09  |  9KB  |  253 lines

  1. code TestProgram1
  2.  
  3. -----------------------------  TestProgram1  ---------------------------------
  4.  
  5.   const
  6.     FILENAME = "MyFileName"
  7.     NAME_OF_PROGRAM2 = "TestProgram2"
  8.  
  9.   var 
  10.     buff: array [10] of char = new array of char { 10 of 'x' }
  11.     arr1: array [10000] of char = new array of char { 10000 of '?' }
  12.  
  13.   function main ()
  14.     --
  15.     -- This program is used to make sure parameters can be passed to and from
  16.     -- the kernel during the syscalls.  It is also used to test the "Exec" syscall.
  17.     --
  18.       print ("User-level program 'TestProgram1' is running...\n")
  19.       TestSyscallParameterPassing ()
  20.       TestExec ()
  21.       Sys_Shutdown ()
  22.     endFunction
  23.  
  24. ------------------------  TestSyscallParameterPassing  ----------------------------
  25.  
  26.   function TestSyscallParameterPassing ()
  27.     --
  28.     -- This function calls each of the kernel functions.  Arguments are passed
  29.     -- to the kernel function to make sure that the syscall mechanism is working
  30.     -- properly and that arguments can be passed and results returned.  However,
  31.     -- the arguments that are passed are meaningless values.
  32.     --
  33.     -- This function contains a lot of print statements, designed to make
  34.     -- the output easier to check.
  35.     --
  36.       var i: int
  37.           fileNamePtr: String
  38.  
  39.       print ("\n***** Testing Syscall Parameter Passing *****\n")
  40.  
  41.       -- The array "arr1" is so big it must contain a page boundary.  Find
  42.       -- a page boundary within arr1 and set p to point 8 bytes before it.
  43.       i = (& arr1[9900]) asInteger
  44.       i = (i & 0xffffe000) - 8
  45.  
  46.       -- Copy string plus length so that the characters cross the page boundary.
  47.       MemoryCopy (i, FILENAME asInteger, FILENAME arraySize+4)
  48.  
  49.       -- Set "fileNamePtr" to point the string "MyFileName", which happens to
  50.       -- cross a page boundary.
  51.       fileNamePtr = i asPtrTo array of char
  52.  
  53.       print ("\n***** About to call Sys_Yield...\n")
  54.       print ("***** Should print:\n")
  55.       print ("*****     Handle_Sys_Yield invoked!\n\n")
  56.  
  57.       Sys_Yield ()
  58.  
  59.       print ("\n***** About to call Sys_Fork...\n")
  60.       print ("***** Should print:\n")
  61.       print ("*****     Handle_Sys_Fork invoked!\n\n")
  62.  
  63.       i = Sys_Fork ()
  64.       if i != 1000
  65.         print ("\n*************** ERROR: Bad return value from Sys_Fork\n")
  66.         printIntVar ("  return value", i)
  67.       endIf
  68.  
  69.       print ("\n***** About to call Sys_Join...\n")
  70.       print ("***** Should print:\n")
  71.       print ("*****     Handle_Sys_Join invoked!\n")
  72.       print ("*****     processID = 1111\n\n")
  73.  
  74.       i = Sys_Join (1111) 
  75.       if i != 2000
  76.         print ("\n*************** ERROR: Bad return value from Sys_Join\n")
  77.         printIntVar ("  return value", i)
  78.       endIf
  79.  
  80. -- The following code can be used to make sure you are getting the right
  81. -- arguments to Handle_Sys_Exec, but this code will not work properly
  82. -- once you have implemented Handle_Sys_Exec
  83.  
  84. /*
  85.       print ("\n***** About to call Sys_Exec...\n")
  86.       print ("***** Should print:\n")
  87.       print ("*****     Handle_Sys_Exec invoked!\n")
  88.       print ("*****     virt addr of filename = 0x0000BFF8\n")
  89.       print ("*****     filename = MyFileName\n\n")
  90.  
  91.       i = Sys_Exec (fileNamePtr)
  92.       if i != 3000
  93.         print ("\n*************** ERROR: Bad return value from Sys_Exec\n")
  94.         printIntVar ("  return value", i)
  95.       endIf
  96. */
  97.  
  98.       print ("\n***** About to call Sys_Create...\n")
  99.       print ("***** Should print:\n")
  100.       print ("*****     Handle_Sys_Create invoked!\n")
  101.       print ("*****     virt addr of filename = 0x0000BFF8\n")
  102.       print ("*****     filename = MyFileName\n\n")
  103.  
  104.       i = Sys_Create (fileNamePtr)
  105.       if i != 4000
  106.         print ("\n*************** ERROR: Bad return value from Sys_Create\n")
  107.         printIntVar ("  return value", i)
  108.       endIf
  109.  
  110.       print ("\n***** About to call Sys_Open...\n")
  111.       print ("***** Should print:\n")
  112.       print ("*****     Handle_Sys_Open invoked!\n")
  113.       print ("*****     virt addr of filename = 0x0000BFF8\n")
  114.       print ("*****     filename = MyFileName\n\n")
  115.  
  116.       i = Sys_Open (fileNamePtr)
  117.       if i != 5000
  118.         print ("\n*************** ERROR: Bad return value from Sys_Open\n")
  119.         printIntVar ("  return value", i)
  120.       endIf
  121.  
  122.       print ("\n***** About to call Sys_Read...\n")
  123.       print ("***** Should print:\n")
  124.       print ("*****     Handle_Sys_Read invoked!\n")
  125.       print ("*****     fileDesc = 2222\n")
  126.       print ("*****     virt addr of buffer = 0x0000B0A8\n")
  127.       print ("*****     sizeInBytes = 3333\n\n")
  128.  
  129.       i = Sys_Read (2222, &buff[0], 3333)
  130.       if i != 6000
  131.         print ("\n*************** ERROR: Bad return value from Sys_Read\n")
  132.         printIntVar ("  return value", i)
  133.       endIf
  134.  
  135.       print ("\n***** About to call Sys_Write...\n")
  136.       print ("***** Should print:\n")
  137.       print ("*****     Handle_Sys_Write invoked!\n")
  138.       print ("*****     fileDesc = 4444\n")
  139.       print ("*****     virt addr of buffer = 0x0000B0A8\n")
  140.       print ("*****     sizeInBytes = 5555\n\n")
  141.  
  142.       i = Sys_Write (4444, &buff[0], 5555)
  143.       if i != 7000
  144.         print ("\n*************** ERROR: Bad return value from Sys_Write\n")
  145.         printIntVar ("  return value", i)
  146.       endIf
  147.  
  148.       print ("\n***** About to call Sys_Seek...\n")
  149.       print ("***** Should print:\n")
  150.       print ("*****     Handle_Sys_Seek invoked!\n")
  151.       print ("*****     fileDesc = 6666\n")
  152.       print ("*****     newCurrentPos = 7777\n\n")
  153.  
  154.       i = Sys_Seek (6666, 7777)
  155.       if i != 8000
  156.         print ("\n*************** ERROR: Bad return value from Sys_Seek\n")
  157.         printIntVar ("  return value", i)
  158.       endIf
  159.  
  160.       print ("\n***** About to call Sys_Close...\n")
  161.       print ("***** Should print:\n")
  162.       print ("*****     Handle_Sys_Close invoked!\n")
  163.       print ("*****     fileDesc = 8888\n\n")
  164.  
  165.       Sys_Close (8888)
  166.  
  167.       print ("\n***** About to call Sys_Exit...\n")
  168.       print ("***** Should print:\n")
  169.       print ("*****     Handle_Sys_Exit invoked!\n")
  170.       print ("*****     returnStatus = 9999\n\n")
  171.  
  172.       Sys_Exit (9999)
  173.  
  174. -- The following code can be used to make sure you are invoking
  175. -- Handle_Sys_Shutdown properly, but this code will prematurely terminate
  176. -- the tests, once you have implemented Handle_Sys_Shutdown.
  177.  
  178. /*
  179.       print ("\n***** About to call Sys_Shutdown...\n")
  180.       print ("***** Should print:\n")
  181.       print ("*****     FATAL ERROR in UserProgram: \"Syscall 'Shutdown' was invoked by a user thread\" -- TERMINATING!\n")
  182.  
  183.       Sys_Shutdown ()
  184.  
  185.       print ("\n*************** ERROR: Execution should not continue after Shutdown\n")
  186. */
  187.  
  188.       print ("\n***** Syscall Test Complete *****\n")
  189.  
  190.     endFunction
  191.  
  192. -----------------------------  TestExec  ---------------------------------
  193.  
  194.   function TestExec ()
  195.     --
  196.     -- This function is used to test the "Exec" syscall.  It will execute an
  197.     -- Exec syscall.  If there are no errors, it should not return.  If there
  198.     -- are errors, it will print the error code and the invoke the "Shutdown"
  199.     -- syscall.
  200.     --
  201.       var i: int
  202.           fileNamePtr: String
  203.  
  204.       print ("\n***** Testing Exec Syscall *****\n")
  205.  
  206.       print ("\n***** About to call Sys_Exec with a non-existant file...\n")
  207.       print ("***** Should print:\n")
  208.       print ("*****     Okay\n\n")
  209.       i = Sys_Exec ("GarbageFilename")
  210.       if i != -1
  211.         print ("\n*************** ERROR: Bad return value from Sys_Exec\n")
  212.         printIntVar ("  return value", i)
  213.       else
  214.         print ("Okay\n")
  215.       endIf
  216.  
  217.       print ("\n***** About to call Sys_Exec with an overly long file name...\n")
  218.       print ("***** Should print:\n")
  219.       print ("*****     Okay\n\n")
  220.       -- This name of this file exceeds the maximum length (MAX_STRING_SIZE)
  221.       -- so Exec should fail.
  222.       i = Sys_Exec ("FileWithVeryLongName012345678901234567890123456789")
  223.       if i != -1
  224.         print ("\n*************** ERROR: Bad return value from Sys_Exec\n")
  225.         printIntVar ("  return value", i)
  226.       else
  227.         print ("Okay\n")
  228.       endIf
  229.  
  230.       -- The array "arr1" is so big it must contain a page boundary.  Find
  231.       -- a page boundary within arr1 and set p to point 8 bytes before it.
  232.       i = (& arr1[9900]) asInteger
  233.       i = (i & 0xffffe000) - 8
  234.  
  235.       -- Copy string plus length so that the characters cross the page boundary.
  236.       MemoryCopy (i, NAME_OF_PROGRAM2 asInteger, NAME_OF_PROGRAM2 arraySize+4)
  237.  
  238.       -- Set "fileNamePtr" to point the string "TestProgram2", which happens to
  239.       -- cross a page boundary.
  240.       fileNamePtr = i asPtrTo array of char
  241.  
  242.       print ("\n***** About to perform a successful Exec and jump to TestProgram2...\n")
  243.       print ("***** Should print:\n")
  244.       print ("*****     User-level program 'TestProgram2' is running!\n\n")
  245.  
  246.       i = Sys_Exec (fileNamePtr)
  247.  
  248.       printIntVar ("***************  ERROR IN EXEC; return code", i)
  249.  
  250.     endFunction
  251.  
  252. endCode
  253.