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

TTQ-788 Dev fuzzer malloc #429

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open

TTQ-788 Dev fuzzer malloc #429

wants to merge 5 commits into from

Conversation

swojo
Copy link

@swojo swojo commented Oct 19, 2016

@frederikvs
-Implementation of pseudo-randomly failing malloc
-Uses env variable 'MEM_TEST_SEED' to specify the seed to rand
-Compile with flag "CHECK_MEM=1' to use this zalloc implementation

@swojo swojo changed the base branch from master to development October 19, 2016 09:03
Copy link
Contributor

@phalox phalox left a comment

Choose a reason for hiding this comment

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

Looks good to me. If @frederikvs can give his 2cts, then he can merge

Copy link
Contributor

@frederikvs frederikvs left a comment

Choose a reason for hiding this comment

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

Nice work.

I'm not sure about the frequency of opening-closing that file there, but l wouldn't worry about that for now. If it turns out to be a problem, it'll only be a problem in our test setup, and we can have a look at it then.

A few minor comments inline, once those are resolved I'll merge.


#ifdef CHECK_MEM
//New log for malloc information
fopen("mem_test.log", "w");
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you doing anything with the file you're opening here?

Copy link
Author

Choose a reason for hiding this comment

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

The idea was to make sure to clear the file before running a new set of tests but this was flawed since it was getting called with each new test and so only the last test's mallocs were getting logged in the end. I changed to outputting this in stdout, which also makes it clear which tests the mallocs occurred in and which ASAN errors are related to them.

fopen("mem_test.log", "w");

//Set rand seed
char *buf = getenv("MEM_TEST_SEED");
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you also putting this seed into some kind of log, so that we can try to recreate afterwards?

Copy link
Author

Choose a reason for hiding this comment

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

I'll try to get this done. Just noticed there's a problem of getting the environment variable when I run it through the RF test rather than just the unit tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could be good to make a single function that reads all environment variables into local/global variables. Then you can also log these immediatly.
What's wrong with getting them in RF tests? it's possible that these set up a virtual environment...

}

#define PICO_ZALLOC(x) \
((start_failing_mallocs && (((double)(rand())/(double)RAND_MAX) < 0.4)) \
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we get the probability of failure out of an environment variable as well? Might be interesting to automatically test with that.

@frederikvs
Copy link
Contributor

Oh, could you attach some example outputs to this PR? Then we could have a quick look, see how easy it is to figure out what's going on :-)

#define PICO_ZALLOC(x) \
((start_failing_mallocs && (((double)(rand())/(double)RAND_MAX) < 0.4)) \
? (log_malloc("mem_test.log", "Malloc FAILED\n"), append_backtrace("mem_test.log"), NULL) \
: (log_malloc("mem_test.log", "Malloc Succeeded\n"), append_backtrace("mem_test.log"), pico_zalloc(x)))
Copy link
Contributor

Choose a reason for hiding this comment

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

An afterthought : it looks like this statement expression is GNU C [0], not entirely standard. In the interest of compiler compatibility, it may be better to just put this into a function...

[0] https://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Statement-Exprs.html

Copy link
Author

Choose a reason for hiding this comment

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

How would you do that? The problem with that is that 'pico_zalloc()' isn't defined yet

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't pico_zalloc() defined in the arch-file that was included a little above this?

Copy link
Author

Choose a reason for hiding this comment

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

Oops you're right. I tried it again. The problem is actually multiple definitions of the function I create since pico_config is compiled into everything. Trying to fix it

Copy link
Contributor

Choose a reason for hiding this comment

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

would inline solve this?

Copy link
Author

Choose a reason for hiding this comment

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

Yup! static inline does. Thanks :)

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.

None yet

3 participants