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

mmk_reset fails when passing a mocked function #7

Open
damienflament opened this issue Jan 23, 2019 · 0 comments
Open

mmk_reset fails when passing a mocked function #7

damienflament opened this issue Jan 23, 2019 · 0 comments

Comments

@damienflament
Copy link

Environment

CPU architecture: x86_64
Operating system: GNU/Linux
Mimick version: 0.3.0

CMake configuration

cmake_minimum_required(VERSION 3.13)

project(vostrod
        DESCRIPTION "Mimick sample"
        LANGUAGES C)

find_package(PkgConfig REQUIRED)

pkg_check_modules(MIMICK REQUIRED mimick)
include_directories(${MIMICK_INCLUDE_DIRS})
link_libraries(${MIMICK_LIBRARIES})

add_executable(mimick_sample mimick_sample.c)

Issue

Running the first README sample:

#include <stdlib.h>
#include <assert.h>
#include <mimick.h>

mmk_mock_define (malloc_mock, void *, size_t);

int main(void) {
    mmk_mock("malloc@self", malloc_mock);

    void *result = NULL;
    mmk_when(malloc(mmk_any(size_t)),
            .then_return = &result,
            .then_errno = ENOMEM);

    assert(malloc(42) == result && errno == ENOMEM);

    mmk_reset(malloc);
}

results in the following error:

> ./mimick_sample
mimick: Could not find GOT entry for function malloc@self.
zsh: abort (core dumped)  ./mimick_sample

Removing the call to mmk_reset prevents the error.
Running the second README example (e.i. calling mmk_reset passing the mock object returned by mmk_mock) succeeds.

ziyao233 pushed a commit to ziyao233/Mimick that referenced this issue Feb 9, 2024
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

No branches or pull requests

1 participant