test_vendor.cpp 2.4 KB

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