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

Problem when mocking printf #15

Open
GoogleCodeExporter opened this issue Dec 8, 2015 · 0 comments
Open

Problem when mocking printf #15

GoogleCodeExporter opened this issue Dec 8, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?

When testing a function, say "foo", that uses "printf", if I a 
mock "printf" using mock() and check_expected() and write a test 
for "foo", when executing the test, cmockery crashes (segfault). Here is a 
small snippet of code illustrating what I mean:

// foo.c
int foo() {
    return printf("toto");
}

// foo_test.c
int printf(const char *format, ...) {
    check_expected(format);
    return (int)mock();
}

void my_test(void **state) {
    expect_string(printf, format, "toto");
    will_return(printf, 30);
    assert_int_equal(foo(), 30);
}

When executing the test, the program segfaults. Here is the gdb backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x0804928b in list_find ()
(gdb) bt
#0  0x0804928b in list_find ()
#1  0x080495fb in get_symbol_value ()
#2  0x0804a6ff in _check_expected ()
#3  0x08048ce3 in printf ()
#4  0x0804aff0 in vprint_message ()
#5  0x0804b057 in print_message ()
#6  0x0804b106 in _run_test ()
#7  0x0804b3d1 in _run_tests ()
#8  0x08048db3 in main ()


What is the expected output? What do you see instead?

the test should pass (?)

What version of the product are you using? On what operating system?

cmockery 0.1.2 on linux (debian 4.1.1-21) with gcc 4.1.2

I attached the code provoking the buf...

Otherwise cmockery rules! ;-)

Thanks for looking into this!

Original issue reported on code.google.com by Cedric.M...@gmail.com on 15 Oct 2009 at 9:22

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant