{"action":"created","issue":{"url":"https://api.github.com/repos/cleanflight/cleanflight/issues/2476","repository_url":"https://api.github.com/repos/cleanflight/cleanflight","labels_url":"https://api.github.com/repos/cleanflight/cleanflight/issues/2476/labels{/name}","comments_url":"https://api.github.com/repos/cleanflight/cleanflight/issues/2476/comments","events_url":"https://api.github.com/repos/cleanflight/cleanflight/issues/2476/events","html_url":"https://github.com/cleanflight/cleanflight/issues/2476","id":187021669,"number":2476,"title":"Unit tests only cover around 1.3% of the code","user":{"login":"mkschreder","id":4483721,"avatar_url":"https://avatars.githubusercontent.com/u/4483721?v=3","gravatar_id":"","url":"https://api.github.com/users/mkschreder","html_url":"https://github.com/mkschreder","followers_url":"https://api.github.com/users/mkschreder/followers","following_url":"https://api.github.com/users/mkschreder/following{/other_user}","gists_url":"https://api.github.com/users/mkschreder/gists{/gist_id}","starred_url":"https://api.github.com/users/mkschreder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkschreder/subscriptions","organizations_url":"https://api.github.com/users/mkschreder/orgs","repos_url":"https://api.github.com/users/mkschreder/repos","events_url":"https://api.github.com/users/mkschreder/events{/privacy}","received_events_url":"https://api.github.com/users/mkschreder/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-11-03T10:24:41Z","updated_at":"2016-11-06T22:53:14Z","closed_at":null,"body":"Are you guys using coverage when writing unit tests? I know unit tests are good and stuff but without doing coverage analysis to write better unit tests, the unit tests will never be adequately exhaustive. \r\n\r\nRunning lcov shows only a handful of files being tested in src/main folder and testing is rarely at 100%. \r\n```\r\nReading tracefile coverage.info\r\n                                   |Lines       |Functions  |Branches    \r\nFilename                           |Rate     Num|Rate    Num|Rate     Num\r\n=========================================================================\r\ncommon/encoding.c                  | 100%      5| 100%     2|    -      0\r\ncommon/filter.c                    |32.7%     49|40.0%     5|    -      0\r\ncommon/maths.c                     |59.6%    146|52.2%    23|    -      0\r\ncommon/streambuf.c                 |71.7%     46|76.9%    13|    -      0\r\ncommon/typeconversion.c            |25.5%    145|30.0%    10|    -      0\r\ncommon/utils.h                     | 0.0%      1| 0.0%     1|    -      0\r\nconfig/config.c                    |74.1%     81|70.0%    10|    -      0\r\nconfig/config.h                    |84.6%     39|86.0%    43|    -      0\r\nconfig/config_eeprom.c             |93.2%     88|87.5%     8|    -      0\r\nconfig/config_streamer.c           |88.4%     43|85.7%     7|    -      0\r\nconfig/config_system.h             | 100%      1| 100%     1|    -      0\r\nconfig/feature.c                   |61.1%     18|57.1%     7|    -      0\r\nconfig/feature.h                   | 100%      1| 100%     1|    -      0\r\nconfig/parameter_group.c           |80.4%     51|77.8%     9|    -      0\r\nconfig/parameter_group.h           | 100%      4| 100%     4|    -      0\r\nconfig/profile.c                   |85.7%      7| 100%     2|    -      0\r\nconfig/profile.h                   | 100%      1| 100%     1|    -      0\r\nconfig/vars.c                      | 100%     55| 100%    12|    -      0\r\ndrivers/barometer_bmp085.c         |36.0%    100|27.3%    11|    -      0\r\ndrivers/barometer_bmp280.c         |49.2%     59|37.5%     8|    -      0\r\ndrivers/barometer_ms5611.c         |49.4%     83|20.0%    10|    -      0\r\ndrivers/buf_writer.c               | 0.0%     17| 0.0%     3|    -      0\r\ndrivers/light_ws2811strip.c        |12.2%     49| 9.1%    11|    -      0\r\ndrivers/sonar_hcsr04.c             | 0.0%     11| 0.0%     3|    -      0\r\nflight/altitudehold.c              |23.2%     99|33.3%     9|    -      0\r\nflight/anglerate.c                 |46.7%    212|64.7%    17|    -      0\r\nflight/failsafe.c                  |88.3%    137|87.5%    16|    -      0\r\nflight/gps_conversion.c            |95.5%     22| 100%     1|    -      0\r\nflight/imu.c                       |71.6%    232|58.3%    24|    -      0\r\nflight/mixer.c                     |32.2%    152|31.2%    16|    -      0\r\nflight/servos.c                    |56.1%    189|66.7%    15|    -      0\r\nio/ledstrip.c                      |28.6%    350|29.2%    24|    -      0\r\nio/ledstrip.h                      | 100%      5| 100%     3|    -      0\r\nio/msp.c                           |51.3%    754|80.0%    15|    -      0\r\nio/rc_adjustments.c                |57.3%    157|66.7%     9|    -      0\r\nio/rc_controls.c                   |16.9%    142|45.5%    11|    -      0\r\nio/rc_controls.h                   | 100%      1| 100%     1|    -      0\r\nio/serial.c                        |13.6%    147|13.6%    22|    -      0\r\nio/serial_msp.c                    |63.4%    112|54.5%    11|    -      0\r\nrx/rx.c                            |19.3%    192|24.1%    29|    -      0\r\nscheduler.c                        |82.0%    128|85.7%    14|    -      0\r\nsensors/battery.c                  |52.1%     96|33.3%    15|    -      0\r\nsensors/boardalignment.c           |75.9%     58|66.7%     3|    -      0\r\nsensors/sonar.c                    | 0.0%     35| 0.0%     6|    -      0\r\ntelemetry/hott.c                   |17.4%    218| 7.1%    28|    -      0\r\n=========================================================================\r\n                             Total:|48.0%   4538|51.8%   494|    -      0\r\nSummary coverage rate:\r\n  lines......: 48.0% (2180 of 4538 lines)\r\n  functions..: 51.8% (256 of 494 functions)\r\n  branches...: no data found\r\n\r\n```\r\n\r\nThere are 165576 lines of code in that folder in total, most of which is not being unit tested. (that's including generated mavlink code. If I exclude that we are at 62282 lines that potentially need to be unit tested. Current unit tests in that case still only cover 3.5% of the code) "},"comment":{"url":"https://api.github.com/repos/cleanflight/cleanflight/issues/comments/258717696","html_url":"https://github.com/cleanflight/cleanflight/issues/2476#issuecomment-258717696","issue_url":"https://api.github.com/repos/cleanflight/cleanflight/issues/2476","id":258717696,"user":{"login":"mkschreder","id":4483721,"avatar_url":"https://avatars.githubusercontent.com/u/4483721?v=3","gravatar_id":"","url":"https://api.github.com/users/mkschreder","html_url":"https://github.com/mkschreder","followers_url":"https://api.github.com/users/mkschreder/followers","following_url":"https://api.github.com/users/mkschreder/following{/other_user}","gists_url":"https://api.github.com/users/mkschreder/gists{/gist_id}","starred_url":"https://api.github.com/users/mkschreder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkschreder/subscriptions","organizations_url":"https://api.github.com/users/mkschreder/orgs","repos_url":"https://api.github.com/users/mkschreder/repos","events_url":"https://api.github.com/users/mkschreder/events{/privacy}","received_events_url":"https://api.github.com/users/mkschreder/received_events","type":"User","site_admin":false},"created_at":"2016-11-06T22:53:14Z","updated_at":"2016-11-06T22:53:14Z","body":"Yeah I have it already added in ninjaflight. When you run \"make test\" it\nwill output the report once all tests have passed (my repo is a major wip\nthough so some tests may actually fail when you build it). As I do more\nrefactoring of the source I also update the tests accordingly.\n\nYou can get the coverage table using lcov like this:\nhttps://github.com/mkschreder/ninjaflight/blob/master/Makefile#L928-L931\n\nAlso I have updated my travis script so that it uploads the coverage into\ninto coveralls and gives nice graphs like this:\nhttps://coveralls.io/github/mkschreder/ninjaflight You can also convert\nlcov info file directly into html using genhtml utility on linux and use\nyour browser to view it.\n\nI'm actually refactoring quite a lot of things including the imu and mixer\nand I'm also doing work on adding SITL support (which actually works\nalready by building only imu and mixer into a shared library and loading it\ninto a simulator. I just have not written any documentation for it yet). If\nyou are interested in pulling any of my changes, feel free to do so. Just\nbe aware that unless it is 100% covered and unit tested, it can never be\nguaranteed to work :-)\n\nOn Sun, Nov 6, 2016 at 10:16 PM, Magnus <notifications@github.com> wrote:\n\n> Hi, I was trying to find the documentation on how to get this report,\n> could not find it. I guess that's a good place to start? Building on a Mac\n> I have got gcov and I get lots of output from that, but not as good looking\n> as the table above.\n>\n> I've been using other tools (lcov) in other projects to get a nice report\n> but it seems like you got something in place already?\n>\n> —\n> You are receiving this because you authored the thread.\n> Reply to this email directly, view it on GitHub\n> <https://github.com/cleanflight/cleanflight/issues/2476#issuecomment-258711300>,\n> or mute the thread\n> <https://github.com/notifications/unsubscribe-auth/AERqibnvf-TjtJBBNeYyHf3P0MnR-FF1ks5q7kOVgaJpZM4KoMNx>\n> .\n>\n"}}
{"actor":{"display_login":"mkschreder"}}