Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright (C) 2017 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 "SystemPropertiesParser.h"
     18 
     19 #include "frameworks/base/core/proto/android/os/system_properties.pb.h"
     20 
     21 #include <android-base/file.h>
     22 #include <android-base/test_utils.h>
     23 #include <gmock/gmock.h>
     24 #include <google/protobuf/message_lite.h>
     25 #include <gtest/gtest.h>
     26 #include <string.h>
     27 #include <fcntl.h>
     28 
     29 using namespace android::base;
     30 using namespace android::os;
     31 using namespace std;
     32 using ::testing::StrEq;
     33 using ::testing::Test;
     34 using ::testing::internal::CaptureStderr;
     35 using ::testing::internal::CaptureStdout;
     36 using ::testing::internal::GetCapturedStderr;
     37 using ::testing::internal::GetCapturedStdout;
     38 
     39 class SystemPropertiesParserTest : public Test {
     40 public:
     41     virtual void SetUp() override {
     42         ASSERT_TRUE(tf.fd != -1);
     43     }
     44 
     45 protected:
     46     TemporaryFile tf;
     47 
     48     const string kTestPath = GetExecutableDirectory();
     49     const string kTestDataPath = kTestPath + "/testdata/";
     50 };
     51 
     52 TEST_F(SystemPropertiesParserTest, HasSwapInfo) {
     53     const string testFile = kTestDataPath + "system_properties.txt";
     54     SystemPropertiesParser parser;
     55     SystemPropertiesProto expected;
     56 
     57     expected.mutable_aac_drc()->set_cut(123);
     58     expected.mutable_aaudio()->set_hw_burst_min_usec(2000);
     59     expected.mutable_aaudio()->set_mmap_exclusive_policy(2);
     60     expected.mutable_dalvik_vm()->set_appimageformat("lz4");
     61     expected.set_drm_64bit_enabled(false);
     62     expected.mutable_init_svc()->set_adbd(
     63         SystemPropertiesProto_InitSvc_Status_STATUS_RUNNING);
     64     expected.mutable_init_svc()->set_lmkd(
     65         SystemPropertiesProto_InitSvc_Status_STATUS_STOPPED);
     66     expected.set_media_mediadrmservice_enable(true);
     67 
     68     SystemPropertiesProto::Ro* ro = expected.mutable_ro();
     69     ro->mutable_boot()->add_boottime("1BLL:85");
     70     ro->mutable_boot()->add_boottime("1BLE:898");
     71     ro->mutable_boot()->add_boottime("2BLL:0");
     72     ro->mutable_boot()->add_boottime("2BLE:862");
     73     ro->mutable_boot()->add_boottime("SW:6739");
     74     ro->mutable_boot()->add_boottime("KL:340");
     75     ro->mutable_bootimage()->set_build_date_utc(1509394807LL);
     76     ro->mutable_bootimage()->set_build_fingerprint(
     77         "google/marlin/marlin:P/MASTER/jinyithu10301320:eng/dev-keys");
     78     ro->mutable_hardware()->set_value("marlin");
     79     ro->mutable_hardware()->set_power("marlin-profile");
     80     ro->mutable_product()->add_cpu_abilist("arm64-v8a");
     81     ro->mutable_product()->add_cpu_abilist("armeabi-v7a");
     82     ro->mutable_product()->add_cpu_abilist("armeabi");
     83     ro->mutable_product()->mutable_vendor()->set_brand("google");
     84 
     85     int fd = open(testFile.c_str(), O_RDONLY);
     86     ASSERT_TRUE(fd != -1);
     87 
     88     CaptureStdout();
     89     ASSERT_EQ(NO_ERROR, parser.Parse(fd, STDOUT_FILENO));
     90     EXPECT_EQ(GetCapturedStdout(), expected.SerializeAsString());
     91     close(fd);
     92 }
     93