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.12.0 lcov report (development 23026-c0ccc8713) Lines: 100 103 97.1 %
Date: 2018-09-25 05:41:47 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          84 : static void pari_error(YYLTYPE *yylloc, char **lex, const char *s)
      28             : {
      29             :   (void) yylloc; (void) lex;
      30          84 :   if (pari_lasterror) cgiv(pari_lasterror);
      31          84 :   pari_lasterror=strtoGENstr(s);
      32          84 : }
      33             : 
      34             : static THREAD pari_stack s_node;
      35             : THREAD node *pari_tree;
      36             : 
      37             : void
      38      113426 : pari_init_parser(void)
      39             : {
      40             :   long i;
      41      113426 :   const char *opname[]={"_||_", "_&&_", "_===_", "_==_", "_!=_", "_>=_", "_>_", "_<=_", "_<_", "_-_","_+_","_<<_", "_>>_", "_%_", "_\\/_", "_\\_", "_/_", "_*_","_^_","__","_--","_++","_-=_", "_+=_", "_<<=_", "_>>=_", "_%=_", "_\\/=_", "_\\=_", "_/=_", "_*=_","+_","-_","!_","_!","_'","_~","[_.._]","[_|_<-_,_]","[_|_<-_,_;_]","%","%#","#_",""};
      42             : 
      43      113426 :   pari_stack_init(&s_node,sizeof(*pari_tree),(void **)&pari_tree);
      44      113370 :   pari_stack_alloc(&s_node,OPnboperator);
      45      113836 :   parsestate_reset();
      46     4983587 :   for (i=0;i<OPnboperator;i++)
      47             :   {
      48     4869763 :     pari_tree[i].f    = Fconst;
      49     4869763 :     pari_tree[i].x    = CSTentry;
      50     4869763 :     pari_tree[i].y    = -1;
      51     4869763 :     pari_tree[i].str  = opname[i];
      52     4869763 :     pari_tree[i].len  = strlen(opname[i]);
      53     4869763 :     pari_tree[i].flags= 0;
      54             :   }
      55      113824 : }
      56             : void
      57      110886 : pari_close_parser(void) { pari_stack_delete(&s_node); }
      58             : 
      59             : void
      60          28 : compile_err(const char *msg, const char *str)
      61             : {
      62          28 :   pari_err(e_SYNTAX, msg, str, pari_lex_start);
      63           0 : }
      64             : 
      65             : void
      66          14 : compile_varerr(const char *str)
      67             : {
      68          14 :   pari_err(e_SYNTAX, "variable name expected", str, pari_lex_start);
      69           0 : }
      70             : 
      71             : void
      72      114115 : parsestate_reset(void)
      73             : {
      74      114115 :   s_node.n = OPnboperator;
      75      114115 :   pari_lex_start = NULL;
      76      114115 :   pari_once=1;
      77      114115 :   pari_discarded=0;
      78      114115 :   pari_lasterror=NULL;
      79      114115 : }
      80             : void
      81      190705 : parsestate_save(struct pari_parsestate *state)
      82             : {
      83      190705 :   state->node = s_node.n;
      84      190705 :   state->lex_start = pari_lex_start;
      85      190705 :   state->once = pari_once;
      86      190705 :   state->discarded = pari_discarded;
      87      190705 :   state->lasterror = pari_lasterror;
      88      190705 : }
      89             : void
      90      103882 : parsestate_restore(struct pari_parsestate *state)
      91             : {
      92      103882 :   s_node.n = state->node;
      93      103882 :   pari_lex_start = state->lex_start;
      94      103882 :   pari_once = state->once;
      95      103882 :   pari_discarded = state->discarded;
      96      103882 :   pari_lasterror = state->lasterror;
      97      103882 : }
      98             : 
      99             : GEN
     100       95035 : pari_compile_str(const char *lex)
     101             : {
     102       95035 :   pari_sp ltop=avma;
     103             :   GEN code;
     104             :   struct pari_parsestate state;
     105       95035 :   parsestate_save(&state);
     106       95035 :   pari_lex_start = lex;
     107       95035 :   pari_once=1;
     108       95035 :   pari_discarded=0;
     109       95035 :   pari_lasterror=NULL;
     110       95035 :   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       95028 :   set_avma(ltop);
     118       95028 :   optimizenode(s_node.n-1);
     119       95014 :   code=gp_closure(s_node.n-1);
     120       94993 :   parsestate_restore(&state);
     121       94993 :   return code;
     122             : }
     123             : 
     124             : static long
     125    25612429 : newnode(Ffunc f, long x, long y, struct node_loc *loc)
     126             : {
     127    25612429 :   long n=pari_stack_new(&s_node);
     128    25612429 :   pari_tree[n].f=f;
     129    25612429 :   pari_tree[n].x=x;
     130    25612429 :   pari_tree[n].y=y;
     131    25612429 :   pari_tree[n].str=loc->start;
     132    25612429 :   pari_tree[n].len=loc->end-loc->start;
     133    25612429 :   pari_tree[n].flags=0;
     134    25612429 :   return n;
     135             : }
     136             : 
     137             : static long
     138     2319434 : newconst(long x, struct node_loc *loc)
     139             : {
     140     2319434 :   return newnode(Fconst,x,-1,loc);
     141             : }
     142             : 
     143             : static long
     144     2654357 : newopcall(OPerator op, long x, long y, struct node_loc *loc)
     145             : {
     146     2654357 :   if (y==-1)
     147     2385758 :     return newnode(Ffunction,op,x,loc);
     148             :   else
     149      268599 :     return newnode(Ffunction,op,newnode(Flistarg,x,y,loc),loc);
     150             : }
     151             : 
     152             : static long
     153         133 : newopcall3(OPerator op, long x, long y, long z, struct node_loc *loc)
     154             : {
     155         133 :   return newopcall(op,newnode(Flistarg,x,y,loc),z,loc);
     156             : }
     157             : 
     158             : static long
     159         644 : countarg(long n)
     160             : {
     161             :   long i;
     162        2065 :   for(i=1; pari_tree[n].f==Flistarg; i++)
     163        1421 :     n = pari_tree[n].x;
     164         644 :   return i;
     165             : }
     166             : 
     167             : static long
     168         553 : addcurrexpr(long n, long currexpr, struct node_loc *loc)
     169             : {
     170         553 :   long y, m = n;
     171        1197 :   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         553 :   y = pari_tree[m].y; if (countarg(y)==4) y = pari_tree[y].x;
     177         553 :   pari_tree[y].y = currexpr;
     178         553 :   pari_tree[n].str=loc->start;
     179         553 :   pari_tree[n].len=loc->end-loc->start;
     180         553 :   return n;
     181             : }
     182             : 
     183             : static long
     184     7679405 : newintnode(struct node_loc *loc)
     185             : {
     186     7679405 :   if (loc->end-loc->start<=(long)(1+LOG10_2*BITS_IN_LONG))
     187             :   {
     188     6879503 :     pari_sp ltop=avma;
     189     6879503 :     GEN g=strtoi(loc->start);
     190     6879503 :     long s = itos_or_0(g), sg = signe(g);
     191     6879503 :     set_avma(ltop);
     192     6879503 :     if (sg==0 || s) return newnode(Fsmall,s,-1,loc);
     193             :   }
     194      812027 :   return newconst(CSTint,loc);
     195             : }
     196             : 
     197             : static long
     198        2795 : newfunc(CSTtype t, struct node_loc *func, long args, long code,
     199             :                    struct node_loc *loc)
     200             : {
     201        2795 :   long name=newnode(Fentry,newconst(t,func),-1,func);
     202        2795 :   return newnode(Fassign,name,newnode(Flambda,args,code,loc),loc);
     203             : }
     204             : 
     205             : 

Generated by: LCOV version 1.13