blob: 0cf34bd0f4a687e4a2c9e02cbee1dcd76dedcf7e [file] [log] [blame]
Jiakai Zhang39f6d002022-02-10 18:20:50 +00001/*
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
22namespace art {
23namespace odrefresh {
24
Jiakai Zhang38fd2542022-03-07 15:58:59 +000025namespace {
26
27using ::android::base::Result;
28
29}
30
31TEST(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
40TEST(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 Zhang39f6d002022-02-10 18:20:50 +000050TEST(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 Zhangccc70db2023-09-20 16:01:03 +010058TEST(OdrCommonTest, CheckBuildUserfaultFdGc) {
59 EXPECT_TRUE(CheckBuildUserfaultFdGc(
Roland Levillaind4b899e2024-01-17 16:23:59 +000060 /*build_enable_uffd_gc=*/false, /*is_at_most_u=*/false, /*kernel_supports_uffd=*/false));
Jiakai Zhangccc70db2023-09-20 16:01:03 +010061 EXPECT_FALSE(CheckBuildUserfaultFdGc(
Roland Levillaind4b899e2024-01-17 16:23:59 +000062 /*build_enable_uffd_gc=*/true, /*is_at_most_u=*/false, /*kernel_supports_uffd=*/false));
Martin Stjernholma9102c12023-10-24 19:23:24 +010063 EXPECT_TRUE(CheckBuildUserfaultFdGc(
Roland Levillaind4b899e2024-01-17 16:23:59 +000064 /*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 Zhangccc70db2023-09-20 16:01:03 +010075}
76
Jiakai Zhang39f6d002022-02-10 18:20:50 +000077} // namespace odrefresh
78} // namespace art