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