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 - language - parsec.h (source / functions) Hit Total Coverage
Test: PARI/GP v2.10.0 lcov report (development 19837-cc815bb) Lines: 100 103 97.1 %
Date: 2016-12-10 05:49:10 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. 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             : #include "pari.h"
      15             : #include "paripriv.h"
      16             : BEGINEXTERN
      17             : #include "parse.h"
      18             : ENDEXTERN
      19             : #include "anal.h"
      20             : #include "tree.h"
      21             : 
      22             : static THREAD int pari_once;
      23             : static THREAD long pari_discarded;
      24             : static THREAD const char *pari_lex_start;
      25             : static THREAD GEN pari_lasterror;
      26             : 
      27          98 : static void pari_error(YYLTYPE *yylloc, char **lex, const char *s)
      28             : {
      29             :   (void) yylloc; (void) lex;
      30          98 :   if (pari_lasterror) cgiv(pari_lasterror);
      31          98 :   pari_lasterror=strtoGENstr(s);
      32          98 : }
      33             : 
      34             : static THREAD pari_stack s_node;
      35             : THREAD node *pari_tree;
      36             : 
      37             : void
      38       63957 : pari_init_parser(void)
      39             : {
      40             :   long i;
      41       63957 :   const char *opname[]={"_||_", "_&&_", "_===_", "_==_", "_!=_", "_>=_", "_>_", "_<=_", "_<_", "_-_","_+_","_<<_", "_>>_", "_%_", "_\\/_", "_\\_", "_/_", "_*_","_^_","__","_--","_++","_-=_", "_+=_", "_<<=_", "_>>=_", "_%=_", "_\\/=_", "_\\=_", "_/=_", "_*=_","+_","-_","!_","_!","_'","_~","[_.._]","[_|_<-_,_]","[_|_<-_,_;_]","%","%#","#_",""};
      42             : 
      43       63957 :   pari_stack_init(&s_node,sizeof(*pari_tree),(void **)&pari_tree);
      44       63992 :   pari_stack_alloc(&s_node,OPnboperator);
      45       64091 :   parsestate_reset();
      46     2731388 :   for (i=0;i<OPnboperator;i++)
      47             :   {
      48     2667259 :     pari_tree[i].f    = Fconst;
      49     2667259 :     pari_tree[i].x    = CSTentry;
      50     2667259 :     pari_tree[i].y    = -1;
      51     2667259 :     pari_tree[i].str  = opname[i];
      52     2667259 :     pari_tree[i].len  = strlen(opname[i]);
      53     2667259 :     pari_tree[i].flags= 0;
      54             :   }
      55       64129 : }
      56             : void
      57       64327 : pari_close_parser(void) { pari_stack_delete(&s_node); }
      58             : 
      59             : void
      60          21 : compile_err(const char *msg, const char *str)
      61             : {
      62          21 :   pari_err(e_SYNTAX, msg, str, pari_lex_start);
      63           0 : }
      64             : 
      65             : void
      66           7 : compile_varerr(const char *str)
      67             : {
      68           7 :   pari_err(e_SYNTAX, "variable name expected", str, pari_lex_start);
      69           0 : }
      70             : 
      71             : void
      72       64255 : parsestate_reset(void)
      73             : {
      74       64255 :   s_node.n = OPnboperator;
      75       64255 :   pari_lex_start = NULL;
      76       64255 :   pari_once=1;
      77       64255 :   pari_discarded=0;
      78       64255 :   pari_lasterror=NULL;
      79       64255 : }
      80             : void
      81      163960 : parsestate_save(struct pari_parsestate *state)
      82             : {
      83      163960 :   state->node = s_node.n;
      84      163960 :   state->lex_start = pari_lex_start;
      85      163960 :   state->once = pari_once;
      86      163960 :   state->discarded = pari_discarded;
      87      163960 :   state->lasterror = pari_lasterror;
      88      163960 : }
      89             : void
      90       97587 : parsestate_restore(struct pari_parsestate *state)
      91             : {
      92       97587 :   s_node.n = state->node;
      93       97587 :   pari_lex_start = state->lex_start;
      94       97587 :   pari_once = state->once;
      95       97587 :   pari_discarded = state->discarded;
      96       97587 :   pari_lasterror = state->lasterror;
      97       97587 : }
      98             : 
      99             : GEN
     100       81698 : pari_compile_str(const char *lex)
     101             : {
     102       81698 :   pari_sp ltop=avma;
     103             :   GEN code;
     104             :   struct pari_parsestate state;
     105       81698 :   parsestate_save(&state);
     106       81698 :   pari_lex_start = lex;
     107       81698 :   pari_once=1;
     108       81698 :   pari_discarded=0;
     109       81698 :   pari_lasterror=NULL;
     110       81698 :   if (pari_parse((char**)&lex) || pari_discarded)
     111             :   {
     112           7 :     if (pari_lasterror)
     113           7 :       compile_err(GSTR(pari_lasterror),lex-1);
     114             :     else /* should not happen */
     115           0 :       compile_err("syntax error",lex-1);
     116             :   }
     117       81691 :   avma=ltop;
     118       81691 :   optimizenode(s_node.n-1);
     119       81677 :   code=gp_closure(s_node.n-1);
     120       81670 :   parsestate_restore(&state);
     121       81670 :   return code;
     122             : }
     123             : 
     124             : static long
     125    24678063 : newnode(Ffunc f, long x, long y, struct node_loc *loc)
     126             : {
     127    24678063 :   long n=pari_stack_new(&s_node);
     128    24678063 :   pari_tree[n].f=f;
     129    24678063 :   pari_tree[n].x=x;
     130    24678063 :   pari_tree[n].y=y;
     131    24678063 :   pari_tree[n].str=loc->start;
     132    24678063 :   pari_tree[n].len=loc->end-loc->start;
     133    24678063 :   pari_tree[n].flags=0;
     134    24678063 :   return n;
     135             : }
     136             : 
     137             : static long
     138     2083137 : newconst(long x, struct node_loc *loc)
     139             : {
     140     2083137 :   return newnode(Fconst,x,-1,loc);
     141             : }
     142             : 
     143             : static long
     144     2517913 : newopcall(OPerator op, long x, long y, struct node_loc *loc)
     145             : {
     146     2517913 :   if (y==-1)
     147     2274019 :     return newnode(Ffunction,op,x,loc);
     148             :   else
     149      243894 :     return newnode(Ffunction,op,newnode(Flistarg,x,y,loc),loc);
     150             : }
     151             : 
     152             : static long
     153         119 : newopcall3(OPerator op, long x, long y, long z, struct node_loc *loc)
     154             : {
     155         119 :   return newopcall(op,newnode(Flistarg,x,y,loc),z,loc);
     156             : }
     157             : 
     158             : static long
     159         539 : countarg(long n)
     160             : {
     161             :   long i;
     162        1736 :   for(i=1; pari_tree[n].f==Flistarg; i++)
     163        1197 :     n = pari_tree[n].x;
     164         539 :   return i;
     165             : }
     166             : 
     167             : static long
     168         448 : addcurrexpr(long n, long currexpr, struct node_loc *loc)
     169             : {
     170         448 :   long y, m = n;
     171         987 :   while (pari_tree[m].x==OPcomprc)
     172             :   {
     173          91 :     y = pari_tree[m].y; if (countarg(y)==4) y = pari_tree[y].x;
     174          91 :     m = pari_tree[y].y;
     175             :   }
     176         448 :   y = pari_tree[m].y; if (countarg(y)==4) y = pari_tree[y].x;
     177         448 :   pari_tree[y].y = currexpr;
     178         448 :   pari_tree[n].str=loc->start;
     179         448 :   pari_tree[n].len=loc->end-loc->start;
     180         448 :   return n;
     181             : }
     182             : 
     183             : static long
     184     7406023 : newintnode(struct node_loc *loc)
     185             : {
     186     7406023 :   if (loc->end-loc->start<=(long)(1+LOG10_2*BITS_IN_LONG))
     187             :   {
     188     6762594 :     pari_sp ltop=avma;
     189     6762594 :     GEN g=strtoi(loc->start);
     190             :     long s;
     191     6762594 :     avma=ltop;
     192     6762594 :     if (signe(g)==0)      return newnode(Fsmall,0,-1,loc);
     193     5204980 :     if ((s=itos_or_0(g))) return newnode(Fsmall,s,-1,loc);
     194             :   }
     195      653772 :   return newconst(CSTint,loc);
     196             : }
     197             : 
     198             : static long
     199        2186 : newfunc(CSTtype t, struct node_loc *func, long args, long code,
     200             :                    struct node_loc *loc)
     201             : {
     202        2186 :   long name=newnode(Fentry,newconst(t,func),-1,func);
     203        2186 :   return newnode(Fassign,name,newnode(Flambda,args,code,loc),loc);
     204             : }
     205             : 
     206             : 

Generated by: LCOV version 1.11