Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. QA Tools
  3. Coco
  4. End of function coverage after switch case
QtWS25 Last Chance

End of function coverage after switch case

Scheduled Pinned Locked Moved Unsolved Coco
6 Posts 5 Posters 546 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rbrook08
    wrote on last edited by rbrook08
    #1

    Hi there, my organization is currently attempting to integrate coco into our development for code coverage. We're attempting to do mc/dc coverage on some code of ours and ran into a bit of a snag.

    Here is the coveragescanner results of some of the code:

    da60e4e9-97a3-4ab6-b2e7-7423fe594ee3-image.png

    Our concern is that we need to show that we are able to hit each function entrance and exit (if possible), and in this case after breaking out of the switch statement the reports do not indicate that the end of the function was hit.

    Testing without the final break in the default case of the switch statement does hit the end of the function:

    ee69b179-64e8-4a1e-bdf8-5356c3751bb4-image.png

    Here are some further examples we ran into playing around with the code:

    ece426ca-0846-473a-bd2e-d2b44afc5ec0-image.png

    Removing the break on the default statement reached the end of the function as did adding a line of code after the switch statement.

    I was wondering if anybody ran into any kind of a similar issue and might know what is going on here?

    Thank you

    Axel SpoerlA 1 Reply Last reply
    0
    • R rbrook08

      Hi there, my organization is currently attempting to integrate coco into our development for code coverage. We're attempting to do mc/dc coverage on some code of ours and ran into a bit of a snag.

      Here is the coveragescanner results of some of the code:

      da60e4e9-97a3-4ab6-b2e7-7423fe594ee3-image.png

      Our concern is that we need to show that we are able to hit each function entrance and exit (if possible), and in this case after breaking out of the switch statement the reports do not indicate that the end of the function was hit.

      Testing without the final break in the default case of the switch statement does hit the end of the function:

      ee69b179-64e8-4a1e-bdf8-5356c3751bb4-image.png

      Here are some further examples we ran into playing around with the code:

      ece426ca-0846-473a-bd2e-d2b44afc5ec0-image.png

      Removing the break on the default statement reached the end of the function as did adding a line of code after the switch statement.

      I was wondering if anybody ran into any kind of a similar issue and might know what is going on here?

      Thank you

      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      I don't fully understand what the question is, and how it relates to Qt.

      Our concern is that we need to show that we are able to hit each function entrance and exit (if possible), and in this case after breaking out of the switch statement the reports do not indicate that the end of the function was hit.

      All examples shown always reach the end of the function, simply because there is no return in the switch.
      Adding a default handler doesn't change that, neither does adding a breakto the default section.

      The breaksimply means, that there is no "fallthrough" to the next case.

      switch (a) {
      case 0:
          // do something only if a == 0
      case 1:
          // do something if a == 0 or a == 1
          break;
      case 2:
          // do something only if a == 2
          break;
      default:
          // do something in all other cases
          break; // technically not necessary, but good practice anyway.
      }
      
      qDebug() << "end of function reached";

      Software Engineer
      The Qt Company, Oslo

      JonBJ 1 Reply Last reply
      0
      • Axel SpoerlA Axel Spoerl

        I don't fully understand what the question is, and how it relates to Qt.

        Our concern is that we need to show that we are able to hit each function entrance and exit (if possible), and in this case after breaking out of the switch statement the reports do not indicate that the end of the function was hit.

        All examples shown always reach the end of the function, simply because there is no return in the switch.
        Adding a default handler doesn't change that, neither does adding a breakto the default section.

        The breaksimply means, that there is no "fallthrough" to the next case.

        switch (a) {
        case 0:
            // do something only if a == 0
        case 1:
            // do something if a == 0 or a == 1
            break;
        case 2:
            // do something only if a == 2
            break;
        default:
            // do something in all other cases
            break; // technically not necessary, but good practice anyway.
        }
        
        qDebug() << "end of function reached";
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @Axel-Spoerl
        I think the problem is that OP is using some tool to analyze code coverage

        Here is the coveragescanner results of

        While it is true that all the code blocks he shows are "good", for whatever reason his "coveragescanner" tool does not report that the end of the function is reached in certain cases where default/break are/are not used.

        As you say, however, this does not relate to Qt and seems to be an issue OP needs to take up with code coverage tool or find a workaround which keeps it happy.

        Axel SpoerlA 1 Reply Last reply
        2
        • JonBJ JonB

          @Axel-Spoerl
          I think the problem is that OP is using some tool to analyze code coverage

          Here is the coveragescanner results of

          While it is true that all the code blocks he shows are "good", for whatever reason his "coveragescanner" tool does not report that the end of the function is reached in certain cases where default/break are/are not used.

          As you say, however, this does not relate to Qt and seems to be an issue OP needs to take up with code coverage tool or find a workaround which keeps it happy.

          Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by
          #4

          Q_UNREACHABLE() and Q_UNREACHABLE_RETURN(x) - another pair of magic macros, working wonders ;-)

          Software Engineer
          The Qt Company, Oslo

          1 Reply Last reply
          3
          • R Offline
            R Offline
            rubyrhodes
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • LarisabrownbL Offline
              LarisabrownbL Offline
              Larisabrownb
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved