1 /* 2 * Copyright (C) 2022 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 "test/gtest_and_gmock.h" 18 19 #include "perfetto/tracing.h" 20 21 namespace { 22 23 class PerfettoApiEnvironment : public ::testing::Environment { 24 public: TearDown()25 void TearDown() override { 26 // Test shutting down Perfetto only when all other tests have been run and 27 // no more tracing code will be executed. 28 PERFETTO_CHECK(!perfetto::Tracing::IsInitialized()); 29 perfetto::TracingInitArgs args; 30 args.backends = perfetto::kInProcessBackend; 31 perfetto::Tracing::Initialize(args); 32 perfetto::Tracing::Shutdown(); 33 PERFETTO_CHECK(!perfetto::Tracing::IsInitialized()); 34 // Shutting down again is a no-op. 35 perfetto::Tracing::Shutdown(); 36 PERFETTO_CHECK(!perfetto::Tracing::IsInitialized()); 37 } 38 }; 39 40 } // namespace 41 main(int argc,char ** argv)42int main(int argc, char** argv) { 43 ::testing::AddGlobalTestEnvironment(new PerfettoApiEnvironment); 44 ::testing::InitGoogleTest(&argc, argv); 45 return RUN_ALL_TESTS(); 46 } 47