This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: libc-time-clock test doesn't seem to be written correctly??



The for loop counts how long it takes for the return value of clock() to change, that's all. Since the code is looped over in a consistent way, how far the for loop counts should be roughly the same if you run it again and again.


then following change will achieve more correctly and closely what you have mentioned above i.e. -- "how long it takes for the return value of clock() to change".

static unsigned long
clock_loop( const int timeout, clock_t prevclock, clock_t *newclock )
{
    clock_t c=0;
    long i;

// ++++++++++++++++

    c = clock();
    while ((prevclock = clock()) == c) /* do nothing */ ;

// now when we enter the for-loop below, clock() value has just changed

// ++++++++++++++++

    for (i=0; i<timeout; i++) {
        c = clock();
        if ( c != prevclock )
            break; // Hit the next clock pulse
    }

    if (i==timeout)
        CYG_TEST_FAIL_FINISH("No change in clock state!");

// ???????????????
// why should following be a fail condition in test where we are trying to
// check for clock stability
// ???????????????

// NRN-start : Not Really Needed, in the view of what test is aiming at

    // it should not overflow in the lifetime of this test
    if (c < prevclock)
        CYG_TEST_FAIL_FINISH("Clock decremented!");

*newclock = c;

// NRN-end

    return i;
} // clock_loop()

test possibly could be simplified more, as the clock_t arguments to clock_loop might not be required, if code b/w "// NRN-start ..... // NRN-end" is removed.

further leadeding to simplifications in main().


only use of obtained clock() value in main() is to test for "... meaning unimplemented", that will


remain even w/o need of clocks[].


-- regards sandeep ----------------------------------------------------------------------- Ashes to ashes,dust to dust, if the Lord won't have you, the Devil must. -----------------------------------------------------------------------


-- Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]