Skip to content

Clar XML output redux - #4778

Merged
ethomson merged 15 commits into
masterfrom
ethomson/clar-xml
Sep 9, 2018
Merged

Clar XML output redux#4778
ethomson merged 15 commits into
masterfrom
ethomson/clar-xml

Conversation

@ethomson

Copy link
Copy Markdown
Member

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

@ethomson ethomson mentioned this pull request Aug 24, 2018
@ethomson
ethomson force-pushed the ethomson/clar-xml branch 4 times, most recently from af1594c to 7175af6 Compare August 26, 2018 15:36
@ethomson

Copy link
Copy Markdown
Member Author

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 -s test arguments.

So I changed a bit about the way clar handles -s arguments. Previously, in the arg parser, it would just run the tests when it saw a -s and then skip the usual test running that it does.

I made it so that -s actually enables the tests that were specified (disabling everything else). This means that we don't have to set up the sandbox before we parse arguments. So now if we have a -r, we can open the file in the current working directory, then do the sandbox.

I also made -r take an optional argument with the filename. This is because we have five separate libgit2_clar invocations in the CMakeLists.txt and they should have unique filenames. We also need to be able to write them into the build output directory since on the Linux builds (which are run in containers) we need to write to a directory that's mapped back to the host.

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!

@ethomson
ethomson force-pushed the ethomson/clar-xml branch 11 times, most recently from 559ac97 to 4e300c7 Compare August 26, 2018 23:37
@ethomson

Copy link
Copy Markdown
Member Author

It turns out that the linux failures were because my original take at refactoring -s support was far too liberal in enabling tests. It enabled whole suites, so the ssh tests that turn on a single test would actually run the entire online::clone suite. Oops.

Originally, I had hoped to avoid any allocations, but that was a silly and unnecessary false optimization. As a result, I refactored the -s parsing so that we now store the values in the argument parsing loop and run them later.

@ethomson

Copy link
Copy Markdown
Member Author

Cool, looks like we've got it working, @tiennou!

screen shot 2018-08-27 at 1 17 44 am

@ethomson

Copy link
Copy Markdown
Member Author

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 :shipit: .

@ethomson

Copy link
Copy Markdown
Member Author

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.

@ethomson
ethomson force-pushed the ethomson/clar-xml branch 3 times, most recently from 0a44546 to f653450 Compare August 27, 2018 08:28
Comment thread tests/clar.c

_clar_suites[j].enabled = 1;
_clar.last_explicit = explicit;
break;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread tests/clar/summary.h Outdated
{
struct clar_report *report;
const char *last_suite = NULL;
char wd[1024];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PATH_MAX?

Comment thread tests/clar/summary.h Outdated

clar_summary_close_tag("testsuites", 0);

fclose(summary);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread tests/clar/summary.h Outdated

last_suite = report->suite;

clar_summary_testcase(report->test, "what", 0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree with that.

Comment thread CMakeLists.txt Outdated
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.")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .vsts-ci.yml Outdated
inputs:
testResultsFiles: 'results_*.xml'
searchFolder: '$(Build.BinariesDirectory)'
mergeTestResults: true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely, all these repetitive job descriptions were bothering me since the inception. Really sice that you can simply use templates instead

ethomson and others added 4 commits September 6, 2018 11:17
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.
@ethomson

ethomson commented Sep 6, 2018

Copy link
Copy Markdown
Member Author

Fixed this up per your comments, @pks-t

Comment thread tests/clar.c Outdated
/* Core test functions */
static void
clar_report_errors(void)
clar_report(int *i, struct clar_error *error)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh. Thanks for the detailed review, I had missed that. I agree and will fix it up before I merge it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pks-t

pks-t commented Sep 7, 2018

Copy link
Copy Markdown
Member

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.

@ethomson

ethomson commented Sep 8, 2018

Copy link
Copy Markdown
Member Author

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.
@ethomson
ethomson force-pushed the ethomson/clar-xml branch 6 times, most recently from c99abed to d17e67d Compare September 9, 2018 13:25
@ethomson

ethomson commented Sep 9, 2018

Copy link
Copy Markdown
Member Author

I was playing around with some other things but I'll open a new PR if I decide to pursue them. Shipping this one.

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

Successfully merging this pull request may close these issues.

3 participants