LCOV - code coverage report
Current view: top level - src/test/isolation - specparse.y (source / functions) Hit Total Coverage
Test: PostgreSQL 17devel Lines: 94 98 95.9 %
Date: 2024-04-18 12:11:35 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : %{
       2             : /*-------------------------------------------------------------------------
       3             :  *
       4             :  * specparse.y
       5             :  *    bison grammar for the isolation test file format
       6             :  *
       7             :  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
       8             :  * Portions Copyright (c) 1994, Regents of the University of California
       9             :  *
      10             :  *-------------------------------------------------------------------------
      11             :  */
      12             : 
      13             : #include "postgres_fe.h"
      14             : 
      15             : #include "isolationtester.h"
      16             : 
      17             : 
      18             : TestSpec        parseresult;            /* result of parsing is left here */
      19             : 
      20             : %}
      21             : 
      22             : %expect 0
      23             : %name-prefix="spec_yy"
      24             : 
      25             : %union
      26             : {
      27             :     char       *str;
      28             :     int         integer;
      29             :     Session    *session;
      30             :     Step       *step;
      31             :     Permutation *permutation;
      32             :     PermutationStep *permutationstep;
      33             :     PermutationStepBlocker *blocker;
      34             :     struct
      35             :     {
      36             :         void  **elements;
      37             :         int     nelements;
      38             :     }           ptr_list;
      39             : }
      40             : 
      41             : %type <ptr_list> setup_list
      42             : %type <str>  opt_setup opt_teardown
      43             : %type <str> setup
      44             : %type <ptr_list> step_list session_list permutation_list opt_permutation_list
      45             : %type <ptr_list> permutation_step_list blocker_list
      46             : %type <session> session
      47             : %type <step> step
      48             : %type <permutation> permutation
      49             : %type <permutationstep> permutation_step
      50             : %type <blocker> blocker
      51             : 
      52             : %token <str> sqlblock identifier
      53             : %token <integer> INTEGER
      54             : %token NOTICES PERMUTATION SESSION SETUP STEP TEARDOWN TEST
      55             : 
      56             : %%
      57             : 
      58             : TestSpec:
      59             :             setup_list
      60             :             opt_teardown
      61             :             session_list
      62             :             opt_permutation_list
      63             :             {
      64         264 :                 parseresult.setupsqls = (char **) $1.elements;
      65         264 :                 parseresult.nsetupsqls = $1.nelements;
      66         264 :                 parseresult.teardownsql = $2;
      67         264 :                 parseresult.sessions = (Session **) $3.elements;
      68         264 :                 parseresult.nsessions = $3.nelements;
      69         264 :                 parseresult.permutations = (Permutation **) $4.elements;
      70         264 :                 parseresult.npermutations = $4.nelements;
      71             :             }
      72             :         ;
      73             : 
      74             : setup_list:
      75             :             /* EMPTY */
      76             :             {
      77         264 :                 $$.elements = NULL;
      78         264 :                 $$.nelements = 0;
      79             :             }
      80             :             | setup_list setup
      81             :             {
      82         532 :                 $$.elements = pg_realloc($1.elements,
      83         266 :                                          ($1.nelements + 1) * sizeof(void *));
      84         266 :                 $$.elements[$1.nelements] = $2;
      85         266 :                 $$.nelements = $1.nelements + 1;
      86             :             }
      87             :         ;
      88             : 
      89             : opt_setup:
      90         254 :             /* EMPTY */         { $$ = NULL; }
      91         390 :             | setup             { $$ = $1; }
      92             :         ;
      93             : 
      94             : setup:
      95         656 :             SETUP sqlblock      { $$ = $2; }
      96             :         ;
      97             : 
      98             : opt_teardown:
      99         622 :             /* EMPTY */         { $$ = NULL; }
     100         286 :             | TEARDOWN sqlblock { $$ = $2; }
     101             :         ;
     102             : 
     103             : session_list:
     104             :             session_list session
     105             :             {
     106         760 :                 $$.elements = pg_realloc($1.elements,
     107         380 :                                          ($1.nelements + 1) * sizeof(void *));
     108         380 :                 $$.elements[$1.nelements] = $2;
     109         380 :                 $$.nelements = $1.nelements + 1;
     110             :             }
     111             :             | session
     112             :             {
     113         264 :                 $$.nelements = 1;
     114         264 :                 $$.elements = pg_malloc(sizeof(void *));
     115         264 :                 $$.elements[0] = $1;
     116             :             }
     117             :         ;
     118             : 
     119             : session:
     120             :             SESSION identifier opt_setup step_list opt_teardown
     121             :             {
     122         644 :                 $$ = pg_malloc(sizeof(Session));
     123         644 :                 $$->name = $2;
     124         644 :                 $$->setupsql = $3;
     125         644 :                 $$->steps = (Step **) $4.elements;
     126         644 :                 $$->nsteps = $4.nelements;
     127         644 :                 $$->teardownsql = $5;
     128             :             }
     129             :         ;
     130             : 
     131             : step_list:
     132             :             step_list step
     133             :             {
     134        4136 :                 $$.elements = pg_realloc($1.elements,
     135        2068 :                                          ($1.nelements + 1) * sizeof(void *));
     136        2068 :                 $$.elements[$1.nelements] = $2;
     137        2068 :                 $$.nelements = $1.nelements + 1;
     138             :             }
     139             :             | step
     140             :             {
     141         644 :                 $$.nelements = 1;
     142         644 :                 $$.elements = pg_malloc(sizeof(void *));
     143         644 :                 $$.elements[0] = $1;
     144             :             }
     145             :         ;
     146             : 
     147             : 
     148             : step:
     149             :             STEP identifier sqlblock
     150             :             {
     151        2712 :                 $$ = pg_malloc(sizeof(Step));
     152        2712 :                 $$->name = $2;
     153        2712 :                 $$->sql = $3;
     154        2712 :                 $$->session = -1; /* until filled */
     155        2712 :                 $$->used = false;
     156             :             }
     157             :         ;
     158             : 
     159             : 
     160             : opt_permutation_list:
     161             :             permutation_list
     162             :             {
     163         236 :                 $$ = $1;
     164             :             }
     165             :             | /* EMPTY */
     166             :             {
     167          28 :                 $$.elements = NULL;
     168          28 :                 $$.nelements = 0;
     169             :             }
     170             : 
     171             : permutation_list:
     172             :             permutation_list permutation
     173             :             {
     174        4276 :                 $$.elements = pg_realloc($1.elements,
     175        2138 :                                          ($1.nelements + 1) * sizeof(void *));
     176        2138 :                 $$.elements[$1.nelements] = $2;
     177        2138 :                 $$.nelements = $1.nelements + 1;
     178             :             }
     179             :             | permutation
     180             :             {
     181         236 :                 $$.nelements = 1;
     182         236 :                 $$.elements = pg_malloc(sizeof(void *));
     183         236 :                 $$.elements[0] = $1;
     184             :             }
     185             :         ;
     186             : 
     187             : 
     188             : permutation:
     189             :             PERMUTATION permutation_step_list
     190             :             {
     191        2374 :                 $$ = pg_malloc(sizeof(Permutation));
     192        2374 :                 $$->nsteps = $2.nelements;
     193        2374 :                 $$->steps = (PermutationStep **) $2.elements;
     194             :             }
     195             :         ;
     196             : 
     197             : permutation_step_list:
     198             :             permutation_step_list permutation_step
     199             :             {
     200       30676 :                 $$.elements = pg_realloc($1.elements,
     201       15338 :                                          ($1.nelements + 1) * sizeof(void *));
     202       15338 :                 $$.elements[$1.nelements] = $2;
     203       15338 :                 $$.nelements = $1.nelements + 1;
     204             :             }
     205             :             | permutation_step
     206             :             {
     207        2374 :                 $$.nelements = 1;
     208        2374 :                 $$.elements = pg_malloc(sizeof(void *));
     209        2374 :                 $$.elements[0] = $1;
     210             :             }
     211             :         ;
     212             : 
     213             : permutation_step:
     214             :             identifier
     215             :             {
     216       17616 :                 $$ = pg_malloc(sizeof(PermutationStep));
     217       17616 :                 $$->name = $1;
     218       17616 :                 $$->blockers = NULL;
     219       17616 :                 $$->nblockers = 0;
     220       17616 :                 $$->step = NULL;
     221             :             }
     222             :             | identifier '(' blocker_list ')'
     223             :             {
     224          96 :                 $$ = pg_malloc(sizeof(PermutationStep));
     225          96 :                 $$->name = $1;
     226          96 :                 $$->blockers = (PermutationStepBlocker **) $3.elements;
     227          96 :                 $$->nblockers = $3.nelements;
     228          96 :                 $$->step = NULL;
     229             :             }
     230             :         ;
     231             : 
     232             : blocker_list:
     233             :             blocker_list ',' blocker
     234             :             {
     235           0 :                 $$.elements = pg_realloc($1.elements,
     236           0 :                                          ($1.nelements + 1) * sizeof(void *));
     237           0 :                 $$.elements[$1.nelements] = $3;
     238           0 :                 $$.nelements = $1.nelements + 1;
     239             :             }
     240             :             | blocker
     241             :             {
     242          96 :                 $$.nelements = 1;
     243          96 :                 $$.elements = pg_malloc(sizeof(void *));
     244          96 :                 $$.elements[0] = $1;
     245             :             }
     246             :         ;
     247             : 
     248             : blocker:
     249             :             identifier
     250             :             {
     251          72 :                 $$ = pg_malloc(sizeof(PermutationStepBlocker));
     252          72 :                 $$->stepname = $1;
     253          72 :                 $$->blocktype = PSB_OTHER_STEP;
     254          72 :                 $$->num_notices = -1;
     255          72 :                 $$->step = NULL;
     256          72 :                 $$->target_notices = -1;
     257             :             }
     258             :             | identifier NOTICES INTEGER
     259             :             {
     260           2 :                 $$ = pg_malloc(sizeof(PermutationStepBlocker));
     261           2 :                 $$->stepname = $1;
     262           2 :                 $$->blocktype = PSB_NUM_NOTICES;
     263           2 :                 $$->num_notices = $3;
     264           2 :                 $$->step = NULL;
     265           2 :                 $$->target_notices = -1;
     266             :             }
     267             :             | '*'
     268             :             {
     269          22 :                 $$ = pg_malloc(sizeof(PermutationStepBlocker));
     270          22 :                 $$->stepname = NULL;
     271          22 :                 $$->blocktype = PSB_ONCE;
     272          22 :                 $$->num_notices = -1;
     273          22 :                 $$->step = NULL;
     274          22 :                 $$->target_notices = -1;
     275             :             }
     276             :         ;
     277             : 
     278             : %%

Generated by: LCOV version 1.14