blob: 0c307c2c1cb83c95f15c3c49104153f89fe4b871 [file] [log] [blame]
Zane Shelley11b89942019-11-07 11:07:28 -06001#include "simulator.hpp"
2
3using namespace libhei;
4
5//------------------------------------------------------------------------------
6
7void SimulatorData::addChip(const Chip& i_chip)
8{
9 // First check if this entry already exists.
10 auto itr = std::find(iv_chipList.begin(), iv_chipList.end(), i_chip);
11 ASSERT_EQ(iv_chipList.end(), itr);
12
13 // Add the new entry.
14 iv_chipList.push_back(i_chip);
15
16 // TODO: Find the chip data file based on the chip type from i_chip. Read
17 // that file in to memory and call initialize.
18 void* buffer = nullptr;
19 size_t sz_buffer = 0;
20
21 ReturnCode rc = initialize(buffer, sz_buffer);
22 ASSERT_TRUE(RC_SUCCESS == rc || RC_CHIP_DATA_INITIALIZED == rc);
23}
24
25//------------------------------------------------------------------------------
26
27void SimulatorData::endIteration()
28{
29 // Start by calling libhei::isolate().
30 IsolationData isoData{};
31 ReturnCode rc = isolate(iv_chipList, isoData);
32
33 // It is possible that even in a failure scenario the information in the
34 // returned IsolationData would be useful.
35 // TODO: Figure out where to put the data.
36
37 // Verify if isolation completed successfully.
38 ASSERT_TRUE(RC_SUCCESS == rc);
39
40 // Get the list of signatures found in isolation.
41 std::vector<Signature> givenSigList = isoData.getSignatureList();
42
43 // Verify the expected list and given list are the same.
44 ASSERT_EQ(iv_expSigList.size(), givenSigList.size());
45
46 std::sort(iv_expSigList.begin(), iv_expSigList.end());
47 std::sort(givenSigList.begin(), givenSigList.end());
48
49 ASSERT_TRUE(std::equal(givenSigList.begin(), givenSigList.end(),
50 iv_expSigList.begin()));
51
52 // The iteration is complete so we can flush the data.
53 flushIterationData();
54}