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 - str.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.12.1 lcov report (development 23973-710cd294d) Lines: 108 108 100.0 %
Date: 2019-06-18 05:51:50 Functions: 14 14 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2018  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             : #include "pari.h"
      15             : #include "paripriv.h"
      16             : 
      17             : /********************************************************************/
      18             : /**                                                                **/
      19             : /**                       CHARACTER STRINGS                        **/
      20             : /**                                                                **/
      21             : /********************************************************************/
      22             : 
      23             : /* Utillity functions */
      24             : char *
      25        2184 : stack_strdup(const char *s)
      26             : {
      27        2184 :   long n = strlen(s)+1;
      28        2184 :   char *t = stack_malloc(n);
      29        2184 :   memcpy(t,s,n); return t;
      30             : }
      31             : char *
      32        1232 : stack_strcat(const char *s, const char *t)
      33             : {
      34        1232 :   long ls = strlen(s), lt = strlen(t);
      35        1232 :   long n = ls + lt + 1;
      36        1232 :   char *u = stack_malloc(n);
      37        1232 :   memcpy(u,     s, ls);
      38        1232 :   memcpy(u + ls,t, lt+1); return u;
      39             : }
      40             : 
      41             : char *
      42       30987 : pari_strdup(const char *s)
      43             : {
      44       30987 :   long n = strlen(s)+1;
      45       30987 :   char *t = (char*)pari_malloc(n);
      46       30987 :   memcpy(t,s,n); return t;
      47             : }
      48             : char *
      49        4758 : pari_strndup(const char *s, long n)
      50             : {
      51        4758 :   char *t = (char*)pari_malloc(n+1);
      52        4758 :   memcpy(t,s,n); t[n] = 0; return t;
      53             : }
      54             : 
      55             : /* return the first n0 chars of s as a GEN [s may not be 0-terminated] */
      56             : GEN
      57      120226 : strntoGENstr(const char *s, long n0)
      58             : {
      59      120226 :   long n = nchar2nlong(n0+1); /* +1 for trailing 0 */
      60      120226 :   GEN x = cgetg(n+1, t_STR);
      61      120226 :   char *t = GSTR(x);
      62      120226 :   x[n] = 0; /* avoid uninitialized memory */
      63      120226 :   strncpy(t, s, n0); t[n0] = 0; return x;
      64             : }
      65             : 
      66             : /* strntoGENstr would trigger gcc-8 stringop-truncation warning */
      67             : GEN
      68     8900426 : strtoGENstr(const char *s)
      69             : {
      70     8900426 :   long n0 = strlen(s) + 1, n = nchar2nlong(n0);
      71     8900426 :   GEN x = cgetg(n+1, t_STR);
      72     8900427 :   char *t = GSTR(x);
      73     8900427 :   x[n] = 0; strncpy(t, s, n0); return x;
      74             : }
      75             : 
      76             : GEN
      77      339322 : chartoGENstr(char c)
      78             : {
      79      339322 :   GEN x = cgetg(2, t_STR);
      80      339322 :   char *t = GSTR(x);
      81      339322 :   t[0] = c; t[1] = 0; return x;
      82             : }
      83             : 
      84             : const char *
      85       34988 : type_name(long t)
      86             : {
      87             :   const char *s;
      88       34988 :   switch(t)
      89             :   {
      90        9579 :     case t_INT    : s="t_INT";     break;
      91        1981 :     case t_REAL   : s="t_REAL";    break;
      92        2450 :     case t_INTMOD : s="t_INTMOD";  break;
      93         364 :     case t_FRAC   : s="t_FRAC";    break;
      94        2520 :     case t_FFELT  : s="t_FFELT";   break;
      95         966 :     case t_COMPLEX: s="t_COMPLEX"; break;
      96         770 :     case t_PADIC  : s="t_PADIC";   break;
      97         693 :     case t_QUAD   : s="t_QUAD";    break;
      98         840 :     case t_POLMOD : s="t_POLMOD";  break;
      99        1225 :     case t_POL    : s="t_POL";     break;
     100         427 :     case t_SER    : s="t_SER";     break;
     101          42 :     case t_RFRAC  : s="t_RFRAC";   break;
     102          14 :     case t_QFR    : s="t_QFR";     break;
     103          21 :     case t_QFI    : s="t_QFI";     break;
     104        7004 :     case t_VEC    : s="t_VEC";     break;
     105        3072 :     case t_COL    : s="t_COL";     break;
     106        2038 :     case t_MAT    : s="t_MAT";     break;
     107          84 :     case t_LIST   : s="t_LIST";    break;
     108         497 :     case t_STR    : s="t_STR";     break;
     109         147 :     case t_VECSMALL:s="t_VECSMALL";break;
     110          21 :     case t_CLOSURE: s="t_CLOSURE"; break;
     111         212 :     case t_ERROR:   s="t_ERROR";   break;
     112          21 :     case t_INFINITY:s="t_INFINITY";break;
     113             :     default: pari_err_BUG("type"); s = NULL; /* LCOV_EXCL_LINE */
     114             :   }
     115       34988 :   return s;
     116             : }
     117             : 
     118             : GEN
     119       24004 : type0(GEN x)
     120             : {
     121       24004 :   const char *s = type_name(typ(x));
     122       24004 :   return strtoGENstr(s);
     123             : }
     124             : 
     125             : static char
     126        1960 : ltoc(long n) {
     127        1960 :   if (n <= 0 || n > 255)
     128           7 :     pari_err(e_MISC, "out of range in integer -> character conversion (%ld)", n);
     129        1953 :   return (char)n;
     130             : }
     131             : static char
     132          91 : itoc(GEN x) { return ltoc(gtos(x)); }
     133             : 
     134             : GEN
     135          28 : pari_strchr(GEN g)
     136             : {
     137          28 :   long i, l, len, t = typ(g);
     138             :   char *s;
     139             :   GEN x;
     140          28 :   if (is_vec_t(t)) {
     141           7 :     l = lg(g); len = nchar2nlong(l);
     142           7 :     x = cgetg(len+1, t_STR); s = GSTR(x);
     143           7 :     for (i=1; i<l; i++) *s++ = itoc(gel(g,i));
     144             :   }
     145          21 :   else if (t == t_VECSMALL)
     146             :   {
     147          14 :     l = lg(g); len = nchar2nlong(l);
     148          14 :     x = cgetg(len+1, t_STR); s = GSTR(x);
     149          14 :     for (i=1; i<l; i++) *s++ = ltoc(g[i]);
     150             :   }
     151             :   else
     152           7 :     return chartoGENstr(itoc(g));
     153          21 :   *s = 0; return x;
     154             : }
     155             : 
     156             : GEN
     157          70 : strsplit(GEN x, GEN p)
     158             : {
     159             :   long i0, i, iv, ls, lt;
     160             :   char *s, *t;
     161             :   GEN v;
     162          70 :   if (typ(x) != t_STR) pari_err_TYPE("strsplit",x);
     163          63 :   s = GSTR(x); ls = strlen(s);
     164          63 :   if (!p) lt = 0;
     165             :   else
     166             :   {
     167          56 :     if (typ(p) != t_STR) pari_err_TYPE("strsplit",p);
     168          49 :     t = GSTR(p); lt = strlen(t);
     169             :   }
     170          56 :   if (!lt) /* empty separator: split by char */
     171             :   {
     172          14 :     v = cgetg(ls+1, t_VEC);
     173          14 :     for (i = 1; i <= ls; i++) gel(v,i) = chartoGENstr(s[i-1]);
     174          14 :     return v;
     175             :   }
     176          42 :   v = cgetg(ls + 2, t_VEC); iv = 1;
     177       33901 :   for (i = i0 = 0; i < ls; i++)
     178       68992 :     while (!strncmp(s + i, t, lt))
     179             :     {
     180        1274 :       gel(v, iv++) = strntoGENstr(s + i0, i - i0);
     181        1274 :       i += lt; i0 = i;
     182             :     }
     183          42 :   gel(v, iv++) = strntoGENstr(s + i0, i - i0);
     184          42 :   stackdummy((pari_sp)(v + iv), (pari_sp)(v + ls + 2));
     185          42 :   setlg(v, iv); return v;
     186             : }
     187             : 
     188             : GEN
     189          42 : strjoin(GEN v, GEN p)
     190             : {
     191          42 :   pari_sp av = avma;
     192             :   long i, l;
     193             :   GEN w;
     194          42 :   if (!is_vec_t(typ(v))) pari_err_TYPE("strjoin",v);
     195          35 :   if (!p) p = strtoGENstr("");
     196          35 :   if (typ(p) != t_STR) pari_err_TYPE("strjoin",p);
     197          28 :   l = lg(v); if (l == 1) return strtoGENstr("");
     198          28 :   w = cgetg(2*l - 2, t_VEC);
     199          28 :   gel(w, 1) = gel(v, 1);
     200        1225 :   for (i = 2; i < l; i++)
     201             :   {
     202        1197 :     gel(w, 2*i-2) = p;
     203        1197 :     gel(w, 2*i-1) = gel(v, i);
     204             :   }
     205          28 :   return gerepileuptoleaf(av, shallowconcat1(w));
     206             : }

Generated by: LCOV version 1.13