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

Generated by: LCOV version 1.11