1
我想写一个D类包装I2C device driver (/dev interface -> I2C device files/character device files)。为了在执行过程中打破HW的依赖关系,我想模拟ioctl()。我怎样才能最轻松地做到这一点?如何在D中模拟ioctl?
我想写一个D类包装I2C device driver (/dev interface -> I2C device files/character device files)。为了在执行过程中打破HW的依赖关系,我想模拟ioctl()。我怎样才能最轻松地做到这一点?如何在D中模拟ioctl?
writeln("hey ioctl, your mother is a hamster and your father smells of elderberries!");
我只是在开玩笑。
我会做的是prolly写一个假的ioctl函数,看起来相同,并使用进口和版本,以诱骗:
import core.sys.posix.sys.ioctl;
version(unittest)
int ioctl(int d, int request, ...) {
import std.stdio;
writeln("its a fake!");
return 0;
}
void main() {
ioctl(0, 0);
}
编译+运行有和没有单元测试将产生不同的结果。你的本地功能可以被调用,而不是真正的功能。