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 - modules - elldata.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.8.0 lcov report (development 19619-c9e92b8) Lines: 135 147 91.8 %
Date: 2016-09-29 05:54:10 Functions: 15 15 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2005  The PARI group.
       2             : 
       3             : This file is part of the PARI/GP package.
       4             : 
       5             : PARI/GP is free software; you can redistribute it and/or modify it under the
       6             : terms of the GNU General Public License as published by the Free Software
       7             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       8             : ANY WARRANTY WHATSOEVER.
       9             : 
      10             : Check the License for details. You should have received a copy of it, along
      11             : with the package; see the file 'COPYING'. If not, write to the Free Software
      12             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      13             : 
      14             : /********************************************************************/
      15             : /**                                                                **/
      16             : /**  INTERFACE TO JOHN CREMONA ELLIPTIC CURVES DATABASE            **/
      17             : /**                                                                **/
      18             : /********************************************************************/
      19             : #include "pari.h"
      20             : #include "paripriv.h"
      21             : 
      22             : static long
      23         126 : strtoclass(const char *s)
      24             : {
      25         126 :   long c=0;
      26         126 :   while (*s && *s<='9') s++;
      27         126 :   if (!*s) return -1;
      28         126 :   while ('a'<=*s && *s<='z') c = 26*c + *(s++)-'a';
      29         126 :   return c;
      30             : }
      31             : 
      32             : /*Take a curve name like "100a2" and set
      33             :  * f to the conductor, (100)
      34             :  * c to the isogeny class (in base 26), ("a" or 0)
      35             :  * i to the curve index (2).
      36             :  * return 0 if parse error. */
      37             : static int
      38      490784 : ellparsename(const char *s, long *f, long *c, long *i)
      39             : {
      40             :   long j;
      41      490784 :   *f=-1; *c=-1; *i=-1;
      42      490784 :   if (*s<'0' || *s>'9') return 0;
      43      490777 :   *f=0;
      44     2373749 :   for (j=0;j<10 && '0'<=*s && *s<='9';j++)
      45     1882972 :     *f=10**f+*(s++)-'0';
      46      490777 :   if (j==10) {*f=-1; return 0;}
      47      490777 :   if (*s<'a' || *s>'z') return !*s;
      48      490770 :   *c=0;
      49     1008490 :   for (j=0; j<7 && 'a'<=*s && *s<='z';j++)
      50      517720 :     *c=26**c+*(s++)-'a';
      51      490770 :   if (j==7) {*c=-1; return 0;}
      52      490770 :   if (*s<'0' || *s>'9') return !*s;
      53      490756 :   *i=0;
      54      981512 :   for (j=0; j<10 && '0'<=*s && *s<='9';j++)
      55      490756 :     *i=10**i+*(s++)-'0';
      56      490756 :   if (j==10) {*i=-1; return 0;}
      57      490756 :   return !*s;
      58             : }
      59             : 
      60             : /* Take an integer and convert it to base 26 */
      61             : static GEN
      62          14 : ellrecode(long x)
      63             : {
      64             :   GEN str;
      65             :   char *s;
      66          14 :   long d = 0, n = x;
      67          14 :   do { d++; n /= 26; } while (n);
      68          14 :   str = cgetg(nchar2nlong(d+1)+1, t_STR);
      69          14 :   s = GSTR(str); s[d] = 0;
      70          14 :   n = x;
      71          14 :   do { s[--d] = n%26 + 'a'; n /= 26; } while (n);
      72          14 :   return str;
      73             : }
      74             : 
      75             : GEN
      76      488614 : ellconvertname(GEN n)
      77             : {
      78      488614 :   switch(typ(n))
      79             :   {
      80             :   case t_STR:
      81             :     {
      82             :       long f,i,c;
      83      488600 :       if (!ellparsename(GSTR(n),&f,&c,&i)) pari_err_TYPE("ellconvertname", n);
      84      488600 :       if (f<0 || c<0 || i<0)
      85           0 :         pari_err_TYPE("ellconvertname [incomplete name]", n);
      86      488600 :       return mkvec3s(f,c,i);
      87             :     }
      88             :   case t_VEC:
      89          14 :     if (lg(n)==4)
      90             :     {
      91          14 :       pari_sp av = avma;
      92          14 :       GEN f=gel(n,1), c=gel(n,2), s=gel(n,3);
      93          14 :       if (typ(f)!=t_INT || typ(c)!=t_INT || typ(s)!=t_INT)
      94           0 :         pari_err_TYPE("ellconvertname",n);
      95          14 :       return gerepilecopy(av, shallowconcat1(mkvec3(f, ellrecode(itos(c)), s)));
      96             :     }
      97             :     /*fall through*/
      98             :   }
      99           0 :   pari_err_TYPE("ellconvertname",n);
     100           0 :   return NULL; /*Not reached*/
     101             : }
     102             : 
     103             : static GEN
     104         175 : ellcondfile(long f)
     105             : {
     106         175 :   pari_sp av = avma;
     107         175 :   long n = f / 1000;
     108         175 :   char *s = stack_malloc(strlen(pari_datadir) + 12 + 20 + 1);
     109             :   pariFILE *F;
     110             :   GEN V;
     111         175 :   sprintf(s, "%s/elldata/ell%ld", pari_datadir, n);
     112         175 :   F = pari_fopengz(s);
     113         175 :   if (!F) pari_err_FILE("elldata file",s);
     114         175 :   avma = av;
     115         175 :   V = gp_read_stream(F->file);
     116         175 :   if (!V || typ(V)!=t_VEC ) pari_err_FILE("elldata file [read]",s);
     117         175 :   pari_fclose(F); return V;
     118             : }
     119             : 
     120             : /* return the vector of all curves of conductor f */
     121         686 : static int cmpi1(GEN x, GEN v) { return cmpii(x, gel(v,1)); }
     122             : static GEN
     123          77 : ellcondlist(long f)
     124             : {
     125          77 :   pari_sp av = avma;
     126          77 :   GEN V = ellcondfile(f);
     127          77 :   long i = tablesearch(V, utoipos(f), &cmpi1);
     128          77 :   if (i)
     129             :   {
     130          77 :     GEN v = gel(V,i);
     131          77 :     return vecslice(v,2, lg(v)-1);
     132             :   }
     133           0 :   avma = av; return cgetg(1,t_VEC);
     134             : }
     135             : 
     136             : static GEN
     137          21 : ellsearchbyname(GEN V, char *name)
     138             : {
     139             :   GEN x;
     140             :   long j;
     141          21 :   for (j=1; j<lg(V); j++)
     142             :   {
     143          21 :     GEN v = gel(V,j);
     144          21 :     if (!strcmp(GSTR(gel(v,1)), name)) return v;
     145             :   }
     146           0 :   x = strtoGENstr(name);
     147           0 :   pari_err_DOMAIN("ellsearchbyname", "name", "=", x,x);
     148           0 :   return NULL;
     149             : }
     150             : 
     151             : static GEN
     152          21 : ellsearchbyclass(GEN V, long c)
     153             : {
     154             :   long i,j,n;
     155             :   GEN res;
     156          84 :   for (n=0,j=1; j<lg(V); j++)
     157          63 :     if (strtoclass(GSTR(gmael(V,j,1)))==c) n++;
     158          21 :   res = cgetg(n+1,t_VEC);
     159          84 :   for (i=1,j=1; j<lg(V); j++)
     160          63 :     if (strtoclass(GSTR(gmael(V,j,1)))==c) res[i++] = V[j];
     161          21 :   return res;
     162             : }
     163             : 
     164             : GEN
     165          84 : ellsearch(GEN A)
     166             : {
     167          84 :   pari_sp av = avma;
     168             :   long f, c, i;
     169             :   GEN V;
     170          84 :   if      (typ(A)==t_INT) { f = itos(A); c = i = -1; }
     171          77 :   else if  (typ(A)==t_VEC)
     172             :   {
     173          35 :     long l = lg(A)-1;
     174          35 :     if (l<1 || l>3)
     175           7 :       pari_err_TYPE("ellsearch",A);
     176          28 :     f = gtos(gel(A,1));
     177          28 :     c = l>=2 ? gtos(gel(A,2)): -1;
     178          28 :     i = l>=3 ? gtos(gel(A,3)): -1;
     179          28 :     if (l>=3) A = ellconvertname(A);
     180             :   }
     181          42 :   else if (typ(A)==t_STR) {
     182          35 :     if (!ellparsename(GSTR(A),&f,&c,&i))
     183           7 :       pari_err_TYPE("ellsearch",A);
     184             :   } else {
     185           7 :     pari_err_TYPE("ellsearch",A);
     186           0 :     return NULL;
     187             :   }
     188          63 :   if (f <= 0) pari_err_DOMAIN("ellsearch", "conductor", "<=", gen_0,stoi(f));
     189          56 :   V = ellcondlist(f);
     190          56 :   if (c >= 0)
     191          35 :     V = (i < 0)? ellsearchbyclass(V,c): ellsearchbyname(V, GSTR(A));
     192          56 :   return gerepilecopy(av, V);
     193             : }
     194             : 
     195             : GEN
     196           7 : ellsearchcurve(GEN name)
     197             : {
     198           7 :   pari_sp ltop=avma;
     199             :   long f, c, i;
     200           7 :   if (!ellparsename(GSTR(name),&f,&c,&i)) pari_err_TYPE("ellsearch",name);
     201           7 :   if (f<0 || c<0 || i<0) pari_err_TYPE("ellsearch [incomplete name]", name);
     202           7 :   return gerepilecopy(ltop, ellsearchbyname(ellcondlist(f), GSTR(name)));
     203             : }
     204             : 
     205             : GEN
     206          14 : ellidentify(GEN E)
     207             : {
     208          14 :   pari_sp ltop=avma;
     209          14 :   GEN V, M, G = ellglobalred(E), N = gel(G,1);
     210             :   long j;
     211          14 :   V = ellcondlist(itos(N));
     212          14 :   M = ellchangecurve(vecslice(E,1,5),gel(G,2));
     213          14 :   for (j=1; j<lg(V); j++)
     214          14 :     if (ZV_equal(gmael(V,j,2), M))
     215          14 :       return gerepilecopy(ltop, mkvec2(gel(V,j),gel(G,2)));
     216           0 :   pari_err_BUG("ellidentify [missing curve]");
     217           0 :   return NULL;
     218             : }
     219             : 
     220             : GEN
     221           7 : elldatagenerators(GEN E)
     222             : {
     223           7 :   pari_sp ltop=avma;
     224           7 :   GEN V=ellidentify(E);
     225           7 :   GEN gens=gmael(V,1,3);
     226           7 :   GEN W=ellchangepointinv(gens,gel(V,2));
     227           7 :   return gerepileupto(ltop,W);
     228             : }
     229             : 
     230             : void
     231          28 : forell(void *E, long call(void*, GEN), long a, long b, long flag)
     232             : {
     233          28 :   long ca=a/1000, cb=b/1000;
     234             :   long i, j, k;
     235             : 
     236          28 :   if (ca < 0) ca = 0;
     237         126 :   for(i=ca; i<=cb; i++)
     238             :   {
     239          98 :     pari_sp ltop=avma;
     240          98 :     GEN V = ellcondfile(i*1000);
     241       53046 :     for (j=1; j<lg(V); j++)
     242             :     {
     243       52969 :       GEN ells = gel(V,j);
     244       52969 :       long cond= itos(gel(ells,1));
     245             : 
     246       52969 :       if (i==ca && cond<a) continue;
     247       52969 :       if (i==cb && cond>b) break;
     248      545832 :       for(k=2; k<lg(ells); k++)
     249             :       {
     250      492884 :         GEN e = gel(ells,k);
     251      492884 :         if (flag) {
     252        2142 :           GEN n = gel(e,1); /* Cremona label */
     253             :           long f, c, x;
     254        2142 :           if (!ellparsename(GSTR(n),&f,&c,&x))
     255           0 :             pari_err_TYPE("ellconvertname", n);
     256        2142 :           if (x != 1) continue;
     257             :         }
     258      491421 :         if (call(E, e)) return;
     259             :       }
     260             :     }
     261          98 :     avma = ltop;
     262             :   }
     263             : }
     264             : 
     265             : void
     266          28 : forell0(long a, long b, GEN code, long flag)
     267             : {
     268          28 :   push_lex(gen_0, code);
     269          28 :   forell((void*)code, &gp_evalvoid, a, b, flag);
     270          28 :   pop_lex(1);
     271          28 : }

Generated by: LCOV version 1.11