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 to exceed 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 - language - parsec.h (source / functions) Hit Total Coverage
Test: PARI/GP v2.14.0 lcov report (development 27783-affec94c65) Lines: 98 103 95.1 %
Date: 2022-07-07 07:34:25 Functions: 17 17 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2006-2008  The PARI group.
       2             : 
       3             : This file is part of the PARI 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; either version 2 of the License, or (at your option) any later
       8             : version. 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             : #include "pari.h"
      16             : #include "paripriv.h"
      17             : BEGINEXTERN
      18             : #include "parse.h"
      19             : ENDEXTERN
      20             : #include "anal.h"
      21             : #include "tree.h"
      22             : 
      23             : static THREAD int pari_once;
      24             : static THREAD long pari_discarded;
      25             : static THREAD const char *pari_lex_start;
      26             : static THREAD GEN pari_lasterror;
      27             : 
      28          28 : static void pari_error(PARI_LTYPE *yylloc, char **lex, const char *s)
      29             : {
      30             :   (void) yylloc; (void) lex;
      31          28 :   if (pari_lasterror) cgiv(pari_lasterror);
      32          28 :   pari_lasterror=strtoGENstr(s);
      33          28 : }
      34             : 
      35             : static THREAD pari_stack s_node;
      36             : THREAD node *pari_tree;
      37             : 
      38             : void
      39      228508 : pari_init_parser(void)
      40             : {
      41             :   long i;
      42      228508 :   const char *opname[]={"_||_", "_&&_", "_===_", "_==_", "_!=_", "_>=_", "_>_", "_<=_", "_<_", "_-_","_+_","_<<_", "_>>_", "_%_", "_\\/_", "_\\_", "_/_", "_*_","_^_","__","_--","_++","_-=_", "_+=_", "_<<=_", "_>>=_", "_%=_", "_\\/=_", "_\\=_", "_/=_", "_*=_","+_","-_","!_","_!","_'_","_~","[_.._]","[_|_<-_,_]","[_|_<-_,_;_]","%","%#","#_",""};
      43             : 
      44      228508 :   pari_stack_init(&s_node,sizeof(*pari_tree),(void **)&pari_tree);
      45      229689 :   pari_stack_alloc(&s_node,OPnboperator);
      46      230169 :   parsestate_reset();
      47     9655610 :   for (i=0;i<OPnboperator;i++)
      48             :   {
      49     9427513 :     pari_tree[i].f    = Fconst;
      50     9427513 :     pari_tree[i].x    = CSTentry;
      51     9427513 :     pari_tree[i].y    = -1;
      52     9427513 :     pari_tree[i].str  = opname[i];
      53     9427513 :     pari_tree[i].len  = strlen(opname[i]);
      54     9427513 :     pari_tree[i].flags= 0;
      55             :   }
      56      228097 : }
      57             : void
      58      225713 : pari_close_parser(void) { pari_stack_delete(&s_node); }
      59             : 
      60             : void
      61          49 : compile_err(const char *msg, const char *str)
      62             : {
      63          49 :   pari_err(e_SYNTAX, msg, str, pari_lex_start);
      64           0 : }
      65             : 
      66             : void
      67          28 : compile_varerr(const char *str)
      68             : {
      69          28 :   pari_err(e_SYNTAX, "variable name expected", str, pari_lex_start);
      70           0 : }
      71             : 
      72             : void
      73      230605 : parsestate_reset(void)
      74             : {
      75      230605 :   s_node.n = OPnboperator;
      76      230605 :   pari_lex_start = NULL;
      77      230605 :   pari_once=1;
      78      230605 :   pari_discarded=0;
      79      230605 :   pari_lasterror=NULL;
      80      230605 : }
      81             : void
      82     9235833 : parsestate_save(struct pari_parsestate *state)
      83             : {
      84     9235833 :   state->node = s_node.n;
      85     9235833 :   state->lex_start = pari_lex_start;
      86     9235833 :   state->once = pari_once;
      87     9235833 :   state->discarded = pari_discarded;
      88     9235833 :   state->lasterror = pari_lasterror;
      89     9235833 : }
      90             : void
      91     9120915 : parsestate_restore(struct pari_parsestate *state)
      92             : {
      93     9120915 :   s_node.n = state->node;
      94     9120915 :   pari_lex_start = state->lex_start;
      95     9120915 :   pari_once = state->once;
      96     9120915 :   pari_discarded = state->discarded;
      97     9120915 :   pari_lasterror = state->lasterror;
      98     9120915 : }
      99             : 
     100             : GEN
     101     9109884 : pari_compile_str(const char *lex)
     102             : {
     103     9109884 :   pari_sp ltop=avma;
     104             :   GEN code;
     105             :   struct pari_parsestate state;
     106     9109884 :   parsestate_save(&state);
     107     9109884 :   pari_lex_start = lex;
     108     9109884 :   pari_once=1;
     109     9109884 :   pari_discarded=0;
     110     9109884 :   pari_lasterror=NULL;
     111     9109884 :   if (pari_parse((char**)&lex) || pari_discarded)
     112             :   {
     113           0 :     if (pari_lasterror)
     114           0 :       compile_err(GSTR(pari_lasterror),lex-1);
     115             :     else /* should not happen */
     116           0 :       compile_err("syntax error",lex-1);
     117             :   }
     118     9109884 :   set_avma(ltop);
     119     9109884 :   optimizenode(s_node.n-1);
     120     9109849 :   code=gp_closure(s_node.n-1);
     121     9109807 :   parsestate_restore(&state);
     122     9109807 :   return code;
     123             : }
     124             : 
     125             : static long
     126   178561408 : newnode(Ffunc f, long x, long y, struct node_loc *loc)
     127             : {
     128   178561408 :   long n=pari_stack_new(&s_node);
     129   178561408 :   pari_tree[n].f=f;
     130   178561408 :   pari_tree[n].x=x;
     131   178561408 :   pari_tree[n].y=y;
     132   178561408 :   pari_tree[n].str=loc->start;
     133   178561408 :   pari_tree[n].len=loc->end-loc->start;
     134   178561408 :   pari_tree[n].flags=0;
     135   178561408 :   return n;
     136             : }
     137             : 
     138             : static long
     139     2606983 : newconst(long x, struct node_loc *loc)
     140             : {
     141     2606983 :   return newnode(Fconst,x,-1,loc);
     142             : }
     143             : 
     144             : static long
     145    26927462 : newopcall(OPerator op, long x, long y, struct node_loc *loc)
     146             : {
     147    26927462 :   if (y==-1)
     148    26607092 :     return newnode(Ffunction,op,x,loc);
     149             :   else
     150      320370 :     return newnode(Ffunction,op,newnode(Flistarg,x,y,loc),loc);
     151             : }
     152             : 
     153             : static long
     154         161 : newopcall3(OPerator op, long x, long y, long z, struct node_loc *loc)
     155             : {
     156         161 :   return newopcall(op,newnode(Flistarg,x,y,loc),z,loc);
     157             : }
     158             : 
     159             : static long
     160         753 : countarg(long n)
     161             : {
     162             :   long i;
     163        2420 :   for(i=1; pari_tree[n].f==Flistarg; i++)
     164        1667 :     n = pari_tree[n].x;
     165         753 :   return i;
     166             : }
     167             : 
     168             : static long
     169         662 : addcurrexpr(long n, long currexpr, struct node_loc *loc)
     170             : {
     171         662 :   long y, m = n;
     172         753 :   while (pari_tree[m].x==OPcomprc)
     173             :   {
     174          91 :     y = pari_tree[m].y; if (countarg(y)==4) y = pari_tree[y].x;
     175          91 :     m = pari_tree[y].y;
     176             :   }
     177         662 :   y = pari_tree[m].y; if (countarg(y)==4) y = pari_tree[y].x;
     178         662 :   pari_tree[y].y = currexpr;
     179         662 :   pari_tree[n].str=loc->start;
     180         662 :   pari_tree[n].len=loc->end-loc->start;
     181         662 :   return n;
     182             : }
     183             : 
     184             : static long
     185    68544707 : newintnode(struct node_loc *loc)
     186             : {
     187    68544707 :   if (loc->end-loc->start<=(long)(1+LOG10_2*BITS_IN_LONG))
     188             :   {
     189    67316331 :     pari_sp ltop=avma;
     190    67316331 :     GEN g=strtoi(loc->start);
     191    67316331 :     long s = itos_or_0(g), sg = signe(g);
     192    67316331 :     set_avma(ltop);
     193    67316331 :     if (sg==0 || s) return newnode(Fsmall,s,-1,loc);
     194             :   }
     195     1337250 :   return newconst(CSTint,loc);
     196             : }
     197             : 
     198             : static long
     199        3451 : newfunc(CSTtype t, struct node_loc *func, long args, long code,
     200             :                    struct node_loc *loc)
     201             : {
     202        3451 :   long name=newnode(Fentry,newconst(t,func),-1,func);
     203        3451 :   return newnode(Fassign,name,newnode(Flambda,args,code,loc),loc);
     204             : }
     205             : 
     206             : 

Generated by: LCOV version 1.13