blob: 8061f3be19150535f84fa6bf06e64a51ca3c7eb3 [file] [log] [blame]
Tianjie Xu2b1a4642018-09-06 11:58:55 -07001/*
2 * Copyright (C) 2018 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 <map>
18#include <string>
19#include <vector>
20
21#include <android-base/file.h>
22#include <android-base/strings.h>
23#include <android-base/test_utils.h>
24#include <gtest/gtest.h>
25
26#include "otautil/parse_install_logs.h"
27
28TEST(ParseInstallLogsTest, EmptyFile) {
29 TemporaryFile last_install;
30
31 auto metrics = ParseLastInstall(last_install.path);
32 ASSERT_TRUE(metrics.empty());
33}
34
35TEST(ParseInstallLogsTest, SideloadSmoke) {
36 TemporaryFile last_install;
37 ASSERT_TRUE(android::base::WriteStringToFile("/cache/recovery/ota.zip\n0\n", last_install.path));
38 auto metrics = ParseLastInstall(last_install.path);
39 ASSERT_EQ(metrics.end(), metrics.find("ota_sideload"));
40
41 ASSERT_TRUE(android::base::WriteStringToFile("/sideload/package.zip\n0\n", last_install.path));
42 metrics = ParseLastInstall(last_install.path);
43 ASSERT_NE(metrics.end(), metrics.find("ota_sideload"));
44}
45
46TEST(ParseInstallLogsTest, ParseRecoveryUpdateMetrics) {
47 std::vector<std::string> lines = {
48 "/sideload/package.zip",
49 "0",
50 "time_total: 300",
51 "uncrypt_time: 40",
52 "source_build: 4973410",
53 "bytes_written_system: " + std::to_string(1200 * 1024 * 1024),
54 "bytes_stashed_system: " + std::to_string(300 * 1024 * 1024),
55 "bytes_written_vendor: " + std::to_string(40 * 1024 * 1024),
56 "bytes_stashed_vendor: " + std::to_string(50 * 1024 * 1024),
57 "temperature_start: 37000",
58 "temperature_end: 38000",
59 "temperature_max: 39000",
60 "error: 22",
61 "cause: 55",
62 };
63
64 auto metrics = ParseRecoveryUpdateMetrics(lines);
65
66 std::map<std::string, int64_t> expected_result = {
67 { "ota_time_total", 300 }, { "ota_uncrypt_time", 40 },
68 { "ota_source_version", 4973410 }, { "ota_written_in_MiBs", 1240 },
69 { "ota_stashed_in_MiBs", 350 }, { "ota_temperature_start", 37000 },
70 { "ota_temperature_end", 38000 }, { "ota_temperature_max", 39000 },
71 { "ota_non_ab_error_code", 22 }, { "ota_non_ab_cause_code", 55 },
72 };
73
74 ASSERT_EQ(expected_result, metrics);
75}