Jiakai Zhang | 39f6d00 | 2022-02-10 18:20:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "odr_common.h" |
| 18 | |
| 19 | #include "gmock/gmock.h" |
| 20 | #include "gtest/gtest.h" |
| 21 | |
| 22 | namespace art { |
| 23 | namespace odrefresh { |
| 24 | |
Jiakai Zhang | 38fd254 | 2022-03-07 15:58:59 +0000 | [diff] [blame] | 25 | namespace { |
| 26 | |
| 27 | using ::android::base::Result; |
| 28 | |
| 29 | } |
| 30 | |
| 31 | TEST(OdrCommonTest, ParseSecurityPatchStr) { |
| 32 | Result<int> result = ParseSecurityPatchStr("2022-03-08"); |
| 33 | EXPECT_TRUE(result.ok()); |
| 34 | EXPECT_EQ(result.value(), 20220308); |
| 35 | EXPECT_FALSE(ParseSecurityPatchStr("").ok()); |
| 36 | EXPECT_FALSE(ParseSecurityPatchStr("20-2203-08").ok()); |
| 37 | EXPECT_FALSE(ParseSecurityPatchStr("20220308").ok()); |
| 38 | } |
| 39 | |
| 40 | TEST(OdrCommonTest, ShouldDisablePartialCompilation) { |
| 41 | EXPECT_TRUE(ShouldDisablePartialCompilation("2021-03-05")); |
| 42 | EXPECT_TRUE(ShouldDisablePartialCompilation("2022-02-05")); |
| 43 | EXPECT_TRUE(ShouldDisablePartialCompilation("2022-03-04")); |
| 44 | EXPECT_FALSE(ShouldDisablePartialCompilation("2022-03-05")); |
| 45 | EXPECT_FALSE(ShouldDisablePartialCompilation("2022-03-06")); |
| 46 | EXPECT_FALSE(ShouldDisablePartialCompilation("2022-04-04")); |
| 47 | EXPECT_FALSE(ShouldDisablePartialCompilation("2023-03-04")); |
| 48 | } |
| 49 | |
Jiakai Zhang | 39f6d00 | 2022-02-10 18:20:50 +0000 | [diff] [blame] | 50 | TEST(OdrCommonTest, ShouldDisableRefresh) { |
| 51 | EXPECT_TRUE(ShouldDisableRefresh("32")); |
| 52 | EXPECT_TRUE(ShouldDisableRefresh("33")); |
| 53 | EXPECT_FALSE(ShouldDisableRefresh("31")); |
| 54 | EXPECT_FALSE(ShouldDisableRefresh("")); |
| 55 | EXPECT_FALSE(ShouldDisableRefresh("invalid")); |
| 56 | } |
| 57 | |
Jiakai Zhang | ccc70db | 2023-09-20 16:01:03 +0100 | [diff] [blame] | 58 | TEST(OdrCommonTest, CheckBuildUserfaultFdGc) { |
| 59 | EXPECT_TRUE(CheckBuildUserfaultFdGc( |
Roland Levillain | d4b899e | 2024-01-17 16:23:59 +0000 | [diff] [blame] | 60 | /*build_enable_uffd_gc=*/false, /*is_at_most_u=*/false, /*kernel_supports_uffd=*/false)); |
Jiakai Zhang | ccc70db | 2023-09-20 16:01:03 +0100 | [diff] [blame] | 61 | EXPECT_FALSE(CheckBuildUserfaultFdGc( |
Roland Levillain | d4b899e | 2024-01-17 16:23:59 +0000 | [diff] [blame] | 62 | /*build_enable_uffd_gc=*/true, /*is_at_most_u=*/false, /*kernel_supports_uffd=*/false)); |
Martin Stjernholm | a9102c1 | 2023-10-24 19:23:24 +0100 | [diff] [blame] | 63 | EXPECT_TRUE(CheckBuildUserfaultFdGc( |
Roland Levillain | d4b899e | 2024-01-17 16:23:59 +0000 | [diff] [blame] | 64 | /*build_enable_uffd_gc=*/false, /*is_at_most_u=*/true, /*kernel_supports_uffd=*/false)); |
| 65 | EXPECT_FALSE(CheckBuildUserfaultFdGc( |
| 66 | /*build_enable_uffd_gc=*/true, /*is_at_most_u=*/true, /*kernel_supports_uffd=*/false)); |
| 67 | EXPECT_TRUE(CheckBuildUserfaultFdGc( |
| 68 | /*build_enable_uffd_gc=*/false, /*is_at_most_u=*/false, /*kernel_supports_uffd=*/true)); |
| 69 | EXPECT_TRUE(CheckBuildUserfaultFdGc( |
| 70 | /*build_enable_uffd_gc=*/true, /*is_at_most_u=*/false, /*kernel_supports_uffd=*/true)); |
| 71 | EXPECT_FALSE(CheckBuildUserfaultFdGc( |
| 72 | /*build_enable_uffd_gc=*/false, /*is_at_most_u=*/true, /*kernel_supports_uffd=*/true)); |
| 73 | EXPECT_TRUE(CheckBuildUserfaultFdGc( |
| 74 | /*build_enable_uffd_gc=*/true, /*is_at_most_u=*/true, /*kernel_supports_uffd=*/true)); |
Jiakai Zhang | ccc70db | 2023-09-20 16:01:03 +0100 | [diff] [blame] | 75 | } |
| 76 | |
Jiakai Zhang | 39f6d00 | 2022-02-10 18:20:50 +0000 | [diff] [blame] | 77 | } // namespace odrefresh |
| 78 | } // namespace art |