Skip to content

Commit

Permalink
Merge branch 'config-dialog-ut-refactor-standalone' into 'jumping'
Browse files Browse the repository at this point in the history
Refactor and add UT for processor config dialog

See merge request tfg-riscv-sim/ripes!10
  • Loading branch information
Silvia González Rodríguez committed Feb 3, 2025
2 parents da3ca44 + 0035a24 commit 988b39c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 31 deletions.
23 changes: 18 additions & 5 deletions src/processorregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,28 @@ QString enumToString(T value) {

// =============================== Processors =================================
// The order of the ProcessorID enum defines the order in which the processors'
// properties populate the options in the processor configuration dialog.
// properties populate the datapath and branch strategy options in the processor
// configuration dialog.
enum ProcessorID {
RV32_SS,
RV32_5S_1S,
RV32_5S_1S_DB,
RV32_5S_NO_FW_HZ,
RV32_5S_NO_HZ,
RV32_5S_NO_FW,
RV32_5S,
RV32_5S_1S,
RV32_5S_1S_DB,
RV32_5S_2S_DB,
RV32_5S_3S,
RV32_5S_3S_DB,
RV32_6S_DUAL,

RV64_SS,
RV64_5S_1S,
RV64_5S_1S_DB,
RV64_5S_NO_FW_HZ,
RV64_5S_NO_HZ,
RV64_5S_NO_FW,
RV64_5S,
RV64_5S_1S,
RV64_5S_1S_DB,
RV64_5S_2S_DB,
RV64_5S_3S,
RV64_5S_3S_DB,
Expand Down Expand Up @@ -157,6 +158,18 @@ class ProcessorRegistry {
return it->second->construct(extensions);
}

static QList<ProcessorID> getProcessor(ISA isa, ProcessorTags tags) {
QList<ProcessorID> ids = {};

for (const auto &desc : ProcessorRegistry::getAvailableProcessors())
if (desc.second->isaInfo().isa->isaID() == isa &&
desc.second->tags == tags)
ids.append(desc.first);

// ids.size() should be 1, else there are processors with identical tags
return ids;
}

private:
template <typename T>
void addProcessor(const ProcInfo<T> &pinfo) {
Expand Down
37 changes: 13 additions & 24 deletions src/processorselectiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,6 @@ ProcessorSelectionDialog::getRegisterInitialization() const {
return m_ui->regInitWidget->getInitialization();
}

QList<ProcessorID>
ProcessorSelectionDialog::getSelectedProcessor(ISA isa,
ProcessorTags tags) const {
QList<ProcessorID> ids = {};

for (const auto &desc : ProcessorRegistry::getAvailableProcessors())
if (desc.second->isaInfo().isa->isaID() == isa && desc.second->tags == tags)
ids.append(desc.first);

// ids.size() should be 1, otherwise there are processors with identical tags
return ids;
}

const Layout *ProcessorSelectionDialog::getSelectedLayout() const {
const auto &desc =
ProcessorRegistry::getAvailableProcessors().at(m_selectedID);
Expand All @@ -185,14 +172,14 @@ void ProcessorSelectionDialog::updateSelectedTags() {

if (m_selectedISA != selectedISA || m_selectedTags != selectedTags) {
// Check that a processor exists with the selected properties
if (getSelectedProcessor(selectedISA, selectedTags).size() > 0) {
if (ProcessorRegistry::getProcessor(selectedISA, selectedTags).size() > 0) {
m_selectedISA = selectedISA;
m_selectedTags = selectedTags;
}
// Otherwise, redirect to the closest valid processor
else {
const auto &desc = ProcessorRegistry::getDescription(
redirectToValidProcessor(selectedISA, selectedTags)[0]);
redirectToValidProcessor(selectedISA, selectedTags));
selectedISA = desc.isaInfo().isa->isaID();
selectedTags = desc.tags;
m_selectedISA = selectedISA;
Expand All @@ -204,7 +191,7 @@ void ProcessorSelectionDialog::updateSelectedTags() {
}

void ProcessorSelectionDialog::updateDialog(ISA isa, ProcessorTags tags) {
QList<ProcessorID> selected = getSelectedProcessor(isa, tags);
QList<ProcessorID> selected = ProcessorRegistry::getProcessor(isa, tags);

// Check valid selection and update selected processor
m_ui->buttonBox->button(QDialogButtonBox::Ok)
Expand Down Expand Up @@ -304,6 +291,8 @@ void ProcessorSelectionDialog::populateVariants() {
}
}
}
// Sort branch delay slot options in ascending order
m_ui->branchSlots->model()->sort(0);
}

void ProcessorSelectionDialog::setEnabledVariants() {
Expand Down Expand Up @@ -338,7 +327,7 @@ void ProcessorSelectionDialog::setEnabledVariants() {
}
}

QList<ProcessorID>
ProcessorID
ProcessorSelectionDialog::redirectToValidProcessor(ISA isa,
ProcessorTags tags) {
QList<ProcessorID> selected = {};
Expand All @@ -354,7 +343,7 @@ ProcessorSelectionDialog::redirectToValidProcessor(ISA isa,
if (!availableOptions.isEmpty())
selected = availableOptions;
if (selected.size() == 1)
return selected;
return selected[0];

// Explore datapaths
availableOptions = {};
Expand All @@ -366,7 +355,7 @@ ProcessorSelectionDialog::redirectToValidProcessor(ISA isa,
if (!availableOptions.isEmpty())
selected = availableOptions;
if (selected.size() == 1)
return selected;
return selected[0];

// Explore branch options
availableOptions = {};
Expand All @@ -378,7 +367,7 @@ ProcessorSelectionDialog::redirectToValidProcessor(ISA isa,
if (!availableOptions.isEmpty())
selected = availableOptions;
if (selected.size() == 1)
return selected;
return selected[0];

availableOptions = {};
for (auto id : selected) {
Expand All @@ -389,7 +378,7 @@ ProcessorSelectionDialog::redirectToValidProcessor(ISA isa,
if (!availableOptions.isEmpty())
selected = availableOptions;
if (selected.size() == 1)
return selected;
return selected[0];

// Explore forwarding/hazard detection
availableOptions = {};
Expand All @@ -401,7 +390,7 @@ ProcessorSelectionDialog::redirectToValidProcessor(ISA isa,
if (!availableOptions.isEmpty())
selected = availableOptions;
if (selected.size() == 1)
return selected;
return selected[0];

availableOptions = {};
for (auto id : selected) {
Expand All @@ -412,9 +401,9 @@ ProcessorSelectionDialog::redirectToValidProcessor(ISA isa,
if (!availableOptions.isEmpty())
selected = availableOptions;
if (selected.size() == 1)
return selected;
return selected[0];

return selected;
return selected[0];
}

} // namespace Ripes
3 changes: 1 addition & 2 deletions src/processorselectiondialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class ProcessorSelectionDialog : public QDialog {

QStringList getEnabledExtensions() const;
RegisterInitialization getRegisterInitialization() const;
QList<ProcessorID> getSelectedProcessor(ISA isa, ProcessorTags tags) const;
const Layout *getSelectedLayout() const;

ProcessorID getSelectedId() const { return m_selectedID; }
Expand All @@ -34,7 +33,7 @@ private slots:
private:
void populateVariants();
void setEnabledVariants();
QList<ProcessorID> redirectToValidProcessor(ISA isa, ProcessorTags tags);
ProcessorID redirectToValidProcessor(ISA isa, ProcessorTags tags);

ISA m_selectedISA;
ProcessorID m_selectedID;
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ create_qtest(tst_assembler)
create_qtest(tst_expreval)
create_qtest(tst_cosimulate)
create_qtest(tst_reverse)
create_qtest(tst_cpu_selection)
42 changes: 42 additions & 0 deletions test/tst_cpu_selection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <QTest>
#include <qlist.h>
#include <qtestcase.h>

#include "isainfo.h"
#include "processorregistry.h"

using namespace Ripes;

class tst_CPU_Selection : public QObject {
Q_OBJECT

private slots:
void tst_no_duplicates();
void tst_no_duplicates_data();
};

void tst_CPU_Selection::tst_no_duplicates_data() {
QTest::addColumn<ISA>("isa");
QTest::addColumn<ProcessorTags>("tags");
QTest::addColumn<QList<ProcessorID>>("exp_result");

for (const auto &desc : Ripes::ProcessorRegistry::getAvailableProcessors()) {
QList<ProcessorID> id(1, desc.first);
QTest::addRow("%d", desc.first)
<< desc.second->isaInfo().isa->isaID() << desc.second->tags << id;
}
}

void tst_CPU_Selection::tst_no_duplicates() {
// Check that there aren't any processors with identical tags
// getProcessor should always return a list of length 1

QFETCH(ISA, isa);
QFETCH(ProcessorTags, tags);
QFETCH(QList<ProcessorID>, exp_result);

QCOMPARE(Ripes::ProcessorRegistry::getProcessor(isa, tags), exp_result);
}

QTEST_APPLESS_MAIN(tst_CPU_Selection)
#include "tst_cpu_selection.moc"

0 comments on commit 988b39c

Please sign in to comment.