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.10.0 lcov report (development 21196-f12677d) Lines: 136 147 92.5 %
Date: 2017-10-22 06:23:24 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      490798 : ellparsename(const char *s, long *f, long *c, long *i)
      39             : {
      40             :   long j;
      41      490798 :   *f=-1; *c=-1; *i=-1;
      42      490798 :   if (*s<'0' || *s>'9') return 0;
      43      490791 :   *f=0;
      44     2373791 :   for (j=0;j<10 && '0'<=*s && *s<='9';j++)
      45     1883000 :     *f=10**f+*(s++)-'0';
      46      490791 :   if (j==10) {*f=-1; return 0;}
      47      490791 :   if (*s<'a' || *s>'z') return !*s;
      48      490784 :   *c=0;
      49     1008518 :   for (j=0; j<7 && 'a'<=*s && *s<='z';j++)
      50      517734 :     *c=26**c+*(s++)-'a';
      51      490784 :   if (j==7) {*c=-1; return 0;}
      52      490784 :   if (*s<'0' || *s>'9') return !*s;
      53      490770 :   *i=0;
      54      981540 :   for (j=0; j<10 && '0'<=*s && *s<='9';j++)
      55      490770 :     *i=10**i+*(s++)-'0';
      56      490770 :   if (j==10) {*i=-1; return 0;}
      57      490770 :   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             :   return NULL; /*LCOV_EXCL_LINE*/
     101             : }
     102             : 
     103             : static GEN
     104         189 : ellcondfile(long f)
     105             : {
     106         189 :   pari_sp av = avma;
     107         189 :   long n = f / 1000;
     108         189 :   char *s = stack_malloc(strlen(pari_datadir) + 12 + 20 + 1);
     109             :   pariFILE *F;
     110             :   GEN V;
     111         189 :   sprintf(s, "%s/elldata/ell%ld", pari_datadir, n);
     112         189 :   F = pari_fopengz(s);
     113         189 :   if (!F) pari_err_FILE("elldata file",s);
     114         189 :   avma = av;
     115         189 :   V = gp_read_stream(F->file);
     116         189 :   if (!V || typ(V)!=t_VEC ) pari_err_FILE("elldata file [read]",s);
     117         189 :   pari_fclose(F); return V;
     118             : }
     119             : 
     120             : /* return the vector of all curves of conductor f */
     121         805 : static int cmpi1(GEN x, GEN v) { return cmpii(x, gel(v,1)); }
     122             : static GEN
     123          91 : ellcondlist(long f)
     124             : {
     125          91 :   pari_sp av = avma;
     126          91 :   GEN V = ellcondfile(f);
     127          91 :   long i = tablesearch(V, utoipos(f), &cmpi1);
     128          91 :   if (i)
     129             :   {
     130          91 :     GEN v = gel(V,i);
     131          91 :     return vecslice(v,2, lg(v)-1);
     132             :   }
     133           0 :   avma = av; return cgetg(1,t_VEC);
     134             : }
     135             : 
     136             : static GEN
     137          35 : ellsearchbyname(GEN V, char *name)
     138             : {
     139             :   GEN x;
     140             :   long j;
     141          35 :   for (j=1; j<lg(V); j++)
     142             :   {
     143          35 :     GEN v = gel(V,j);
     144          35 :     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          21 : ellsearchcurve(GEN name)
     197             : {
     198          21 :   pari_sp ltop=avma;
     199             :   long f, c, i;
     200          21 :   if (!ellparsename(GSTR(name),&f,&c,&i)) pari_err_TYPE("ellsearch",name);
     201          21 :   if (f<0 || c<0 || i<0) pari_err_TYPE("ellsearch [incomplete name]", name);
     202          21 :   return gerepilecopy(ltop, ellsearchbyname(ellcondlist(f), GSTR(name)));
     203             : }
     204             : 
     205             : GEN
     206          21 : ellidentify(GEN E)
     207             : {
     208          21 :   pari_sp ltop=avma;
     209             :   long j;
     210             :   GEN V, M, G, N;
     211          21 :   checkell_Q(E);
     212          14 :   G = ellglobalred(E); N = gel(G,1);
     213          14 :   V = ellcondlist(itos(N));
     214          14 :   M = ellchangecurve(vecslice(E,1,5),gel(G,2));
     215          14 :   for (j=1; j<lg(V); j++)
     216          14 :     if (ZV_equal(gmael(V,j,2), M))
     217          14 :       return gerepilecopy(ltop, mkvec2(gel(V,j),gel(G,2)));
     218           0 :   pari_err_BUG("ellidentify [missing curve]");
     219           0 :   return NULL;
     220             : }
     221             : 
     222             : GEN
     223           7 : elldatagenerators(GEN E)
     224             : {
     225           7 :   pari_sp ltop=avma;
     226           7 :   GEN V=ellidentify(E);
     227           7 :   GEN gens=gmael(V,1,3);
     228           7 :   GEN W=ellchangepointinv(gens,gel(V,2));
     229           7 :   return gerepileupto(ltop,W);
     230             : }
     231             : 
     232             : void
     233          28 : forell(void *E, long call(void*, GEN), long a, long b, long flag)
     234             : {
     235          28 :   long ca=a/1000, cb=b/1000;
     236             :   long i, j, k;
     237             : 
     238          28 :   if (ca < 0) ca = 0;
     239         126 :   for(i=ca; i<=cb; i++)
     240             :   {
     241          98 :     pari_sp ltop=avma;
     242          98 :     GEN V = ellcondfile(i*1000);
     243       53046 :     for (j=1; j<lg(V); j++)
     244             :     {
     245       52969 :       GEN ells = gel(V,j);
     246       52969 :       long cond= itos(gel(ells,1));
     247             : 
     248       52969 :       if (i==ca && cond<a) continue;
     249       52969 :       if (i==cb && cond>b) break;
     250      545832 :       for(k=2; k<lg(ells); k++)
     251             :       {
     252      492884 :         GEN e = gel(ells,k);
     253      492884 :         if (flag) {
     254        2142 :           GEN n = gel(e,1); /* Cremona label */
     255             :           long f, c, x;
     256        2142 :           if (!ellparsename(GSTR(n),&f,&c,&x))
     257           0 :             pari_err_TYPE("ellconvertname", n);
     258        2142 :           if (x != 1) continue;
     259             :         }
     260      491421 :         if (call(E, e)) return;
     261             :       }
     262             :     }
     263          98 :     avma = ltop;
     264             :   }
     265             : }
     266             : 
     267             : void
     268          28 : forell0(long a, long b, GEN code, long flag)
     269             : {
     270          28 :   push_lex(gen_0, code);
     271          28 :   forell((void*)code, &gp_evalvoid, a, b, flag);
     272          28 :   pop_lex(1);
     273          28 : }

Generated by: LCOV version 1.11