Linux device driver 如何在D中模拟ioctl?

Linux device driver 如何在D中模拟ioctl?,linux-device-driver,embedded-linux,d,i2c,Linux Device Driver,Embedded Linux,D,I2c,我想写一个D类,它封装了a。为了在实现过程中打破对硬件的依赖,我想模拟一下。我怎样才能最容易地做到这一点 writeln("hey ioctl, your mother is a hamster and your father smells of elderberries!"); 不,我只是开玩笑 我要做的是编写一个外观相同的假ioctl函数,并使用导入和版本来欺骗它: import core.sys.posix.sys.ioctl; version(unittest) int ioctl(

我想写一个D类,它封装了a。为了在实现过程中打破对硬件的依赖,我想模拟一下。我怎样才能最容易地做到这一点

writeln("hey ioctl, your mother is a hamster and your father smells of elderberries!");
不,我只是开玩笑

我要做的是编写一个外观相同的假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);
}
编译+运行有单元测试和没有单元测试将产生不同的结果。可以调用本地函数而不是实际函数

不,我只是开玩笑

我要做的是编写一个外观相同的假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);
}
编译+运行有单元测试和没有单元测试将产生不同的结果。可以调用本地函数而不是实际函数