comparison packages/language/c/libc/time/current/tests/time.c @ 115:6ed91473a1cd ecos-sw-2000-08-21

Merge from eCos master repository on 2000-08-21-22:40:54-BST
author jlarmour
date Fri, 25 Aug 2000 17:32:38 +0000
parents
children ac086aa3217e
comparison
equal deleted inserted replaced
114:5ad2b71d525e 115:6ed91473a1cd
1 //=================================================================
2 //
3 // time.c
4 //
5 // Testcase for C library time()
6 //
7 //=================================================================
8 //####COPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 // The contents of this file are subject to the Red Hat eCos Public License
12 // Version 1.1 (the "License"); you may not use this file except in
13 // compliance with the License. You may obtain a copy of the License at
14 // http://www.redhat.com/
15 //
16 // Software distributed under the License is distributed on an "AS IS"
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
18 // License for the specific language governing rights and limitations under
19 // the License.
20 //
21 // The Original Code is eCos - Embedded Configurable Operating System,
22 // released September 30, 1998.
23 //
24 // The Initial Developer of the Original Code is Red Hat.
25 // Portions created by Red Hat are
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
27 // All Rights Reserved.
28 // -------------------------------------------
29 //
30 //####COPYRIGHTEND####
31 //=================================================================
32 //#####DESCRIPTIONBEGIN####
33 //
34 // Author(s): jlarmour
35 // Contributors: jlarmour
36 // Date: 1999-03-05
37 // Description: Contains testcode for C library time() function
38 //
39 //
40 //####DESCRIPTIONEND####
41
42 // CONFIGURATION
43
44 #include <pkgconf/libc_time.h> // Configuration header
45
46 // INCLUDES
47
48 #include <time.h>
49 #include <cyg/infra/testcase.h>
50
51 // CONSTANTS
52
53 // This defines how many loops before we decide that
54 // time() doesn't work
55 #define MAX_TIMEOUT 5000000
56
57
58 // FUNCTIONS
59
60 int
61 main(int argc, char *argv[])
62 {
63 time_t t1, t2;
64 unsigned long ctr;
65
66 CYG_TEST_INIT();
67
68 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
69 "time() function");
70
71 t1 = time(&t2);
72
73 CYG_TEST_PASS_FAIL(t1==t2, "time() return value == argument");
74
75 if (t1 == (time_t)-1) // unimplemented is just as valid
76 {
77 #ifndef CYGSEM_LIBC_TIME_TIME_WORKING
78 CYG_TEST_PASS_FINISH( "time() returns -1, meaning unimplemented");
79 #else
80 CYG_TEST_FAIL("time() returned -1 unnecessarily");
81 #endif
82 } // if
83
84 // First wait for a clock tick
85
86 for (ctr = 0; ctr<MAX_TIMEOUT; ctr++) {
87 if ((t2=time(NULL)) > t1)
88 break; // Hit the next time pulse
89 }
90 CYG_TEST_PASS_FAIL( ctr< MAX_TIMEOUT, "time()'s state changes");
91
92 #ifdef CYGSEM_LIBC_TIME_SETTIME_WORKING
93 CYG_TEST_PASS_FAIL(cyg_libc_time_settime(0)==0, "Set time to 0");
94
95 t1 = time(NULL);
96
97 // give it a small amount of tolerance
98 CYG_TEST_PASS_FAIL(t1 < 3, "t1 remembered setting");
99
100 CYG_TEST_PASS_FAIL(cyg_libc_time_settime(1000)==0, "Set time to 1000");
101
102 // give it a small amount of tolerance
103 CYG_TEST_PASS_FAIL(t1 < 1003, "t1 remembered setting");
104
105 #else // ! CYGSEM_LIBC_TIME_SETTIME_WORKING
106 CYG_TEST_PASS_FAIL(cyg_libc_time_settime(0)!=0,
107 "Set time expected fail");
108 #endif // CYGSEM_LIBC_TIME_SETTIME_WORKING
109
110 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
111 "time() function");
112 } // main()
113
114 // EOF time.c