Clar XML output redux - #4778
Conversation
af1594c to
7175af6
Compare
|
I didn't really like that it was writing the XML output to the temporary directory (since it opened the file after being sandboxed). This is a result of the aggressively early sandbox, so that it can handle So I changed a bit about the way clar handles I made it so that I also made So there's some success now. You can see that the although there are linux test failures (because of leaks), they're actually publishing the test results. So that's neat! But indeed there are still a few problems: this has introduced some leaks, the macOS tests aren't getting picked up, the Windows XML isn't getting written, and there's a failure in one of the Windows builds. But it's getting close! |
559ac97 to
4e300c7
Compare
|
It turns out that the linux failures were because my original take at refactoring Originally, I had hoped to avoid any allocations, but that was a silly and unnecessary false optimization. As a result, I refactored the |
|
Cool, looks like we've got it working, @tiennou! |
|
I introduced a few memory leaks into clar, which are being detected by valgrind (yay!) but are not failing the build (boo). I'll have to take a look at this before this is ready to |
|
Okay, I just pushed up a quick test to validate that valgrind was still failing on leaks in the actual product code - it is definitely failing when we "definitely lose" memory. (But not when allocations are "still reachable" at termination.) This seems reasonable to me but it appears that the macOS and Windows builds are not failing when they detect memory leaks. Since this didn't regress, I want to limit the scope of this PR, so I'll try to address this in a separate one soon. |
0a44546 to
f653450
Compare
|
|
||
| _clar_suites[j].enabled = 1; | ||
| _clar.last_explicit = explicit; | ||
| break; |
There was a problem hiding this comment.
I stumbled upon this behaviour before, and didn't quite like it. It also resulted in weird cases with "./libgit2_clar -sodb -sgarbage", where it first runs the odb suite an then complains about the "garbage" suite not being found. So this is a very nice improvement
| { | ||
| struct clar_report *report; | ||
| const char *last_suite = NULL; | ||
| char wd[1024]; |
|
|
||
| clar_summary_close_tag("testsuites", 0); | ||
|
|
||
| fclose(summary); |
There was a problem hiding this comment.
One always has to check fclose, as it may produce errors that indicate a file not having been written. Especially so if one uses the buffered interface
|
|
||
| last_suite = report->suite; | ||
|
|
||
| clar_summary_testcase(report->test, "what", 0); |
There was a problem hiding this comment.
We should also do error checking for these, as we're writing into the FILE pointer. Personally, I'd also vote for making the dependency on the FILE explicit by passing it into the functions, instead of having it implicit via a global. It makes the object's lifetime a lot clearer
| OPTION(ENABLE_WERROR "Enable compilation with -Werror" OFF) | ||
| OPTION(USE_BUNDLED_ZLIB "Use the bundled version of zlib" OFF) | ||
| SET(CLAR_XML "OFF" CACHE STRING | ||
| "Writes test results in XML format. One of ON, OFF or the directory to write to.") |
There was a problem hiding this comment.
Does this really have to be a build configuration? Why can't I just specify this on libgit2_clar's command line?
Edit: oh, because we use it for our CMake-defined tests, that's why. I think we should clarify the documentation a bit, as it sounds like this will enable it for libgit2_clar in general, and not for our CMake tests.
| inputs: | ||
| testResultsFiles: 'results_*.xml' | ||
| searchFolder: '$(Build.BinariesDirectory)' | ||
| mergeTestResults: true |
There was a problem hiding this comment.
Lovely, all these repetitive job descriptions were bothering me since the inception. Really sice that you can simply use templates instead
f653450 to
734a6fa
Compare
Previously, supplying `-s` to explicitly enable some test(s) would run the tests immediately from the argument parser. This forces us to set up the entire clar environment (for example: sandboxing) before argument parsing takes place. Refactor the behavior of `-s` to add the explicitly chosen tests to a list that is executed later. This untangles the argument parsing from the setup lifecycle, allowing us to use the arguments to perform the setup.
This makes it possible to keep track of every test status (even successful ones), and their errors, if any.
Accept an (optional) value for the summary filename. Continues to default to summary.xml.
Introduce a CLAR_XML option, to run the `ctest` commands with the new `-r` flag to clar. Permitted values are `OFF`, `ON` and a directory to write the XML test results to.
Remove the global summary filename and file pointer; pass them in to the summary functions as needed. Error check the results of buffered I/O calls.
CMake treats backslashes as escape characters; use forward slashes for the XML output path.
Explicitly run from the build directory, not the source. (I was mistaken about the default working directory for VSTS agents.)
Our build YAML is becoming unweildly and full of copy-pasta. Simplify with templates.
Windows lacks %F and %T formats for strftime. Expand them to the year/month/day and hour/minute/second formats, respectively.
bc8de73 to
e595eeb
Compare
|
Fixed this up per your comments, @pks-t |
| /* Core test functions */ | ||
| static void | ||
| clar_report_errors(void) | ||
| clar_report(int *i, struct clar_error *error) |
There was a problem hiding this comment.
By the way, this interface is a bit funny, as it's kind of emulating an iterator via this integer. But in my opinion, using this integer makes code less understandable compared to simply iterating over the linked list of errors ourselves.
Feel free to ignore this comment -- it's not that important after all and can easily be cleaned up later
There was a problem hiding this comment.
Huh. Thanks for the detailed review, I had missed that. I agree and will fix it up before I merge it.
There was a problem hiding this comment.
And, actually, I decided that I didn't like the way that I fixed it. One of the report functions was still assuming knowledge of the clar structure that a caller also had knowledge of, so I simply passed that in as an arg and I think it's quite a bit nicer. Thanks again for catching this.
|
Despite the minor comment I have about the weird iterating interface, the PR looks good to me. By the way -- do we really have 16000 tests? I cannot quite believe that it's that many tests and tend to think the XML output is to blame. |
No - sorry - to clarify, that's an aggregation of all the unit tests run for the build, so it's across all the build hosts. We actually end up executing 23,854 tests in total. |
Instead of trying to have a clever iterator pattern that increments the error number, just iterate over errors in the report errors or report all functions as it's easier to reason about in this fashion.
c99abed to
d17e67d
Compare
|
I was playing around with some other things but I'll open a new PR if I decide to pursue them. Shipping this one. |

Reopening a new PR with @tiennou's work in #4741 so that the CI will pick it up.