PageRenderTime 62ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/simulator/syscall_tests/usctest.h

https://bitbucket.org/bathtub/rose
C Header | 329 lines | 107 code | 33 blank | 189 comment | 15 complexity | b7a9084b297cadd96486c63258aa6e53 MD5 | raw file
  1. /*
  2. * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Further, this software is distributed without any warranty that it is
  13. * free of the rightful claim of any third person regarding infringement
  14. * or the like. Any license provided herein, whether implied or
  15. * otherwise, applies only to this software file. Patent licenses, if
  16. * any, provided herein do not apply to combinations of this program with
  17. * other software, or any other product whatsoever.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
  31. */
  32. /* $Id: usctest.h,v 1.14 2009/08/28 10:03:01 vapier Exp $ */
  33. /**********************************************************
  34. *
  35. * IRIX/Linux Feature Test and Evaluation - Silicon Graphics, Inc.
  36. *
  37. * FUNCTION NAME : usctest.h
  38. *
  39. * FUNCTION TITLE : System Call Test Macros
  40. *
  41. * SYNOPSIS:
  42. * See DESCRIPTION below.
  43. *
  44. * AUTHOR : William Roske
  45. *
  46. * INITIAL RELEASE : UNICOS 7.0
  47. *
  48. * DESCRIPTION
  49. * TEST(SCALL) - calls a system call
  50. * TEST_VOID(SCALL) - same as TEST() but for syscalls with no return value.
  51. * TEST_CLEANUP - print the log of errno return counts if STD_ERRNO_LOG
  52. * is set.
  53. * TEST_PAUSEF(HAND) - Pause for SIGUSR1 if the pause flag is set.
  54. * Use "hand" as the interrupt handling function
  55. * TEST_PAUSE - Pause for SIGUSR1 if the pause flag is set.
  56. * Use internal function to do nothing on signal and go on.
  57. * TEST_LOOPING(COUNTER) - Conditional to check if test should
  58. * loop. Evaluates to TRUE (1) or FALSE (0).
  59. * TEST_ERROR_LOG(eno) - log that this errno was received,
  60. * if STD_ERRNO_LOG is set.
  61. * TEST_EXP_ENOS(array) - set the bits in TEST_VALID_ENO array at
  62. * positions specified in integer "array"
  63. *
  64. * RETURN VALUE
  65. * TEST(SCALL) - Global Variables set:
  66. * int TEST_RETURN=return code from SCALL
  67. * int TEST_ERRNO=value of errno at return from SCALL
  68. * TEST_VOID(SCALL) - Global Variables set:
  69. * int TEST_ERRNO=value of errno at return from SCALL
  70. * TEST_CLEANUP - None.
  71. * TEST_PAUSEF(HAND) - None.
  72. * TEST_PAUSE - None.
  73. * TEST_LOOPING(COUNTER) - True if COUNTER < STD_LOOP_COUNT or
  74. * STD_INFINITE is set.
  75. * TEST_ERROR_LOG(eno) - None
  76. * TEST_EXP_ENOS(array) - None
  77. *
  78. * KNOWN BUGS
  79. * If you use the TEST_PAUSE or TEST_LOOPING macros, you must
  80. * link in parse_opts.o, which contains the code for those functions.
  81. *
  82. *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
  83. #ifndef __USCTEST_H__
  84. #define __USCTEST_H__ 1
  85. #ifndef _SC_CLK_TCK
  86. #include <unistd.h>
  87. #endif
  88. #include <sys/param.h>
  89. /*
  90. * Ensure that PATH_MAX is defined
  91. */
  92. #ifndef PATH_MAX
  93. #ifdef MAXPATHLEN
  94. #define PATH_MAX MAXPATHLEN
  95. #else
  96. #define PATH_MAX 1024
  97. #endif
  98. #endif
  99. #ifndef CRAY
  100. #ifndef BSIZE
  101. #define BSIZE BBSIZE
  102. #endif
  103. #endif
  104. /***********************************************************************
  105. * Define option_t structure type.
  106. * Entries in this struct are used by the parse_opts routine
  107. * to indicate valid options and return option arguments
  108. ***********************************************************************/
  109. typedef struct {
  110. char *option; /* Valid option string (one option only) like "a:" */
  111. int *flag; /* pointer to location to set true if option given */
  112. char **arg; /* pointer to location to place argument, if needed */
  113. } option_t;
  114. /***********************************************************************
  115. * The following globals are defined in parse_opts.c but must be
  116. * externed here because they are used in the macros defined below.
  117. ***********************************************************************/
  118. extern int STD_FUNCTIONAL_TEST, /* turned off by -f to not do functional test */
  119. STD_TIMING_ON, /* turned on by -t to print timing stats */
  120. STD_PAUSE, /* turned on by -p to pause before loop */
  121. STD_INFINITE, /* turned on by -i0 to loop forever */
  122. STD_LOOP_COUNT, /* changed by -in to set loop count to n */
  123. STD_ERRNO_LOG, /* turned on by -e to log errnos returned */
  124. STD_ERRNO_LIST[], /* counts of errnos returned. indexed by errno */
  125. STD_COPIES,
  126. STD_argind;
  127. extern float STD_LOOP_DURATION, /* wall clock time to iterate */
  128. STD_LOOP_DELAY; /* delay time after each iteration */
  129. #define USC_MAX_ERRNO 2000
  130. /**********************************************************************
  131. * Prototype for parse_opts routine
  132. **********************************************************************/
  133. extern char *parse_opts(int ac, char **av, option_t *user_optarr, void (*uhf)());
  134. /*
  135. * define a structure
  136. */
  137. struct usc_errno_t {
  138. int flag;
  139. };
  140. /***********************************************************************
  141. ****
  142. ****
  143. ****
  144. **********************************************************************/
  145. #ifdef _USC_LIB_
  146. extern long TEST_RETURN;
  147. extern int TEST_ERRNO;
  148. extern struct usc_errno_t TEST_VALID_ENO[USC_MAX_ERRNO];
  149. #else
  150. /***********************************************************************
  151. * Global array of bit masks to indicate errnos that are expected.
  152. * Bits set by TEST_EXP_ENOS() macro and used by TEST_CLEANUP() macro.
  153. ***********************************************************************/
  154. struct usc_errno_t TEST_VALID_ENO[USC_MAX_ERRNO];
  155. /***********************************************************************
  156. * Globals for returning the return code and errno from the system call
  157. * test macros.
  158. ***********************************************************************/
  159. long TEST_RETURN;
  160. int TEST_ERRNO;
  161. #endif /* _USC_LIB_ */
  162. /***********************************************************************
  163. * structure for timing accumulator and counters
  164. ***********************************************************************/
  165. struct tblock {
  166. long tb_max;
  167. long tb_min;
  168. long tb_total;
  169. long tb_count;
  170. };
  171. /***********************************************************************
  172. * The following globals are externed here so that they are accessable
  173. * in the macros that follow.
  174. ***********************************************************************/
  175. extern struct tblock tblock;
  176. extern void STD_go();
  177. extern int (*_TMP_FUNC)(void);
  178. extern void STD_opts_help();
  179. /***********************************************************************
  180. * TEST: calls a system call
  181. *
  182. * parameters:
  183. * SCALL = system call and parameters to execute
  184. *
  185. ***********************************************************************/
  186. #define TEST(SCALL) \
  187. do { \
  188. errno = 0; \
  189. TEST_RETURN = SCALL; \
  190. TEST_ERRNO = errno; \
  191. } while (0)
  192. /***********************************************************************
  193. * TEST_VOID: calls a system call
  194. *
  195. * parameters:
  196. * SCALL = system call and parameters to execute
  197. *
  198. * Note: This is IDENTICAL to the TEST() macro except that it is intended
  199. * for use with syscalls returning no values (void syscall()). The
  200. * Typecasting nothing (void) into an unsigned integer causes compilation
  201. * errors.
  202. *
  203. ***********************************************************************/
  204. #define TEST_VOID(SCALL) do { errno = 0; SCALL; TEST_ERRNO = errno; } while (0)
  205. /***********************************************************************
  206. * TEST_CLEANUP: print system call timing stats and errno log entries
  207. * to stdout if STD_TIMING_ON and STD_ERRNO_LOG are set, respectively.
  208. * Do NOT print ANY information if no system calls logged.
  209. *
  210. * parameters:
  211. * none
  212. *
  213. ***********************************************************************/
  214. #define TEST_CLEANUP \
  215. do { \
  216. int i; \
  217. if (!STD_ERRNO_LOG) \
  218. break; \
  219. for (i = 0; i < USC_MAX_ERRNO; ++i) { \
  220. if (!STD_ERRNO_LIST[i]) \
  221. continue; \
  222. tst_resm(TINFO, "ERRNO %d:\tReceived %d Times%s", \
  223. i, STD_ERRNO_LIST[i], \
  224. TEST_VALID_ENO[i].flag ? "" : " ** UNEXPECTED **"); \
  225. } \
  226. } while (0)
  227. /***********************************************************************
  228. * TEST_PAUSEF: Pause for SIGUSR1 if the pause flag is set.
  229. * Set the user specified function as the interrupt
  230. * handler instead of "STD_go"
  231. *
  232. * parameters:
  233. * none
  234. *
  235. ***********************************************************************/
  236. #define TEST_PAUSEF(HANDLER) \
  237. do { \
  238. if (STD_PAUSE) { \
  239. _TMP_FUNC = (int (*)())signal(SIGUSR1, HANDLER); \
  240. pause(); \
  241. signal(SIGUSR1, (void (*)())_TMP_FUNC); \
  242. } \
  243. } while (0)
  244. /***********************************************************************
  245. * TEST_PAUSE: Pause for SIGUSR1 if the pause flag is set.
  246. * Just continue when signal comes in.
  247. *
  248. * parameters:
  249. * none
  250. *
  251. ***********************************************************************/
  252. #define TEST_PAUSE usc_global_setup_hook();
  253. int usc_global_setup_hook();
  254. /***********************************************************************
  255. * TEST_LOOPING now call the usc_test_looping function.
  256. * The function will return 1 if the test should continue
  257. * iterating.
  258. *
  259. ***********************************************************************/
  260. #define TEST_LOOPING simple_test_looping
  261. int simple_test_looping(int counter);
  262. //FIXME: Floating point not supported in the simulator so we need to replace
  263. //this function with one that does NOT contain floating point instructions.
  264. //#define TEST_LOOPING usc_test_looping
  265. int usc_test_looping(int counter);
  266. /***********************************************************************
  267. * TEST_ERROR_LOG(eno): log this errno if STD_ERRNO_LOG flag set
  268. *
  269. * parameters:
  270. * int eno: the errno location in STD_ERRNO_LIST to log.
  271. *
  272. ***********************************************************************/
  273. #define TEST_ERROR_LOG(eno) \
  274. do { \
  275. int _eno = (eno); \
  276. if ((STD_ERRNO_LOG) && (_eno < USC_MAX_ERRNO)) \
  277. STD_ERRNO_LIST[_eno]++; \
  278. } while (0)
  279. /***********************************************************************
  280. * TEST_EXP_ENOS(array): set the bits associated with the nput errnos
  281. * in the TEST_VALID_ENO array.
  282. *
  283. * parameters:
  284. * int array[]: a zero terminated array of errnos expected.
  285. *
  286. ***********************************************************************/
  287. #define TEST_EXP_ENOS(array) \
  288. do { \
  289. int i = 0; \
  290. while (array[i] != 0) { \
  291. if (array[i] < USC_MAX_ERRNO) \
  292. TEST_VALID_ENO[array[i]].flag = 1; \
  293. ++i; \
  294. } \
  295. } while (0)
  296. #endif /* end of __USCTEST_H__ */