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.0 lcov report (development 23509-020931de0) Lines: 101 104 97.1 %
Date: 2019-01-23 05:41:35 Functions: 13 14 92.9 %
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        1225 : stack_strcat(const char *s, const char *t)
      33             : {
      34        1225 :   long ls = strlen(s), lt = strlen(t);
      35        1225 :   long n = ls + lt + 1;
      36        1225 :   char *u = stack_malloc(n);
      37        1225 :   memcpy(u,     s, ls);
      38        1225 :   memcpy(u + ls,t, lt+1); return u;
      39             : }
      40             : 
      41             : char *
      42       30675 : pari_strdup(const char *s)
      43             : {
      44       30675 :   long n = strlen(s)+1;
      45       30675 :   char *t = (char*)pari_malloc(n);
      46       30675 :   memcpy(t,s,n); return t;
      47             : }
      48             : char *
      49           0 : pari_strndup(const char *s, long n)
      50             : {
      51           0 :   char *t = (char*)pari_malloc(n+1);
      52           0 :   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      484442 : strntoGENstr(const char *s, long n0)
      58             : {
      59      484442 :   long n = nchar2nlong(n0+1);
      60      484442 :   GEN x = cgetg(n+1, t_STR);
      61      484442 :   char *t = GSTR(x);
      62      484442 :   x[n] = 0;
      63      484442 :   strncpy(t, s, n0); t[n0] = 0; return x;
      64             : }
      65             : 
      66             : GEN
      67      366225 : strtoGENstr(const char *s) { return strntoGENstr(s, strlen(s)); }
      68             : 
      69             : GEN
      70      339322 : chartoGENstr(char c)
      71             : {
      72      339322 :   GEN x = cgetg(2, t_STR);
      73      339322 :   char *t = GSTR(x);
      74      339322 :   t[0] = c; t[1] = 0; return x;
      75             : }
      76             : 
      77             : const char *
      78       34931 : type_name(long t)
      79             : {
      80             :   const char *s;
      81       34931 :   switch(t)
      82             :   {
      83        9578 :     case t_INT    : s="t_INT";     break;
      84        1981 :     case t_REAL   : s="t_REAL";    break;
      85        2450 :     case t_INTMOD : s="t_INTMOD";  break;
      86         357 :     case t_FRAC   : s="t_FRAC";    break;
      87        2520 :     case t_FFELT  : s="t_FFELT";   break;
      88         966 :     case t_COMPLEX: s="t_COMPLEX"; break;
      89         770 :     case t_PADIC  : s="t_PADIC";   break;
      90         693 :     case t_QUAD   : s="t_QUAD";    break;
      91         840 :     case t_POLMOD : s="t_POLMOD";  break;
      92        1218 :     case t_POL    : s="t_POL";     break;
      93         427 :     case t_SER    : s="t_SER";     break;
      94          35 :     case t_RFRAC  : s="t_RFRAC";   break;
      95          14 :     case t_QFR    : s="t_QFR";     break;
      96          21 :     case t_QFI    : s="t_QFI";     break;
      97        7004 :     case t_VEC    : s="t_VEC";     break;
      98        3073 :     case t_COL    : s="t_COL";     break;
      99        2030 :     case t_MAT    : s="t_MAT";     break;
     100          84 :     case t_LIST   : s="t_LIST";    break;
     101         476 :     case t_STR    : s="t_STR";     break;
     102         147 :     case t_VECSMALL:s="t_VECSMALL";break;
     103          14 :     case t_CLOSURE: s="t_CLOSURE"; break;
     104         212 :     case t_ERROR:   s="t_ERROR";   break;
     105          21 :     case t_INFINITY:s="t_INFINITY";break;
     106             :     default: pari_err_BUG("type"); s = NULL; /* LCOV_EXCL_LINE */
     107             :   }
     108       34931 :   return s;
     109             : }
     110             : 
     111             : GEN
     112       24003 : type0(GEN x)
     113             : {
     114       24003 :   const char *s = type_name(typ(x));
     115       24003 :   return strtoGENstr(s);
     116             : }
     117             : 
     118             : static char
     119        1960 : ltoc(long n) {
     120        1960 :   if (n <= 0 || n > 255)
     121           7 :     pari_err(e_MISC, "out of range in integer -> character conversion (%ld)", n);
     122        1953 :   return (char)n;
     123             : }
     124             : static char
     125          91 : itoc(GEN x) { return ltoc(gtos(x)); }
     126             : 
     127             : GEN
     128          28 : pari_strchr(GEN g)
     129             : {
     130          28 :   long i, l, len, t = typ(g);
     131             :   char *s;
     132             :   GEN x;
     133          28 :   if (is_vec_t(t)) {
     134           7 :     l = lg(g); len = nchar2nlong(l);
     135           7 :     x = cgetg(len+1, t_STR); s = GSTR(x);
     136           7 :     for (i=1; i<l; i++) *s++ = itoc(gel(g,i));
     137             :   }
     138          21 :   else if (t == t_VECSMALL)
     139             :   {
     140          14 :     l = lg(g); len = nchar2nlong(l);
     141          14 :     x = cgetg(len+1, t_STR); s = GSTR(x);
     142          14 :     for (i=1; i<l; i++) *s++ = ltoc(g[i]);
     143             :   }
     144             :   else
     145           7 :     return chartoGENstr(itoc(g));
     146          21 :   *s = 0; return x;
     147             : }
     148             : 
     149             : GEN
     150          70 : strsplit(GEN x, GEN p)
     151             : {
     152             :   long i0, i, iv, ls, lt;
     153             :   char *s, *t;
     154             :   GEN v;
     155          70 :   if (typ(x) != t_STR) pari_err_TYPE("strsplit",x);
     156          63 :   s = GSTR(x); ls = strlen(s);
     157          63 :   if (!p) lt = 0;
     158             :   else
     159             :   {
     160          56 :     if (typ(p) != t_STR) pari_err_TYPE("strsplit",p);
     161          49 :     t = GSTR(p); lt = strlen(t);
     162             :   }
     163          56 :   if (!lt) /* empty separator: split by char */
     164             :   {
     165          14 :     v = cgetg(ls+1, t_VEC);
     166          14 :     for (i = 1; i <= ls; i++) gel(v,i) = chartoGENstr(s[i-1]);
     167          14 :     return v;
     168             :   }
     169          42 :   v = cgetg(ls + 2, t_VEC); iv = 1;
     170       33901 :   for (i = i0 = 0; i < ls; i++)
     171       68992 :     while (!strncmp(s + i, t, lt))
     172             :     {
     173        1274 :       gel(v, iv++) = strntoGENstr(s + i0, i - i0);
     174        1274 :       i += lt; i0 = i;
     175             :     }
     176          42 :   gel(v, iv++) = strntoGENstr(s + i0, i - i0);
     177          42 :   stackdummy((pari_sp)(v + iv), (pari_sp)(v + ls + 2));
     178          42 :   setlg(v, iv); return v;
     179             : }
     180             : 
     181             : GEN
     182          42 : strjoin(GEN v, GEN p)
     183             : {
     184          42 :   pari_sp av = avma;
     185             :   long i, l;
     186             :   GEN w;
     187          42 :   if (!is_vec_t(typ(v))) pari_err_TYPE("strjoin",v);
     188          35 :   if (!p) p = strtoGENstr("");
     189          35 :   if (typ(p) != t_STR) pari_err_TYPE("strjoin",p);
     190          28 :   l = lg(v); if (l == 1) return strtoGENstr("");
     191          28 :   w = cgetg(2*l - 2, t_VEC);
     192          28 :   gel(w, 1) = gel(v, 1);
     193        1225 :   for (i = 2; i < l; i++)
     194             :   {
     195        1197 :     gel(w, 2*i-2) = p;
     196        1197 :     gel(w, 2*i-1) = gel(v, i);
     197             :   }
     198          28 :   return gerepileuptoleaf(av, shallowconcat1(w));
     199             : }

Generated by: LCOV version 1.13