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.8.0 lcov report (development 19214-1621e44) Lines: 100 103 97.1 %
Date: 2016-07-26 07:10:39 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      201836 : pari_init_parser(void)
      39             : {
      40             :   long i;
      41      201836 :   const char *opname[]={"_||_", "_&&_", "_===_", "_==_", "_!=_", "_>=_", "_>_", "_<=_", "_<_", "_-_","_+_","_<<_", "_>>_", "_%_", "_\\/_", "_\\_", "_/_", "_*_","_^_","__","_--","_++","_-=_", "_+=_", "_<<=_", "_>>=_", "_%=_", "_\\/=_", "_\\=_", "_/=_", "_*=_","+_","-_","!_","_!","_'","_~","[_.._]","[_|_<-_,_]","[_|_<-_,_;_]","%","%#","#_",""};
      42             : 
      43      201836 :   pari_stack_init(&s_node,sizeof(*pari_tree),(void **)&pari_tree);
      44      201858 :   pari_stack_alloc(&s_node,OPnboperator);
      45      202100 :   parsestate_reset();
      46     8710118 :   for (i=0;i<OPnboperator;i++)
      47             :   {
      48     8507992 :     pari_tree[i].f    = Fconst;
      49     8507992 :     pari_tree[i].x    = CSTentry;
      50     8507992 :     pari_tree[i].y    = -1;
      51     8507992 :     pari_tree[i].str  = opname[i];
      52     8507992 :     pari_tree[i].len  = strlen(opname[i]);
      53     8507992 :     pari_tree[i].flags= 0;
      54             :   }
      55      202126 : }
      56             : void
      57      201542 : 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      202224 : parsestate_reset(void)
      73             : {
      74      202224 :   s_node.n = OPnboperator;
      75      202224 :   pari_lex_start = NULL;
      76      202224 :   pari_once=1;
      77      202224 :   pari_discarded=0;
      78      202224 :   pari_lasterror=NULL;
      79      202224 : }
      80             : void
      81      157990 : parsestate_save(struct pari_parsestate *state)
      82             : {
      83      157990 :   state->node = s_node.n;
      84      157990 :   state->lex_start = pari_lex_start;
      85      157990 :   state->once = pari_once;
      86      157990 :   state->discarded = pari_discarded;
      87      157990 :   state->lasterror = pari_lasterror;
      88      157990 : }
      89             : void
      90       94603 : parsestate_restore(struct pari_parsestate *state)
      91             : {
      92       94603 :   s_node.n = state->node;
      93       94603 :   pari_lex_start = state->lex_start;
      94       94603 :   pari_once = state->once;
      95       94603 :   pari_discarded = state->discarded;
      96       94603 :   pari_lasterror = state->lasterror;
      97       94603 : }
      98             : 
      99             : GEN
     100       78861 : pari_compile_str(const char *lex)
     101             : {
     102       78861 :   pari_sp ltop=avma;
     103             :   GEN code;
     104             :   struct pari_parsestate state;
     105       78861 :   parsestate_save(&state);
     106       78861 :   pari_lex_start = lex;
     107       78861 :   pari_once=1;
     108       78861 :   pari_discarded=0;
     109       78861 :   pari_lasterror=NULL;
     110       78861 :   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       78854 :   avma=ltop;
     118       78854 :   optimizenode(s_node.n-1);
     119       78840 :   code=gp_closure(s_node.n-1);
     120       78833 :   parsestate_restore(&state);
     121       78833 :   return code;
     122             : }
     123             : 
     124             : static long
     125    24163586 : newnode(Ffunc f, long x, long y, struct node_loc *loc)
     126             : {
     127    24163586 :   long n=pari_stack_new(&s_node);
     128    24163586 :   pari_tree[n].f=f;
     129    24163586 :   pari_tree[n].x=x;
     130    24163586 :   pari_tree[n].y=y;
     131    24163586 :   pari_tree[n].str=loc->start;
     132    24163586 :   pari_tree[n].len=loc->end-loc->start;
     133    24163586 :   pari_tree[n].flags=0;
     134    24163586 :   return n;
     135             : }
     136             : 
     137             : static long
     138     1914888 : newconst(long x, struct node_loc *loc)
     139             : {
     140     1914888 :   return newnode(Fconst,x,-1,loc);
     141             : }
     142             : 
     143             : static long
     144     2431673 : newopcall(OPerator op, long x, long y, struct node_loc *loc)
     145             : {
     146     2431673 :   if (y==-1)
     147     2191321 :     return newnode(Ffunction,op,x,loc);
     148             :   else
     149      240352 :     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         497 : countarg(long n)
     160             : {
     161             :   long i;
     162        1610 :   for(i=1; pari_tree[n].f==Flistarg; i++)
     163        1113 :     n = pari_tree[n].x;
     164         497 :   return i;
     165             : }
     166             : 
     167             : static long
     168         406 : addcurrexpr(long n, long currexpr, struct node_loc *loc)
     169             : {
     170         406 :   long y, m = n;
     171         903 :   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         406 :   y = pari_tree[m].y; if (countarg(y)==4) y = pari_tree[y].x;
     177         406 :   pari_tree[y].y = currexpr;
     178         406 :   pari_tree[n].str=loc->start;
     179         406 :   pari_tree[n].len=loc->end-loc->start;
     180         406 :   return n;
     181             : }
     182             : 
     183             : static long
     184     7220155 : newintnode(struct node_loc *loc)
     185             : {
     186     7220155 :   if (loc->end-loc->start<=(long)(1+LOG10_2*BITS_IN_LONG))
     187             :   {
     188     6732885 :     pari_sp ltop=avma;
     189     6732885 :     GEN g=strtoi(loc->start);
     190             :     long s;
     191     6732885 :     avma=ltop;
     192     6732885 :     if (signe(g)==0)      return newnode(Fsmall,0,-1,loc);
     193     5177294 :     if ((s=itos_or_0(g))) return newnode(Fsmall,s,-1,loc);
     194             :   }
     195      495933 :   return newconst(CSTint,loc);
     196             : }
     197             : 
     198             : static long
     199        2102 : newfunc(CSTtype t, struct node_loc *func, long args, long code,
     200             :                    struct node_loc *loc)
     201             : {
     202        2102 :   long name=newnode(Fentry,newconst(t,func),-1,func);
     203        2102 :   return newnode(Fassign,name,newnode(Flambda,args,code,loc),loc);
     204             : }
     205             : 
     206             : 

Generated by: LCOV version 1.11