Yifan Hong | fd6640f | 2020-08-27 19:13:17 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2020 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 <gtest/gtest.h> |
| 18 | |
| 19 | #include "update_engine/common/error_code.h" |
| 20 | #include "update_engine/common/test_utils.h" |
| 21 | #include "update_engine/hardware_android.h" |
| 22 | |
| 23 | namespace chromeos_update_engine { |
| 24 | |
| 25 | TEST(HardwareAndroidTest, IsKernelUpdateValid) { |
| 26 | EXPECT_EQ(ErrorCode::kSuccess, |
| 27 | HardwareAndroid::IsKernelUpdateValid("5.4.42-not-gki", "")) |
| 28 | << "Legacy update should be fine"; |
| 29 | |
| 30 | EXPECT_EQ(ErrorCode::kSuccess, |
| 31 | HardwareAndroid::IsKernelUpdateValid("5.4.42-not-gki", |
| 32 | "5.4.42-android12-0")) |
| 33 | << "Update to GKI should be fine"; |
| 34 | |
| 35 | EXPECT_EQ( |
| 36 | ErrorCode::kDownloadManifestParseError, |
| 37 | HardwareAndroid::IsKernelUpdateValid("5.4.42-not-gki", "5.4.42-not-gki")) |
| 38 | << "Should report parse error for invalid version field"; |
| 39 | |
| 40 | EXPECT_EQ(ErrorCode::kSuccess, |
| 41 | HardwareAndroid::IsKernelUpdateValid( |
| 42 | "5.4.42-android12-0-something", "5.4.42-android12-0-something")) |
| 43 | << "Self update should be fine"; |
| 44 | |
| 45 | EXPECT_EQ(ErrorCode::kSuccess, |
| 46 | HardwareAndroid::IsKernelUpdateValid( |
| 47 | "5.4.42-android12-0-something", "5.4.43-android12-0-something")) |
| 48 | << "Sub-level update should be fine"; |
| 49 | |
| 50 | EXPECT_EQ( |
| 51 | ErrorCode::kSuccess, |
| 52 | HardwareAndroid::IsKernelUpdateValid("5.4.42-android12-0-something", |
| 53 | "5.10.10-android12-0-something")) |
| 54 | << "KMI version update should be fine"; |
| 55 | |
| 56 | EXPECT_EQ(ErrorCode::kPayloadTimestampError, |
| 57 | HardwareAndroid::IsKernelUpdateValid("5.4.42-android12-0-something", |
| 58 | "5.4.5-android12-0-something")) |
| 59 | << "Should detect sub-level downgrade"; |
| 60 | |
| 61 | EXPECT_EQ(ErrorCode::kPayloadTimestampError, |
| 62 | HardwareAndroid::IsKernelUpdateValid("5.4.42-android12-0-something", |
| 63 | "5.1.5-android12-0-something")) |
| 64 | << "Should detect KMI version downgrade"; |
| 65 | } |
| 66 | |
| 67 | } // namespace chromeos_update_engine |