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);
}
編譯+運行有和沒有單元測試將產生不同的結果。你的本地功能可以被調用,而不是真正的功能。