PageRenderTime 76ms CodeModel.GetById 38ms RepoModel.GetById 0ms app.codeStats 1ms

/test.c

https://bitbucket.org/tyc1031/cs502
C | 2743 lines | 1588 code | 491 blank | 664 comment | 158 complexity | 275cb323385a166f20cd2dae60cb3916 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /************************************************************************
  2. test.c
  3. These programs are designed to test the OS502 functionality
  4. Read Appendix B about test programs and Appendix C concerning
  5. system calls when attempting to understand these programs.
  6. Revision History:
  7. 1.0 August 1990
  8. 1.1 December 1990: Tests cleaned up; 1b, 1e - 1k added
  9. Portability attempted.
  10. 1.2 December 1991: Still working on portabililty.
  11. 1.3 July 1992: tests1i/1j made re-entrant.
  12. 1.4 December 1992: Minor changes - portability
  13. tests2c/2d added. 2f/2g rewritten
  14. 1.5 August 1993: Produced new test2g to replace old
  15. 2g that did a swapping test.
  16. 1.6 June 1995: Test Cleanup.
  17. 1.7 June 1999: Add test0, minor fixes.
  18. 2.0 January 2000: Lots of small changes & bug fixes
  19. 2.1 March 2001: Minor Bugfixes.
  20. Rewrote get_skewed_random_number
  21. 2.2 July 2002: Make appropriate for undergrads
  22. 3.0 August 2004: Modified to support memory mapped IO
  23. 3.1 August 2004: hardware interrupt runs on separate thread
  24. 3.11 August 2004: Support for OS level locking
  25. 3.13 November 2004: Minor fix defining USER
  26. 3.41 August 2009: Additional work for multiprocessor + 64 bit
  27. 3.53 November 2011: Changed test2c so data structure used
  28. ints (4 bytes) rather than longs.
  29. ************************************************************************/
  30. #define USER
  31. #include "global.h"
  32. #include "syscalls.h"
  33. #include "z502.h"
  34. #include "protos.h"
  35. #include "stdio.h"
  36. #include "string.h"
  37. #include "stdlib.h"
  38. #include "math.h"
  39. extern INT16 Z502_PROGRAM_COUNTER;
  40. extern INT32 SYS_CALL_CALL_TYPE;
  41. extern Z502_ARG Z502_ARG1;
  42. extern Z502_ARG Z502_ARG2;
  43. extern Z502_ARG Z502_ARG3;
  44. extern Z502_ARG Z502_ARG4;
  45. extern Z502_ARG Z502_ARG5;
  46. extern Z502_ARG Z502_ARG6;
  47. extern long Z502_REG_1;
  48. extern long Z502_REG_2;
  49. extern long Z502_REG_3;
  50. extern long Z502_REG_4;
  51. extern long Z502_REG_5;
  52. extern long Z502_REG_6;
  53. extern long Z502_REG_7;
  54. extern long Z502_REG_8;
  55. extern long Z502_REG_9;
  56. extern INT16 Z502_MODE;
  57. /* Prototypes for internally called routines. */
  58. void test1x( void );
  59. void test1j_echo( void );
  60. void test2gx( void );
  61. void error_expected( INT32, char[] );
  62. void success_expected( INT32, char[] );
  63. /**************************************************************************
  64. Test0
  65. Exercises GET_TIME_OF_DAY and TERMINATE_PROCESS
  66. Z502_REG_1 Time returned from call
  67. Z502_REG_9 Error returned
  68. **************************************************************************/
  69. void test0( void ) {
  70. SELECT_STEP {
  71. STEP( 0 )
  72. printf( "This is Release %s: Test 0\n", CURRENT_REL );
  73. GET_TIME_OF_DAY( &Z502_REG_1 );
  74. STEP( 1 )
  75. printf( "Time of day is %ld\n", Z502_REG_1 );
  76. TERMINATE_PROCESS( -1, &Z502_REG_9 );
  77. STEP( 2 )
  78. printf( "ERROR: Test should be terminated but isn't.\n");
  79. break;
  80. } // End of SELECT
  81. } // End of test0
  82. /**************************************************************************
  83. Test1a
  84. Exercises GET_TIME_OF_DAY and SLEEP and TERMINATE_PROCESS
  85. Z502_REG_9 Error returned
  86. **************************************************************************/
  87. void test1a( void ) {
  88. static INT32 sleep_time = 100;
  89. static INT32 time1, time2;
  90. SELECT_STEP {
  91. STEP( 0 )
  92. printf( "This is Release %s: Test 1a\n", CURRENT_REL );
  93. GET_TIME_OF_DAY( &time1 );
  94. STEP( 1 )
  95. SLEEP ( sleep_time );
  96. STEP( 2 )
  97. GET_TIME_OF_DAY( &time2 );
  98. STEP( 3 )
  99. printf( "sleep time= %d, elapsed time= %d\n",
  100. sleep_time, time2 - time1 );
  101. TERMINATE_PROCESS( -1, &Z502_REG_9 );
  102. STEP( 4 )
  103. printf( "ERROR: Test should be terminated but isn't.\n");
  104. break;
  105. } /* End of SELECT */
  106. } /* End of test1a */
  107. /**************************************************************************
  108. Test1b
  109. Exercises the CREATE_PROCESS and GET_PROCESS_ID commands.
  110. This test tries lots of different inputs for create_process.
  111. In particular, there are tests for each of the following:
  112. 1. use of illegal priorities
  113. 2. use of a process name of an already existing process.
  114. 3. creation of a LARGE number of processes, showing that
  115. there is a limit somewhere ( you run out of some
  116. resource ) in which case you take appropriate action.
  117. Test the following items for get_process_id:
  118. 1. Various legal process id inputs.
  119. 2. An illegal/non-existant name.
  120. Z502_REG_1, _2 Used as return of process id's.
  121. Z502_REG_3 Cntr of # of processes created.
  122. Z502_REG_9 Used as return of error code.
  123. **************************************************************************/
  124. #define ILLEGAL_PRIORITY -3
  125. #define LEGAL_PRIORITY 10
  126. void test1b( void) {
  127. static char process_name[16];
  128. while (1) {
  129. SELECT_STEP {
  130. /* Try to create a process with an illegal priority. */
  131. STEP( 0 )
  132. printf( "This is Release %s: Test 1b\n", CURRENT_REL );
  133. CREATE_PROCESS( "test1b_a", test1x, ILLEGAL_PRIORITY,
  134. &Z502_REG_1, &Z502_REG_9 );
  135. STEP( 1 )
  136. error_expected( Z502_REG_9, "CREATE_PROCESS" );
  137. /* Create two processes with same name - 1st succeeds, 2nd fails */
  138. CREATE_PROCESS( "two_the_same", test1x, LEGAL_PRIORITY,
  139. &Z502_REG_2, &Z502_REG_9 );
  140. STEP( 2 )
  141. success_expected( Z502_REG_9, "CREATE_PROCESS" );
  142. CREATE_PROCESS( "two_the_same", test1x, LEGAL_PRIORITY,
  143. &Z502_REG_1, &Z502_REG_9 );
  144. STEP( 3 )
  145. error_expected( Z502_REG_9, "CREATE_PROCESS" );
  146. TERMINATE_PROCESS( Z502_REG_2, &Z502_REG_9 );
  147. STEP( 4 )
  148. success_expected( Z502_REG_9, "TERMINATE_PROCESS" );
  149. break;
  150. /* Loop until an error is found on the create_process.
  151. Since the call itself is legal, we must get an error
  152. because we exceed some limit. */
  153. STEP( 5 )
  154. Z502_REG_3++; /* Generate next prog name*/
  155. sprintf( process_name, "Test1b_%ld", Z502_REG_3 );
  156. printf( "Creating process \"%s\"\n", process_name );
  157. CREATE_PROCESS( process_name, test1x, LEGAL_PRIORITY,
  158. &Z502_REG_1, &Z502_REG_9 );
  159. STEP( 6 )
  160. if ( Z502_REG_9 == ERR_SUCCESS )
  161. {
  162. GO_NEXT_TO( 5 ) /* LOOP BACK */
  163. }
  164. break;
  165. /* When we get here, we've created all the processes we can.*/
  166. STEP( 7 )
  167. error_expected( Z502_REG_9, "CREATE_PROCESS" );
  168. printf( "%ld processes were created in all.\n", Z502_REG_3 );
  169. /* Now test the call GET_PROCESS_ID */
  170. GET_PROCESS_ID( "", &Z502_REG_2, &Z502_REG_9 ); /* Legal */
  171. STEP( 8 )
  172. success_expected( Z502_REG_9, "GET_PROCESS_ID" );
  173. printf( "The PID of this process is %ld\n", Z502_REG_2 );
  174. strcpy( process_name, "Test1b_1" );
  175. GET_PROCESS_ID( process_name, &Z502_REG_1,
  176. &Z502_REG_9 ); /* Legal */
  177. STEP( 9 )
  178. success_expected( Z502_REG_9, "GET_PROCESS_ID" );
  179. printf( "The PID of target process is %ld\n", Z502_REG_1 );
  180. GET_PROCESS_ID( "bogus_name", &Z502_REG_1,
  181. &Z502_REG_9 ); /* Illegal */
  182. STEP( 10 )
  183. error_expected( Z502_REG_9, "GET_PROCESS_ID" );
  184. GET_TIME_OF_DAY( &Z502_REG_4 );
  185. STEP( 11 )
  186. printf( "Test1b, PID %ld, Ends at Time %ld\n",
  187. Z502_REG_2, Z502_REG_4);
  188. TERMINATE_PROCESS( -2, &Z502_REG_9 )
  189. } /* End of SELECT */
  190. } /* End of while */
  191. } /* End of test1b */
  192. /**************************************************************************
  193. Test1c
  194. Tests multiple copies of test1x running simultaneously.
  195. Test1c runs these with the same priority in order to show
  196. FCFS scheduling behavior; Test1d uses different priorities
  197. in order to show priority scheduling.
  198. WARNING: This test assumes tests 1a - 1b run successfully
  199. Z502_REG_1, 2, 3, 4, 5 Used as return of process id's.
  200. Z502_REG_6 Return of PID on GET_PROCESS_ID
  201. Z502_REG_9 Used as return of error code.
  202. **************************************************************************/
  203. #define PRIORITY1C 10
  204. void test1c( void)
  205. {
  206. static INT32 sleep_time = 1000;
  207. while( 1 )
  208. {
  209. SELECT_STEP
  210. {
  211. STEP( 0 )
  212. printf( "This is Release %s: Test 1c\n", CURRENT_REL );
  213. CREATE_PROCESS( "test1c_a", test1x, PRIORITY1C,
  214. &Z502_REG_1, &Z502_REG_9 );
  215. STEP( 1 )
  216. success_expected( Z502_REG_9, "CREATE_PROCESS" );
  217. CREATE_PROCESS( "test1c_b", test1x, PRIORITY1C,
  218. &Z502_REG_2, &Z502_REG_9 );
  219. STEP( 2 )
  220. CREATE_PROCESS( "test1c_c", test1x, PRIORITY1C,
  221. &Z502_REG_3, &Z502_REG_9 );
  222. STEP( 3 )
  223. CREATE_PROCESS( "test1c_d", test1x, PRIORITY1C,
  224. &Z502_REG_4, &Z502_REG_9 );
  225. STEP( 4 )
  226. CREATE_PROCESS( "test1c_e", test1x, PRIORITY1C,
  227. &Z502_REG_5, &Z502_REG_9 );
  228. /* In these next three cases, we will loop until the target
  229. process ( test1c_e ) has terminated. We know it
  230. terminated because for a while we get success on the call
  231. GET_PROCESS_ID, and then we get failure when the process
  232. no longer exists. */
  233. STEP( 5 )
  234. SLEEP ( sleep_time );
  235. STEP( 6 )
  236. GET_PROCESS_ID( "test1c_e", &Z502_REG_6, &Z502_REG_9 );
  237. STEP( 7 )
  238. if ( Z502_REG_9 == ERR_SUCCESS )
  239. GO_NEXT_TO( 5 ) /* Loop back */
  240. break;
  241. STEP( 8 )
  242. TERMINATE_PROCESS( -2, &Z502_REG_9 ); /* Terminate all */
  243. } /* End switch */
  244. } /* End while */
  245. } /* End test1c */
  246. /**************************************************************************
  247. Test 1d
  248. Tests multiple copies of test1x running simultaneously.
  249. Test1c runs these with the same priority in order to show
  250. FCFS scheduling behavior; Test1d uses different priorities
  251. in order to show priority scheduling.
  252. WARNING: This test assumes tests 1a - 1b run successfully
  253. Z502_REG_1, 2, 3, 4, 5 Used as return of process id's.
  254. Z502_REG_6 Return of PID on GET_PROCESS_ID
  255. Z502_REG_9 Used as return of error code.
  256. **************************************************************************/
  257. #define PRIORITY1 10
  258. #define PRIORITY2 11
  259. #define PRIORITY3 11
  260. #define PRIORITY4 90
  261. #define PRIORITY5 40
  262. void test1d( void)
  263. {
  264. static INT32 sleep_time = 1000;
  265. while( 1 )
  266. {
  267. SELECT_STEP
  268. {
  269. STEP( 0 )
  270. printf( "This is Release %s: Test 1d\n", CURRENT_REL );
  271. CREATE_PROCESS( "test1d_1", test1x, PRIORITY1,
  272. &Z502_REG_1, &Z502_REG_9 );
  273. STEP( 1 )
  274. success_expected( Z502_REG_9, "CREATE_PROCESS" );
  275. CREATE_PROCESS( "test1d_2", test1x, PRIORITY2,
  276. &Z502_REG_2, &Z502_REG_9 );
  277. STEP( 2 )
  278. CREATE_PROCESS( "test1d_3", test1x, PRIORITY3,
  279. &Z502_REG_3, &Z502_REG_9 );
  280. STEP( 3 )
  281. CREATE_PROCESS( "test1d_4", test1x, PRIORITY4,
  282. &Z502_REG_4, &Z502_REG_9 );
  283. STEP( 4 )
  284. CREATE_PROCESS( "test1d_5", test1x, PRIORITY5,
  285. &Z502_REG_5, &Z502_REG_9 );
  286. /* We will loop until the target process ( test1d_4 ) has terminated.
  287. We know it terminated because for a while we get success on the call
  288. GET_PROCESS_ID, and then failure when the process no longer exists. */
  289. STEP( 5 )
  290. SLEEP ( sleep_time );
  291. STEP( 6 )
  292. GET_PROCESS_ID( "test1d_4", &Z502_REG_6, &Z502_REG_9 );
  293. STEP( 7 )
  294. if ( Z502_REG_9 == ERR_SUCCESS )
  295. GO_NEXT_TO( 5 ) /* Loop back */
  296. break;
  297. STEP( 8 )
  298. TERMINATE_PROCESS( -2, &Z502_REG_9 );
  299. } /* End switch */
  300. } /* End while */
  301. } /* End test1d */
  302. /**************************************************************************
  303. Test 1e exercises the SUSPEND_PROCESS and RESUME_PROCESS commands
  304. This test should try lots of different inputs for suspend and resume.
  305. In particular, there should be tests for each of the following:
  306. 1. use of illegal process id.
  307. 2. what happens when you suspend yourself - is it legal? The answer
  308. to this depends on the OS architecture and is up to the developer.
  309. 3. suspending an already suspended process.
  310. 4. resuming a process that's not suspended.
  311. there are probably lots of other conditions possible.
  312. Z502_REG_1 Target process ID
  313. Z502_REG_2 OUR process ID
  314. Z502_REG_9 Error returned
  315. **************************************************************************/
  316. #define LEGAL_PRIORITY_1E 10
  317. void test1e( void)
  318. {
  319. SELECT_STEP
  320. {
  321. STEP( 0 ) /* Get OUR PID */
  322. GET_PROCESS_ID( "", &Z502_REG_2, &Z502_REG_9 );
  323. STEP( 1 ) /* Make legal target */
  324. printf( "Release %s:Test 1e: Pid %ld\n", CURRENT_REL, Z502_REG_2 );
  325. CREATE_PROCESS( "test1e_a", test1x, LEGAL_PRIORITY_1E,
  326. &Z502_REG_1, &Z502_REG_9);
  327. STEP( 2 )
  328. success_expected( Z502_REG_9, "CREATE_PROCESS" );
  329. /* Suspend Illegal PID */
  330. SUSPEND_PROCESS( (INT32)9999, &Z502_REG_9);
  331. STEP( 3 )
  332. error_expected( Z502_REG_9, "SUSPEND_PROCESS" );
  333. /* Resume Illegal PID */
  334. RESUME_PROCESS( (INT32)9999, &Z502_REG_9);
  335. STEP( 4 )
  336. error_expected( Z502_REG_9, "RESUME_PROCESS" );
  337. /* Suspend legal PID */
  338. SUSPEND_PROCESS(Z502_REG_1, &Z502_REG_9);
  339. STEP( 5 )
  340. success_expected( Z502_REG_9, "SUSPEND_PROCESS" );
  341. /* Suspend already suspended PID */
  342. SUSPEND_PROCESS(Z502_REG_1, &Z502_REG_9);
  343. STEP( 6 )
  344. error_expected( Z502_REG_9, "SUSPEND_PROCESS" );
  345. /* Do a legal resume */
  346. RESUME_PROCESS(Z502_REG_1, &Z502_REG_9);
  347. STEP( 7 )
  348. success_expected( Z502_REG_9, "RESUME_PROCESS" );
  349. /* Resume an already resumed process */
  350. RESUME_PROCESS(Z502_REG_1, &Z502_REG_9);
  351. STEP( 8 )
  352. error_expected( Z502_REG_9, "RESUME_PROCESS" );
  353. /* Try to resume ourselves */
  354. RESUME_PROCESS(Z502_REG_2, &Z502_REG_9);
  355. STEP( 9 )
  356. error_expected( Z502_REG_9, "RESUME_PROCESS" );
  357. /* It may or may not be legal to suspend ourselves;
  358. architectural decision. */
  359. SUSPEND_PROCESS(-1, &Z502_REG_9);
  360. STEP( 10 )
  361. /* If we returned "SUCCESS" here, then there is an inconsistancy;
  362. * success implies that the process was suspended. But if we
  363. * get here, then we obviously weren't suspended. Therefore
  364. * this must be an error. */
  365. error_expected( Z502_REG_9, "SUSPEND_PROCESS" );
  366. GET_TIME_OF_DAY( &Z502_REG_4 );
  367. STEP( 11 )
  368. printf( "Test1e, PID %ld, Ends at Time %ld\n", Z502_REG_2, Z502_REG_4);
  369. TERMINATE_PROCESS(-2, &Z502_REG_9);
  370. } /* End of SELECT */
  371. } /* End of test1e */
  372. /**************************************************************************
  373. Test1f Successfully suspend and resume processes.
  374. In particular, show what happens to scheduling when processes
  375. are temporarily suspended.
  376. This test works by starting up a number of processes at different
  377. priorities. Then some of them are suspended. Then some are resumed.
  378. Z502_REG_1 Loop counter
  379. Z502_REG_2 OUR process ID
  380. Z502_REG_3,4,5,6,7 Target process ID
  381. Z502_REG_9 Error returned
  382. **************************************************************************/
  383. #define PRIORITY_1F1 5
  384. #define PRIORITY_1F2 10
  385. #define PRIORITY_1F3 15
  386. #define PRIORITY_1F4 20
  387. #define PRIORITY_1F5 25
  388. void test1f( void)
  389. {
  390. static INT32 sleep_time = 300;
  391. SELECT_STEP
  392. {
  393. STEP( 0 ) /* Get OUR PID */
  394. Z502_REG_1 = 0; /* Initialize */
  395. GET_PROCESS_ID( "", &Z502_REG_2, &Z502_REG_9 );
  396. STEP( 1 ) /* Make legal target */
  397. printf( "Release %s:Test 1f: Pid %ld\n",
  398. CURRENT_REL, Z502_REG_2 );
  399. CREATE_PROCESS( "test1f_a", test1x, PRIORITY_1F1,
  400. &Z502_REG_3, &Z502_REG_9);
  401. STEP( 2 ) /* Make legal target */
  402. CREATE_PROCESS( "test1f_b", test1x, PRIORITY_1F2,
  403. &Z502_REG_4, &Z502_REG_9);
  404. STEP( 3 ) /* Make legal target */
  405. CREATE_PROCESS( "test1f_c", test1x, PRIORITY_1F3,
  406. &Z502_REG_5, &Z502_REG_9);
  407. STEP( 4 ) /* Make legal target */
  408. CREATE_PROCESS( "test1f_d", test1x, PRIORITY_1F4,
  409. &Z502_REG_6, &Z502_REG_9);
  410. STEP( 5 ) /* Make legal target */
  411. CREATE_PROCESS( "test1f_e", test1x, PRIORITY_1F5,
  412. &Z502_REG_7, &Z502_REG_9);
  413. /* Let the 5 pids go for a bit */
  414. STEP( 6 )
  415. SLEEP ( sleep_time );
  416. /* Suspend 3 of the pids and see what happens - we
  417. should see scheduling behavior where the processes
  418. are yanked out of the ready and the waiting states,
  419. and placed into the suspended state. */
  420. STEP( 7 )
  421. SUSPEND_PROCESS(Z502_REG_3, &Z502_REG_9);
  422. STEP( 8 )
  423. SUSPEND_PROCESS(Z502_REG_5, &Z502_REG_9);
  424. STEP( 9 )
  425. SUSPEND_PROCESS(Z502_REG_7, &Z502_REG_9);
  426. STEP( 10 )
  427. SLEEP ( sleep_time );
  428. STEP( 11 )
  429. RESUME_PROCESS(Z502_REG_3, &Z502_REG_9);
  430. STEP( 12 )
  431. RESUME_PROCESS(Z502_REG_5, &Z502_REG_9);
  432. STEP( 13 )
  433. if ( Z502_REG_1 < 4 )
  434. GO_NEXT_TO( 6 )
  435. Z502_REG_1++; /* Inc the loop counter */
  436. RESUME_PROCESS(Z502_REG_7, &Z502_REG_9);
  437. /* Wait for children to finish, then quit */
  438. STEP( 14 )
  439. SLEEP ( (INT32)10000 );
  440. STEP( 15 )
  441. TERMINATE_PROCESS(-1, &Z502_REG_9);
  442. } /* End of SELECT */
  443. } /* End of test1f */
  444. /**************************************************************************
  445. Test1g Generate lots of errors for CHANGE_PRIORITY
  446. Try lots of different inputs: In particular, some of the possible
  447. inputs include:
  448. 1. use of illegal priorities
  449. 2. use of an illegal process id.
  450. Z502_REG_1 Target process ID
  451. Z502_REG_2 OUR process ID
  452. Z502_REG_9 Error returned
  453. **************************************************************************/
  454. #define LEGAL_PRIORITY_1G 10
  455. #define ILLEGAL_PRIORITY_1G 999
  456. void test1g( void)
  457. {
  458. SELECT_STEP
  459. {
  460. STEP( 0 ) /* Get OUR PID */
  461. GET_PROCESS_ID( "", &Z502_REG_2, &Z502_REG_9 );
  462. STEP( 1 ) /* Make legal target */
  463. printf( "Release %s:Test 1g: Pid %ld\n", CURRENT_REL, Z502_REG_2 );
  464. CREATE_PROCESS( "test1g_a", test1x, LEGAL_PRIORITY_1G,
  465. &Z502_REG_1, &Z502_REG_9);
  466. STEP( 2 )
  467. success_expected( Z502_REG_9, "CREATE_PROCESS" );
  468. /* Target Illegal PID */
  469. CHANGE_PRIORITY( (INT32)9999, LEGAL_PRIORITY_1G, &Z502_REG_9);
  470. STEP( 3 )
  471. error_expected( Z502_REG_9, "CHANGE_PRIORITY" );
  472. /* Use illegal priority */
  473. CHANGE_PRIORITY( Z502_REG_1, ILLEGAL_PRIORITY_1G, &Z502_REG_9);
  474. STEP( 4 )
  475. error_expected( Z502_REG_9, "CHANGE_PRIORITY" );
  476. // Change made - I assume both proce
  477. TERMINATE_PROCESS(-2, &Z502_REG_9);
  478. } /* End of SELECT */
  479. } /* End of test1g */
  480. /**************************************************************************
  481. Test1h Successfully change the priority of a process
  482. When you change the priority, it should be possible to see
  483. the scheduling behaviour of the system change; processes
  484. that used to be scheduled first are no longer first.
  485. Z502_REG_2 OUR process ID
  486. Z502_REG_3 - 5 Target process IDs
  487. Z502_REG_9 Error returned
  488. **************************************************************************/
  489. #define MOST_FAVORABLE_PRIORITY 1
  490. #define FAVORABLE_PRIORITY 10
  491. #define NORMAL_PRIORITY 20
  492. #define LEAST_FAVORABLE_PRIORITY 30
  493. void test1h( void)
  494. {
  495. INT32 ourself;
  496. SELECT_STEP
  497. {
  498. STEP( 0 ) /* Get OUR PID */
  499. GET_PROCESS_ID( "", &Z502_REG_2, &Z502_REG_9 );
  500. STEP( 1 ) /* Make our priority high */
  501. printf( "Release %s:Test 1h: Pid %ld\n",
  502. CURRENT_REL, Z502_REG_2 );
  503. ourself = -1;
  504. CHANGE_PRIORITY( ourself, MOST_FAVORABLE_PRIORITY,
  505. &Z502_REG_9);
  506. STEP( 2 ) /* Make legal targets */
  507. CREATE_PROCESS( "test1h_a", test1x, NORMAL_PRIORITY,
  508. &Z502_REG_3, &Z502_REG_9);
  509. STEP( 3 ) /* Make legal targets */
  510. CREATE_PROCESS( "test1h_b", test1x, NORMAL_PRIORITY,
  511. &Z502_REG_4, &Z502_REG_9);
  512. STEP( 4 ) /* Make legal targets */
  513. CREATE_PROCESS( "test1h_c", test1x, NORMAL_PRIORITY,
  514. &Z502_REG_5, &Z502_REG_9);
  515. /* Sleep awhile to watch the scheduling */
  516. STEP( 5 )
  517. SLEEP( 200 );
  518. /* Now change the priority - it should be possible to see
  519. that the priorities have been changed for processes that
  520. are ready and for processes that are sleeping. */
  521. STEP( 6 )
  522. CHANGE_PRIORITY( Z502_REG_3, FAVORABLE_PRIORITY,
  523. &Z502_REG_9);
  524. STEP( 7 )
  525. CHANGE_PRIORITY( Z502_REG_5, LEAST_FAVORABLE_PRIORITY,
  526. &Z502_REG_9);
  527. /* Sleep awhile to watch the scheduling */
  528. STEP( 8 )
  529. SLEEP( 200 );
  530. /* Now change the priority - it should be possible to see
  531. that the priorities have been changed for processes that
  532. are ready and for processes that are sleeping. */
  533. STEP( 9 )
  534. CHANGE_PRIORITY( Z502_REG_3, LEAST_FAVORABLE_PRIORITY,
  535. &Z502_REG_9);
  536. STEP( 10 )
  537. CHANGE_PRIORITY( Z502_REG_4, FAVORABLE_PRIORITY,
  538. &Z502_REG_9);
  539. /* Sleep awhile to watch the scheduling */
  540. STEP( 11 )
  541. SLEEP( 600 );
  542. STEP( 12 )
  543. TERMINATE_PROCESS(-2, &Z502_REG_9);
  544. } /* End of SELECT */
  545. } /* End of test1h */
  546. /**************************************************************************
  547. Test1i SEND_MESSAGE and RECEIVE_MESSAGE with errors.
  548. This has the same kind of error conditions that previous tests did;
  549. bad PIDs, bad message lengths, illegal buffer addresses, etc.
  550. Your imagination can go WILD on this one.
  551. This is a good time to mention os_switch_context_complete:::::
  552. As you know, after doing a switch_context, the hardware passes
  553. control to the code in this test. What hasn't been obvious thus
  554. far, is that control passes from swich_context, THEN to routine,
  555. os_switch_context_complete, and THEN to this test code.
  556. What it does: This function allows you to gain control in the
  557. OS of a scheduled-in process before it goes to test.
  558. Where to find it: The code is in base.c - right now it does nothing.
  559. Why use it: Suppose process A has sent a message to
  560. process B. It so happens that you may well want
  561. to do some preparation in process B once it's
  562. registers are in memory, but BEFORE it executes
  563. the test. In other words, it allows you to
  564. complete the work for the send to process B.
  565. Z502_REG_1 Pointer to data private to each process
  566. running this routine.
  567. Z502_REG_2 OUR process ID
  568. Z502_REG_3 Target process IDs
  569. Z502_REG_9 Error returned
  570. **************************************************************************/
  571. #define LEGAL_MESSAGE_LENGTH (INT16)64
  572. #define ILLEGAL_MESSAGE_LENGTH (INT16)1000
  573. #define MOST_FAVORABLE_PRIORITY 1
  574. #define NORMAL_PRIORITY 20
  575. typedef struct
  576. {
  577. INT32 target_pid;
  578. INT32 source_pid;
  579. INT32 actual_source_pid;
  580. INT32 send_length;
  581. INT32 receive_length;
  582. INT32 actual_send_length;
  583. INT32 loop_count;
  584. char msg_buffer[LEGAL_MESSAGE_LENGTH];
  585. } TEST1I_DATA;
  586. void test1i( void)
  587. {
  588. TEST1I_DATA *td; /* Use as ptr to data */
  589. /* Here we maintain the data to be used by this process when running
  590. on this routine. This code should be re-entrant. */
  591. if ( Z502_REG_1 == 0 )
  592. {
  593. Z502_REG_1 = (long)calloc( 1, sizeof ( TEST1I_DATA ));
  594. if ( Z502_REG_1 == 0 )
  595. {
  596. printf( "Something screwed up allocating space in test1i\n" );
  597. }
  598. td = ( TEST1I_DATA *)Z502_REG_1;
  599. td->loop_count = 0;
  600. }
  601. td = ( TEST1I_DATA *)Z502_REG_1;
  602. while ( 1 )
  603. {
  604. SELECT_STEP
  605. {
  606. STEP( 0 ) /* Get OUR PID */
  607. GET_PROCESS_ID( "", &Z502_REG_2, &Z502_REG_9 );
  608. STEP( 1 ) /* Make our prior high */
  609. printf( "Release %s:Test 1i: Pid %ld\n", CURRENT_REL, Z502_REG_2 );
  610. CHANGE_PRIORITY( -1, MOST_FAVORABLE_PRIORITY, &Z502_REG_9);
  611. STEP( 2 ) /* Make legal targets */
  612. CREATE_PROCESS( "test1i_a", test1x, NORMAL_PRIORITY,
  613. &Z502_REG_3, &Z502_REG_9);
  614. STEP( 3 ) /* Send to illegal process */
  615. td->target_pid = 9999;
  616. td->send_length= 8;
  617. SEND_MESSAGE( td->target_pid, "message", td->send_length, &Z502_REG_9 );
  618. STEP( 4 )
  619. error_expected( Z502_REG_9, "SEND_MESSAGE" );
  620. /* Try an illegal message length */
  621. td->target_pid = Z502_REG_3;
  622. td->send_length= ILLEGAL_MESSAGE_LENGTH;
  623. SEND_MESSAGE( td->target_pid, "message", td->send_length, &Z502_REG_9 );
  624. STEP( 5 )
  625. error_expected( Z502_REG_9, "SEND_MESSAGE" );
  626. /* Receive from illegal process */
  627. td->source_pid = 9999;
  628. td->receive_length = LEGAL_MESSAGE_LENGTH;
  629. RECEIVE_MESSAGE( td->source_pid, td->msg_buffer,
  630. td->receive_length, &(td->actual_send_length),
  631. &(td->actual_source_pid), &Z502_REG_9 );
  632. STEP( 6 )
  633. error_expected( Z502_REG_9, "RECEIVE_MESSAGE" );
  634. /* Receive with illegal buffer size */
  635. td->source_pid = Z502_REG_3;
  636. td->receive_length = ILLEGAL_MESSAGE_LENGTH;
  637. RECEIVE_MESSAGE( td->source_pid, td->msg_buffer,
  638. td->receive_length, &(td->actual_send_length),
  639. &(td->actual_source_pid), &Z502_REG_9 );
  640. STEP( 7 )
  641. error_expected( Z502_REG_9, "RECEIVE_MESSAGE" );
  642. /* Send a legal ( but long ) message to self */
  643. td->target_pid = Z502_REG_2;
  644. td->send_length= LEGAL_MESSAGE_LENGTH;
  645. SEND_MESSAGE( td->target_pid, "a long but legal message",
  646. td->send_length, &Z502_REG_9 );
  647. STEP( 8 )
  648. success_expected( Z502_REG_9, "SEND_MESSAGE" );
  649. td->loop_count++;
  650. /* Receive this long message, which should error
  651. because the receive buffer is too small */
  652. td->source_pid = Z502_REG_2;
  653. td->receive_length = 10;
  654. RECEIVE_MESSAGE( td->source_pid, td->msg_buffer,
  655. td->receive_length, &(td->actual_send_length),
  656. &(td->actual_source_pid), &Z502_REG_9 );
  657. STEP( 9 )
  658. error_expected( Z502_REG_9, "RECEIVE_MESSAGE" );
  659. break;
  660. /* Keep sending legal messages until the architectural
  661. limit for buffer space is exhausted. In order to pass
  662. the test1j, this number should be at least EIGHT */
  663. STEP( 10 )
  664. td->target_pid = Z502_REG_3;
  665. td->send_length= LEGAL_MESSAGE_LENGTH;
  666. SEND_MESSAGE( td->target_pid, "message", td->send_length, &Z502_REG_9 );
  667. STEP( 11 )
  668. if (Z502_REG_9 == ERR_SUCCESS)
  669. GO_NEXT_TO( 10 ) /* Loop back */
  670. td->loop_count++;
  671. break;
  672. STEP( 12 )
  673. printf( "A total of %d messages were enqueued.\n", td->loop_count - 1 );
  674. TERMINATE_PROCESS(-2, &Z502_REG_9);
  675. } /* End of SELECT */
  676. } /* End of while */
  677. } /* End of test1i */
  678. /**************************************************************************
  679. Test1j SEND_MESSAGE and RECEIVE_MESSAGE Successfully.
  680. Creates three other processes, each running their own code.
  681. RECEIVE and SEND messages are winged back and forth at them.
  682. Z502_REG_1 Pointer to data private to each process
  683. running this routine.
  684. Z502_REG_2 OUR process ID
  685. Z502_REG_3 - 5 Target process IDs
  686. Z502_REG_9 Error returned
  687. Again, as mentioned in detail on Test1i, use of the code in
  688. os_switch_context_complete could be beneficial here. In fact
  689. it will be difficult to make the test work successfully UNLESS
  690. you use the os_switch_context_complete().
  691. The SEND and RECEIVE system calls as implemented by this test
  692. imply the following behavior:
  693. SENDER = PID A RECEIVER = PID B,
  694. Designates source_pid =
  695. target_pid = A C -1
  696. ----------------+------------+------------+--------------+
  697. | | | |
  698. B | Message | X | Message |
  699. |Transmitted | | Transmitted |
  700. ----------------+------------+------------+--------------+
  701. | | | |
  702. C | X | X | X |
  703. | | | |
  704. ----------------+------------+------------+--------------+
  705. | | | |
  706. -1 | Message | X | Message |
  707. | Transmitted| | Transmitted |
  708. ----------------+------------+------------+--------------+
  709. A broadcast ( target_pid = -1 ) means send to everyone BUT yourself.
  710. ANY of the receiving processes can handle a broadcast message.
  711. A receive ( source_pid = -1 ) means receive from anyone.
  712. **************************************************************************/
  713. #define LEGAL_MESSAGE_LENGTH (INT16)64
  714. #define ILLEGAL_MESSAGE_LENGTH (INT16)1000
  715. #define MOST_FAVORABLE_PRIORITY 1
  716. #define NORMAL_PRIORITY 20
  717. typedef struct
  718. {
  719. INT32 target_pid;
  720. INT32 source_pid;
  721. INT32 actual_source_pid;
  722. INT32 send_length;
  723. INT32 receive_length;
  724. INT32 actual_send_length;
  725. INT32 send_loop_count;
  726. INT32 receive_loop_count;
  727. char msg_buffer[LEGAL_MESSAGE_LENGTH];
  728. char msg_sent[LEGAL_MESSAGE_LENGTH];
  729. } TEST1J_DATA;
  730. void test1j( void)
  731. {
  732. TEST1J_DATA *td; /* Use as ptr to data */
  733. /* Here we maintain the data to be used by this process when running
  734. on this routine. This code should be re-entrant. */
  735. if ( Z502_REG_1 == 0 )
  736. {
  737. Z502_REG_1 = (long)calloc( 1, sizeof ( TEST1J_DATA ));
  738. if ( Z502_REG_1 == 0 )
  739. {
  740. printf( "Something screwed up allocating space in test1j\n" );
  741. }
  742. td = ( TEST1J_DATA *)Z502_REG_1;
  743. td->send_loop_count = 0;
  744. td->receive_loop_count = 0;
  745. }
  746. td = ( TEST1J_DATA *)Z502_REG_1;
  747. while ( 1 )
  748. {
  749. SELECT_STEP
  750. {
  751. STEP( 0 ) /* Get OUR PID */
  752. GET_PROCESS_ID( "", &Z502_REG_2, &Z502_REG_9 );
  753. STEP( 1 ) /* Make our prior high */
  754. printf( "Release %s:Test 1j: Pid %ld\n",
  755. CURRENT_REL, Z502_REG_2 );
  756. CHANGE_PRIORITY( -1, MOST_FAVORABLE_PRIORITY,
  757. &Z502_REG_9);
  758. STEP( 2 ) /* Make legal targets */
  759. success_expected( Z502_REG_9, "CHANGE_PRIORITY" );
  760. CREATE_PROCESS( "test1j_1", test1j_echo, NORMAL_PRIORITY,
  761. &Z502_REG_3, &Z502_REG_9);
  762. STEP( 3 ) /* Make legal targets */
  763. success_expected( Z502_REG_9, "CREATE_PROCESS" );
  764. CREATE_PROCESS( "test1j_2", test1j_echo, NORMAL_PRIORITY,
  765. &Z502_REG_4, &Z502_REG_9);
  766. STEP( 4 ) /* Make legal targets */
  767. success_expected( Z502_REG_9, "CREATE_PROCESS" );
  768. CREATE_PROCESS( "test1j_3", test1j_echo, NORMAL_PRIORITY,
  769. &Z502_REG_5, &Z502_REG_9);
  770. STEP( 5 )
  771. success_expected( Z502_REG_9, "CREATE_PROCESS" );
  772. /* Send/receive a legal message to each child */
  773. td->target_pid = Z502_REG_3;
  774. td->send_length= 20;
  775. strcpy( td->msg_sent, "message to #3" );
  776. SEND_MESSAGE( td->target_pid, td->msg_sent,
  777. td->send_length, &Z502_REG_9 );
  778. STEP( 6 )
  779. success_expected( Z502_REG_9, "SEND_MESSAGE" );
  780. td->source_pid = -1;
  781. td->receive_length = LEGAL_MESSAGE_LENGTH;
  782. RECEIVE_MESSAGE( td->source_pid, td->msg_buffer,
  783. td->receive_length, &(td->actual_send_length),
  784. &(td->actual_source_pid), &Z502_REG_9 );
  785. STEP( 7 )
  786. success_expected( Z502_REG_9, "RECEIVE_MESSAGE" );
  787. if ( strcmp( td->msg_buffer, td->msg_sent ) != 0 )
  788. printf("ERROR - msg sent != msg received.\n");
  789. if ( td->actual_source_pid != Z502_REG_3 )
  790. printf( "ERROR - source PID not correct.\n" );
  791. if ( td->actual_send_length != td->send_length )
  792. printf( "ERROR - send length not sent correctly.\n" );
  793. td->target_pid = Z502_REG_4;
  794. td->send_length= 20;
  795. strcpy( td->msg_sent, "message to #4" );
  796. SEND_MESSAGE( td->target_pid, td->msg_sent,
  797. td->send_length, &Z502_REG_9 );
  798. STEP( 8 )
  799. success_expected( Z502_REG_9, "SEND_MESSAGE" );
  800. td->source_pid = -1;
  801. td->receive_length = LEGAL_MESSAGE_LENGTH;
  802. RECEIVE_MESSAGE( td->source_pid, td->msg_buffer,
  803. td->receive_length, &(td->actual_send_length),
  804. &(td->actual_source_pid), &Z502_REG_9 );
  805. STEP( 9 )
  806. success_expected( Z502_REG_9, "RECEIVE_MESSAGE" );
  807. if ( strcmp( td->msg_buffer, td->msg_sent ) != 0 )
  808. printf("ERROR - msg sent != msg received.\n");
  809. if ( td->actual_source_pid != Z502_REG_4 )
  810. printf( "ERROR - source PID not correct.\n" );
  811. if ( td->actual_send_length != td->send_length )
  812. printf( "ERROR - send length not sent correctly.\n" );
  813. td->target_pid = Z502_REG_5;
  814. td->send_length= 20;
  815. strcpy( td->msg_sent, "message to #5" );
  816. SEND_MESSAGE( td->target_pid, td->msg_sent,
  817. td->send_length, &Z502_REG_9 );
  818. STEP( 10 )
  819. success_expected( Z502_REG_9, "SEND_MESSAGE" );
  820. td->source_pid = -1;
  821. td->receive_length = LEGAL_MESSAGE_LENGTH;
  822. RECEIVE_MESSAGE( td->source_pid, td->msg_buffer,
  823. td->receive_length, &(td->actual_send_length),
  824. &(td->actual_source_pid), &Z502_REG_9 );
  825. STEP( 11 )
  826. success_expected( Z502_REG_9, "RECEIVE_MESSAGE" );
  827. if ( strcmp( td->msg_buffer, td->msg_sent ) != 0 )
  828. printf("ERROR - msg sent != msg received.\n");
  829. if ( td->actual_source_pid != Z502_REG_5 )
  830. printf( "ERROR - source PID not correct.\n" );
  831. if ( td->actual_send_length != td->send_length )
  832. printf( "ERROR - send length not sent correctly.\n" );
  833. break; // Bugfix 08/2012 - Rel 3.60 so we explicitly
  834. // go to the next step
  835. /* Keep sending legal messages until the architectural (OS)
  836. limit for buffer space is exhausted. */
  837. STEP( 12 )
  838. td->target_pid = -1;
  839. sprintf( td->msg_sent, "This is message %d",
  840. td->send_loop_count );
  841. td->send_length= 20;
  842. SEND_MESSAGE( td->target_pid, td->msg_sent,
  843. td->send_length, &Z502_REG_9 );
  844. STEP( 13 )
  845. if (Z502_REG_9 == ERR_SUCCESS)
  846. GO_NEXT_TO( 12 ) /* Loop back */
  847. td->send_loop_count++;
  848. break;
  849. STEP( 14 )
  850. td->send_loop_count--;
  851. printf( "A total of %d messages were enqueued.\n",
  852. td->send_loop_count );
  853. break;
  854. STEP( 15 )
  855. td->source_pid = -1;
  856. td->receive_length = LEGAL_MESSAGE_LENGTH;
  857. RECEIVE_MESSAGE( td->source_pid, td->msg_buffer,
  858. td->receive_length, &(td->actual_send_length),
  859. &(td->actual_source_pid), &Z502_REG_9 );
  860. STEP( 16 )
  861. success_expected( Z502_REG_9, "RECEIVE_MESSAGE" );
  862. printf( "Receive from PID = %d: length = %d: msg = %s:\n",
  863. td->actual_source_pid, td->actual_send_length,
  864. td->msg_buffer );
  865. td->receive_loop_count++;
  866. if ( td->receive_loop_count < td->send_loop_count )
  867. GO_NEXT_TO( 15 ) /* Loop back */
  868. break;
  869. STEP( 17 )
  870. printf( "A total of %d messages were received.\n",
  871. td->receive_loop_count - 1 );
  872. TERMINATE_PROCESS(-2, &Z502_REG_9);
  873. } /* End of SELECT */
  874. } /* End of while */
  875. } /* End of test1j */
  876. /**************************************************************************
  877. Test1k Test other oddities in your system.
  878. There are many other strange effects, not taken into account
  879. by the previous tests. One of these is:
  880. 1. Executing a privileged instruction from a user program
  881. Registers Used:
  882. Z502_REG_2 OUR process ID
  883. Z502_REG_9 Error returned
  884. **************************************************************************/
  885. void test1k( void)
  886. {
  887. INT32 Result;
  888. SELECT_STEP
  889. {
  890. STEP( 0 )
  891. GET_PROCESS_ID( "", &Z502_REG_2, &Z502_REG_9 );
  892. STEP( 1 )
  893. printf( "Release %s:Test 1k: Pid %ld\n", CURRENT_REL, Z502_REG_2 );
  894. /* Do an illegal hardware instruction - we will
  895. not return from this. */
  896. MEM_READ( Z502TimerStatus, &Result);
  897. } /* End of SELECT */
  898. } /* End of test1k */
  899. /**************************************************************************
  900. Test1l SEND_MESSAGE and RECEIVE_MESSAGE with SUSPEND/RESUME
  901. Explores how message handling is done in the midst of SUSPEND/RESUME
  902. system calls,
  903. The SEND and RECEIVE system calls as implemented by this test
  904. imply the following behavior:
  905. Case 1:
  906. - a process waiting to recieve a message can be suspended
  907. - a process waiting to recieve a message can be resumed
  908. - after being resumed, it can receive a message
  909. Case 2:
  910. - when a process waiting for a message is suspended, it is out of
  911. circulation and cannot recieve any message
  912. - once it is unsuspended, it may recieve a message and go on the ready
  913. queue
  914. Case 3:
  915. - a process that waited for and found a message is now the ready queue
  916. - this process can be suspended before handling the message
  917. - the message and process remain paired up, no other process can have
  918. that message
  919. - when resumed, the process will handle the message
  920. **************************************************************************/
  921. #define LEGAL_MESSAGE_LENGTH (INT16)64
  922. #define MOST_FAVORABLE_PRIORITY 1
  923. #define NORMAL_PRIORITY 20
  924. typedef struct
  925. {
  926. INT32 target_pid;
  927. INT32 source_pid;
  928. INT32 actual_source_pid;
  929. INT32 send_length;
  930. INT32 receive_length;
  931. INT32 actual_send_length;
  932. INT32 send_loop_count;
  933. INT32 receive_loop_count;
  934. char msg_buffer[LEGAL_MESSAGE_LENGTH];
  935. char msg_sent[LEGAL_MESSAGE_LENGTH];
  936. } TEST1L_DATA;
  937. void test1l( void)
  938. {
  939. TEST1L_DATA *td; /* Use as ptr to data */
  940. /* Here we maintain the data to be used by this process when running
  941. on this routine. This code should be re-entrant. */
  942. if ( Z502_REG_1 == 0 )
  943. {
  944. Z502_REG_1 = (long)calloc( 1, sizeof ( TEST1L_DATA ));
  945. if ( Z502_REG_1 == 0 )
  946. {
  947. printf( "Something screwed up allocating space in test1j\n" );
  948. }
  949. td = ( TEST1L_DATA *)Z502_REG_1;
  950. td->send_loop_count = 0;
  951. td->receive_loop_count = 0;
  952. }
  953. td = ( TEST1L_DATA *)Z502_REG_1;
  954. while ( 1 )
  955. {
  956. SELECT_STEP
  957. {
  958. STEP( 0 ) /* Get OUR PID */
  959. GET_PROCESS_ID( "", &Z502_REG_2, &Z502_REG_9 );
  960. STEP( 1 ) /* Make our prior high */
  961. printf( "Release %s:Test 1l: Pid %ld\n",
  962. CURRENT_REL, Z502_REG_2 );
  963. CHANGE_PRIORITY( -1, MOST_FAVORABLE_PRIORITY,
  964. &Z502_REG_9);
  965. STEP( 2 ) /* Make process to test with */
  966. succes

Large files files are truncated, but you can click here to view the full file