OpenCores
URL https://opencores.org/ocsvn/s80186/s80186/trunk

Subversion Repositories s80186

[/] [s80186/] [trunk/] [tests/] [rtl/] [TestCSIPSync.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
// Copyright Jamie Iles, 2017
2
//
3
// This file is part of s80x86.
4
//
5
// s80x86 is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// s80x86 is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with s80x86.  If not, see <http://www.gnu.org/licenses/>.
17
 
18
#include <gtest/gtest.h>
19
#include <VCSIPSync.h>
20
 
21
#include "VerilogTestbench.h"
22
 
23
class CSIPSyncTestFixture : public VerilogTestbench<VCSIPSync>,
24
                            public ::testing::Test
25
{
26
public:
27
    CSIPSyncTestFixture();
28
 
29
protected:
30
    void update_ip(uint16_t newip);
31
    void update_cs();
32
    void propagate();
33
    bool updated;
34
    uint16_t updated_ip;
35
};
36
 
37
CSIPSyncTestFixture::CSIPSyncTestFixture() : updated(false), updated_ip(true)
38
{
39
    reset();
40
 
41
    periodic(ClockCapture, [&] {
42
        if (this->dut.update_out) {
43
            this->updated = true;
44
            this->updated_ip = this->dut.ip_out;
45
        }
46
    });
47
}
48
 
49
void CSIPSyncTestFixture::update_ip(uint16_t newip)
50
{
51
    after_n_cycles(0, [&] {
52
        this->dut.new_ip = newip;
53
        this->dut.ip_update = 1;
54
        after_n_cycles(1, [&] {
55
            this->dut.ip_update = 0;
56
            this->dut.new_ip = 0;
57
        });
58
    });
59
    cycle(10);
60
}
61
 
62
void CSIPSyncTestFixture::update_cs()
63
{
64
    after_n_cycles(0, [&] {
65
        this->dut.cs_update = 1;
66
        after_n_cycles(1, [&] { this->dut.cs_update = 0; });
67
    });
68
    cycle(10);
69
}
70
 
71
void CSIPSyncTestFixture::propagate()
72
{
73
    after_n_cycles(0, [&] {
74
        this->dut.propagate = 1;
75
        after_n_cycles(1, [&] { this->dut.propagate = 0; });
76
    });
77
    cycle();
78
}
79
 
80
TEST_F(CSIPSyncTestFixture, NoChangeNoUpdate)
81
{
82
    propagate();
83
 
84
    ASSERT_FALSE(updated);
85
}
86
 
87
TEST_F(CSIPSyncTestFixture, IPPropagateDelayed)
88
{
89
    update_ip(0x1234);
90
    propagate();
91
 
92
    EXPECT_TRUE(updated);
93
    EXPECT_EQ(updated_ip, 0x1234);
94
 
95
    cycle();
96
}
97
 
98
TEST_F(CSIPSyncTestFixture, CSPropagateDelayed)
99
{
100
    update_cs();
101
    propagate();
102
 
103
    EXPECT_TRUE(updated);
104
    EXPECT_EQ(updated_ip, 0);
105
 
106
    cycle();
107
}
108
 
109
TEST_F(CSIPSyncTestFixture, SimultaneousUpdatePropagateDoesntLatch)
110
{
111
    after_n_cycles(0, [&] {
112
        this->dut.new_ip = 0xf00f;
113
        this->dut.propagate = 1;
114
        this->dut.ip_update = 1;
115
        after_n_cycles(1, [&] {
116
            this->dut.propagate = 0;
117
            this->dut.ip_in = 0x1001;
118
            this->dut.new_ip = 0x1001;
119
        });
120
    });
121
    cycle(1);
122
    ASSERT_EQ(this->dut.ip_out, 0xf00f);
123
 
124
    propagate();
125
    ASSERT_EQ(this->dut.ip_out, 0x1001);
126
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.