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

clar: use internal functions instead of /bin/cp and /bin/rm #5528

Merged
merged 4 commits into from
Jun 2, 2020

Conversation

ethomson
Copy link
Member

clar has historically shelled out to /bin/cp to copy test fixtures into a sandbox and /bin/rm to clean them up. This has two deficiencies:

  1. /bin/cp is slower than simply opening the source and destination and copying them in a read/write loop. On my Mac, the /bin/cp based approach takes ~2:40 for a full test pass. Using a read/write loop to copy the files ourselves takes ~1:50. Similarly, /bin/rm is slower than doing this internally. Moving to an internal traversal shaves another 20 seconds off.

    These numbers are less impressive on Linux, but using sendfile there makes a notable improvement.

  2. It's noisy. Since the leak detector follows fork/exec, we'll end up running the leak detector on /bin/cp and /bin/rm. This would be fine, except that the leak detector spams the console on startup and shutdown, so it adds a lot of additional information to the test runs that is useless. By not forking and using this internal system, we see much less output.

Since this repo actually has tests and fixtures, I'm opening this PR here and will port it to https://github.com/clar-test/clar once approved.

@ethomson ethomson force-pushed the ethomson/clar_internal branch from 467d2a9 to fdfa742 Compare May 23, 2020 15:23
Copy link
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

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

I had created a similar implementation multiple years ago which used our own internal futil helpers to do this, so I'm very much in favor of doing the conversion! Your approach definitely makes more sense, though, as it's also upstreamable.

There's a few small remarks, but overall this looks good to me!

cl_assert(ret <= (ssize_t)len);
len -= ret;
}
cl_assert(ret >= 0);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this can be cl_assert(ret == 0)

Copy link
Member Author

Choose a reason for hiding this comment

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

Writing the last chunk of the buffer will return a positive ret (indicating the number of bytes written). That will be subtracted from len, which will now be 0. In this case, ret will be positive but we should stop the loop successfully.

tests/clar/fs.h Outdated

close(in);
close(out);

Copy link
Member

Choose a reason for hiding this comment

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

Nit: trailing newline

tests/clar/fs.h Outdated
const char *base;
int base_len;

/* Target exists; append basename */
Copy link
Member

Choose a reason for hiding this comment

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

I think this is the case where we copy a file into a pre-existing directory, right? In that case, we should also assert S_ISDIR(dest_st.mode) so that one gets a proper error message if it isn't.

@pks-t
Copy link
Member

pks-t commented Jun 1, 2020

It's noisy. Since the leak detector follows fork/exec, we'll end up running the leak detector on /bin/cp and /bin/rm. This would be fine, except that the leak detector spams the console on startup and shutdown, so it adds a lot of additional information to the test runs that is useless. By not forking and using this internal system, we see much less output.

Ah, interesting. I always wondered where all those messages on macOS came from, but that makes a lot of sense to me!

ethomson added 4 commits June 2, 2020 09:03
clar has historically shelled out to `/bin/cp` to copy test fixtures
into a sandbox.  This has two deficiencies:

1. It's slower than simply opening the source and destination and
   copying them in a read/write loop.  On my Mac, the `/bin/cp` based
   approach takes ~2:40 for a full test pass.  Using a read/write loop
   to copy the files ourselves takes ~1:50.

2. It's noisy.  Since the leak detector follows fork/exec, we'll end up
   running the leak detector on `/bin/cp`.  This would be fine, except
   that the leak detector spams the console on startup and shutdown, so
   it adds a _lot_ of additional information to the test runs that is
   useless.  By not forking and using this internal system, we see much
   less output.
Similar to how clar has used `/bin/cp` to copy files, it's used
`/bin/rm` to remove them.  This has similar deficiencies; meaning that
leaks is noisy and it's slow.  Move it to an internal function.
@ethomson ethomson force-pushed the ethomson/clar_internal branch from fdfa742 to 2a2c5b4 Compare June 2, 2020 08:06
@ethomson ethomson merged commit d4b953f into master Jun 2, 2020
@ethomson ethomson deleted the ethomson/clar_internal branch June 3, 2020 09:06
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.

2 participants