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 - graph - plotX.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.10.0 lcov report (development 21739-44c3c17) Lines: 12 146 8.2 %
Date: 2018-01-20 06:18:48 Functions: 2 14 14.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2000  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             : /*******************************************************************/
      15             : /*                                                                 */
      16             : /*                       HIGH RESOLUTION PLOT                      */
      17             : /*                                                                 */
      18             : /*******************************************************************/
      19             : 
      20             : #include "pari.h"
      21             : #include "rect.h"
      22             : 
      23             : #ifdef HPPA
      24             : #  ifndef __GNUC__
      25             :      typedef char *caddr_t;
      26             : #  endif
      27             : #endif
      28             : 
      29             : BEGINEXTERN
      30             : #include <X11/XKBlib.h>
      31             : #include <X11/Xutil.h>
      32             : #include <X11/Xos.h>
      33             : #ifndef XK_c
      34             : #  include <X11/keysym.h>
      35             : #endif
      36             : ENDEXTERN
      37             : 
      38             : static Colormap PARI_Colormap;
      39             : static XColor  *PARI_Colors;
      40             : 
      41             : struct data_x
      42             : {
      43             :   Display *display;
      44             :   Window win;
      45             :   int numcolors;
      46             :   GC gc;
      47             : };
      48             : 
      49             : /* after fork(), we don't want the child to recover but to exit */
      50             : static void
      51           0 : exiterr(const char *str)
      52             : {
      53           0 :   term_color(c_ERR);
      54           0 :   err_printf("\n  *** X fatal error: %s\n",str);
      55           0 :   term_color(c_NONE); exit(1);
      56             : }
      57             : 
      58           0 : static void SetForeground(void *data, long col)
      59             : {
      60           0 :   struct data_x *dx = (struct data_x *) data;
      61           0 :   XSetForeground(dx->display,dx->gc, PARI_Colors[col].pixel);
      62           0 : }
      63             : 
      64           0 : static void DrawPoint(void *data, long x, long y)
      65             : {
      66           0 :   struct data_x *dx = (struct data_x *) data;
      67           0 :   XDrawPoint(dx->display,dx->win,dx->gc, x,y);
      68           0 : }
      69             : 
      70           0 : static void DrawLine(void *data, long x1, long y1, long x2, long y2)
      71             : {
      72           0 :   struct data_x *dx = (struct data_x *) data;
      73           0 :   XDrawLine(dx->display,dx->win,dx->gc, x1,y1, x2,y2);
      74           0 : }
      75             : 
      76           0 : static void DrawRectangle(void *data, long x, long y, long w, long h)
      77             : {
      78           0 :   struct data_x *dx = (struct data_x *) data;
      79           0 :   XDrawRectangle(dx->display,dx->win,dx->gc, x,y, w,h);
      80           0 : }
      81             : 
      82           0 : static void FillRectangle(void *data, long x, long y, long w, long h)
      83             : {
      84           0 :   struct data_x *dx = (struct data_x *) data;
      85           0 :   XFillRectangle(dx->display,dx->win,dx->gc, x,y, w,h);
      86           0 : }
      87             : 
      88           0 : static void DrawPoints(void *data, long nb, struct plot_points *p)
      89             : {
      90           0 :   struct data_x *dx = (struct data_x *) data;
      91           0 :   XPoint *xp=(XPoint*)pari_malloc(sizeof(xp)*nb);
      92             :   long i;
      93           0 :   for (i=0;i<nb;i++)
      94             :   {
      95           0 :     xp[i].x=p[i].x;
      96           0 :     xp[i].y=p[i].y;
      97             :   }
      98           0 :   XDrawPoints(dx->display,dx->win,dx->gc, xp, nb, 0);
      99           0 :   pari_free(xp);
     100           0 : }
     101             : 
     102           0 : static void DrawLines(void *data, long nb, struct plot_points *p)
     103             : {
     104           0 :   struct data_x *dx = (struct data_x *) data;
     105           0 :   XPoint *xp=(XPoint*)pari_malloc(sizeof(xp)*nb);
     106             :   long i;
     107           0 :   for (i=0;i<nb;i++)
     108             :   {
     109           0 :     xp[i].x=p[i].x;
     110           0 :     xp[i].y=p[i].y;
     111             :   }
     112           0 :   XDrawLines(dx->display,dx->win,dx->gc, xp, nb, 0);
     113           0 :   pari_free(xp);
     114           0 : }
     115             : 
     116           0 : static void DrawString(void *data, long x, long y, char *text, long numtext)
     117             : {
     118           0 :   struct data_x *dx = (struct data_x *) data;
     119           0 :   XDrawString(dx->display,dx->win,dx->gc, x,y, text, numtext);
     120           0 : }
     121             : 
     122             : #define MAX_BUF 256
     123             : 
     124             : static int
     125           0 : Xerror(Display *d, XErrorEvent *pari_err) {
     126             :   char buf[MAX_BUF];
     127           0 :   XGetErrorText(d,pari_err->error_code,buf,MAX_BUF);
     128           0 :   exiterr(buf); return 0;
     129             : }
     130             : 
     131             : static int
     132           0 : IOerror(Display *d) {
     133             :   char buf[MAX_BUF];
     134           0 :   sprintf(buf, "lost display on %s", DisplayString(d));
     135           0 :   exiterr(buf); return 0;
     136             : }
     137             : 
     138             : static void
     139           0 : PARI_ColorSetUp(Display *display, GEN colors)
     140             : {
     141             :   static int init_done = 0;
     142           0 :   long i, n = lg(colors)-1;
     143             : 
     144           0 :   if (init_done) return;
     145           0 :   init_done=1;
     146             : 
     147           0 :   PARI_Colormap = DefaultColormap(display, 0);
     148           0 :   PARI_Colors = (XColor *) pari_malloc((n+1) * sizeof(XColor));
     149           0 :   for (i=0; i<n; i++)
     150             :   {
     151             :     int r, g, b;
     152           0 :     color_to_rgb(gel(colors,i+1), &r, &g, &b);
     153           0 :     PARI_Colors[i].red   = r*65535/255;
     154           0 :     PARI_Colors[i].green = g*65535/255;
     155           0 :     PARI_Colors[i].blue  = b*65535/255;
     156           0 :     PARI_Colors[i].flags = DoRed | DoGreen | DoBlue;
     157           0 :     if (!XAllocColor(display, PARI_Colormap, &PARI_Colors[i]))
     158           0 :       exiterr("cannot allocate color");
     159             :   }
     160             : }
     161             : 
     162             : static void
     163          60 : draw(PARI_plot *T, GEN w, GEN x, GEN y)
     164             : {
     165             :   long oldwidth,oldheight;
     166             :   struct plot_eng plotX;
     167             :   struct data_x dx;
     168          60 :   double xs = 1, ys = 1;
     169             :   int screen, keystate;
     170             :   Display *display;
     171             :   GC gc;
     172             :   Window win;
     173             :   XEvent event;
     174             :   XSizeHints size_hints;
     175             :   XFontStruct *font_info;
     176             :   XSetWindowAttributes attrib;
     177             :   Atom wm_delete_window, wm_protocols;
     178             : 
     179         120 :   if (pari_daemon()) return;  /* parent process returns */
     180             : 
     181           0 :   pari_close();
     182             : 
     183           0 :   display = XOpenDisplay(NULL);
     184           0 :   font_info = XLoadQueryFont(display, "7x13");
     185           0 :   if (!font_info) exiterr("cannot open 7x13 font");
     186           0 :   XSetErrorHandler(Xerror);
     187           0 :   XSetIOErrorHandler(IOerror);
     188           0 :   PARI_ColorSetUp(display,GP_DATA->colormap);
     189             : 
     190           0 :   screen = DefaultScreen(display);
     191           0 :   win = XCreateSimpleWindow
     192           0 :     (display, RootWindow(display, screen), 0, 0,
     193           0 :      T->width, T->height, 4,
     194           0 :      PARI_Colors[1].pixel, PARI_Colors[0].pixel);
     195             : 
     196           0 :   size_hints.flags = PPosition | PSize;
     197           0 :   size_hints.x = 0;
     198           0 :   size_hints.y = 0;
     199           0 :   size_hints.width  = T->width;
     200           0 :   size_hints.height = T->height;
     201           0 :   XSetStandardProperties
     202             :     (display, win, "PARI plot", NULL, None, NULL, 0, &size_hints);
     203             : 
     204           0 :   wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", False);
     205           0 :   wm_protocols = XInternAtom(display, "WM_PROTOCOLS", False);
     206           0 :   XSetWMProtocols(display,win,&wm_delete_window, 1);
     207             : 
     208           0 :   XSelectInput (display, win,
     209             :     ExposureMask | ButtonPressMask | KeyReleaseMask | StructureNotifyMask);
     210             : 
     211             :   /* enable backing-store */
     212           0 :   attrib.backing_store = Always;
     213           0 :   attrib.backing_planes = AllPlanes;
     214           0 :   XChangeWindowAttributes(display,win,CWBackingStore|CWBackingPlanes,&attrib);
     215             : 
     216           0 :   gc = XCreateGC(display, win, 0, NULL);
     217           0 :   XSetFont(display, gc, font_info->fid);
     218             : 
     219           0 :   XClearWindow(display, win);
     220           0 :   XMapWindow(display, win);
     221           0 :   oldwidth  = T->width;
     222           0 :   oldheight = T->height;
     223           0 :   dx.display= display;
     224           0 :   dx.win = win;
     225           0 :   dx.numcolors = lg(GP_DATA->colormap)-1;
     226           0 :   dx.gc = gc;
     227           0 :   plotX.sc = &SetForeground;
     228           0 :   plotX.pt = &DrawPoint;
     229           0 :   plotX.ln = &DrawLine;
     230           0 :   plotX.bx = &DrawRectangle;
     231           0 :   plotX.fb = &FillRectangle;
     232           0 :   plotX.mp = &DrawPoints;
     233           0 :   plotX.ml = &DrawLines;
     234           0 :   plotX.st = &DrawString;
     235           0 :   plotX.pl = T;
     236           0 :   plotX.data = (void*)&dx;
     237             : 
     238             :   for(;;)
     239             :   {
     240           0 :     XNextEvent(display, &event);
     241           0 :     switch(event.type)
     242             :     {
     243             :       case ClientMessage:
     244           0 :         if (event.xclient.message_type != wm_protocols ||
     245           0 :             (Atom)event.xclient.data.l[0] != wm_delete_window) break;
     246             :       case ButtonPress:
     247             :       case DestroyNotify:
     248             : EXIT:
     249           0 :         XUnloadFont(display,font_info->fid);
     250           0 :         XFreeGC(display,gc);
     251           0 :         XCloseDisplay(display); exit(0);
     252             : 
     253             :       case KeyRelease:
     254             :         /* Mod4 == Super on "std" Linux */
     255           0 :         keystate = event.xkey.state & (ShiftMask|ControlMask|Mod1Mask|Mod4Mask);
     256           0 :         switch (XkbKeycodeToKeysym(display, event.xkey.keycode, 0,0))
     257             :         {
     258             :         case XK_q:
     259           0 :           if (!keystate || keystate == ControlMask) goto EXIT;
     260           0 :           break;
     261             :         case XK_c:
     262           0 :           if (keystate == ControlMask) goto EXIT;
     263           0 :           break;
     264             :         }
     265           0 :         break;
     266             : 
     267             :       case ConfigureNotify:
     268             :       {
     269           0 :         int width  = event.xconfigure.width;
     270           0 :         int height = event.xconfigure.height;
     271             : 
     272           0 :         if (width == oldwidth && height == oldheight) break;
     273           0 :         oldwidth  = width;
     274           0 :         oldheight = height;
     275             : 
     276             :         /* recompute scale */
     277           0 :         xs = ((double)width)/T->width;
     278           0 :         ys = ((double)height)/T->height;
     279             :       }
     280             :       case Expose:
     281           0 :         gen_draw(&plotX, w, x, y, xs, ys);
     282             :     }
     283           0 :   }
     284             : }
     285             : 
     286             : void
     287         124 : gp_get_plot(PARI_plot *T)
     288             : {
     289         124 :   T->width  = 800;
     290         124 :   T->height = 600;
     291         124 :   T->fheight = 13;
     292         124 :   T->fwidth  = 7;
     293         124 :   T->hunit   = 5;
     294         124 :   T->vunit   = 5;
     295         124 :   T->draw = &draw;
     296         124 : }

Generated by: LCOV version 1.11