| 38 | namespace tests { |
| 39 | |
| 40 | TEST(Ldd, BinSh) |
| 41 | { |
| 42 | Try<vector<ldcache::Entry>> cache = ldcache::parse(); |
| 43 | ASSERT_SOME(cache); |
| 44 | |
| 45 | Try<hashset<string>> dependencies = ldd("/bin/sh", cache.get()); |
| 46 | ASSERT_SOME(dependencies); |
| 47 | |
| 48 | EXPECT_FALSE(dependencies->contains("/bin/sh")); |
| 49 | |
| 50 | auto libc = std::find_if( |
| 51 | dependencies->begin(), |
| 52 | dependencies->end(), |
| 53 | [](const string& dependency) { |
| 54 | // On most Linux systems, libc would be in libc.so.6, but |
| 55 | // checking the unversioned prefix is robust and is enough |
| 56 | // to know that ldd() worked. |
| 57 | string basename = Path(dependency).basename(); |
| 58 | return strings::startsWith(basename, "libc.so"); |
| 59 | }); |
| 60 | |
| 61 | EXPECT_TRUE(libc != dependencies->end()); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | TEST(Ldd, EmptyCache) |