Download OpenROAD/src/utl/test/cpp/TestSuppressStdout.cpp from SAIFIINDUSTRIES/verilog_data-1: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/datasets/SAIFIINDUSTRIES/verilog_data-1/resolve/main/OpenROAD/src/utl/test/cpp/TestSuppressStdout.cpp
- Command line
-
hf download hf://datasets/SAIFIINDUSTRIES/verilog_data-1/OpenROAD/src/utl/test/cpp/TestSuppressStdout.cpp
-
curl -L -o TestSuppressStdout.cpp https://huggingface.co/datasets/SAIFIINDUSTRIES/verilog_data-1/resolve/main/OpenROAD/src/utl/test/cpp/TestSuppressStdout.cpp
1.51 kB
| // SPDX-License-Identifier: BSD-3-Clause | |
| // Copyright (c) 2024, The OpenROAD Authors | |
| namespace utl { | |
| TEST(Utl, SuppressStdout) | |
| { | |
| Logger logger; | |
| // 1. Create a temporary directory managed by GTest | |
| auto temp_dir = testing::TempDir(); | |
| std::string file_path = temp_dir + "/my_file.txt"; | |
| // 3. Create the file and get the file descriptor (fd) | |
| int fd = open(file_path.c_str(), O_WRONLY | O_CREAT, 0600); | |
| ASSERT_NE(fd, -1); | |
| int saved_stdout = dup(STDOUT_FILENO); | |
| ASSERT_NE(saved_stdout, -1); | |
| ASSERT_NE(dup2(fd, STDOUT_FILENO), -1); | |
| fprintf(stdout, "Before suppression\n"); | |
| { | |
| SuppressStdout so(&logger); | |
| fprintf(stdout, "During suppression\n"); | |
| } | |
| fprintf(stdout, "After suppression\n"); | |
| fflush(stdout); | |
| close(fd); | |
| dup2(saved_stdout, STDOUT_FILENO); | |
| close(saved_stdout); | |
| std::ifstream log_file(file_path); | |
| std::string line; | |
| bool before_found = false; | |
| bool during_found = false; | |
| bool after_found = false; | |
| while (std::getline(log_file, line)) { | |
| if (line == "Before suppression") { | |
| before_found = true; | |
| } else if (line == "During suppression") { | |
| during_found = true; | |
| } else if (line == "After suppression") { | |
| after_found = true; | |
| } | |
| } | |
| EXPECT_TRUE(before_found); | |
| EXPECT_FALSE(during_found); | |
| EXPECT_TRUE(after_found); | |
| } | |
| } // namespace utl | |