Menu

Help needed: people writing testcases for improved code coverage

2022-09-28
2024-04-02
1 2 > >> (Page 1 of 2)
  • Simon Sobisch

    Simon Sobisch - 2022-09-28

    We do have internal tests and a build system that allows to check the coverage; for current coverage details, check out the CI generated coverage (unzip, open index.html):


    To create the coverage on your system configure with --enable-debug --enable-code-coverage and then after makeexecute nice make check-code-coverage TESTSUITEFLAGS="--jobs=$(($(nproc)+1))" (drop the TESTSUITEFLAGS or adjust by specifying the actual number of cores you want to spend on that).
    For more information on the coverage and on TESTSUITEFLAGS see the page [Hacking GnuCOBOL].

    The task that needs to be done is to inspect the coverage, then deduce what COBOL code needs to be written (that's sometimes quite obvious because of the comments in the code or because of messages raised for compiler checks, sometimes need a bit more search in the rest of the code - in this case please drop a note because then it is likely useful to also add "missing code comments") and write those.
    Ideally (but not necessary) adding them to the testsuite sources directly and create a patch or a text "this should be added to the following file", otherwise just provide the COBOL sources with a note which coverage should be improved.
    If you add this to the testsuite on your local system (for questions on this just post here) you can also (re-) run the coverage on your machine and check if the parts missing before are now covered (you may want to explicit note the tests via TESTSUITEFLAGS to only check for the new tests to save computing energy).

    Examples:
    One option would be to inspect for missing "run" tests - then navigate to libcob; quite easy should be strings.c and intrinsics.c (the comments note which COBOL code triggers those parts in most places), more complex but still possible would be for example fileio.c where we see a bunch of callable system routines that are obviously not under automated tests yet, further down there are (likely) SORT related functions). Sometimes you'd need to search in cobc where those function calls are generated.

    Another option would be to inspect mostly the compiler part (cobc), ppparse.def would be very easy (just use the internal constants for conditional compilation in a COBOL program) or codeoptim.c (check where the enum values like COB_POINTER_MANIP are referenced, then write up some come code that should trigger it). Those above are also runtime checks; but we also have "compile only (syntax) checks", for this inspect parser.y and maybe typeck.c.

    If you want to give that a try - help is definitely needed and very useful here.

    Side note: To be able to distribute those additional tests (= include it in our testsuite), we'd need either a copyright disclaimer or assignment, see the [Copyright reassignment] page for detail on this.

     

    Related

    Wiki: Copyright reassignment
    Wiki: Hacking GnuCOBOL


    Last edit: Simon Sobisch 2024-03-03
  • Denis HUGONNARD-ROCHE

    HI Simon

    Here is my first modest contribution ..
    I've added the following code to the run_extension.at file

    AT_SETUP([INSPECT TRAILING]) # Shouldn't this be in run_fundamentals?
    AT_KEYWORDS([extensions])
    
    AT_DATA([prog.cob], [
           identification division.
           program-id . prog .
    
           DATA DIVISION .
           WORKING-STORAGE  SECTION.
    
    
           01  W01-STRING    PIC X(20) VALUE '0123456789          ' .
           01  W01-INDEX     PIC 9(04) BINARY   .
    
           PROCEDURE DIVISION .
          *>   
               MOVE 0  TO W01-INDEX .
               INSPECT W01-STRING 
                       TALLYING W01-INDEX FOR TRAILING SPACE  .
               IF W01-INDEX NOT = 10
               THEN
                   DISPLAY 'Bad Result for Inspect Trailing Case 1'
               END-IF . 
          *>
               INSPECT W01-STRING REPLACING TRAILING SPACE BY 'A' . 
               IF W01-STRING NOT = '0123456789AAAAAAAAAA' 
               THEN
                   DISPLAY 'Bad Result for Inspect Trailing Case 2' 
               END-IF .
          *>
               MOVE 0  TO W01-INDEX .
               INSPECT W01-STRING 
                       TALLYING W01-INDEX FOR TRAILING SPACE  
                       REPLACING TRAILING 'A' BY 'B'.
          *>
               IF     W01-STRING NOT = '0123456789BBBBBBBBBB' 
               THEN
                   DISPLAY 'Bad Result for Inspect Trailing Case 3' 
               END-IF .
          *>
               MOVE 0  TO W01-INDEX .
               MOVE SPACES TO W01-STRING .
               INSPECT W01-STRING
                       TALLYING W01-INDEX FOR TRAILING 'A' .
          *>
               IF W01-INDEX  NOT = 0
               THEN
                   DISPLAY 'Bad Result for Inspect Trailing Case 4'
                   W01-INDEX
               END-IF .
          *>           
               MOVE 0  TO W01-INDEX .
               MOVE SPACES TO W01-STRING .
               INSPECT W01-STRING
                       TALLYING W01-INDEX FOR TRAILING SPACES .
          *>
               IF W01-INDEX  NOT = 20
               THEN
                   DISPLAY 'Bad Result for Inspect Trailing Case 5'
                   W01-INDEX
               END-IF .
    
          *>
               GOBACK .
    ])
    
    AT_CHECK([$COMPILE prog.cob], [0], [], [])
    AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [], [])
    
    AT_CLEANUP
    

    It allows to complete the code coverage in the inspect_common_no_replace function ( case type == INSPECT_TRAILING).

     

    Last edit: Simon Sobisch 2022-09-30
    • Simon Sobisch

      Simon Sobisch - 2022-09-30

      Thank you, that's actually a nice addition!
      Checked in already with [r4721]. I haven't checked the code-coverage change but guess you did that :-) .

      Please see the [Copyright reassignment] page on necessary papers to allow us to also include more / bigger changes to the testsuite (that page misses the option to use a copyright disclaimer, but as I hope you are able to contribute more [a bunch of or even regular] tests, an assignment would be definitely preferable).

       

      Related

      Commit: [r4721]
      Wiki: Copyright reassignment

  • Denis HUGONNARD-ROCHE

    Yes , I 've checked the code coverage :-)
    I use this method as i don't know if it's the best one :

    I have downloaded the snapshot and unzip it in two different directories :
    - gnucobol-code-r4719-branches-gnucobol-3.x
    - gnucobol-code-r4719-test

    I have run the testsuite with the code coverage in he first directory, which is my reference, and i work in the second and then visually compare the resulting html to the reference files via my web browser

    For the copyright i'll will see that this we.

     
    • Simon Sobisch

      Simon Sobisch - 2022-09-30

      I'd use one snapshot, then run the coverage check once, rename the resulting directory, then adjust the testsuite source and re-run - this way there is no need to build twice while still having both coverages to compare.

      Thanks again!

       
  • Denis HUGONNARD-ROCHE

    HI Simon

    Please find in attached another program that allows to increase the strings.c test code coverage.

    On the r4722-branches-gnucobol-3.x snapshot :
    Strings.c :
    Line coverage 85,6 % ---> 87,7%
    Functions coverage 96,4%---> 100 %

    Denis.

    PS : i don't forget what you wrote me about copyright. I just had a glance ... and have to read it better in order to understand what i have to do :-)

     
    • Simon Sobisch

      Simon Sobisch - 2022-10-02

      Thank you for the test. Checked in with modifications to make it more concise with slightly less readability with [r4728].

      Aiming for general 100% function coverage in each file seems definitely useful :-)
      Doing that for the runtime first will also include line and branch coverage in the compiler, so that's a very reasonable way to tackle that.
      Tackling coverage under cobc should mostly be about improving line coverage for syntax checks.

      Note: In every case you may have seen LCOV exclusion markers, if you ever stumble over those and thing "that can be tested" - please drop a note, similar for code that seems to be not possible to test; which commonly should only be code that leads to an abort during compile or runtime, or is only called in that context.
      ... but often often that is possible to test, too, for example by producing too much syntax errors /non-COBOL input files or a runtime error.

      Just out of interest: is there already a kind of list of things you want to tackle for coverage next?

       

      Related

      Commit: [r4728]

  • Denis HUGONNARD-ROCHE

    Hi Simon

    I saw you have integrate the nex test program ...
    I have leaved the program name to UnstringTest ...but i guess it had to be rename to prog to be integrated to the testsuite ?

    Denis

     
    • Simon Sobisch

      Simon Sobisch - 2022-10-02

      :-) Using "prog" for the filename is a way to not need to think about good names; as long as it is compiled to an executable the internal entry name does not matter (to not have that matter for modules is a FR somewhere with a clear solution that is possibly outlined there, it is just one of the not-that-important things currently more or less on hold because too much to do; some of those are also "good first issue" points - so issues people that want to start contributing to the code could have a look at after discussion in the specific issue).
      I've found your program id matching the test and left it in as "part of the style used by the test writer".

       
  • Denis HUGONNARD-ROCHE

    I indeed prepare some notes on C code to be cover .. that i not able yet to link to Cobol fonctionnalities .
    A question : is is possible to include the NIST testsuite to the code coverage tools. Is it's increase the code coverage we would be able to pick the rights cases, recode them in the gnucobol testsuite ?

     
    • Simon Sobisch

      Simon Sobisch - 2022-10-02

      A question : is is possible to include the NIST testsuite to the code coverage tools. Is it's increase the code coverage we would be able to pick the rights cases, recode them in the gnucobol testsuite ?

      Hm, yes, that would be possible. When looking at the Makefile we see that check-code-coverage consist of two steps:

      # Use recursive makes in order to ignore errors during check
      check-code-coverage:
          -$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -k check
          $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) code-coverage-capture
      

      So we can also do those manually - and extending it in between. I think the following should be what you want to do:

      $ make -k check
      $ make -k test
      $ make code-coverage-capture
      

      In general the data is likely still available, in this case you'd only want to run the NIST part and specify a different output directory. If that works - I did not tested that yet - you can do:

      $ make check-code-coverage # run the test and write the normal output
      $ make -k test             # add the NIST testsuite to the coverage data
      $ make code-coverage-capture CODE_COVERAGE_OUTPUT_DIRECTORY=extended-coverage CODE_COVERAGE_OUTPUT_FILE=extended-coverage.info # calculate coverage, now from both, write the output to a separate place
      
       
    • Simon Sobisch

      Simon Sobisch - 2022-10-02

      Is it's increase the code coverage we would be able to pick the rights cases, recode them in the gnucobol testsuite ?

      That may be harder than it sounds - because the NIST suite is huge and you'd have to first find out where something comes from.

      But if the suggested way of "adding" to the coverage data works you can likely also do make test -C cobol85/RW to be able to inspect the coverage increase for a smaller subset (a single module only).

      "In the end" the goal is that make test adds zero coverage, so we are quite sure that running it is not as necessary as it is currently; but I guess that will be a long way (if your combined coverage works then you likely know)...

       
  • Denis HUGONNARD-ROCHE

    Ok , i'll try :-)

     
  • Denis HUGONNARD-ROCHE

    Simon
    Another program to improve strings.c code coverage (cobol string statement) (87,7% --> 91%)
    Line coverage 87,7% ---> 91%
    It remains some code in the cob_inspect_characters to complete.
    Hope i will have some time next week ...as i begin a new job ... and i have received all the stuffs that
    i ordered to built my DIY NAS :-)

    Regards

     
  • Simon Sobisch

    Simon Sobisch - 2023-02-05

    @dhugonnard Do we still have some of those missing and/or there are new tests from your side to add?

     
  • Denis HUGONNARD-ROCHE

    Hi Simon , i have been quiet busy these last weeks.
    But i have finished some complementayr cases tests for move statement.
    I'll send you on a svn patch format this evening

    Denis

     
  • Denis HUGONNARD-ROCHE

    Hi Simon

    Here is a patch taht contains nex tests programs and a correction of one that is already included
    With this patch we increase move.c coverage from 67.7 to 72.2

    Denis

     
  • Denis HUGONNARD-ROCHE

    Hi Simon

    Did you received my previous poist with new programs. ?

    Denis.
    Regards

     
    • Simon Sobisch

      Simon Sobisch - 2023-02-12

      Yes, thank you. I want to have a look at them in about 8 days (I'm not near a computer over the next week).

       
  • Denis HUGONNARD-ROCHE

    Hi Simon

    A question ..
    How could I insert in some libcob source file, a instruction that prints the current cobol program running ?
    IS there a macro or a function that could do the job ?

    Regards

     
    • Simon Sobisch

      Simon Sobisch - 2023-02-27

      You can compile with -ftrace and run with COB_SET_TRACE=1.

      For the internal testsuite that would be make check COBOL_FLAGS=-ftrace + adding export COB_SET_TRACE=1 to test/atlocal - obvioulsy most of the testsuite cases wouzld fail because of the unexpected output, but this can be reduced to only the tracing tests by also doing export COB_TRACE_FILE /some/dir/testtrace.log.
      For NIST the procedure you'd need to directly add the flag to COBC.

      I guess that possibly answers your question?

      If not: from C COB_MODULE_PTR->module_name gives you the current module, with GC3.2's extended frame information you also have section + paragraph names along with the statement in COB_MODULE_PTR->frame_ptr.

       

      Last edit: Simon Sobisch 2023-02-27
  • Denis HUGONNARD-ROCHE

    Yes it's ok with COB_MODULE_PTR->module_name
    Thx

     
  • Denis HUGONNARD-ROCHE

    Hi Simon

    Please find here the following programs to enhanced the MOVE statement tests
    (Some i have already sent to you)

    MoveAlphanumToDisplay.cbl
    Move_Basic_P_Pic.cbl
    MoveDeEditing_2.cbl
    MoveDeEditing_3.cbl
    MoveDeEditing_4.cbl
    MoveDeEditing_5.cbl
    MoveDeEditing.cbl
    MoveEditedToDisplay.cbl
    MoveJustified.cbl
    MoveOtherCases.cbl
    MoveTestCobMove.cbl
    MoveToEditedZero.cbl

    Compilation status :

    All compile without warning with -Wall excepted Move_Basic_P_Pic.cbl

    Move_Basic_P_Pic.cbl :

    This program contains basic tests with P Picture
    I know that the P picture functionalities are not finished but as the NIST tests contains
    some programs with P Picture I wrote a small tests
    The GC compiler generates warning about truncation but it runs ok.

    Run status :

    All run ok except MoveTestCobMove.cbl that displays errors due to the bug i mentioned
    regarding 'binary-c..' (Tickets #877).

    I'm pretty confident about these test programs, but due to the different behavior of
    cobol compilers if you could test on MF the following two programs it would be an additional guarantee :
    - MoveAlphanumToDisplay.cbl
    - MoveEditedToDisplay.cbl

    Results of move.c coverage with make check-code-coverage

    With defaultbyte=0    move.c 66.1% --> 73.9%
    With defaultbyte=init move.c 69.2% --> 73.9%
    With NIST + GC tests  move.c 75%
    

    So, there are still some few cases to add that I will look into, but most of
    the remaining code to test in move.c is the c api "convenient function"

    Denis

     
    • Simon Sobisch

      Simon Sobisch - 2023-07-21

      As requested I gave it a try with MF:

      MoveAlphanumToDisplay:
      runtime error with MF on line 22:

      21     MOVE '  +4567.89'        TO SRC-STRING .
      22     MOVE SRC-STRING          TO DST-DISP   .
      

      163 Illegal character in numeric field [line 22]

      This also happens without the "+" (I'd consider that bad and if it works with GC consider it superior here).

      similar for MoveEditedToDisplay, same runtime error message, but this is a testcase problem, the testcase should use:

      -              DISPLAY '1: DST-FIELD-1 <' DST-FIELD-2 '> != 1234005' . 
      +              DISPLAY '1: DST-FIELD-1 <' DST-FIELD-1 '> != 1234005' . 
      

      not sure what it should test the value against, for MF it contains numeric 12345.0, data (which you'd get to by using (1:)) contains "00000123450000".

       
  • Denis HUGONNARD-ROCHE

    Hi Simon
    I'll have som others tests programs that i will be able to send until end of July for c api move.c functions.
    I 'have begun to work on test programs for class clause and swith.
    Regarding class clause, the following programs does not compile , i'm not sur that this is a "normal" compilation error.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. tstclass.
    
       ENVIRONMENT  DIVISION.
       CONFIGURATION SECTION .
       SPECIAL-NAMES         .
       CLASS HEXA IS '0' THRU '9'
                     'A' THRU 'F' .
       CLASS ODD   IS '1' '3' '5' '7' '9'   .
       CLASS EVEN  IS  0 2 .
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  ALPHA       PIC X(01)  .
       01  NUM-1       PIC 9(01)  .
      *>
       PROCEDURE DIVISION.
      *>
           MOVE '3' TO ALPHA .
           IF ALPHA IS HEXA
           THEN
               CONTINUE
           ELSE
               DISPLAY 'ERROR 1'
           END-IF.
      *>
           IF ALPHA IS ODD
           THEN
               CONTINUE
           ELSE
               DISPLAY 'ERROR 2'
           END-IF.
      *>
           MOVE  2  TO NUM-1
           IF NUM-1 IS EVEN
           THEN
               CONTINUE
           ELSE
               DISPLAY 'ERROR 3'
           END-IF.
      *>
           GOBACK  .
    

    PS
    Regarding the previous batch of programs i sent , none of them have been integrated, does they have to be modified ?

    Denis

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.