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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [wallclock/] [v2_0/] [tests/] [wallclock2.cxx] - Blame information for rev 565

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
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 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):     jskov
44
// Contributors:  jskov
45
// Date:          2000-03-29
46
// Description:   Tests the WallClock device.
47
//                Prints wallclock setting (for human verification that time
48
//                matches the expected value). Then tries to set/restore
49
//                clock value, and verifies that the WallClock epoch matches
50
//                that of the libc.
51
//####DESCRIPTIONEND####
52
// -------------------------------------------------------------------------
53
 
54
#include <pkgconf/system.h>
55
#include <cyg/infra/testcase.h>
56
#include <cyg/infra/diag.h>
57
#ifdef CYGPKG_LIBC_TIME
58
#include <pkgconf/libc_time.h>
59
#endif
60
#ifdef CYGPKG_LIBC_STARTUP
61
#include <pkgconf/libc_startup.h>
62
#endif
63
 
64
#if !defined(CYGSEM_LIBC_TIME_CLOCK_WORKING)
65
# define NA_MSG "Requires libc time functions"
66
#elif !defined(CYGPKG_LIBC_STARTUP)
67
# define NA_MSG "Requires libc startup package"
68
#endif
69
 
70
#ifndef NA_MSG
71
#include <time.h>
72
#include <string.h>                     // strcmp
73
#include <cyg/io/wallclock.hxx>         // The WallClock API
74
 
75
// -------------------------------------------------------------------------
76
 
77
 
78
externC int
79
main (void )
80
{
81
    time_t now, test, test2;
82
 
83
    CYG_TEST_INIT();
84
 
85
    // make this predictable - independent of the user option
86
    cyg_libc_time_setzoneoffsets(0, 3600);
87
    cyg_libc_time_setdst( CYG_LIBC_TIME_DSTOFF );
88
 
89
    // Print out current setting so a human can verify that clock state
90
    // was valid.
91
    now = (time_t) Cyg_WallClock::wallclock->get_current_time();
92
    diag_printf("WallClock is set to: %s", ctime(&now));
93
 
94
    // Check that set/get works
95
    Cyg_WallClock::wallclock->set_current_time( 0 );
96
    test = (time_t) Cyg_WallClock::wallclock->get_current_time();
97
    // 2000.03.01 00:00:00 UTC
98
    Cyg_WallClock::wallclock->set_current_time( 951868800 );
99
    test2 = (time_t) Cyg_WallClock::wallclock->get_current_time();
100
    // Should test 2100 and 2400 leap year calculations as well, but 
101
    // these would overflow with today's time_t.
102
    Cyg_WallClock::wallclock->set_current_time( now );
103
    CYG_TEST_PASS_FAIL(2 >= test,  // each operation can take one second
104
                       "Can set WallClock to epoch");
105
    CYG_TEST_PASS_FAIL(951868800+2 > test2 &&
106
                       951868800 <= test2,
107
                       "WallClock date conversion Y2K safe");
108
 
109
    // Test that the wallclock and libc use same epoch.
110
    test = (time_t) 0;
111
    CYG_TEST_PASS_FAIL(!strcmp(ctime(&test), "Thu Jan 01 00:00:00 1970\n"),
112
                       "WallClock epoch matches libc epoch");
113
 
114
    CYG_TEST_FINISH("Finished wallclock battery test");
115
}
116
 
117
#else 
118
 
119
externC void
120
cyg_start( void )
121
{
122
    CYG_TEST_INIT();
123
    CYG_TEST_PASS_FINISH(NA_MSG);
124
}
125
 
126
#endif // NA_MSG
127
 
128
// -------------------------------------------------------------------------
129
// EOF wallclock2.cxx

powered by: WebSVN 2.1.0

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