OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [language/] [c/] [libc/] [time/] [v2_0/] [tests/] [time.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//=================================================================
2
//
3
//        time.c
4
//
5
//        Testcase for C library time()
6
//
7
//=================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//=================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):     jlarmour
44
// Contributors:  jlarmour
45
// Date:          1999-03-05
46
// Description:   Contains testcode for C library time() function
47
//
48
//
49
//####DESCRIPTIONEND####
50
 
51
// CONFIGURATION
52
 
53
#include <pkgconf/libc_time.h>   // Configuration header
54
 
55
// INCLUDES
56
 
57
#include <time.h>
58
#include <cyg/infra/testcase.h>
59
 
60
// CONSTANTS
61
 
62
// This defines how many loops before we decide that
63
// time() doesn't work
64
#define MAX_TIMEOUT 50000000
65
 
66
 
67
// FUNCTIONS
68
 
69
int
70
main(int argc, char *argv[])
71
{
72
    time_t t1, t2;
73
    unsigned long ctr;
74
 
75
    CYG_TEST_INIT();
76
 
77
    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
78
                  "time() function");
79
 
80
    t1 = time(&t2);
81
 
82
    CYG_TEST_PASS_FAIL(t1==t2, "time() return value == argument");
83
 
84
    if (t1 == (time_t)-1)  // unimplemented is just as valid
85
    {
86
#ifndef CYGSEM_LIBC_TIME_TIME_WORKING
87
        CYG_TEST_PASS_FINISH( "time() returns -1, meaning unimplemented");
88
#else
89
        CYG_TEST_FAIL("time() returned -1 unnecessarily");
90
#endif
91
    } // if
92
 
93
    // First wait for a clock tick 
94
 
95
    for (ctr = 0; ctr<MAX_TIMEOUT; ctr++) {
96
        if ((t2=time(NULL)) > t1)
97
            break; // Hit the next time pulse
98
    }
99
    CYG_TEST_PASS_FAIL( ctr< MAX_TIMEOUT, "time()'s state changes");
100
 
101
#ifdef CYGSEM_LIBC_TIME_SETTIME_WORKING
102
    CYG_TEST_PASS_FAIL(cyg_libc_time_settime(0)==0, "Set time to 0");
103
 
104
    t1 = time(NULL);
105
 
106
    // give it a small amount of tolerance
107
    CYG_TEST_PASS_FAIL(t1 < 3, "t1 remembered setting");
108
 
109
    CYG_TEST_PASS_FAIL(cyg_libc_time_settime(1000)==0, "Set time to 1000");
110
 
111
    // give it a small amount of tolerance
112
    CYG_TEST_PASS_FAIL(t1 < 1003, "t1 remembered setting");
113
 
114
#else // ! CYGSEM_LIBC_TIME_SETTIME_WORKING
115
    CYG_TEST_PASS_FAIL(cyg_libc_time_settime(0)!=0,
116
                       "Set time expected fail");
117
#endif // CYGSEM_LIBC_TIME_SETTIME_WORKING
118
 
119
    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
120
                    "time() function");
121
} // main()
122
 
123
// EOF time.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.