filex_system_date_time_test.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /* This FileX test concentrates on the system date/time set/get operations. */
  2. #ifndef FX_STANDALONE_ENABLE
  3. #include "tx_api.h"
  4. #endif
  5. #include "fx_api.h"
  6. #include "fx_system.h"
  7. #include <stdio.h>
  8. #include "fx_ram_driver_test.h"
  9. #define DEMO_STACK_SIZE 4096
  10. #define CACHE_SIZE 16*128
  11. /* Define the ThreadX and FileX object control blocks... */
  12. #ifndef FX_STANDALONE_ENABLE
  13. static TX_THREAD ftest_0;
  14. #endif
  15. static FX_MEDIA ram_disk;
  16. /* Define the counters used in the test application... */
  17. #ifndef FX_STANDALONE_ENABLE
  18. static UCHAR *ram_disk_memory;
  19. static UCHAR *cache_buffer;
  20. #else
  21. static UCHAR cache_buffer[CACHE_SIZE];
  22. #endif
  23. /* Define thread prototypes. */
  24. void filex_system_date_time_application_define(void *first_unused_memory);
  25. static void ftest_0_entry(ULONG thread_input);
  26. VOID _fx_ram_driver(FX_MEDIA *media_ptr);
  27. void test_control_return(UINT status);
  28. /* Define what the initial system looks like. */
  29. #ifdef CTEST
  30. void test_application_define(void *first_unused_memory)
  31. #else
  32. void filex_system_date_time_application_define(void *first_unused_memory)
  33. #endif
  34. {
  35. #ifndef FX_STANDALONE_ENABLE
  36. UCHAR *pointer;
  37. /* Setup the working pointer. */
  38. pointer = (UCHAR *) first_unused_memory;
  39. /* Create the main thread. */
  40. tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
  41. pointer, DEMO_STACK_SIZE,
  42. 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
  43. pointer = pointer + DEMO_STACK_SIZE;
  44. /* Setup memory for the RAM disk and the sector cache. */
  45. cache_buffer = pointer;
  46. pointer = pointer + CACHE_SIZE;
  47. ram_disk_memory = pointer;
  48. #endif
  49. /* Initialize the FileX system. */
  50. fx_system_initialize();
  51. #ifdef FX_STANDALONE_ENABLE
  52. ftest_0_entry(0);
  53. #endif
  54. }
  55. /* Define the test threads. */
  56. static void ftest_0_entry(ULONG thread_input)
  57. {
  58. UINT status;
  59. UINT save_time;
  60. UINT save_date;
  61. UINT year, month, day, hour, minute, second;
  62. UINT i;
  63. FX_PARAMETER_NOT_USED(thread_input);
  64. /* Print out some test information banners. */
  65. printf("FileX Test: System date/time get/set test..........................");
  66. /* Format the media. This needs to be done before opening it! */
  67. status = fx_media_format(&ram_disk,
  68. _fx_ram_driver, // Driver entry
  69. ram_disk_memory, // RAM disk memory pointer
  70. cache_buffer, // Media buffer pointer
  71. CACHE_SIZE, // Media buffer size
  72. "MY_RAM_DISK", // Volume Name
  73. 1, // Number of FATs
  74. 32, // Directory Entries
  75. 0, // Hidden sectors
  76. 256, // Total sectors
  77. 128, // Sector size
  78. 1, // Sectors per cluster
  79. 1, // Heads
  80. 1); // Sectors per track
  81. /* Determine if the format had an error. */
  82. if (status)
  83. {
  84. printf("ERROR!\n");
  85. test_control_return(2);
  86. }
  87. /* Open the ram_disk. */
  88. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  89. /* Check the status. */
  90. if (status != FX_SUCCESS)
  91. {
  92. /* Error, return error code. */
  93. printf("ERROR!\n");
  94. test_control_return(3);
  95. }
  96. /* test for error checking by sending bad information */
  97. #ifndef FX_DISABLE_ERROR_CHECKING
  98. /* check system date get pointer error */
  99. status = fx_system_date_get(FX_NULL, FX_NULL, FX_NULL);
  100. if (status != FX_PTR_ERROR)
  101. {
  102. printf("ERROR!\n");
  103. test_control_return(4);
  104. }
  105. /* check system time get pointer error */
  106. status = fx_system_time_get(FX_NULL, FX_NULL, FX_NULL);
  107. if (status != FX_PTR_ERROR)
  108. {
  109. printf("ERROR!\n");
  110. test_control_return(5);
  111. }
  112. /* check system time set bad hours */
  113. status = fx_system_time_set(99, 0, 0);
  114. if (status != FX_INVALID_HOUR)
  115. {
  116. printf("ERROR!\n");
  117. test_control_return(6);
  118. }
  119. /* check system time set bad minutes */
  120. status = fx_system_time_set(0, 99, 0);
  121. if (status != FX_INVALID_MINUTE)
  122. {
  123. printf("ERROR!\n");
  124. test_control_return(7);
  125. }
  126. /* check system time set bad seconds */
  127. status = fx_system_time_set(0, 0, 99);
  128. if (status != FX_INVALID_SECOND)
  129. {
  130. printf("ERROR!\n");
  131. test_control_return(8);
  132. }
  133. /* check system date set bad year */
  134. status = fx_system_date_set(99, 6, 6);
  135. if (status != FX_INVALID_YEAR)
  136. {
  137. printf("ERROR!\n");
  138. test_control_return(9);
  139. }
  140. /* check system date set bad month */
  141. status = fx_system_date_set(2015, 99, 6);
  142. if (status != FX_INVALID_MONTH)
  143. {
  144. printf("ERROR!\n");
  145. test_control_return(10);
  146. }
  147. /* check good and bad inputs for each month */
  148. for (i = 1; i <= 12; i++)
  149. {
  150. /* valid input for month i */
  151. status = fx_system_date_set(2015, i, 6);
  152. if (status != FX_SUCCESS)
  153. {
  154. printf("ERROR!\n");
  155. test_control_return(11);
  156. }
  157. /* invalid input for month i */
  158. status = fx_system_date_set(2015, i, 99);
  159. if (status != FX_INVALID_DAY)
  160. {
  161. printf("ERROR!\n");
  162. test_control_return(12);
  163. }
  164. }
  165. /* check bad input for feb on a leap year */
  166. status = fx_system_date_set(2016, 2, 99);
  167. if (status != FX_INVALID_DAY)
  168. {
  169. printf("ERROR!\n");
  170. test_control_return(13);
  171. }
  172. #endif
  173. /* Set the date and time. */
  174. status = fx_system_date_set(1999, 12, 31);
  175. /* Check for successful date set. */
  176. if (status != FX_SUCCESS)
  177. {
  178. /* Error setting date. Return to caller. */
  179. printf("ERROR!\n");
  180. test_control_return(4);
  181. }
  182. status = fx_system_time_set(23, 59, 58);
  183. /* Check for successful time set. */
  184. if (status != FX_SUCCESS)
  185. {
  186. /* Error setting time. Return to caller. */
  187. printf("ERROR!\n");
  188. test_control_return(14);
  189. }
  190. /* Call the internal system date get with NULL values. */
  191. status = _fx_system_date_get(FX_NULL, FX_NULL, FX_NULL);
  192. /* Get the date. */
  193. status += fx_system_date_get(&year, &month, &day);
  194. /* Check for successful date get. */
  195. if ((status != FX_SUCCESS) ||
  196. (year != 1999) ||
  197. (month != 12) ||
  198. (day != 31))
  199. {
  200. /* Error getting date. Return to caller. */
  201. printf("ERROR!\n");
  202. test_control_return(15);
  203. }
  204. /* Call the internal system time get. */
  205. status = _fx_system_time_get(FX_NULL, FX_NULL, FX_NULL);
  206. /* Get the time. */
  207. status += fx_system_time_get(&hour, &minute, &second);
  208. /* Check for successful time get. */
  209. if ((status != FX_SUCCESS) ||
  210. (hour != 23) ||
  211. (minute != 59) ||
  212. (second != 58))
  213. {
  214. /* Error getting time. Return to caller. */
  215. printf("ERROR!\n");
  216. test_control_return(16);
  217. }
  218. #ifndef FX_DISABLE_ERROR_CHECKING
  219. /* Get the time, but with a NULL value for month. */
  220. status = fx_system_time_get(&hour, FX_NULL, &second);
  221. /* Check for successful time get. */
  222. if (status != FX_PTR_ERROR)
  223. {
  224. /* Error getting time. Return to caller. */
  225. printf("ERROR!\n");
  226. test_control_return(17);
  227. }
  228. /* Get the time, but with a NULL value for second. */
  229. status = fx_system_time_get(&hour, &minute, FX_NULL);
  230. /* Check for successful time get. */
  231. if (status != FX_PTR_ERROR)
  232. {
  233. /* Error getting time. Return to caller. */
  234. printf("ERROR!\n");
  235. test_control_return(18);
  236. }
  237. /* Get the date, but with a NULL value for month. */
  238. status = fx_system_date_get(&year, FX_NULL, &day);
  239. /* Check for successful date get. */
  240. if (status != FX_PTR_ERROR)
  241. {
  242. /* Error getting date. Return to caller. */
  243. printf("ERROR!\n");
  244. test_control_return(19);
  245. }
  246. /* Get the date, but with a NULL value for day. */
  247. status = fx_system_date_get(&year, &month, FX_NULL);
  248. /* Check for successful date get. */
  249. if (status != FX_PTR_ERROR)
  250. {
  251. /* Error getting date. Return to caller. */
  252. printf("ERROR!\n");
  253. test_control_return(20);
  254. }
  255. /* Set the date, but with an invalid year over the max. */
  256. status = fx_system_date_set(FX_MAXIMUM_YEAR+1, 12, 1);
  257. /* Check for successful date set. */
  258. if (status != FX_INVALID_YEAR)
  259. {
  260. /* Error setting date. Return to caller. */
  261. printf("ERROR!\n");
  262. test_control_return(21);
  263. }
  264. /* Set the date, but with an invalid day (0). */
  265. status = fx_system_date_set(2016, 12, 0);
  266. /* Check for successful date set. */
  267. if (status != FX_INVALID_DAY)
  268. {
  269. /* Error setting date. Return to caller. */
  270. printf("ERROR!\n");
  271. test_control_return(22);
  272. }
  273. /* Set the date, but with a leap year an invalid day 30 for February. */
  274. status = fx_system_date_set(2016, 2, 30);
  275. /* Check for successful date set. */
  276. if (status != FX_INVALID_DAY)
  277. {
  278. /* Error setting date. Return to caller. */
  279. printf("ERROR!\n");
  280. test_control_return(22);
  281. }
  282. /* Set the date, but with a leap year and a valid day 29 for February. */
  283. status = fx_system_date_set(2016, 2, 29);
  284. /* Check for successful date set. */
  285. if (status != FX_SUCCESS)
  286. {
  287. /* Error setting date. Return to caller. */
  288. printf("ERROR!\n");
  289. test_control_return(23);
  290. }
  291. #endif
  292. /* Close the media. */
  293. status = fx_media_close(&ram_disk);
  294. /* Drive the system time logic. */
  295. /* Save the system date/time. */
  296. save_date = _fx_system_date;
  297. save_time = _fx_system_time;
  298. /* First call the system timer entry function with an invalid ID. */
  299. _fx_system_timer_entry(0);
  300. /* Now setup an invalid month to cause the error logic to hit. */
  301. _fx_system_date = _fx_system_date | 0x1E0; /* Set month to all ones - invalid > 12 */
  302. /* Now loop for the amount of updates (10 seconds per update) to cause the day to wrap. */
  303. for (i = 0; i < 86400; i++)
  304. {
  305. /* Adjust the time by calling the time update function. */
  306. _fx_system_timer_entry(FX_TIMER_ID);
  307. }
  308. /* Restore the system date/time. */
  309. _fx_system_date = save_date;
  310. _fx_system_time = save_time;
  311. /* Now call the system timer entry to walk through the maximum system time. */
  312. for (i = 0; i < 315360000; i++)
  313. {
  314. /* Adjust the time by calling the time update function. */
  315. _fx_system_timer_entry(FX_TIMER_ID);
  316. }
  317. /* Restore the system date/time. */
  318. _fx_system_date = save_date;
  319. _fx_system_time = save_time;
  320. /* Determine if the test was successful. */
  321. if (status != FX_SUCCESS)
  322. {
  323. printf("ERROR!\n");
  324. test_control_return(10);
  325. }
  326. else
  327. {
  328. printf("SUCCESS!\n");
  329. test_control_return(0);
  330. }
  331. }