AutoTest: Avoid concurrent access on static function members

First thread using the helper function initialized the list
object another thread accesses it afterwards. This could be
problematic under some circumstances.

Issue was detected using Helgrind.

Change-Id: I1520b1f7364742cb02630af1fd9d98960dec1f41
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2016-11-08 09:46:22 +01:00
parent 2ccacf1fe6
commit c07c4eb068
7 changed files with 223 additions and 99 deletions

View File

@@ -25,45 +25,17 @@
#pragma once
#include "../testframeworkmanager.h"
#include <QHash>
#include <utils/qtcassert.h>
#include <QByteArrayList>
namespace Core { class Id; }
namespace Autotest {
namespace Internal {
namespace QTestUtils {
class QTestUtils
{
public:
static bool isQTestMacro(const QByteArray &macro)
{
static QByteArrayList valid = {"QTEST_MAIN", "QTEST_APPLESS_MAIN", "QTEST_GUILESS_MAIN"};
return valid.contains(macro);
}
static QHash<QString, QString> testCaseNamesForFiles(const Core::Id &id,
const QStringList &files)
{
QHash<QString, QString> result;
TestTreeItem *rootNode = TestFrameworkManager::instance()->rootNodeForTestFramework(id);
QTC_ASSERT(rootNode, return result);
for (int row = 0, rootCount = rootNode->childCount(); row < rootCount; ++row) {
const TestTreeItem *child = rootNode->childItem(row);
if (files.contains(child->filePath())) {
result.insert(child->filePath(), child->name());
}
for (int childRow = 0, count = child->childCount(); childRow < count; ++childRow) {
const TestTreeItem *grandChild = child->childItem(childRow);
if (files.contains(grandChild->filePath()))
result.insert(grandChild->filePath(), child->name());
}
}
return result;
}
};
bool isQTestMacro(const QByteArray &macro);
QHash<QString, QString> testCaseNamesForFiles(const Core::Id &id, const QStringList &files);
} // namespace QTestUtils
} // namespace Internal
} // namespace Autotest