1 // Copyright 2021 The ANGLE Project Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 // 5 // TestStatusReporter: 6 // Broadcasts test status to any listening {@link org.chromium.test.reporter.TestStatusReceiver}. 7 8 package com.android.angle.test; 9 10 import android.content.Context; 11 import android.content.Intent; 12 import android.util.Log; 13 14 import org.chromium.build.gtest_apk.TestStatusIntent; 15 16 public class TestStatusReporter 17 { 18 private final Context mContext; 19 TestStatusReporter(Context c)20 public TestStatusReporter(Context c) 21 { 22 mContext = c; 23 } 24 testRunStarted(int pid)25 public void testRunStarted(int pid) 26 { 27 sendTestRunBroadcast(TestStatusIntent.ACTION_TEST_RUN_STARTED, pid); 28 } 29 testRunFinished(int pid)30 public void testRunFinished(int pid) 31 { 32 sendTestRunBroadcast(TestStatusIntent.ACTION_TEST_RUN_FINISHED, pid); 33 } 34 sendTestRunBroadcast(String action, int pid)35 private void sendTestRunBroadcast(String action, int pid) 36 { 37 Intent i = new Intent(action); 38 i.setType(TestStatusIntent.DATA_TYPE_RESULT); 39 i.putExtra(TestStatusIntent.EXTRA_PID, pid); 40 mContext.sendBroadcast(i); 41 } 42 uncaughtException(int pid, Throwable ex)43 public void uncaughtException(int pid, Throwable ex) 44 { 45 Intent i = new Intent(TestStatusIntent.ACTION_UNCAUGHT_EXCEPTION); 46 i.setType(TestStatusIntent.DATA_TYPE_RESULT); 47 i.putExtra(TestStatusIntent.EXTRA_PID, pid); 48 i.putExtra(TestStatusIntent.EXTRA_STACK_TRACE, Log.getStackTraceString(ex)); 49 mContext.sendBroadcast(i); 50 } 51 } 52