1 /* This test is designed to test simple tx_time_get and set services.  */
2 
3 #include   <stdio.h>
4 #include   "tx_api.h"
5 #include   "tx_timer.h"
6 
7 static unsigned long   thread_0_counter =  0;
8 static TX_THREAD       thread_0;
9 
10 
11 /* Prototype for test control return.  */
12 void  test_control_return(UINT status);
13 
14 
15 /* Define thread prototypes.  */
16 
17 static void    thread_0_entry(ULONG thread_input);
18 
19 
20 /* Define what the initial system looks like.  */
21 
22 #ifdef CTEST
test_application_define(void * first_unused_memory)23 void test_application_define(void *first_unused_memory)
24 #else
25 void    threadx_time_get_set_application_define(void *first_unused_memory)
26 #endif
27 {
28 
29 UINT    status;
30 CHAR    *pointer;
31 
32     /* Put first available memory address into a character pointer.  */
33     pointer =  (CHAR *) first_unused_memory;
34 
35     /* Put system definition stuff in here, e.g. thread creates and other assorted
36        create information.  */
37 
38     status =  tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
39             pointer, TEST_STACK_SIZE_PRINTF,
40             16, 16, 3, TX_AUTO_START);
41     pointer = pointer + TEST_STACK_SIZE_PRINTF;
42 
43     /* Check for status.  */
44     if (status != TX_SUCCESS)
45     {
46 
47         printf("Running Time Simple Get/Set Test.................................... ERROR #1\n");
48         test_control_return(1);
49     }
50 }
51 
52 
53 
54 /* Define the test threads.  */
55 
thread_0_entry(ULONG thread_input)56 static void    thread_0_entry(ULONG thread_input)
57 {
58 
59 ULONG   current_time;
60 
61 
62     /* Inform user.  */
63     printf("Running Time Simple Get/Set Test.................................... ");
64 
65     /* Increment thread 0 counter.  */
66     thread_0_counter++;
67 
68     /* Sleep for 1 tick to get a fresh timer.  */
69     tx_thread_sleep(1);
70 
71     /* Set time to 0.  */
72     tx_time_set(0);
73 
74     /* Sleep for a couple ticks.  */
75     tx_thread_sleep(35);
76 
77     /* Pickup the current time.  */
78     /* Call internal function to cover this function.  */
79     current_time =  _tx_time_get();
80 
81     /* Check Current time.  It should be 35. */
82     if (current_time != 35)
83     {
84 
85         /* System time error.  */
86         printf("ERROR #2\n");
87         test_control_return(1);
88     }
89 
90     /* Set the new time.  */
91     tx_time_set(7);
92 
93     /* Check the new time.  */
94     if (tx_time_get() != 7)
95     {
96 
97         /* System time error.  */
98         printf("ERROR #3\n");
99         test_control_return(1);
100     }
101     else
102     {
103 
104         /* Successful time test.  */
105         printf("SUCCESS!\n");
106         test_control_return(0);
107     }
108 }
109 
110