1*1b191cb5SApple OSS Distributions #include <stdio.h> 2*1b191cb5SApple OSS Distributions #include <fcntl.h> 3*1b191cb5SApple OSS Distributions #include <util.h> 4*1b191cb5SApple OSS Distributions #include <unistd.h> 5*1b191cb5SApple OSS Distributions #include <darwintest.h> 6*1b191cb5SApple OSS Distributions 7*1b191cb5SApple OSS Distributions T_DECL(dev_zero, 8*1b191cb5SApple OSS Distributions "test reading from /dev/zero", 9*1b191cb5SApple OSS Distributions T_META_ASROOT(false)) 10*1b191cb5SApple OSS Distributions { 11*1b191cb5SApple OSS Distributions int dev = opendev("/dev/zero", O_RDONLY, NULL, NULL); 12*1b191cb5SApple OSS Distributions char buffer[100]; 13*1b191cb5SApple OSS Distributions 14*1b191cb5SApple OSS Distributions for (int i = 0; i < 100; i++) { 15*1b191cb5SApple OSS Distributions buffer[i] = 0xff; 16*1b191cb5SApple OSS Distributions } 17*1b191cb5SApple OSS Distributions 18*1b191cb5SApple OSS Distributions int rd_sz = read(dev, buffer, sizeof(buffer)); 19*1b191cb5SApple OSS Distributions 20*1b191cb5SApple OSS Distributions T_EXPECT_EQ(rd_sz, 100, "read from /dev/zero failed"); 21*1b191cb5SApple OSS Distributions 22*1b191cb5SApple OSS Distributions for (int i = 0; i < 100; i++) { 23*1b191cb5SApple OSS Distributions if (buffer[i]) { 24*1b191cb5SApple OSS Distributions T_FAIL("Unexpected non-zero character read from /dev/zero"); 25*1b191cb5SApple OSS Distributions } 26*1b191cb5SApple OSS Distributions } 27*1b191cb5SApple OSS Distributions 28*1b191cb5SApple OSS Distributions close(dev); 29*1b191cb5SApple OSS Distributions } 30