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.11.0 lcov report (development 22860-5579deb0b) Lines: 22 154 14.3 %
Date: 2018-07-18 05:36:42 Functions: 4 17 23.5 %
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             : 
      40             : struct data_x
      41             : {
      42             :   Display *display;
      43             :   Window win;
      44             :   int numcolors;
      45             :   GC gc;
      46             : };
      47             : 
      48             : /* after fork(), we don't want the child to recover but to exit */
      49             : static void
      50          60 : exiterr(const char *str)
      51             : {
      52          60 :   term_color(c_ERR);
      53          60 :   err_printf("\n  *** X fatal error: %s\n",str);
      54          60 :   term_color(c_NONE); exit(1);
      55             : }
      56             : 
      57             : static long
      58           0 : rgb_to_pixel(Display *display, int r, int g, int b)
      59             : {
      60             :   XColor X;
      61           0 :   X.red   = r*65535/255;
      62           0 :   X.green = g*65535/255;
      63           0 :   X.blue  = b*65535/255;
      64           0 :   X.flags = DoRed | DoGreen | DoBlue;
      65           0 :   if (!XAllocColor(display,PARI_Colormap,&X)) exiterr("cannot allocate color");
      66           0 :   return X.pixel;
      67             : }
      68             : static long
      69           0 : colormapindex_to_pixel(Display *display, long i)
      70             : {
      71           0 :   GEN c = gel(GP_DATA->colormap, i+1);
      72           0 :   int r,g,b; color_to_rgb(c, &r,&g,&b);
      73           0 :   return rgb_to_pixel(display, r, g, b);
      74             : }
      75             : static long
      76           0 : rgb_color(Display *display, long c)
      77             : {
      78           0 :   int r,g,b; long_to_rgb(c, &r, &g, &b);
      79           0 :   return rgb_to_pixel(display, r, g, b);
      80             : }
      81             : 
      82           0 : static void SetForeground(void *data, long col)
      83             : {
      84           0 :   struct data_x *dx = (struct data_x *) data;
      85           0 :   XSetForeground(dx->display,dx->gc, rgb_color(dx->display,col));
      86           0 : }
      87             : 
      88           0 : static void DrawPoint(void *data, long x, long y)
      89             : {
      90           0 :   struct data_x *dx = (struct data_x *) data;
      91           0 :   XDrawPoint(dx->display,dx->win,dx->gc, x,y);
      92           0 : }
      93             : 
      94           0 : static void DrawLine(void *data, long x1, long y1, long x2, long y2)
      95             : {
      96           0 :   struct data_x *dx = (struct data_x *) data;
      97           0 :   XDrawLine(dx->display,dx->win,dx->gc, x1,y1, x2,y2);
      98           0 : }
      99             : 
     100           0 : static void DrawRectangle(void *data, long x, long y, long w, long h)
     101             : {
     102           0 :   struct data_x *dx = (struct data_x *) data;
     103           0 :   XDrawRectangle(dx->display,dx->win,dx->gc, x,y, w,h);
     104           0 : }
     105             : 
     106           0 : static void FillRectangle(void *data, long x, long y, long w, long h)
     107             : {
     108           0 :   struct data_x *dx = (struct data_x *) data;
     109           0 :   XFillRectangle(dx->display,dx->win,dx->gc, x,y, w,h);
     110           0 : }
     111             : 
     112           0 : static void DrawPoints(void *data, long nb, struct plot_points *p)
     113             : {
     114           0 :   struct data_x *dx = (struct data_x *) data;
     115           0 :   XPoint *xp=(XPoint*)pari_malloc(sizeof(xp)*nb);
     116             :   long i;
     117           0 :   for (i=0;i<nb;i++)
     118             :   {
     119           0 :     xp[i].x=p[i].x;
     120           0 :     xp[i].y=p[i].y;
     121             :   }
     122           0 :   XDrawPoints(dx->display,dx->win,dx->gc, xp, nb, 0);
     123           0 :   pari_free(xp);
     124           0 : }
     125             : 
     126           0 : static void DrawLines(void *data, long nb, struct plot_points *p)
     127             : {
     128           0 :   struct data_x *dx = (struct data_x *) data;
     129           0 :   XPoint *xp=(XPoint*)pari_malloc(sizeof(xp)*nb);
     130             :   long i;
     131           0 :   for (i=0;i<nb;i++)
     132             :   {
     133           0 :     xp[i].x=p[i].x;
     134           0 :     xp[i].y=p[i].y;
     135             :   }
     136           0 :   XDrawLines(dx->display,dx->win,dx->gc, xp, nb, 0);
     137           0 :   pari_free(xp);
     138           0 : }
     139             : 
     140           0 : static void DrawString(void *data, long x, long y, char *text, long numtext)
     141             : {
     142           0 :   struct data_x *dx = (struct data_x *) data;
     143           0 :   XDrawString(dx->display,dx->win,dx->gc, x,y, text, numtext);
     144           0 : }
     145             : 
     146             : #define MAX_BUF 256
     147             : 
     148             : static int
     149           0 : Xerror(Display *d, XErrorEvent *pari_err) {
     150             :   char buf[MAX_BUF];
     151           0 :   XGetErrorText(d,pari_err->error_code,buf,MAX_BUF);
     152           0 :   exiterr(buf); return 0;
     153             : }
     154             : 
     155             : static int
     156           0 : IOerror(Display *d) {
     157             :   char buf[MAX_BUF];
     158           0 :   sprintf(buf, "lost display on %s", DisplayString(d));
     159           0 :   exiterr(buf); return 0;
     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          60 :   pari_close();
     181             : 
     182          60 :   display = XOpenDisplay(NULL);
     183          60 :   if (!display) exiterr("cannot open Display");
     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_Colormap = DefaultColormap(display, 0);
     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 :      colormapindex_to_pixel(display, 1),
     195           0 :      colormapindex_to_pixel(display, 0));
     196             : 
     197           0 :   size_hints.flags = PPosition | PSize;
     198           0 :   size_hints.x = 0;
     199           0 :   size_hints.y = 0;
     200           0 :   size_hints.width  = T->width;
     201           0 :   size_hints.height = T->height;
     202           0 :   XSetStandardProperties
     203             :     (display, win, "PARI plot", NULL, None, NULL, 0, &size_hints);
     204             : 
     205           0 :   wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", False);
     206           0 :   wm_protocols = XInternAtom(display, "WM_PROTOCOLS", False);
     207           0 :   XSetWMProtocols(display,win,&wm_delete_window, 1);
     208             : 
     209           0 :   XSelectInput (display, win,
     210             :     ExposureMask | ButtonPressMask | KeyReleaseMask | StructureNotifyMask);
     211             : 
     212             :   /* enable backing-store */
     213           0 :   attrib.backing_store = Always;
     214           0 :   attrib.backing_planes = AllPlanes;
     215           0 :   XChangeWindowAttributes(display,win,CWBackingStore|CWBackingPlanes,&attrib);
     216             : 
     217           0 :   gc = XCreateGC(display, win, 0, NULL);
     218           0 :   XSetFont(display, gc, font_info->fid);
     219             : 
     220           0 :   XClearWindow(display, win);
     221           0 :   XMapWindow(display, win);
     222           0 :   oldwidth  = T->width;
     223           0 :   oldheight = T->height;
     224           0 :   dx.display= display;
     225           0 :   dx.win = win;
     226           0 :   dx.numcolors = lg(GP_DATA->colormap)-1;
     227           0 :   dx.gc = gc;
     228           0 :   plotX.sc = &SetForeground;
     229           0 :   plotX.pt = &DrawPoint;
     230           0 :   plotX.ln = &DrawLine;
     231           0 :   plotX.bx = &DrawRectangle;
     232           0 :   plotX.fb = &FillRectangle;
     233           0 :   plotX.mp = &DrawPoints;
     234           0 :   plotX.ml = &DrawLines;
     235           0 :   plotX.st = &DrawString;
     236           0 :   plotX.pl = T;
     237           0 :   plotX.data = (void*)&dx;
     238             : 
     239             :   for(;;)
     240             :   {
     241           0 :     XNextEvent(display, &event);
     242           0 :     switch(event.type)
     243             :     {
     244             :       case ClientMessage:
     245           0 :         if (event.xclient.message_type != wm_protocols ||
     246           0 :             (Atom)event.xclient.data.l[0] != wm_delete_window) break;
     247             :       case ButtonPress:
     248             :       case DestroyNotify:
     249             : EXIT:
     250           0 :         XUnloadFont(display,font_info->fid);
     251           0 :         XFreeGC(display,gc);
     252           0 :         XCloseDisplay(display); exit(0);
     253             : 
     254             :       case KeyRelease:
     255             :         /* Mod4 == Super on "std" Linux */
     256           0 :         keystate = event.xkey.state & (ShiftMask|ControlMask|Mod1Mask|Mod4Mask);
     257           0 :         switch (XkbKeycodeToKeysym(display, event.xkey.keycode, 0,0))
     258             :         {
     259             :         case XK_q:
     260           0 :           if (!keystate || keystate == ControlMask) goto EXIT;
     261           0 :           break;
     262             :         case XK_c:
     263           0 :           if (keystate == ControlMask) goto EXIT;
     264           0 :           break;
     265             :         }
     266           0 :         break;
     267             : 
     268             :       case ConfigureNotify:
     269             :       {
     270           0 :         int width  = event.xconfigure.width;
     271           0 :         int height = event.xconfigure.height;
     272             : 
     273           0 :         if (width == oldwidth && height == oldheight) break;
     274           0 :         oldwidth  = width;
     275           0 :         oldheight = height;
     276             : 
     277             :         /* recompute scale */
     278           0 :         xs = ((double)width)/T->width;
     279           0 :         ys = ((double)height)/T->height;
     280             :       }
     281             :       case Expose:
     282           0 :         gen_draw(&plotX, w, x, y, xs, ys);
     283             :     }
     284             :   }
     285             : }
     286             : 
     287             : INLINE void
     288         124 : gp_get_display_sizes(long *dwidth, long *dheight, long *fwidth, long *fheight)
     289             : {
     290             :   Display *display;
     291             : 
     292         124 :   display = XOpenDisplay(NULL);
     293         124 :   if (display)
     294             :   {
     295           0 :     int screen = DefaultScreen(display);
     296           0 :     *dwidth  = DisplayWidth(display, screen);
     297           0 :     *dheight = DisplayHeight(display, screen);
     298           0 :     XCloseDisplay(display);
     299             :   }
     300             :   else
     301             :   {
     302             :     /* Situation looks grim */
     303         124 :     *dwidth  = 0;
     304         124 :     *dheight = 0;
     305             :   }
     306         124 :   *fwidth  = 7;
     307         124 :   *fheight = 13;
     308         124 : }
     309             : 
     310             : void
     311         124 : gp_get_plot(PARI_plot *T)
     312             : {
     313         124 :   gp_get_plot_generic(T,gp_get_display_sizes);
     314         124 :   T->draw = &draw;
     315         124 : }

Generated by: LCOV version 1.13