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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [wallclock/] [current/] [tests/] [wallclock2.cxx] - Blame information for rev 825

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        wallclock2.cxx
4
//
5
//        WallClock battery backed up test
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 Free Software Foundation, 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      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):     jskov
43
// Contributors:  jskov
44
// Date:          2000-03-29
45
// Description:   Tests the WallClock device.
46
//                Prints wallclock setting (for human verification that time
47
//                matches the expected value). Then tries to set/restore
48
//                clock value, and verifies that the WallClock epoch matches
49
//                that of the libc.
50
//####DESCRIPTIONEND####
51
// -------------------------------------------------------------------------
52
 
53
#include <pkgconf/system.h>
54
#include <cyg/infra/testcase.h>
55
#include <cyg/infra/diag.h>
56
#ifdef CYGPKG_LIBC_TIME
57
#include <pkgconf/libc_time.h>
58
#endif
59
#ifdef CYGPKG_LIBC_STARTUP
60
#include <pkgconf/libc_startup.h>
61
#endif
62
 
63
#if !defined(CYGSEM_LIBC_TIME_CLOCK_WORKING)
64
# define NA_MSG "Requires libc time functions"
65
#elif !defined(CYGPKG_LIBC_STARTUP)
66
# define NA_MSG "Requires libc startup package"
67
#endif
68
 
69
#ifndef NA_MSG
70
#include <time.h>
71
#include <string.h>                     // strcmp
72
#include <cyg/io/wallclock.hxx>         // The WallClock API
73
 
74
// -------------------------------------------------------------------------
75
 
76
 
77
externC int
78
main (void )
79
{
80
    time_t now, test, test2;
81
 
82
    CYG_TEST_INIT();
83
 
84
    // make this predictable - independent of the user option
85
    cyg_libc_time_setzoneoffsets(0, 3600);
86
    cyg_libc_time_setdst( CYG_LIBC_TIME_DSTOFF );
87
 
88
    // Print out current setting so a human can verify that clock state
89
    // was valid.
90
    now = (time_t) Cyg_WallClock::wallclock->get_current_time();
91
    diag_printf("WallClock is set to: %s", ctime(&now));
92
 
93
    // Check that set/get works
94
    Cyg_WallClock::wallclock->set_current_time( 0 );
95
    test = (time_t) Cyg_WallClock::wallclock->get_current_time();
96
    // 2000.03.01 00:00:00 UTC
97
    Cyg_WallClock::wallclock->set_current_time( 951868800 );
98
    test2 = (time_t) Cyg_WallClock::wallclock->get_current_time();
99
    // Should test 2100 and 2400 leap year calculations as well, but 
100
    // these would overflow with today's time_t.
101
    Cyg_WallClock::wallclock->set_current_time( now );
102
    CYG_TEST_PASS_FAIL(2 >= test,  // each operation can take one second
103
                       "Can set WallClock to epoch");
104
    CYG_TEST_PASS_FAIL(951868800+2 > test2 &&
105
                       951868800 <= test2,
106
                       "WallClock date conversion Y2K safe");
107
 
108
    // Test that the wallclock and libc use same epoch.
109
    test = (time_t) 0;
110
    CYG_TEST_PASS_FAIL(!strcmp(ctime(&test), "Thu Jan 01 00:00:00 1970\n"),
111
                       "WallClock epoch matches libc epoch");
112
 
113
    CYG_TEST_FINISH("Finished wallclock battery test");
114
}
115
 
116
#else 
117
 
118
externC void
119
cyg_start( void )
120
{
121
    CYG_TEST_INIT();
122
    CYG_TEST_PASS_FINISH(NA_MSG);
123
}
124
 
125
#endif // NA_MSG
126
 
127
// -------------------------------------------------------------------------
128
// EOF wallclock2.cxx

powered by: WebSVN 2.1.0

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