|
46 | 46 | #include <sys/ioctl.h>
|
47 | 47 | #include <sys/mman.h>
|
48 | 48 | #include <sys/socket.h>
|
| 49 | +#include <sys/stat.h> |
49 | 50 | #include <sys/types.h>
|
50 | 51 | #include <sys/uio.h>
|
51 | 52 |
|
@@ -442,6 +443,60 @@ TEST_F(RtsanOpenedFileTest, Dup2DiesWhenRealtime) {
|
442 | 443 | ExpectNonRealtimeSurvival(Func);
|
443 | 444 | }
|
444 | 445 |
|
| 446 | +TEST_F(RtsanFileTest, ChmodDiesWhenRealtime) { |
| 447 | + auto Func = [this]() { chmod(GetTemporaryFilePath(), 0777); }; |
| 448 | + ExpectRealtimeDeath(Func, "chmod"); |
| 449 | + ExpectNonRealtimeSurvival(Func); |
| 450 | +} |
| 451 | + |
| 452 | +TEST_F(RtsanOpenedFileTest, FchmodDiesWhenRealtime) { |
| 453 | + auto Func = [this]() { fchmod(GetOpenFd(), 0777); }; |
| 454 | + ExpectRealtimeDeath(Func, "fchmod"); |
| 455 | + ExpectNonRealtimeSurvival(Func); |
| 456 | +} |
| 457 | + |
| 458 | +TEST(TestRtsanInterceptors, UmaskDiesWhenRealtime) { |
| 459 | + auto Func = []() { umask(0); }; |
| 460 | + ExpectRealtimeDeath(Func, "umask"); |
| 461 | + ExpectNonRealtimeSurvival(Func); |
| 462 | +} |
| 463 | + |
| 464 | +class RtsanDirectoryTest : public ::testing::Test { |
| 465 | +protected: |
| 466 | + void SetUp() override { |
| 467 | + const ::testing::TestInfo *const test_info = |
| 468 | + ::testing::UnitTest::GetInstance()->current_test_info(); |
| 469 | + directory_path_ = std::string("/tmp/rtsan_temp_dir_") + test_info->name(); |
| 470 | + RemoveTemporaryDirectory(); |
| 471 | + } |
| 472 | + |
| 473 | + const char *GetTemporaryDirectoryPath() const { |
| 474 | + return directory_path_.c_str(); |
| 475 | + } |
| 476 | + |
| 477 | + void TearDown() override { RemoveTemporaryDirectory(); } |
| 478 | + |
| 479 | +private: |
| 480 | + void RemoveTemporaryDirectory() const { |
| 481 | + std::remove(GetTemporaryDirectoryPath()); |
| 482 | + } |
| 483 | + std::string directory_path_; |
| 484 | +}; |
| 485 | + |
| 486 | +TEST_F(RtsanDirectoryTest, MkdirDiesWhenRealtime) { |
| 487 | + auto Func = [this]() { mkdir(GetTemporaryDirectoryPath(), 0777); }; |
| 488 | + ExpectRealtimeDeath(Func, "mkdir"); |
| 489 | + ExpectNonRealtimeSurvival(Func); |
| 490 | +} |
| 491 | + |
| 492 | +TEST_F(RtsanDirectoryTest, RmdirDiesWhenRealtime) { |
| 493 | + // We don't actually create this directory before we try to remove it |
| 494 | + // Thats OK - we are just making sure the call gets intercepted |
| 495 | + auto Func = [this]() { rmdir(GetTemporaryDirectoryPath()); }; |
| 496 | + ExpectRealtimeDeath(Func, "rmdir"); |
| 497 | + ExpectNonRealtimeSurvival(Func); |
| 498 | +} |
| 499 | + |
445 | 500 | TEST_F(RtsanOpenedFileTest, FreadDiesWhenRealtime) {
|
446 | 501 | auto Func = [this]() {
|
447 | 502 | char c{};
|
|
0 commit comments