summaryrefslogtreecommitdiff
path: root/tests/c11.h
blob: 57a8ee1122c1b523cf648330beeea8ae6cbcfdb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef C11_H
#define C11_H

#include "cache.h"
#include "dram.h"
#include "storage.h"
#include <algorithm>
#include <array>
#include <catch2/catch_test_macros.hpp>
#include <functional>

/**
 * one way associative, single level
 */
class C11
{
  public:
	C11()
	{
		this->m_delay = 4;
		this->c_delay = 2;
		this->mem = new int();
		this->fetch = new int();
		this->c = new Cache(new Dram(this->m_delay), 5, 0, this->c_delay);
		this->expected = {0, 0, 0, 0};
		this->actual = this->c->get_data()[0];
	}

	~C11()
	{
		delete this->c;
		delete this->mem;
		delete this->fetch;
	}

	void
	wait_then_do(int delay, std::function<int()> f)
	{
		for (int i = 0; i < delay; ++i) {
			int r = f();

			// check response
			CHECK(!r);
			// check for early modifications
			actual = c->get_data()[0];
			REQUIRE(this->expected == this->actual);
		}
	}

	int m_delay;
	int c_delay;
	Cache *c;
	int *mem;
	int *fetch;
	std::array<signed int, LINE_SIZE> expected;
	std::array<signed int, LINE_SIZE> actual;
};

#endif /* C11_H_INCLUDED */