Raul Silvera | 0c3c35e | 2016-09-21 13:14:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, Google Inc. |
| 3 | * All rights reserved. |
Googler | 3a8b0ae | 2017-07-11 18:19:34 -0700 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
Raul Silvera | 0c3c35e | 2016-09-21 13:14:55 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <vector> |
| 9 | |
| 10 | #include "path_matching.h" |
| 11 | #include "string_compat.h" |
| 12 | #include "test_compat.h" |
| 13 | |
| 14 | namespace perftools { |
Raul Silvera | 0c3c35e | 2016-09-21 13:14:55 -0700 | [diff] [blame] | 15 | |
| 16 | TEST(PathMatching, DeletedSharedObjectMatching) { |
| 17 | const std::vector<string> paths = { |
| 18 | "lib.so.v1(deleted)", |
| 19 | "lib.so.v1(deleted)junk", |
| 20 | "lib.so (deleted)", |
| 21 | "lib.so_junk_(deleted)", |
| 22 | "lib.so .so junk_(deleted)", |
| 23 | }; |
| 24 | for (const auto& path : paths) { |
Alexey Alexandrov | e18bc45 | 2016-11-04 14:55:48 -0700 | [diff] [blame] | 25 | ASSERT_TRUE(IsDeletedSharedObject(path)); |
Raul Silvera | 0c3c35e | 2016-09-21 13:14:55 -0700 | [diff] [blame] | 26 | } |
| 27 | } |
| 28 | |
| 29 | TEST(PathMatching, DeletedSharedObjectNotMatching) { |
| 30 | const std::vector<string> paths = { |
| 31 | "abc", |
| 32 | "lib.so ", |
| 33 | "lib.so(deleted)", |
| 34 | ".so (deleted)", |
| 35 | "lib.sojunk(deleted)", |
| 36 | "", |
| 37 | }; |
| 38 | |
| 39 | for (const auto& path : paths) { |
Alexey Alexandrov | e18bc45 | 2016-11-04 14:55:48 -0700 | [diff] [blame] | 40 | ASSERT_FALSE(IsDeletedSharedObject(path)); |
Raul Silvera | 0c3c35e | 2016-09-21 13:14:55 -0700 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
| 44 | TEST(PathMatching, VersionedSharedObjectMatching) { |
| 45 | const std::vector<string> paths = { |
| 46 | "lib.so.", "lib.so.abc", "lib.so.1", "lib.so.v1", |
| 47 | }; |
| 48 | for (const auto& path : paths) { |
Alexey Alexandrov | e18bc45 | 2016-11-04 14:55:48 -0700 | [diff] [blame] | 49 | ASSERT_TRUE(IsVersionedSharedObject(path)); |
Raul Silvera | 0c3c35e | 2016-09-21 13:14:55 -0700 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
| 53 | TEST(PathMatching, VersionedSharedObjectNotMatching) { |
| 54 | const std::vector<string> paths = { |
| 55 | "abc", "lib.so(deleted)", ".so.v1", ".so.", "", |
| 56 | }; |
| 57 | for (const auto& path : paths) { |
Alexey Alexandrov | e18bc45 | 2016-11-04 14:55:48 -0700 | [diff] [blame] | 58 | ASSERT_FALSE(IsDeletedSharedObject(path)); |
Raul Silvera | 0c3c35e | 2016-09-21 13:14:55 -0700 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
Raul Silvera | 0c3c35e | 2016-09-21 13:14:55 -0700 | [diff] [blame] | 62 | } // namespace perftools |
| 63 | |
| 64 | int main(int argc, char** argv) { |
| 65 | ::testing::InitGoogleTest(&argc, argv); |
| 66 | return RUN_ALL_TESTS(); |
| 67 | } |