• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 <android-base/file.h>
18 #include <gtest/gtest.h>
19 #include <jsonpb/json_schema_test.h>
20 
21 #include "cgroups_test.h"
22 #include "task_profiles_test.h"
23 
24 using ::android::base::GetExecutableDirectory;
25 using namespace ::android::jsonpb;
26 
27 namespace android {
28 namespace profiles {
29 
30 static constexpr const char* kVendorCgroups = "/vendor/etc/cgroups.json";
31 static constexpr const char* kVendorTaskProfiles = "/vendor/etc/task_profiles.json";
32 
33 template <typename T>
34 class TestConfig : public JsonSchemaTestConfig {
35   public:
TestConfig(const std::string & path)36     TestConfig(const std::string& path) : file_path_(path){};
CreateMessage() const37     std::unique_ptr<google::protobuf::Message> CreateMessage() const override {
38         return std::make_unique<T>();
39     }
file_path() const40     std::string file_path() const override { return file_path_; }
optional() const41     bool optional() const override {
42         // Ignore when vendor JSON files are missing.
43         return true;
44     }
45 
46   private:
47     std::string file_path_;
48 };
49 
50 template <typename T>
MakeTestParam(const std::string & path)51 JsonSchemaTestConfigFactory MakeTestParam(const std::string& path) {
52     return [path]() { return std::make_unique<TestConfig<T>>(path); };
53 }
54 
55 INSTANTIATE_TEST_SUITE_P(VendorCgroups, JsonSchemaTest,
56                          ::testing::Values(MakeTestParam<Cgroups>(kVendorCgroups)));
57 INSTANTIATE_TEST_SUITE_P(VendorCgroups, CgroupsTest,
58                          ::testing::Values(MakeTestParam<Cgroups>(kVendorCgroups)));
59 
60 INSTANTIATE_TEST_SUITE_P(VendorTaskProfiles, JsonSchemaTest,
61                          ::testing::Values(MakeTestParam<TaskProfiles>(kVendorTaskProfiles)));
62 INSTANTIATE_TEST_SUITE_P(VendorTaskProfiles, TaskProfilesTest,
63                          ::testing::Values(MakeTestParam<TaskProfiles>(kVendorTaskProfiles)));
64 
65 }  // namespace profiles
66 }  // namespace android
67 
main(int argc,char ** argv)68 int main(int argc, char** argv) {
69     ::testing::InitGoogleTest(&argc, argv);
70     return RUN_ALL_TESTS();
71 }
72