File size: 1,149 Bytes
684db41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#include <gtest/gtest.h>

#include "kernel/rtlil.h"
#include "kernel/yosys.h"

YOSYS_NAMESPACE_BEGIN

namespace {

TEST(DesignStateTest, AutoidxInTwinePool)
{
	TwinePool a, b;
	int start = a.autoidx();
	EXPECT_EQ(b.autoidx(), start);

	IdString first = a.add(NEW_ID);
	EXPECT_EQ(a.autoidx(), start + 1);
	EXPECT_EQ(b.autoidx(), start);

	IdString second = b.add(NEW_ID_SUFFIX("tail"));
	EXPECT_EQ(b.autoidx(), start + 1);

	EXPECT_TRUE(a.str(first).ends_with(std::to_string(start)));
	EXPECT_TRUE(b.str(second).ends_with("tail$" + std::to_string(start)));
}

TEST(DesignStateTest, HashidxPerDesign)
{
	RTLIL::Design old_d;
	RTLIL::Module *old_mod = old_d.addModule(std::string("\\m"));
	RTLIL::Wire *old_wire = old_mod->addWire(NEW_ID, 1);

	RTLIL::Design new_d;
	RTLIL::Module *new_mod = new_d.addModule(std::string("\\m"));
	RTLIL::Wire *new_wire = new_mod->addWire(NEW_ID, 1);

	EXPECT_EQ(run_hash(old_d), run_hash(LARGE_HASHIDX_COLLIDER));
	EXPECT_EQ(run_hash(new_d), run_hash(LARGE_HASHIDX_COLLIDER));

	EXPECT_EQ(run_hash(old_mod), run_hash(new_mod));
	EXPECT_EQ(run_hash(old_wire), run_hash(new_wire));
}

} // namespace

YOSYS_NAMESPACE_END