1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 375226 - Code not indexed properly when changing active

configuration

Change-Id: I75b6eabac1cfde6e3e28a20be372925ef8a88fd8
Reviewed-on: https://git.eclipse.org/r/6143
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Reviewed-by: Marc-Andre Laperle <malaperle@gmail.com>
IP-Clean: Marc-Andre Laperle <malaperle@gmail.com>
Tested-by: Marc-Andre Laperle <malaperle@gmail.com>
This commit is contained in:
Marc-Andre Laperle 2012-06-03 01:06:53 -04:00
parent 2c63700887
commit 4e872b05cb
5 changed files with 149 additions and 13 deletions

View file

@ -0,0 +1,123 @@
/*******************************************************************************
* Copyright (c) 2012 Marc-Andre Laperle and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Marc-Andre Laperle - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests;
import java.util.regex.Pattern;
import junit.framework.Test;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionPreferences;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.CTestPlugin;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
public class ChangeConfigurationTests extends PDOMTestBase {
public static Test suite() {
return suite(ChangeConfigurationTests.class);
}
private void changeConfigRelations(IProject project, int option) throws CoreException {
ICProjectDescription pd= CCorePlugin.getDefault().getProjectDescription(project);
pd.setConfigurationRelations(option);
CCorePlugin.getDefault().setProjectDescription(project, pd);
CCorePlugin.getIndexManager().joinIndexer(8000, npm());
}
// Emulates ChangeConfigAction
private void changeProjectConfiguration(IProject project, String configName) throws CoreException, InterruptedException {
ICProjectDescription prjd = CCorePlugin.getDefault().getProjectDescriptionManager().getProjectDescription(project);
ICConfigurationDescription[] configs = prjd.getConfigurations();
if (configs != null && configs.length > 0) {
for (ICConfigurationDescription config : configs) {
if (config.getName().equals(configName)) {
config.setActive();
CoreModel.getDefault().setProjectDescription(project, prjd);
break;
}
}
}
}
//#ifdef MACRO1
//void testFunc1();
//#endif
//#ifdef MACRO2
//void testFunc2();
//#endif
public void testRepeatedlyChangeConfig_bug375226() throws Exception {
ModelJoiner mj = new ModelJoiner();
ICProject cProject = CProjectHelper.createNewStileCProject("testChangeConfiguration", IPDOMManager.ID_FAST_INDEXER);
IProject project = cProject.getProject();
StringBuilder[] contents= TestSourceReader.getContentsForTest(CTestPlugin.getDefault().getBundle(), "parser", getClass(), getName(), 1);
IFile file= TestSourceReader.createFile(cProject.getProject(), new Path("test.c"), contents[0].toString());
mj.join();
mj.dispose();
changeConfigRelations(cProject.getProject(), ICProjectDescriptionPreferences.CONFIGS_LINK_SETTINGS_AND_ACTIVE);
ICProjectDescription prjd = CCorePlugin.getDefault().getProjectDescriptionManager().getProjectDescription(project);
ICConfigurationDescription configuration1 = prjd.getConfigurations()[0];
String firstConfigName = configuration1.getName();
for(ICLanguageSetting languageSetting : configuration1.getRootFolderDescription().getLanguageSettings())
{
languageSetting.setSettingEntries(ICSettingEntry.MACRO, new ICLanguageSettingEntry[] { CDataUtil.createCMacroEntry("MACRO1", null, 0)});
}
ICConfigurationDescription configuration2 = prjd.createConfiguration("id2", "Configuration2", configuration1);
String secondConfigName = configuration2.getName();
for(ICLanguageSetting languageSetting : configuration2.getRootFolderDescription().getLanguageSettings())
{
languageSetting.setSettingEntries(ICSettingEntry.MACRO, new ICLanguageSettingEntry[] { CDataUtil.createCMacroEntry("MACRO2", null, 0)} );
}
CoreModel.getDefault().setProjectDescription(project, prjd);
CCorePlugin.getIndexManager().reindex(cProject);
waitForIndexer(cProject);
Pattern testFunc1 = Pattern.compile("testFunc1");
Pattern testFunc2 = Pattern.compile("testFunc2");
int i = 0, noTrials = 50;
do {
IIndex index = CCorePlugin.getIndexManager().getIndex(cProject);
index.acquireReadLock();
boolean isFirstConfig = i % 2 == 0;
IBinding[] bindings = index.findBindings(isFirstConfig ? testFunc1 : testFunc2, true, IndexFilter.ALL, new NullProgressMonitor());
IBinding[] noBindings = index.findBindings(isFirstConfig ? testFunc2 : testFunc1, true, IndexFilter.ALL, new NullProgressMonitor());
assertEquals(1, bindings.length);
assertEquals(0, noBindings.length);
index.releaseReadLock();
String nextConfig = isFirstConfig ? secondConfigName : firstConfigName;
changeProjectConfiguration(project, nextConfig);
waitForIndexer(cProject);
i++;
} while (i < noTrials);
}
}

View file

@ -1,14 +1,15 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 QNX Software Systems and others.
* Copyright (c) 2006, 2012 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* IBM Corporation
* Andrew Ferguson (Symbian)
* QNX - Initial API and implementation
* IBM Corporation
* Andrew Ferguson (Symbian)
* Marc-Andre Laperle
*******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests;
@ -55,6 +56,8 @@ public class PDOMTests extends TestSuite {
suite.addTest(CCompositeTypeTests.suite());
suite.addTest(DefDeclTests.suite());
suite.addTest(RaceCondition157992Test.suite());
suite.addTest(ChangeConfigurationTests.suite());
return suite;
}

View file

@ -1,19 +1,22 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 QNX Software Systems and others.
* Copyright (c) 2006, 2012 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Symbian - Repeatedly index classTests test project to detect a particular race condition
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Symbian - Repeatedly index classTests test project to detect a particular race condition
* Marc-Andre Laperle
*******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests;
import java.util.regex.Pattern;
import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.ICProject;
@ -26,6 +29,11 @@ import org.eclipse.core.runtime.NullProgressMonitor;
* Test case for a race condition from Bugzilla#157992
*/
public class RaceCondition157992Test extends PDOMTestBase {
public static Test suite() {
return suite(RaceCondition157992Test.class);
}
public void testRepeatedly() throws Exception {
int successes = 0, noTrials = 100;

View file

@ -1,13 +1,14 @@
/*******************************************************************************
* Copyright (c) 2007, 2011 Intel Corporation and others.
* Copyright (c) 2007, 2012 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
* IBM Corporation
* Intel Corporation - Initial API and implementation
* IBM Corporation
* Marc-Andre Laperle
*******************************************************************************/
package org.eclipse.cdt.internal.core.settings.model;
@ -56,7 +57,7 @@ public class DescriptionScannerInfoProvider implements IScannerInfoProvider, ICP
DescriptionScannerInfoProvider(IProject project){
fProject = project;
CProjectDescriptionManager.getInstance().addCProjectDescriptionListener(this, CProjectDescriptionEvent.APPLIED | CProjectDescriptionEvent.LOADED);
CProjectDescriptionManager.getInstance().addCProjectDescriptionListener(this, CProjectDescriptionEvent.DATA_APPLIED | CProjectDescriptionEvent.LOADED);
}
private void updateProjCfgInfo(ICProjectDescription des){

View file

@ -12,6 +12,7 @@
* Sergey Prigogin (Google)
* Tim Kelly (Nokia)
* Anna Dushistova (MontaVista)
* Marc-Andre Laperle
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom;
@ -242,7 +243,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
model.addElementChangedListener(fCModelListener);
LanguageManager.getInstance().registerLanguageChangeListener(fLanguageChangeListener);
LanguageSettingsManager.registerLanguageSettingsChangeListener(fLanguageSettingsChangeListener);
final int types= CProjectDescriptionEvent.DATA_APPLIED;
final int types= CProjectDescriptionEvent.APPLIED;
CCorePlugin.getDefault().getProjectDescriptionManager().addCProjectDescriptionListener(fProjectDescriptionListener, types);
try {