summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-Andre Laperle2012-06-03 01:06:53 (EDT)
committer Marc-Andre Laperle2012-06-04 11:26:23 (EDT)
commit4e872b05cb5a5f81b6bb5402709bcbfc0d662f64 (patch)
treede1cce929e36f801374ffd22de942cc74954847e
parent2c63700887ee525965cff9d86fb5547bf6f455b3 (diff)
downloadorg.eclipse.cdt-4e872b05cb5a5f81b6bb5402709bcbfc0d662f64.zip
org.eclipse.cdt-4e872b05cb5a5f81b6bb5402709bcbfc0d662f64.tar.gz
org.eclipse.cdt-4e872b05cb5a5f81b6bb5402709bcbfc0d662f64.tar.bz2
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>
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ChangeConfigurationTests.java123
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java11
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/RaceCondition157992Test.java16
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java3
5 files changed, 149 insertions, 13 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ChangeConfigurationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ChangeConfigurationTests.java
new file mode 100644
index 0000000..a8235dc
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ChangeConfigurationTests.java
@@ -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);
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java
index ec57bfb..fd92b1d 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java
@@ -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;
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/RaceCondition157992Test.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/RaceCondition157992Test.java
index 37e1f7e..66dc26f 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/RaceCondition157992Test.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/RaceCondition157992Test.java
@@ -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;
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java
index f6317eb..44056b0 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java
@@ -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){
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
index f4f0219..6a90fe1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
@@ -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 {