Code coverage tests

This page documents the degree to which the PARI/GP source code is tested by our public test suite, distributed with the source distribution in directory src/test/. This is measured by the gcov utility; we then process gcov output using the lcov frond-end.

We test a few variants depending on Configure flags on the pari.math.u-bordeaux1.fr machine (x86_64 architecture), and agregate them in the final report:

The target is 90% coverage for all mathematical modules (given that branches depending on DEBUGLEVEL or DEBUGMEM are not covered). This script is run to produce the results below.

LCOV - code coverage report
Current view: top level - kernel/none - gcd.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.8.0 lcov report (development 16962-5a32637) Lines: 56 56 100.0 %
Date: 2014-10-29 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 52 53 98.1 %

           Branch data     Line data    Source code
       1                 :            : #line 2 "../src/kernel/none/gcd.c"
       2                 :            : /* Copyright (C) 2003  The PARI group.
       3                 :            : 
       4                 :            : This file is part of the PARI/GP package.
       5                 :            : 
       6                 :            : PARI/GP is free software; you can redistribute it and/or modify it under the
       7                 :            : terms of the GNU General Public License as published by the Free Software
       8                 :            : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       9                 :            : ANY WARRANTY WHATSOEVER.
      10                 :            : 
      11                 :            : Check the License for details. You should have received a copy of it, along
      12                 :            : with the package; see the file 'COPYING'. If not, write to the Free Software
      13                 :            : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      14                 :            : 
      15                 :            : /* assume y > x > 0. return y mod x */
      16                 :            : static ulong
      17                 :    2660097 : resiu(GEN y, ulong x)
      18                 :            : {
      19                 :    2660097 :   long i, ly = lgefint(y);
      20                 :    2660097 :   ulong xi = get_Fl_red(x);
      21                 :            :   LOCAL_HIREMAINDER;
      22                 :            : 
      23                 :    2660097 :   hiremainder = 0;
      24 [ +  + ][ +  + ]:   11917392 :   for (i=2; i<ly; i++) (void)divll_pre(y[i],x,xi);
            [ +  + ][ + ]
         [ +  + ][ +  + ]
         [ +  + ][ +  + ]
      25                 :    2660097 :   return hiremainder;
      26                 :            : }
      27                 :            : 
      28                 :            : /* Assume x>y>0, both of them odd. return x-y if x=y mod 4, x+y otherwise */
      29                 :            : static void
      30                 :   83262252 : gcd_plus_minus(GEN x, GEN y, GEN res)
      31                 :            : {
      32                 :   83262252 :   pari_sp av = avma;
      33                 :   83262252 :   long lx = lgefint(x)-1;
      34                 :   83262252 :   long ly = lgefint(y)-1, lt,m,i;
      35                 :            :   GEN t;
      36                 :            : 
      37         [ +  + ]:   83262252 :   if ((x[lx]^y[ly]) & 3) /* x != y mod 4*/
      38                 :   41875806 :     t = addiispec(x+2,y+2,lx-1,ly-1);
      39                 :            :   else
      40                 :   41386446 :     t = subiispec(x+2,y+2,lx-1,ly-1);
      41                 :            : 
      42         [ +  + ]:   83262960 :   lt = lgefint(t)-1; while (!t[lt]) lt--;
      43                 :   83262252 :   m = vals(t[lt]); lt++;
      44         [ +  + ]:   83262252 :   if (m == 0) /* 2^32 | t */
      45                 :            :   {
      46         [ +  + ]:          6 :     for (i = 2; i < lt; i++) res[i] = t[i];
      47                 :            :   }
      48         [ +  + ]:   83262249 :   else if (t[2] >> m)
      49                 :            :   {
      50                 :   78302676 :     shift_right(res,t, 2,lt, 0,m);
      51                 :            :   }
      52                 :            :   else
      53                 :            :   {
      54                 :    4959573 :     lt--; t++;
      55                 :    4959573 :     shift_right(res,t, 2,lt, t[1],m);
      56                 :            :   }
      57                 :   83262252 :   res[1] = evalsigne(1)|evallgefint(lt);
      58                 :   83262252 :   avma = av;
      59                 :   83262252 : }
      60                 :            : 
      61                 :            : /* uses modified right-shift binary algorithm now --GN 1998Jul23 */
      62                 :            : GEN
      63                 :   66461766 : gcdii(GEN a, GEN b)
      64                 :            : {
      65                 :            :   long v, w;
      66                 :            :   pari_sp av;
      67                 :            :   GEN t, p1;
      68                 :            : 
      69      [ +  +  + ]:   66461766 :   switch (absi_cmp(a,b))
      70                 :            :   {
      71                 :   15848646 :     case 0: return absi(a);
      72                 :   13138200 :     case -1: t=b; b=a; a=t;
      73                 :            :   }
      74         [ +  + ]:   50613120 :   if (!signe(b)) return absi(a);
      75                 :            :   /* here |a|>|b|>0. Try single precision first */
      76         [ +  + ]:   21800562 :   if (lgefint(a)==3)
      77                 :   16833312 :     return igcduu((ulong)a[2], (ulong)b[2]);
      78         [ +  + ]:    4967250 :   if (lgefint(b)==3)
      79                 :            :   {
      80                 :    2660097 :     ulong u = resiu(a,(ulong)b[2]);
      81         [ +  + ]:    2660097 :     if (!u) return absi(b);
      82                 :    1572381 :     return igcduu((ulong)b[2], u);
      83                 :            :   }
      84                 :            : 
      85                 :            :   /* larger than gcd: "avma=av" gerepile (erasing t) is valid */
      86                 :    2307153 :   av = avma; (void)new_chunk(lgefint(b)); /* HACK */
      87                 :    2307153 :   t = remii(a,b);
      88         [ +  + ]:    2307153 :   if (!signe(t)) { avma=av; return absi(b); }
      89                 :            : 
      90                 :    1593234 :   a = b; b = t;
      91                 :    1593234 :   v = vali(a); a = shifti(a,-v); setabssign(a);
      92                 :    1593234 :   w = vali(b); b = shifti(b,-w); setabssign(b);
      93         [ +  + ]:    1593234 :   if (w < v) v = w;
      94      [ +  +  + ]:    1593234 :   switch(absi_cmp(a,b))
      95                 :            :   {
      96                 :      70317 :     case  0: avma=av; a=shifti(a,v); return a;
      97                 :     278697 :     case -1: p1=b; b=a; a=p1;
      98                 :            :   }
      99         [ +  + ]:    1522917 :   if (is_pm1(b)) { avma=av; return int2n(v); }
     100                 :            : 
     101                 :            :   /* we have three consecutive memory locations: a,b,t.
     102                 :            :    * All computations are done in place */
     103                 :            : 
     104                 :            :   /* a and b are odd now, and a>b>1 */
     105         [ +  + ]:   84516909 :   while (lgefint(a) > 3)
     106                 :            :   {
     107                 :            :     /* if a=b mod 4 set t=a-b, otherwise t=a+b, then strip powers of 2 */
     108                 :            :     /* so that t <= (a+b)/4 < a/2 */
     109                 :   83262252 :     gcd_plus_minus(a,b, t);
     110         [ +  + ]:   83262252 :     if (is_pm1(t)) { avma=av; return int2n(v); }
     111   [ +  +  +  - ]:   83261595 :     switch(absi_cmp(t,b))
     112                 :            :     {
     113                 :   54916770 :       case -1: p1 = a; a = b; b = t; t = p1; break;
     114                 :   28093395 :       case  1: p1 = a; a = t; t = p1; break;
     115                 :     251430 :       case  0: avma = av; b=shifti(b,v); return b;
     116                 :            :     }
     117                 :            :   }
     118                 :            :   {
     119                 :    1254657 :     long r[] = {evaltyp(t_INT)|_evallg(3), evalsigne(1)|evallgefint(3), 0};
     120                 :    1254657 :     r[2] = (long) gcduodd((ulong)b[2], (ulong)a[2]);
     121                 :   66461766 :     avma = av; return shifti(r,v);
     122                 :            :   }
     123                 :            : }

Generated by: LCOV version 1.9