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-bordeaux.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 19053-42ab05e) Lines: 56 56 100.0 %
Date: 2016-06-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                 :    6167337 : resiu(GEN y, ulong x)
      18                 :            : {
      19                 :    6167337 :   long i, ly = lgefint(y);
      20                 :    6167337 :   ulong xi = get_Fl_red(x);
      21                 :            :   LOCAL_HIREMAINDER;
      22                 :            : 
      23                 :    6167337 :   hiremainder = 0;
      24 [ +  + ][ +  + ]:   39742425 :   for (i=2; i<ly; i++) (void)divll_pre(y[i],x,xi);
            [ +  + ][ + ]
         [ +  + ][ +  + ]
         [ +  + ][ +  + ]
      25                 :    6167337 :   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                 :  591797424 : gcd_plus_minus(GEN x, GEN y, GEN res)
      31                 :            : {
      32                 :  591797424 :   pari_sp av = avma;
      33                 :  591797424 :   long lx = lgefint(x)-1;
      34                 :  591797424 :   long ly = lgefint(y)-1, lt,m,i;
      35                 :            :   GEN t;
      36                 :            : 
      37         [ +  + ]:  591797424 :   if ((x[lx]^y[ly]) & 3) /* x != y mod 4*/
      38                 :  296180361 :     t = addiispec(x+2,y+2,lx-1,ly-1);
      39                 :            :   else
      40                 :  295617063 :     t = subiispec(x+2,y+2,lx-1,ly-1);
      41                 :            : 
      42         [ +  + ]:  592525116 :   lt = lgefint(t)-1; while (!t[lt]) lt--;
      43                 :  591797424 :   m = vals(t[lt]); lt++;
      44         [ +  + ]:  591797424 :   if (m == 0) /* 2^32 | t */
      45                 :            :   {
      46         [ +  + ]:      22287 :     for (i = 2; i < lt; i++) res[i] = t[i];
      47                 :            :   }
      48         [ +  + ]:  591793131 :   else if (t[2] >> m)
      49                 :            :   {
      50                 :  560894508 :     shift_right(res,t, 2,lt, 0,m);
      51                 :            :   }
      52                 :            :   else
      53                 :            :   {
      54                 :   30898623 :     lt--; t++;
      55                 :   30898623 :     shift_right(res,t, 2,lt, t[1],m);
      56                 :            :   }
      57                 :  591797424 :   res[1] = evalsigne(1)|evallgefint(lt);
      58                 :  591797424 :   avma = av;
      59                 :  591797424 : }
      60                 :            : 
      61                 :            : /* uses modified right-shift binary algorithm now --GN 1998Jul23 */
      62                 :            : GEN
      63                 :   95068935 : gcdii(GEN a, GEN b)
      64                 :            : {
      65                 :            :   long v, w;
      66                 :            :   pari_sp av;
      67                 :            :   GEN t, p1;
      68                 :            : 
      69      [ +  +  + ]:   95068935 :   switch (absi_cmp(a,b))
      70                 :            :   {
      71                 :   16881612 :     case 0: return absi(a);
      72                 :   24291198 :     case -1: t=b; b=a; a=t;
      73                 :            :   }
      74         [ +  + ]:   78187323 :   if (!signe(b)) return absi(a);
      75                 :            :   /* here |a|>|b|>0. Try single precision first */
      76         [ +  + ]:   48528720 :   if (lgefint(a)==3)
      77                 :   35928321 :     return igcduu((ulong)a[2], (ulong)b[2]);
      78         [ +  + ]:   12600399 :   if (lgefint(b)==3)
      79                 :            :   {
      80                 :    6167337 :     ulong u = resiu(a,(ulong)b[2]);
      81         [ +  + ]:    6167337 :     if (!u) return absi(b);
      82                 :    4624140 :     return igcduu((ulong)b[2], u);
      83                 :            :   }
      84                 :            : 
      85                 :            :   /* larger than gcd: "avma=av" gerepile (erasing t) is valid */
      86                 :    6433062 :   av = avma; (void)new_chunk(lgefint(b)); /* HACK */
      87                 :    6433062 :   t = remii(a,b);
      88         [ +  + ]:    6433062 :   if (!signe(t)) { avma=av; return absi(b); }
      89                 :            : 
      90                 :    5220129 :   a = b; b = t;
      91                 :    5220129 :   v = vali(a); a = shifti(a,-v); setabssign(a);
      92                 :    5220129 :   w = vali(b); b = shifti(b,-w); setabssign(b);
      93         [ +  + ]:    5220129 :   if (w < v) v = w;
      94      [ +  +  + ]:    5220129 :   switch(absi_cmp(a,b))
      95                 :            :   {
      96                 :      89496 :     case  0: avma=av; a=shifti(a,v); return a;
      97                 :    1027557 :     case -1: p1=b; b=a; a=p1;
      98                 :            :   }
      99         [ +  + ]:    5130633 :   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         [ +  + ]:  596054247 :   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                 :  591797424 :     gcd_plus_minus(a,b, t);
     110         [ +  + ]:  591797424 :     if (is_pm1(t)) { avma=av; return int2n(v); }
     111   [ +  +  +  - ]:  591662016 :     switch(absi_cmp(t,b))
     112                 :            :     {
     113                 :  385779873 :       case -1: p1 = a; a = b; b = t; t = p1; break;
     114                 :  205341255 :       case  1: p1 = a; a = t; t = p1; break;
     115                 :     540888 :       case  0: avma = av; b=shifti(b,v); return b;
     116                 :            :     }
     117                 :            :   }
     118                 :            :   {
     119                 :    4256823 :     long r[] = {evaltyp(t_INT)|_evallg(3), evalsigne(1)|evallgefint(3), 0};
     120                 :    4256823 :     r[2] = (long) gcduodd((ulong)b[2], (ulong)a[2]);
     121                 :   95068935 :     avma = av; return shifti(r,v);
     122                 :            :   }
     123                 :            : }

Generated by: LCOV version 1.9