Austin Schuh | c243b42 | 2020-10-11 15:35:08 -0700 | [diff] [blame] | 1 | #include "aos/testing/tmpdir.h" |
| 2 | |
| 3 | #include <cstdlib> |
| 4 | #include <string> |
| 5 | |
Adam Snaider | c8b7e75 | 2023-09-14 14:27:53 -0700 | [diff] [blame] | 6 | #include "aos/ipc_lib/shm_base.h" |
| 7 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 8 | namespace aos::testing { |
Austin Schuh | c243b42 | 2020-10-11 15:35:08 -0700 | [diff] [blame] | 9 | |
Adam Snaider | c8b7e75 | 2023-09-14 14:27:53 -0700 | [diff] [blame] | 10 | namespace { |
| 11 | std::string TestTmpDirOr(std::string fallback) { |
Austin Schuh | c243b42 | 2020-10-11 15:35:08 -0700 | [diff] [blame] | 12 | const char *tmp_dir = std::getenv("TEST_TMPDIR"); |
| 13 | if (tmp_dir != nullptr) { |
| 14 | return tmp_dir; |
| 15 | } |
Adam Snaider | c8b7e75 | 2023-09-14 14:27:53 -0700 | [diff] [blame] | 16 | return fallback; |
Austin Schuh | c243b42 | 2020-10-11 15:35:08 -0700 | [diff] [blame] | 17 | } |
Adam Snaider | c8b7e75 | 2023-09-14 14:27:53 -0700 | [diff] [blame] | 18 | } // namespace |
| 19 | |
| 20 | std::string TestTmpDir() { return TestTmpDirOr("/tmp"); } |
| 21 | |
| 22 | void SetTestShmBase() { SetShmBase(TestTmpDirOr(FLAGS_shm_base)); } |
Austin Schuh | c243b42 | 2020-10-11 15:35:08 -0700 | [diff] [blame] | 23 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 24 | } // namespace aos::testing |