[dmd-internals] dmd test suite coverage

Don Clugston dclugston at googlemail.com
Mon Sep 6 11:40:07 PDT 2010


On 3 September 2010 23:48, Walter Bright <walter at digitalmars.com> wrote:
> I built dmd with coverage analysis (gcov on linux) and ran the test suite.
> This is one of the result files - there are definitely gaps in the suite.

There were some very large gaps in interpret.c.
This isn't entirely a test suite issue, though -- there's a big block
of unreachable code. ForeachStatement::interpret() and
ForeachRangeStatement::interpret() should be completely deleted. Like
'while', they are turned into 'for' in the semantic pass.
I've made a few tests for the other major gaps. This is by no means
comprehensive, but it should nearly halve the number of uncovered
lines.

Add these tests to the end of interpret3.d
-------------

// Interpreter code coverage tests
int cov1(int a)
{
   a %= 15382;
   a /= 5;
   a = ~ a;
   bool c = (a==0);
   bool b = true && c;
   assert(b==0);
   b = false && c;
   assert(b==0);
   b = false || c;
   assert(b==0);
   a ^= 0x45349;
   a = ~ a;
   a &= 0xFF3F;
   a >>>= 1;
   a = a ^ 0x7393;
   a = a >> 1;
   a = a >>> 1;
   a = a | 0x010101;
   return a;
}
static assert(cov1(534564) == 71589);

int cov2()
{
    int i = 0;
    do{
        goto DOLABEL;
    DOLABEL:
        if (i!=0) {
            goto IFLABEL;
    IFLABEL:
            switch(i) {
            case 3:
                break;
            case 6:
                goto SWITCHLABEL;
    SWITCHLABEL:
                i = 27;
                goto case 3;
            }
            return i;
        }
        i = 6;
    } while(true);
    return 88; // unreachable
}

static assert(cov2()==27);

template CovTuple(T...)
{
  alias T CovTuple;
}

alias CovTuple!(int, long) TCov3;

int cov3(TCov3 t)
{
    TCov3 s;
    s = t;
    assert(s[0] == 1);
    assert(s[1] == 2);
    return 7;
}

static assert(cov3(1, 2) == 7);

template compiles(int T)
{
   bool compiles = true;
}

int badassert1(int z)
{
   assert(z == 5, "xyz");
   return 1;
}

int badslice1(int[] z)
{
  return z[0..3].length;
}

int badslice2(int[] z)
{
  return z[0..badassert1(1)].length;
}

int badslice3(int[] z)
{
  return z[badassert1(1)..2].length;
}

static assert(!is(typeof(compiles!(badassert1(67)))));
static assert(is(typeof(compiles!(badassert1(5)))));
static assert(!is(typeof(compiles!(badslice1([1,2])))));
static assert(!is(typeof(compiles!(badslice2([1,2])))));
static assert(!is(typeof(compiles!(badslice3([1,2,3])))));


More information about the dmd-internals mailing list