Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f87b0c7e authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Trace test viewer config in PerfettoProtoLogImplTest

This is to make sure we still dump the test viewer config when we flip the client side protologging flag which uses the ProtoLogConfigurationService.

Test: atest InternalTests:com.android.internal.protolog.PerfettoProtoLogImplTest
Flag: TEST_ONLY
Bug: 364255103
Change-Id: Ib0ae629e2b8728162a9fe638ec131b509797d68a
parent 1e7e29a1
Loading
Loading
Loading
Loading
+21 −13
Original line number Diff line number Diff line
@@ -45,13 +45,13 @@ import android.util.proto.ProtoInputStream;

import androidx.test.platform.app.InstrumentationRegistry;

import com.android.internal.protolog.ProtoLogConfigurationService.ViewerConfigFileTracer;
import com.android.internal.protolog.common.IProtoLogGroup;
import com.android.internal.protolog.common.LogDataType;
import com.android.internal.protolog.common.LogLevel;

import com.google.common.truth.Truth;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -76,6 +76,7 @@ import java.util.concurrent.atomic.AtomicInteger;
@RunWith(JUnit4.class)
public class PerfettoProtoLogImplTest {
    private static final String TEST_PROTOLOG_DATASOURCE_NAME = "test.android.protolog";
    private static final String MOCK_VIEWER_CONFIG_FILE = "my/mock/viewer/config/file.pb";
    private final File mTracingDirectory = InstrumentationRegistry.getInstrumentation()
            .getTargetContext().getFilesDir();

@@ -168,19 +169,26 @@ public class PerfettoProtoLogImplTest {
        final ProtoLogDataSourceBuilder dataSourceBuilder =
                (onStart, onFlush, onStop) -> new ProtoLogDataSource(
                        onStart, onFlush, onStop, TEST_PROTOLOG_DATASOURCE_NAME);
        mProtoLogConfigurationService =
                new ProtoLogConfigurationService(dataSourceBuilder);
        final ViewerConfigFileTracer tracer = (dataSource, viewerConfigFilePath) -> {
            Utils.dumpViewerConfig(dataSource, () -> {
                if (!viewerConfigFilePath.equals(MOCK_VIEWER_CONFIG_FILE)) {
                    throw new RuntimeException(
                            "Unexpected viewer config file path provided");
                }
                return new ProtoInputStream(mViewerConfigBuilder.build().toByteArray());
            });
        };
        mProtoLogConfigurationService = new ProtoLogConfigurationService(dataSourceBuilder, tracer);

        if (android.tracing.Flags.clientSideProtoLogging()) {
            mProtoLog = new PerfettoProtoLogImpl(
                    MOCK_VIEWER_CONFIG_FILE, mReader, () -> mCacheUpdater.run(),
                    TestProtoLogGroup.values(), dataSourceBuilder, mProtoLogConfigurationService);
        } else {
            mProtoLog = new PerfettoProtoLogImpl(
                    viewerConfigInputStreamProvider, mReader, () -> mCacheUpdater.run(),
                    TestProtoLogGroup.values(), dataSourceBuilder, mProtoLogConfigurationService);
        }

    @After
    public void tearDown() {
        if (mFile != null) {
            //noinspection ResultOfMethodCallIgnored
            mFile.delete();
        }
        ProtoLogImpl.setSingleInstance(null);
    }