view packages/io/wallclock/current/tests/wallclock2.cxx @ 80:2085233a121a ecos-sw-2000-04-07

Merge from eCos master repository on 2000-04-07-07:52:29-BST
author jlarmour
date Fri, 07 Apr 2000 07:45:04 +0000
parents
children 4642a6d35749
line wrap: on
line source

//==========================================================================
//
//        wallclock2.cxx
//
//        WallClock battery backed up test
//
//==========================================================================
//####COPYRIGHTBEGIN####
//                                                                          
// -------------------------------------------                              
// The contents of this file are subject to the Red Hat eCos Public License 
// Version 1.1 (the "License"); you may not use this file except in         
// compliance with the License.  You may obtain a copy of the License at    
// http://www.redhat.com/                                                   
//                                                                          
// Software distributed under the License is distributed on an "AS IS"      
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the 
// License for the specific language governing rights and limitations under 
// the License.                                                             
//                                                                          
// The Original Code is eCos - Embedded Configurable Operating System,      
// released September 30, 1998.                                             
//                                                                          
// The Initial Developer of the Original Code is Red Hat.                   
// Portions created by Red Hat are                                          
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.                             
// All Rights Reserved.                                                     
// -------------------------------------------                              
//                                                                          
//####COPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s):     jskov
// Contributors:  jskov
// Date:          2000-03-29
// Description:   Tests the WallClock device.
//                Prints wallclock setting (for human verification that time
//                matches the expected value). Then tries to set/restore
//                clock value, and verifies that the WallClock epoch matches
//                that of the libc.
//####DESCRIPTIONEND####
// -------------------------------------------------------------------------

#include <pkgconf/system.h>
#include <cyg/infra/testcase.h>
#include <cyg/infra/diag.h>
#ifdef CYGPKG_LIBC
#include <pkgconf/libc.h>
#endif

#if defined(CYGSEM_LIBC_TIME_CLOCK_WORKING)

#include <time.h>
#include <cyg/io/wallclock.hxx>

// -------------------------------------------------------------------------


externC int
main (void )
{
    time_t now, test;

    CYG_TEST_INIT();

    // make this predictable - independent of the user option
    cyg_libc_time_setzoneoffsets(0, 3600);
    cyg_libc_time_setdst( CYG_LIBC_TIME_DSTOFF );

    // Print out current setting so a human can verify that clock state
    // was valid.
    now = (time_t) Cyg_WallClock::wallclock->get_current_time();
    diag_printf("WallClock is set to: %s", ctime(&now));

    // Check that set/get works
    Cyg_WallClock::wallclock->set_current_time( 0 );
    test = (time_t) Cyg_WallClock::wallclock->get_current_time();
    Cyg_WallClock::wallclock->set_current_time( now );
    CYG_TEST_PASS_FAIL(0 == test, "Can set WallClock to epoch");
    
    // Test that the wallclock and libc use same epoch.
    test = (time_t) 0;
    CYG_TEST_PASS_FAIL(!strcmp(ctime(&test), "Thu Jan 01 00:00:00 1970\n"),
                       "WallClock epoch matches libc epoch");

    CYG_TEST_FINISH("Finished wallclock battery test");
}

#else 
#define NA_MSG "Requires libc time functions"
#endif

#ifdef NA_MSG

externC void
cyg_start( void )
{
    CYG_TEST_INIT();
    CYG_TEST_PASS_FINISH(NA_MSG);
}

#endif // NA_MSG

// -------------------------------------------------------------------------
// EOF wallclock2.cxx