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 - gcdext.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.10.0 lcov report (development 19828-fe528f7) Lines: 94 96 97.9 %
Date: 2016-12-07 05:49:12 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #line 2 "../src/kernel/none/gcdext.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             : /*==================================
      16             :  * bezout(a,b,pu,pv)
      17             :  *==================================
      18             :  *    Return g = gcd(a,b) >= 0, and assign GENs u,v through pointers pu,pv
      19             :  *    such that g = u*a + v*b.
      20             :  * Special cases:
      21             :  *    a == b == 0 ==> pick u=1, v=0
      22             :  *    a != 0 == b ==> keep v=0
      23             :  *    a == 0 != b ==> keep u=0
      24             :  *    |a| == |b| != 0 ==> keep u=0, set v=+-1
      25             :  * Assignments through pu,pv will be suppressed when the corresponding
      26             :  * pointer is NULL  (but the computations will happen nonetheless).
      27             :  */
      28             : 
      29             : GEN
      30    65264781 : bezout(GEN a, GEN b, GEN *pu, GEN *pv)
      31             : {
      32             :   GEN t,u,u1,v,v1,d,d1,q,r;
      33             :   GEN *pt;
      34             :   pari_sp av, av1;
      35             :   long s, sa, sb;
      36             :   ulong g;
      37             :   ulong xu,xu1,xv,xv1;                /* Lehmer stage recurrence matrix */
      38             :   int lhmres;                        /* Lehmer stage return value */
      39             : 
      40    65264781 :   s = abscmpii(a,b);
      41    65264781 :   if (s < 0)
      42             :   {
      43    45802229 :     t=b; b=a; a=t;
      44    45802229 :     pt=pu; pu=pv; pv=pt;
      45             :   }
      46             :   /* now |a| >= |b| */
      47             : 
      48    65264781 :   sa = signe(a); sb = signe(b);
      49    65264781 :   if (!sb)
      50             :   {
      51     1363428 :     if (pv) *pv = gen_0;
      52     1363428 :     switch(sa)
      53             :     {
      54           3 :     case  0: if (pu) *pu = gen_0; return gen_0;
      55     1361766 :     case  1: if (pu) *pu = gen_1; return icopy(a);
      56        1659 :     case -1: if (pu) *pu = gen_m1; return(negi(a));
      57             :     }
      58             :   }
      59    63901353 :   if (s == 0)                        /* |a| == |b| != 0 */
      60             :   {
      61     5541085 :     if (pu) *pu = gen_0;
      62     5541085 :     if (sb > 0)
      63     5362183 :     { if (pv) *pv = gen_1; return icopy(b); }
      64             :     else
      65      178902 :     { if (pv) *pv = gen_m1; return(negi(b)); }
      66             :   }
      67             :   /* now |a| > |b| > 0 */
      68             : 
      69    58360268 :   if (lgefint(a) == 3)                /* single-word affair */
      70             :   {
      71    58175552 :     g = xxgcduu(uel(a,2), uel(b,2), 0, &xu, &xu1, &xv, &xv1, &s);
      72    58175552 :     sa = s > 0 ? sa : -sa;
      73    58175552 :     sb = s > 0 ? -sb : sb;
      74    58175552 :     if (pu)
      75             :     {
      76    19629074 :       if (xu == 0) *pu = gen_0; /* can happen when b divides a */
      77    10046898 :       else if (xu == 1) *pu = sa < 0 ? gen_m1 : gen_1;
      78     4202877 :       else if (xu == 2) *pu = sa < 0 ? gen_m2 : gen_2;
      79             :       else
      80             :       {
      81     3663774 :         *pu = cgeti(3);
      82     3663774 :         (*pu)[1] = evalsigne(sa)|evallgefint(3);
      83     3663774 :         (*pu)[2] = xu;
      84             :       }
      85             :     }
      86    58175552 :     if (pv)
      87             :     {
      88    52866224 :       if (xv == 1) *pv = sb < 0 ? gen_m1 : gen_1;
      89    29952213 :       else if (xv == 2) *pv = sb < 0 ? gen_m2 : gen_2;
      90             :       else
      91             :       {
      92    26683917 :         *pv = cgeti(3);
      93    26683917 :         (*pv)[1] = evalsigne(sb)|evallgefint(3);
      94    26683917 :         (*pv)[2] = xv;
      95             :       }
      96             :     }
      97    58175552 :     if      (g == 1) return gen_1;
      98    14914278 :     else if (g == 2) return gen_2;
      99     9376671 :     else return utoipos(g);
     100             :   }
     101             : 
     102             :   /* general case */
     103      184716 :   av = avma;
     104      184716 :   (void)new_chunk(lgefint(b) + (lgefint(a)<<1)); /* room for u,v,gcd */
     105             :   /* if a is significantly larger than b, calling lgcdii() is not the best
     106             :    * way to start -- reduce a mod b first
     107             :    */
     108      184716 :   if (lgefint(a) > lgefint(b))
     109             :   {
     110      155613 :     d = absi(b), q = dvmdii(absi(a), d, &d1);
     111      155613 :     if (!signe(d1))                /* a == qb */
     112             :     {
     113      140652 :       avma = av;
     114      140652 :       if (pu) *pu = gen_0;
     115      140652 :       if (pv) *pv = sb < 0 ? gen_m1 : gen_1;
     116      140652 :       return (icopy(d));
     117             :     }
     118             :     else
     119             :     {
     120       14961 :       u = gen_0;
     121       14961 :       u1 = v = gen_1;
     122       14961 :       v1 = negi(q);
     123             :     }
     124             :     /* if this results in lgefint(d) == 3, will fall past main loop */
     125             :   }
     126             :   else
     127             :   {
     128       29103 :     d = absi(a); d1 = absi(b);
     129       29103 :     u = v1 = gen_1; u1 = v = gen_0;
     130             :   }
     131       44064 :   av1 = avma;
     132             : 
     133             :   /* main loop is almost identical to that of invmod() */
     134      165636 :   while (lgefint(d) > 3 && signe(d1))
     135             :   {
     136       77508 :     lhmres = lgcdii((ulong *)d, (ulong *)d1, &xu, &xu1, &xv, &xv1, ULONG_MAX);
     137       77508 :     if (lhmres != 0)                /* check progress */
     138             :     {                                /* apply matrix */
     139       66798 :       if ((lhmres == 1) || (lhmres == -1))
     140             :       {
     141        2928 :         if (xv1 == 1)
     142             :         {
     143         657 :           r = subii(d,d1); d=d1; d1=r;
     144         657 :           a = subii(u,u1); u=u1; u1=a;
     145         657 :           a = subii(v,v1); v=v1; v1=a;
     146             :         }
     147             :         else
     148             :         {
     149         807 :           r = subii(d, mului(xv1,d1)); d=d1; d1=r;
     150         807 :           a = subii(u, mului(xv1,u1)); u=u1; u1=a;
     151         807 :           a = subii(v, mului(xv1,v1)); v=v1; v1=a;
     152             :         }
     153             :       }
     154             :       else
     155             :       {
     156       65334 :         r  = subii(muliu(d,xu),  muliu(d1,xv));
     157       65334 :         d1 = subii(muliu(d,xu1), muliu(d1,xv1)); d = r;
     158       65334 :         a  = subii(muliu(u,xu),  muliu(u1,xv));
     159       65334 :         u1 = subii(muliu(u,xu1), muliu(u1,xv1)); u = a;
     160       65334 :         a  = subii(muliu(v,xu),  muliu(v1,xv));
     161       65334 :         v1 = subii(muliu(v,xu1), muliu(v1,xv1)); v = a;
     162       65334 :         if (lhmres&1) { togglesign(d);  togglesign(u);  togglesign(v); }
     163       32418 :         else          { togglesign(d1); togglesign(u1); togglesign(v1); }
     164             :       }
     165             :     }
     166       77508 :     if (lhmres <= 0 && signe(d1))
     167             :     {
     168       11475 :       q = dvmdii(d,d1,&r);
     169       11475 :       a = subii(u,mulii(q,u1));
     170       11475 :       u=u1; u1=a;
     171       11475 :       a = subii(v,mulii(q,v1));
     172       11475 :       v=v1; v1=a;
     173       11475 :       d=d1; d1=r;
     174             :     }
     175       77508 :     if (gc_needed(av,1))
     176             :     {
     177           0 :       if(DEBUGMEM>1) pari_warn(warnmem,"bezout");
     178           0 :       gerepileall(av1,6, &d,&d1,&u,&u1,&v,&v1);
     179             :     }
     180             :   } /* end while */
     181             : 
     182             :   /* Postprocessing - final sprint */
     183       44064 :   if (signe(d1))
     184             :   {
     185             :     /* Assertions: lgefint(d)==lgefint(d1)==3, and
     186             :      * gcd(d,d1) is nonzero and fits into one word
     187             :      */
     188       33216 :     g = xxgcduu(uel(d,2), uel(d1,2), 0, &xu, &xu1, &xv, &xv1, &s);
     189       33216 :     u = subii(muliu(u,xu), muliu(u1, xv));
     190       33216 :     v = subii(muliu(v,xu), muliu(v1, xv));
     191       33216 :     if (s < 0) { sa = -sa; sb = -sb; }
     192       33216 :     avma = av;
     193       33216 :     if (pu) *pu = sa < 0 ? negi(u) : icopy(u);
     194       33216 :     if (pv) *pv = sb < 0 ? negi(v) : icopy(v);
     195       33216 :     if (g == 1) return gen_1;
     196       17697 :     else if (g == 2) return gen_2;
     197       15498 :     else return utoipos(g);
     198             :   }
     199             :   /* get here when the final sprint was skipped (d1 was zero already).
     200             :    * Now the matrix is final, and d contains the gcd.
     201             :    */
     202       10848 :   avma = av;
     203       10848 :   if (pu) *pu = sa < 0 ? negi(u) : icopy(u);
     204       10848 :   if (pv) *pv = sb < 0 ? negi(v) : icopy(v);
     205       10848 :   return icopy(d);
     206             : }
     207             : 

Generated by: LCOV version 1.11