| 1 | #include "common/util.h" |
| 2 | #include <cstdlib> |
| 3 | #include <string> |
| 4 | #include <gtest/gtest.h> |
| 5 | #include <boost/optional/optional_io.hpp> /* required to output boost::optional in assertions */ |
| 6 | |
| 7 | #ifndef GTEST_SKIP |
| 8 | #include <iostream> |
| 9 | #define SKIP_TEST(reason) do {std::cerr << "Skipping test: " << reason << std::endl; return;} while(0) |
| 10 | #else |
| 11 | #define SKIP_TEST(reason) GTEST_SKIP() << reason |
| 12 | #endif |
| 13 | |
| 14 | #if defined(__GLIBC__) |
| 15 | TEST(is_hdd, rotational_drive) { |
| 16 | const char *hdd = std::getenv("MONERO_TEST_DEVICE_HDD"); |
| 17 | if (hdd == nullptr) |
| 18 | SKIP_TEST("No rotational disk device configured"); |
| 19 | EXPECT_EQ(tools::is_hdd(hdd), boost::optional<bool>(true)); |
| 20 | } |
| 21 | |
| 22 | TEST(is_hdd, ssd) { |
| 23 | const char *ssd = std::getenv("MONERO_TEST_DEVICE_SSD"); |
| 24 | if (ssd == nullptr) |
| 25 | SKIP_TEST("No SSD device configured"); |
| 26 | EXPECT_EQ(tools::is_hdd(ssd), boost::optional<bool>(false)); |
| 27 | } |
| 28 | |
| 29 | TEST(is_hdd, unknown_attrs) { |
| 30 | EXPECT_EQ(tools::is_hdd("/dev/null"), boost::none); |
| 31 | } |
| 32 | #endif |
| 33 | TEST(is_hdd, stability) |
| 34 | { |
| 35 | EXPECT_NO_THROW(tools::is_hdd("")); |
| 36 | } |