Java Code Examples for com.android.tradefed.config.ConfigurationDef

Following code examples demonstrate how to use com.android.tradefed.config.ConfigurationDeffrom android. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use com.android.tradefed.config.ConfigurationDefand various code implementation of this class.

    public void setUp() {
        mController = new NativeBridgeModuleController();
        mMockDevice = EasyMock.createMock(ITestDevice.class);
        mContext = new InvocationContext();
        mContext.addAllocatedDevice(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockDevice);
        mContext.addInvocationAttribute(ModuleDefinition.MODULE_ABI, "arm64-v8a");
        mContext.addInvocationAttribute(ModuleDefinition.MODULE_NAME, "module1");
        mMockIDevice = EasyMock.createMock(IDevice.class);
    } 


    public void testGetConfigurationDef() throws Exception {
        ConfigurationDef def =
                mGCSConfigurationFactory.getConfigurationDef("common.xml", true, null);
        Assert.assertNotNull(def);
    } 

    public void testGetConfigurationDef_include() throws Exception {
        ConfigurationDef def =
                mGCSConfigurationFactory.getConfigurationDef(
                        "cluster/avd-host-config.xml", true, null);
        Assert.assertNotNull(def);
    } 

    public void testReloadTests() throws Exception {
        EasyMock.expect(mMockProvider.getBuild()).andReturn(createFakeBuild(createBasicResults()));
        mContext.addAllocatedDevice(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockDevice);

        EasyMock.replay(mMockDevice, mMockProvider);
        mLoader.init();
        assertEquals("cts -m CtsGesture --skip-all-system-status-check", mLoader.getCommandLine());
        mLoader.loadPreviousRecord();
        IConfiguration config = new Configuration("name", "desc");
        assertEquals(0, config.getTargetPreparers().size());
        mLoader.customizeConfiguration(config);
        assertEquals(1, config.getTargetPreparers().size());
        ITargetPreparer preparer = config.getTargetPreparers().get(0);
        assertTrue(preparer instanceof BuildFingerPrintPreparer);
        assertEquals("testfingerprint",
                ((BuildFingerPrintPreparer) preparer).getExpectedFingerprint());
        EasyMock.verify(mMockDevice, mMockProvider);
    } 

                    protected IGlobalConfiguration getGlobalConfiguration() {
                        try {
                            return ConfigurationFactory.getInstance()
                                    .createGlobalConfigurationFromArgs(
                                            new String[] {"empty"}, new ArrayList<>());
                        } catch (ConfigurationException e) {
                            throw new RuntimeException(e);
                        }
                    } 

    public void testPreparer_mismatch() throws Exception {
        mMapDeviceTargetPreparer.clear();
        List<ITargetPreparer> preparers = new ArrayList<>();
        preparers.add(mMockTargetPrep);
        mMapDeviceTargetPreparer.put(ConfigurationDef.DEFAULT_DEVICE_NAME, preparers);

        mModule =
                new ModuleDefinition(
                        MODULE_NAME,
                        mTestList,
                        mMapDeviceTargetPreparer,
                        new ArrayList<>(),
                        mMultiDeviceConfiguration);
        mModule.getModuleInvocationContext().addAllocatedDevice(DEVICE_NAME_1, mDevice1);
        mModule.getModuleInvocationContext().addDeviceBuildInfo(DEVICE_NAME_1, mBuildInfo1);
        mModule.getModuleInvocationContext().addAllocatedDevice(DEVICE_NAME_2, mDevice2);
        mModule.getModuleInvocationContext().addDeviceBuildInfo(DEVICE_NAME_2, mBuildInfo2);

        mListener.testRunStarted(MODULE_NAME, 0);
        mListener.testRunEnded(EasyMock.anyLong(), EasyMock.<HashMap<String, Metric>>anyObject());

        EasyMock.expect(mMockTargetPrep.isDisabled()).andReturn(false);
        mMockTargetPrep.setUp(mDevice1, mBuildInfo1);

        replayMocks();
        mModule.run(mListener);
        verifyMocks();
    } 

    public void setUp() throws Exception {
        mMockListener = EasyMock.createMock(ITestInvocationListener.class);
        mMockBuild = EasyMock.createMock(IBuildInfo.class);
        mMockDevice = EasyMock.createMock(ITestDevice.class);
        mMockContext = new InvocationContext();
        mMockContext.addAllocatedDevice(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockDevice);
        mMockContext.addDeviceBuildInfo(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockBuild);

        mHostTest = new HostTest();
        mHostTest.setBuild(mMockBuild);
        mHostTest.setDevice(mMockDevice);
        mHostTest.setInvocationContext(mMockContext);
        OptionSetter setter = new OptionSetter(mHostTest);
        setter.setOptionValue("enable-pretty-logs", "false");
    } 

    public void setUp() {
        mController = new CarModuleController();
        mMockDevice = EasyMock.createMock(ITestDevice.class);
        mContext = new InvocationContext();
        mContext.addAllocatedDevice(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockDevice);
        mContext.addInvocationAttribute(ModuleDefinition.MODULE_ABI, "arm64-v8a");
        mContext.addInvocationAttribute(ModuleDefinition.MODULE_NAME, "module1");
        mMockIDevice = EasyMock.createMock(IDevice.class);
    } 

    public void setUp() {
        mMockListener = EasyMock.createStrictMock(ILogSaverListener.class);
        mParser = new ProtoResultParser(mMockListener, true);
        mTestParser = new TestProtoParser();
        mFinalTestParser = new FinalTestProtoParser();
        mInvocationContext = new InvocationContext();
        mInvocationContext.setConfigurationDescriptor(new ConfigurationDescriptor());
        BuildInfo info = new BuildInfo();
        mInvocationContext.addAllocatedDevice(
                ConfigurationDef.DEFAULT_DEVICE_NAME, EasyMock.createMock(ITestDevice.class));
        mInvocationContext.addDeviceBuildInfo(ConfigurationDef.DEFAULT_DEVICE_NAME, info);
    } 

    public void testRun_sharding_firstModuleRunsAll() throws Exception {
        createConfig(
                mTestConfigFolder, "module1", TEST_STUB, true, true, false, false, false, false);
        createConfig(
                mTestConfigFolder, "module2", TEST_STUB, true, true, true, false, false, false);
        ITestSuite suite = new TestSuiteFolderImpl(mTestConfigFolder);
        IConfiguration config =
                ConfigurationFactory.getInstance()
                        .createConfigurationFromArgs(new String[] {"empty"});
        config.setLogSaver(mock(ILogSaver.class));
        config.setTest(suite);
        config.setSystemStatusCheckers(new ArrayList<ISystemStatusChecker>());
        suite.setSystemStatusChecker(new ArrayList<ISystemStatusChecker>());
        suite.setInvocationContext(mContext);
        suite.setConfiguration(mStubMainConfiguration);
        config.setTestInvocationListener(mListener);
        config.getCommandOptions().setShardCount(5);
        mMockBuildInfo = new BuildInfo("9999", "test-target");
        mContext = new InvocationContext();
        mContext.addAllocatedDevice(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockDevice);
        mContext.addDeviceBuildInfo(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockBuildInfo);

        StrictShardHelper helper = new StrictShardHelper();
        helper.shardConfig(config, mContext, new TestShardRescheduler());

        assertEquals(2, mListener.getTotalModules());
        assertEquals(2, mListener.getCompleteModules());
        assertEquals(6, mListener.getTotalTests());
        assertEquals(5, mListener.getPassedTests());
        assertEquals(1, mListener.getFailedTests());
        assertEquals(2, mContext.getShardsSerials().size());
    } 

    private void helperTestShardIndex(int shardCount, int shardIndex) throws Exception {
        List<TestDescription> tests = new ArrayList<>();
        tests.add(new TestDescription("class1", "test1"));
        tests.add(new TestDescription("class1", "test2"));
        tests.add(new TestDescription("class1", "test3"));
        createConfig(
                mTestConfigFolder, "module1", TEST_STUB, true, true, false, false, false, false);
        ITestSuite suite = new TestSuiteFolderImpl(mTestConfigFolder, tests);
        IConfiguration config =
                ConfigurationFactory.getInstance()
                        .createConfigurationFromArgs(new String[] {"empty"});
        config.setLogSaver(mock(ILogSaver.class));
        config.setTest(suite);
        config.setSystemStatusCheckers(new ArrayList<ISystemStatusChecker>());
        suite.setSystemStatusChecker(new ArrayList<ISystemStatusChecker>());
        suite.setInvocationContext(mContext);
        suite.setConfiguration(mStubMainConfiguration);
        config.setTestInvocationListener(mListener);
        config.getCommandOptions().setShardCount(shardCount);
        config.getCommandOptions().setShardIndex(shardIndex);
        mMockBuildInfo = new BuildInfo("9999", "test-target");
        mContext = new InvocationContext();
        mContext.addAllocatedDevice(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockDevice);
        mContext.addDeviceBuildInfo(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockBuildInfo);

        StrictShardHelper helper = new StrictShardHelper();
        helper.shardConfig(config, mContext, null);
        new ResultForwarder(config.getTestInvocationListeners()).invocationStarted(mContext);
        for (IRemoteTest test : config.getTests()) {
            if (test instanceof ISystemStatusCheckerReceiver) {
                ((ISystemStatusCheckerReceiver) test)
                        .setSystemStatusChecker(config.getSystemStatusCheckers());
            }
            if (test instanceof IInvocationContextReceiver) {
                ((IInvocationContextReceiver) test).setInvocationContext(mContext);
            }
            test.run(new ResultForwarder(config.getTestInvocationListeners()));
        }
        new ResultForwarder(config.getTestInvocationListeners()).invocationEnded(500);
    } 

    public void testRun_sharding_parallelRun() throws Exception {
        createConfig(
                mTestConfigFolder, "module1", TEST_STUB, true, true, false, false, false, false);
        createConfig(
                mTestConfigFolder, "module2", TEST_STUB, true, true, true, false, false, false);
        ITestSuite suite = new TestSuiteFolderImpl(mTestConfigFolder);
        IConfiguration config =
                ConfigurationFactory.getInstance()
                        .createConfigurationFromArgs(new String[] {"empty"});
        config.setLogSaver(mock(ILogSaver.class));
        config.setTest(suite);
        config.setSystemStatusCheckers(new ArrayList<ISystemStatusChecker>());
        suite.setSystemStatusChecker(new ArrayList<ISystemStatusChecker>());
        suite.setInvocationContext(mContext);
        suite.setConfiguration(mStubMainConfiguration);
        config.setTestInvocationListener(mListener);
        config.getCommandOptions().setShardCount(5);
        mMockBuildInfo = new BuildInfo("9999", "test-target");
        mContext = new InvocationContext();
        mContext.addAllocatedDevice(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockDevice);
        mContext.addDeviceBuildInfo(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockBuildInfo);

        StrictShardHelper helper = new StrictShardHelper();
        TestParallelShardRescheduler rescheduler = new TestParallelShardRescheduler();
        helper.shardConfig(config, mContext, rescheduler);
        while (mListener.getTotalModules() < 2) {
            for (Thread t : rescheduler.mRunning) {
                t.join(2000);
            }
        }
        RunUtil.getDefault().sleep(250L);
        assertEquals(2, mListener.getTotalModules());
        assertEquals(2, mListener.getCompleteModules());
        assertEquals(6, mListener.getTotalTests());
        assertEquals(5, mListener.getPassedTests());
        assertEquals(1, mListener.getFailedTests());
        assertEquals(2, mContext.getShardsSerials().size());
    } 

    public void testRun_sharding_withIndex() throws Exception {
        createConfig(
                mTestConfigFolder, "module1", TEST_STUB, true, true, false, false, false, false);
        createConfig(
                mTestConfigFolder, "module2", TEST_STUB, true, true, true, false, false, false);
        ITestSuite suite = new TestSuiteFolderImpl(mTestConfigFolder);
        IConfiguration config =
                ConfigurationFactory.getInstance()
                        .createConfigurationFromArgs(new String[] {"empty"});
        config.setLogSaver(mock(ILogSaver.class));
        config.setTest(suite);
        config.setSystemStatusCheckers(new ArrayList<ISystemStatusChecker>());
        suite.setSystemStatusChecker(new ArrayList<ISystemStatusChecker>());
        suite.setInvocationContext(mContext);
        suite.setConfiguration(mStubMainConfiguration);
        config.setTestInvocationListener(mListener);
        config.getCommandOptions().setShardCount(2);
        config.getCommandOptions().setShardIndex(0);
        mMockBuildInfo = new BuildInfo("9999", "test-target");
        mContext = new InvocationContext();
        mContext.addAllocatedDevice(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockDevice);
        mContext.addDeviceBuildInfo(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockBuildInfo);

        StrictShardHelper helper = new StrictShardHelper();
        helper.shardConfig(config, mContext, null);
        new ResultForwarder(config.getTestInvocationListeners()).invocationStarted(mContext);
        for (IRemoteTest test : config.getTests()) {
            if (test instanceof ISystemStatusCheckerReceiver) {
                ((ISystemStatusCheckerReceiver) test)
                        .setSystemStatusChecker(config.getSystemStatusCheckers());
            }
            if (test instanceof IInvocationContextReceiver) {
                ((IInvocationContextReceiver) test).setInvocationContext(mContext);
            }
            test.run(new ResultForwarder(config.getTestInvocationListeners()));
        }
        new ResultForwarder(config.getTestInvocationListeners()).invocationEnded(500);
        assertEquals(1, mListener.getTotalModules());
        assertEquals(1, mListener.getCompleteModules());
        assertEquals(3, mListener.getTotalTests());
        assertEquals(3, mListener.getPassedTests());
        assertEquals(0, mListener.getFailedTests());
        assertEquals(0, mContext.getShardsSerials().size());
    } 

    public void setUp() throws IOException {
        mTestConfigFolder = FileUtil.createTempDir("suite-integration");
        mMockDevice = mock(ITestDevice.class);
        mMockBuildInfo = mock(IBuildInfo.class);
        mListener = new SuiteResultReporter();
        mContext = new InvocationContext();
        mContext.addAllocatedDevice(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockDevice);
        mContext.addDeviceBuildInfo(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockBuildInfo);

        mMockLogSaver = EasyMock.createMock(ILogSaver.class);
        mStubMainConfiguration = new Configuration("stub", "stub");
        mStubMainConfiguration.setLogSaver(mMockLogSaver);
        doReturn("serial").when(mMockDevice).getSerialNumber();
    } 

    public void setUp() {
        mMockMainConfiguration = new Configuration("mockMain", "mockMain");
        mCheckers = new ArrayList<>();
        mMockInfo = EasyMock.createMock(IDeviceBuildInfo.class);
        mMockDevice = EasyMock.createMock(ITestDevice.class);
        mMockContext = new InvocationContext();
        mMockContext.addAllocatedDevice(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockDevice);
        mMockContext.addDeviceBuildInfo(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockInfo);

        mSpyFilter = new RetryFilterHelper() {
            @Override
            public void validateBuildFingerprint(ITestDevice device)
                    throws DeviceNotAvailableException {
            }
            @Override
            public void setCommandLineOptionsFor(Object obj) {
            }
            @Override
            public void setBuildInfoRetryCommand(IBuildInfo info) {
            }
            @Override
            public void populateFiltersBySubPlan() {
            }
        };
        mFactory = new RetryFactoryTest() {
            @Override
            protected RetryFilterHelper createFilterHelper(CompatibilityBuildHelper buildHelper) {
                return mSpyFilter;
            }
            @Override
            CompatibilityTestSuite createTest() {
                return new VoidCompatibilityTest();
            }
        };
        mMockListener = EasyMock.createMock(ITestInvocationListener.class);
    } 

    @Override
    protected ConfigurationDef getConfigurationDef(
            String name, boolean isGlobal, Map<String, String> templateMap)
            throws ConfigurationException {
        return new GCSConfigLoader(isGlobal).getConfigurationDef(name, templateMap);
    } 

    public void setUp() throws Exception {
        mMockListener = EasyMock.createMock(ITestInvocationListener.class);
        mMockDevice = EasyMock.createMock(ITestDevice.class);
        mContext = new InvocationContext();
        mContext.addAllocatedDevice(ConfigurationDef.DEFAULT_DEVICE_NAME, mMockDevice);
        mCollector = new FilePullerLogCollector();
        OptionSetter setter = new OptionSetter(mCollector);
        setter.setOptionValue("pull-pattern-keys", "log.*");
    }