Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code coverage isn't correct #16

Open
wspr opened this issue Feb 22, 2019 · 4 comments
Open

Code coverage isn't correct #16

wspr opened this issue Feb 22, 2019 · 4 comments

Comments

@wspr
Copy link
Member

wspr commented Feb 22, 2019

Maybe @ranford can help me here :)

For one test

I've added a choice = 3; option in runtestsuite.m which runs the test suite on ONLY testcuboidtorque03.m and produces coverage-debug.xml. Comparing the output here for private/cuboid_torque_z_z.m, there are lines in the coverage XML like:

              <line hits="384" number="82"/>
              <line hits="4" number="84"/>
              <line hits="4" number="85"/>
              <line hits="4" number="86"/>
              <line hits="384" number="89"/>
              <line hits="4" number="90"/>
              <line hits="4" number="91"/>
              ...

which match up with the edge case calculations:

        if any(a)
          Ex(a) = 1/8*w(a).*(-w2(a)-2*Cw.*w(a)-8*Cv.*abs(w(a))+w(a).*(2*Cw+w(a)).*log(w2(a)));
          Ey(a) = 1/8*w(a).*(+w2(a)+2*Cw.*w(a)+8*Cu.*abs(w(a))-w(a).*(2*Cw+w(a)).*log(w2(a)));
          Ez(a) = 1/4*(Cu-Cv)*w2(a).*log(w2(a));
        end

These are explicitly tested in this test, hence the 4 hits on such lines.

For all tests

But if I change to choice=2; in runtestsuite.m the test suite runs on all tests, and produce coverage.xml — this is the file that is linked to CodeCov. After running all tests I receive:

              <line hits="192" number="82"/>
              <line hits="0" number="84"/>
              <line hits="0" number="85"/>
              <line hits="0" number="86"/>
              <line hits="192" number="89"/>
              <line hits="0" number="90"/>
              <line hits="0" number="91"/>

Clearly something is going wrong here; shouldn't the hits per line accumulate as the entire test suite is run? More importantly, my coverage for this file is less than it should be!

@wspr
Copy link
Member Author

wspr commented Feb 22, 2019

For reference, this is the setup for creating the coverage file:

  import matlab.unittest.TestSuite
  import matlab.unittest.TestRunner
  import matlab.unittest.plugins.CodeCoveragePlugin
  import matlab.unittest.plugins.codecoverage.CoberturaFormat
  
  suite  = TestSuite.fromFolder('testsuite/');
  runner = TestRunner.withTextOutput;
  plugin = CodeCoveragePlugin.forFolder(pwd+["","/private"],...
    'Producing',CoberturaFormat('coverage.xml'));
  
  runner.addPlugin(plugin);
  results = runner.run(suite);

@acampbel
Copy link

Yes that does seem wonky. The first thing I'd suggest looking into is whether any of the code you are executing uses the profiler. This can invalidate the overall numbers, where a call to the profiler (while you are profiling to gather coverage) can result in losing prior coverage. Do you know if any of your code or any code you are calling is using the profiler?

@wspr
Copy link
Member Author

wspr commented Feb 24, 2019

@acampbel — no, pretty sure there's nothing like that. When I get a bit more time I'll try to break up the tests and see if I can reproduce the issue with a minimal example.

@wspr
Copy link
Member Author

wspr commented May 5, 2019

I tried to create a truly minimal example and couldn't reproduce this behaviour... I wonder if it's because the test cases are held in a separate folder. Snowed under again right now so will have to come back to this again later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants