sorry one more question: assert statements in tests

Misha Koshelev misha680 at gmail.com
Sat Jul 10 11:40:20 CDT 2010


On Sat, 2010-07-10 at 07:40 +0100, Reece Dunn wrote:
> On 10 July 2010 03:40, Misha Koshelev <misha680 at gmail.com> wrote:
> > I am implementing my tests as follows:
> >
> > * patch 1: general test for a D3DX function (D3DXCreateBox for example,
> > testing specific vertices and indices for _specific_ dimensions).
> > * patch 2: separate into function that works with arbitrary dimensions
> > for the box, etc. I restrict to the dimensions from patch 1 using assert
> > statements.
> > * patch 3: expand to allow arbitrary parameters to the function, e.g.,
> > arbitrary dimensions, removing the assert statements.
> >
> > For example, see
> >
> > patch 2 =
> > http://github.com/misha680/wine/commit/6291ca28593c78761ccef3137b1014bae87d24b6
> >
> > patch 3 =
> > http://github.com/misha680/wine/commit/7b09cfb661bf1d03fd80195c0cd2b7b3bb9f1561
> >
> > Is assert the right way to do this? If not, what is?
> 
> Assert should be avoided in the tests.
> 
> If the assert fails, you will see that the test crashed -- especially
> when the results are on tests.winehq.org. This makes it difficult to
> track what went wrong.
> 
> You should use an ok or skip/win_skip message so that information gets
> logged and people looking at the failure can see what failed.
> 
> - Reece

Ok that makes sense.

What about in the case of something like this:

/*
http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
 * "I think the answer is 10,000 but since floating point math is
imperfect I’ll accept the maxUlps floats above and the maxUlps floats
below that value." */
static BOOLEAN AlmostEqual2sComplement(float A, float B, int maxUlps)
{
    int aInt, bInt, intDiff;
    /* Make sure maxUlps is non-negative and small enough that the
     * default NAN won't compare as equal to anything. */
    assert(maxUlps > 0 && maxUlps < 4 * 1024 * 1024);
    aInt= *(int*)&A;
    /* Make aInt lexicographically ordered as a twos-complement int */
    if (aInt < 0)
        aInt = 0x80000000 - aInt;
    /* Make bInt lexicographically ordered as a twos-complement int */
    bInt = *(int*)&B;
    if (bInt < 0)
        bInt = 0x80000000 - bInt;
    intDiff = abs(aInt - bInt);
    if (intDiff <= maxUlps)
        return TRUE;
    return FALSE;
}

Is assert ok here or do I need to change it to some kind of skip
statement as well?

The problem here is that the skip statement would be inside a helper
function, and I guess it wouldn't actually skip.

I could always return FALSE, but that doesn't seem quite right here.

Should I just take the assert out altogether here then if they are not
allowed in tests or is it not so black & white?

Thanks
Misha




More information about the wine-devel mailing list