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

是否支持 stub 命名空间函数? #41

Open
yiyiarrow opened this issue Jul 27, 2024 · 6 comments
Open

是否支持 stub 命名空间函数? #41

yiyiarrow opened this issue Jul 27, 2024 · 6 comments

Comments

@yiyiarrow
Copy link

example:
namespace A {
namespace B {
namespace C {
int func(int a, std::string b)
{
xxxx;
return 0;
}
}
}
}

int stub_func(int a, std::string b)
{
return 1;
}

我试了以下几种方式都不行:
Stub stub;
stub.set(func, stub_func);
stub.set(A::B::C::func, stub_func);
stub.set(ADDR(A::B::C, func), stub_func);

@coolxv
Copy link
Owner

coolxv commented Jul 27, 2024

stub.set(&A::B::C::func, stub_func);

@yiyiarrow
Copy link
Author

yiyiarrow commented Jul 27, 2024

stub.set(&A::B::C::func, stub_func);

这样 stub,我单独写的 demo 代码可以的。但是在我的工程里就不行,比较奇怪。

@coolxv
Copy link
Owner

coolxv commented Jul 28, 2024

你工程里的函数是不是特殊函数,例如虚函数

@yiyiarrow
Copy link
Author

你工程里的函数是不是特殊函数,例如虚函数

不是虚函数。就是开源代码库 ceph 的 src/cls/clock/cls_lock_client.cc 里面的 get_lock_info 函数。不知道是不是 ceph 工程的问题,使用 cpp_free_mock 也没办法 mock 这个命名空间函数。(但是其它源文件的类成员函数是可以 mock 的)。
我在工程里面的测试文件简单写了一个全局函数测试,发现也 stub 不了。

@coolxv
Copy link
Owner

coolxv commented Jul 29, 2024

nm ceph | c++filter | grep get_lock_info

@yiyiarrow
Copy link
Author

nm ceph | c++filter | grep get_lock_info

编译是没问题的。能调用到 get_lock_info,但是没进 stub_get_lock_info

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

2 participants