[compiler-rt] [rtsan] Add ioctl interceptor (PR #117569)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 26 15:03:48 PST 2024


================
@@ -373,6 +375,57 @@ class RtsanOpenedFileTest : public RtsanFileTest {
   int fd = -1;
 };
 
+TEST(TestRtsanInterceptors, IoctlDiesWhenRealtime) {
+  auto Func = []() { ioctl(0, FIONREAD); };
+  ExpectRealtimeDeath(Func, "ioctl");
+  ExpectNonRealtimeSurvival(Func);
+}
+
+TEST_F(RtsanOpenedFileTest, IoctlBehavesWithOutputArg) {
+  int arg{};
+  ioctl(GetOpenFd(), FIONREAD, &arg);
+
+  EXPECT_THAT(arg, Ge(0));
+}
+
+TEST(TestRtsanInterceptors, IoctlBehavesWithOutputPointer) {
+  // These initial checks just see if we CAN run these tests.
+  // If we can't (can't open a socket, or can't find an interface, just
+  // gracefully skip.
+  int sock = socket(AF_INET, SOCK_STREAM, 0);
+  if (sock == -1) {
+    perror("socket");
----------------
davidtrevelyan wrote:

`perror` is new to me, so I may have misunderstood - but are they really needed? If you're not aware already, you can stream to `GTEST_SKIP` like `GTEST_SKIP() << "socket failed to open"`

Also, no code should be executed after `GTEST_SKIP()`, so the `return;`s can, I believe, be stripped out for more clarity

https://github.com/llvm/llvm-project/pull/117569


More information about the llvm-commits mailing list