Add a sample Chip Data File to the simulator
Change-Id: I4cf0bd61c660505c453edc1afe5900c357ade9de
Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
diff --git a/test/simulator/chip_data/sample.cdb b/test/simulator/chip_data/sample.cdb
new file mode 100644
index 0000000..2e36af5
--- /dev/null
+++ b/test/simulator/chip_data/sample.cdb
Binary files differ
diff --git a/test/simulator/sample_test_case.cpp b/test/simulator/sample_test_case.cpp
index 1a44a32..af78ce0 100644
--- a/test/simulator/sample_test_case.cpp
+++ b/test/simulator/sample_test_case.cpp
@@ -2,7 +2,7 @@
START_TEST_CASE(SampleTestSet1)
-CHIP(proc0, 0xdeadbeef)
+CHIP(proc0, SAMPLE)
START_ITERATION
diff --git a/test/simulator/simulator.cpp b/test/simulator/simulator.cpp
index 0c307c2..2e480ac 100644
--- a/test/simulator/simulator.cpp
+++ b/test/simulator/simulator.cpp
@@ -1,25 +1,58 @@
#include "simulator.hpp"
-using namespace libhei;
+#include <fstream> // std::ifstream
+
+namespace libhei
+{
+
+//------------------------------------------------------------------------------
+
+// Paths are relative from the build/ directory
+const std::map<SimulatorData::ChipType, const char*>
+ SimulatorData::cv_chipPath = {
+ {SAMPLE, "../test/simulator/chip_data/sample.cdb"},
+};
//------------------------------------------------------------------------------
void SimulatorData::addChip(const Chip& i_chip)
{
// First check if this entry already exists.
- auto itr = std::find(iv_chipList.begin(), iv_chipList.end(), i_chip);
- ASSERT_EQ(iv_chipList.end(), itr);
+ auto itr1 = std::find(iv_chipList.begin(), iv_chipList.end(), i_chip);
+ ASSERT_EQ(iv_chipList.end(), itr1);
// Add the new entry.
iv_chipList.push_back(i_chip);
- // TODO: Find the chip data file based on the chip type from i_chip. Read
- // that file in to memory and call initialize.
- void* buffer = nullptr;
- size_t sz_buffer = 0;
+ // Look for the file path
+ auto itr2 = cv_chipPath.find(static_cast<ChipType>(i_chip.getType()));
+ ASSERT_NE(cv_chipPath.end(), itr2);
+ const char* path = itr2->second;
+ // Open the Chip Data File
+ std::ifstream cdf{path, std::ifstream::binary};
+ ASSERT_TRUE(cdf.good());
+
+ // Get the length of file
+ cdf.seekg(0, cdf.end);
+ size_t sz_buffer = cdf.tellg();
+ cdf.seekg(0, cdf.beg);
+
+ // Allocate memory
+ char* buffer = new char[sz_buffer];
+
+ // Read data as a block
+ cdf.read(buffer, sz_buffer);
+
+ // Close the Chip Data File
+ cdf.close();
+
+ // Initilize the chip with this Chip Data File.
ReturnCode rc = initialize(buffer, sz_buffer);
ASSERT_TRUE(RC_SUCCESS == rc || RC_CHIP_DATA_INITIALIZED == rc);
+
+ // Clean up the buffer
+ delete[] buffer;
}
//------------------------------------------------------------------------------
@@ -52,3 +85,5 @@
// The iteration is complete so we can flush the data.
flushIterationData();
}
+
+} // end namespace libhei
diff --git a/test/simulator/simulator.hpp b/test/simulator/simulator.hpp
index 29d1ef6..e5526d8 100644
--- a/test/simulator/simulator.hpp
+++ b/test/simulator/simulator.hpp
@@ -35,7 +35,17 @@
return theSimData;
}
+ public:
+ /** The list of supported chip types for the simulator. */
+ enum ChipType
+ {
+ SAMPLE = 0xdeadbeef,
+ };
+
private:
+ /** The Chip Data file paths for each support chip type. */
+ static const std::map<ChipType, const char*> cv_chipPath;
+
/** The list of configured chips used throughout a test case. */
std::vector<Chip> iv_chipList;
@@ -163,7 +173,8 @@
{ \
libhei::SimulatorData& simData = \
libhei::SimulatorData::getSingleton(); \
- simData.flushAll();
+ simData.flushAll(); \
+ libhei::ChipType_t chipType;
/**
* Use this to configure a chip object for the test case. There should be an
@@ -174,7 +185,8 @@
* macros.
*/
#define CHIP(CHIP, TYPE) \
- libhei::Chip CHIP{#CHIP, static_cast<libhei::ChipType_t>(TYPE)}; \
+ chipType = static_cast<libhei::ChipType_t>(libhei::SimulatorData::TYPE); \
+ libhei::Chip CHIP{#CHIP, chipType}; \
simData.addChip(CHIP);
/**