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 21348-d75f58f) Lines: 12 141 8.5 %
Date: 2017-11-20 06:21:05 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 "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 DrawPoints(void *data, long nb, struct plot_points *p)
      83             : {
      84           0 :   struct data_x *dx = (struct data_x *) data;
      85           0 :   XPoint *xp=(XPoint*)pari_malloc(sizeof(xp)*nb);
      86             :   long i;
      87           0 :   for (i=0;i<nb;i++)
      88             :   {
      89           0 :     xp[i].x=p[i].x;
      90           0 :     xp[i].y=p[i].y;
      91             :   }
      92           0 :   XDrawPoints(dx->display,dx->win,dx->gc, xp, nb, 0);
      93           0 :   pari_free(xp);
      94           0 : }
      95             : 
      96           0 : static void DrawLines(void *data, long nb, struct plot_points *p)
      97             : {
      98           0 :   struct data_x *dx = (struct data_x *) data;
      99           0 :   XPoint *xp=(XPoint*)pari_malloc(sizeof(xp)*nb);
     100             :   long i;
     101           0 :   for (i=0;i<nb;i++)
     102             :   {
     103           0 :     xp[i].x=p[i].x;
     104           0 :     xp[i].y=p[i].y;
     105             :   }
     106           0 :   XDrawLines(dx->display,dx->win,dx->gc, xp, nb, 0);
     107           0 :   pari_free(xp);
     108           0 : }
     109             : 
     110           0 : static void DrawString(void *data, long x, long y, char *text, long numtext)
     111             : {
     112           0 :   struct data_x *dx = (struct data_x *) data;
     113           0 :   XDrawString(dx->display,dx->win,dx->gc, x,y, text, numtext);
     114           0 : }
     115             : 
     116             : #define MAX_BUF 256
     117             : 
     118             : static int
     119           0 : Xerror(Display *d, XErrorEvent *pari_err) {
     120             :   char buf[MAX_BUF];
     121           0 :   XGetErrorText(d,pari_err->error_code,buf,MAX_BUF);
     122           0 :   exiterr(buf); return 0;
     123             : }
     124             : 
     125             : static int
     126           0 : IOerror(Display *d) {
     127             :   char buf[MAX_BUF];
     128           0 :   sprintf(buf, "lost display on %s", DisplayString(d));
     129           0 :   exiterr(buf); return 0;
     130             : }
     131             : 
     132             : static void
     133           0 : PARI_ColorSetUp(Display *display, GEN colors)
     134             : {
     135             :   static int init_done = 0;
     136           0 :   long i, n = lg(colors)-1;
     137             : 
     138           0 :   if (init_done) return;
     139           0 :   init_done=1;
     140             : 
     141           0 :   PARI_Colormap = DefaultColormap(display, 0);
     142           0 :   PARI_Colors = (XColor *) pari_malloc((n+1) * sizeof(XColor));
     143           0 :   for (i=0; i<n; i++)
     144             :   {
     145             :     int r, g, b;
     146           0 :     color_to_rgb(gel(colors,i+1), &r, &g, &b);
     147           0 :     PARI_Colors[i].red   = r*65535/255;
     148           0 :     PARI_Colors[i].green = g*65535/255;
     149           0 :     PARI_Colors[i].blue  = b*65535/255;
     150           0 :     PARI_Colors[i].flags = DoRed | DoGreen | DoBlue;
     151           0 :     if (!XAllocColor(display, PARI_Colormap, &PARI_Colors[i]))
     152           0 :       exiterr("cannot allocate color");
     153             :   }
     154             : }
     155             : 
     156             : static void
     157          60 : draw(PARI_plot *T, GEN w, GEN x, GEN y)
     158             : {
     159             :   long oldwidth,oldheight;
     160             :   struct plot_eng plotX;
     161             :   struct data_x dx;
     162          60 :   double xs = 1, ys = 1;
     163             :   int screen, keystate;
     164             :   Display *display;
     165             :   GC gc;
     166             :   Window win;
     167             :   XEvent event;
     168             :   XSizeHints size_hints;
     169             :   XFontStruct *font_info;
     170             :   XSetWindowAttributes attrib;
     171             :   Atom wm_delete_window, wm_protocols;
     172             : 
     173         120 :   if (pari_daemon()) return;  /* parent process returns */
     174             : 
     175           0 :   pari_close();
     176             : 
     177           0 :   display = XOpenDisplay(NULL);
     178           0 :   font_info = XLoadQueryFont(display, "7x13");
     179           0 :   if (!font_info) exiterr("cannot open 7x13 font");
     180           0 :   XSetErrorHandler(Xerror);
     181           0 :   XSetIOErrorHandler(IOerror);
     182           0 :   PARI_ColorSetUp(display,GP_DATA->colormap);
     183             : 
     184           0 :   screen = DefaultScreen(display);
     185           0 :   win = XCreateSimpleWindow
     186           0 :     (display, RootWindow(display, screen), 0, 0,
     187           0 :      T->width, T->height, 4,
     188           0 :      PARI_Colors[1].pixel, PARI_Colors[0].pixel);
     189             : 
     190           0 :   size_hints.flags = PPosition | PSize;
     191           0 :   size_hints.x = 0;
     192           0 :   size_hints.y = 0;
     193           0 :   size_hints.width  = T->width;
     194           0 :   size_hints.height = T->height;
     195           0 :   XSetStandardProperties
     196             :     (display, win, "PARI plot", NULL, None, NULL, 0, &size_hints);
     197             : 
     198           0 :   wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", False);
     199           0 :   wm_protocols = XInternAtom(display, "WM_PROTOCOLS", False);
     200           0 :   XSetWMProtocols(display,win,&wm_delete_window, 1);
     201             : 
     202           0 :   XSelectInput (display, win,
     203             :     ExposureMask | ButtonPressMask | KeyReleaseMask | StructureNotifyMask);
     204             : 
     205             :   /* enable backing-store */
     206           0 :   attrib.backing_store = Always;
     207           0 :   attrib.backing_planes = AllPlanes;
     208           0 :   XChangeWindowAttributes(display,win,CWBackingStore|CWBackingPlanes,&attrib);
     209             : 
     210           0 :   gc = XCreateGC(display, win, 0, NULL);
     211           0 :   XSetFont(display, gc, font_info->fid);
     212             : 
     213           0 :   XClearWindow(display, win);
     214           0 :   XMapWindow(display, win);
     215           0 :   oldwidth  = T->width;
     216           0 :   oldheight = T->height;
     217           0 :   dx.display= display;
     218           0 :   dx.win = win;
     219           0 :   dx.numcolors = lg(GP_DATA->colormap)-1;
     220           0 :   dx.gc = gc;
     221           0 :   plotX.sc = &SetForeground;
     222           0 :   plotX.pt = &DrawPoint;
     223           0 :   plotX.ln = &DrawLine;
     224           0 :   plotX.bx = &DrawRectangle;
     225           0 :   plotX.mp = &DrawPoints;
     226           0 :   plotX.ml = &DrawLines;
     227           0 :   plotX.st = &DrawString;
     228           0 :   plotX.pl = T;
     229           0 :   plotX.data = (void*)&dx;
     230             : 
     231             :   for(;;)
     232             :   {
     233           0 :     XNextEvent(display, &event);
     234           0 :     switch(event.type)
     235             :     {
     236             :       case ClientMessage:
     237           0 :         if (event.xclient.message_type != wm_protocols ||
     238           0 :             (Atom)event.xclient.data.l[0] != wm_delete_window) break;
     239             :       case ButtonPress:
     240             :       case DestroyNotify:
     241             : EXIT:
     242           0 :         XUnloadFont(display,font_info->fid);
     243           0 :         XFreeGC(display,gc);
     244           0 :         XCloseDisplay(display); exit(0);
     245             : 
     246             :       case KeyRelease:
     247             :         /* Mod4 == Super on "std" Linux */
     248           0 :         keystate = event.xkey.state & (ShiftMask|ControlMask|Mod1Mask|Mod4Mask);
     249           0 :         switch (XkbKeycodeToKeysym(display, event.xkey.keycode, 0,0))
     250             :         {
     251             :         case XK_q:
     252           0 :           if (!keystate || keystate == ControlMask) goto EXIT;
     253           0 :           break;
     254             :         case XK_c:
     255           0 :           if (keystate == ControlMask) goto EXIT;
     256           0 :           break;
     257             :         }
     258           0 :         break;
     259             : 
     260             :       case ConfigureNotify:
     261             :       {
     262           0 :         int width  = event.xconfigure.width;
     263           0 :         int height = event.xconfigure.height;
     264             : 
     265           0 :         if (width == oldwidth && height == oldheight) break;
     266           0 :         oldwidth  = width;
     267           0 :         oldheight = height;
     268             : 
     269             :         /* recompute scale */
     270           0 :         xs = ((double)width)/T->width;
     271           0 :         ys = ((double)height)/T->height;
     272             :       }
     273             :       case Expose:
     274           0 :         gen_draw(&plotX, w, x, y, xs, ys);
     275             :     }
     276           0 :   }
     277             : }
     278             : 
     279             : void
     280         124 : gp_get_plot(PARI_plot *T)
     281             : {
     282         124 :   T->width  = 800;
     283         124 :   T->height = 600;
     284         124 :   T->fheight = 13;
     285         124 :   T->fwidth  = 7;
     286         124 :   T->hunit   = 5;
     287         124 :   T->vunit   = 5;
     288         124 :   T->draw = &draw;
     289         124 : }

Generated by: LCOV version 1.11