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