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