• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 package com.google.perfetto.sdk.test;
18 
19 import static org.junit.Assert.assertNotNull;
20 
21 import android.util.Log;
22 import android.content.Context;
23 import androidx.test.platform.app.InstrumentationRegistry;
24 import androidx.test.runner.AndroidJUnit4;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 
28 import org.junit.Assert;
29 import java.io.File;
30 
31 import com.google.perfetto.sdk.PerfettoExampleWrapper;
32 
33 @RunWith(AndroidJUnit4.class)
34 public class SimpleInstrumentationTest {
35 
36     private static final String TAG = SimpleInstrumentationTest.class.getSimpleName();
37 
38     @Test
testDoRunPerfettoMain()39     public void testDoRunPerfettoMain() {
40         Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
41         File perfettoOutput = new File(appContext.getFilesDir(), "from_java_example.pftrace");
42         String perfettoOutputPath = perfettoOutput.getAbsolutePath();
43         Log.i(TAG, "perfettoOutputPath: " + perfettoOutputPath);
44 
45         int perfettoResult = PerfettoExampleWrapper.doRunPerfettoMain(perfettoOutputPath);
46         Assert.assertEquals(0, perfettoResult);
47         Assert.assertTrue(perfettoOutput.exists());
48         Assert.assertTrue(perfettoOutput.length() > 0);
49 
50         int criticalValuePlusOne = PerfettoExampleWrapper.incrementIntCritical(10);
51         Log.i(TAG, "criticalValuePlusOne: " + criticalValuePlusOne);
52         Assert.assertEquals(11, criticalValuePlusOne);
53     }
54 }