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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [tests/] [rtl/] [TestSegmentRegisterFile.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 <VSegmentRegisterFile.h>
20
 
21
#include "VerilogTestbench.h"
22
#include "RTLCPU.h"
23
 
24
class SegmentRegisterFileTestFixture
25
    : public VerilogTestbench<VSegmentRegisterFile>,
26
      public ::testing::Test
27
{
28
public:
29
    void write_sr(uint8_t sr, uint16_t v);
30
    void trigger_read_sr(uint8_t sr);
31
    uint16_t get_sr() const;
32
};
33
 
34
void SegmentRegisterFileTestFixture::write_sr(uint8_t sr, uint16_t v)
35
{
36
    dut.wr_sel = sr;
37
    dut.wr_val = v;
38
    dut.wr_en = 1;
39
    cycle();
40
    dut.wr_en = 0;
41
}
42
 
43
void SegmentRegisterFileTestFixture::trigger_read_sr(uint8_t sr)
44
{
45
    dut.rd_sel = sr;
46
    cycle();
47
}
48
 
49
uint16_t SegmentRegisterFileTestFixture::get_sr() const
50
{
51
    return dut.rd_val;
52
}
53
 
54
TEST_F(SegmentRegisterFileTestFixture, segment_read_write)
55
{
56
    for (auto r = 0; r < 4; ++r)
57
        write_sr(r, ~r);
58
 
59
    for (auto r = 0; r < 4; ++r) {
60
        trigger_read_sr(r);
61
        EXPECT_EQ(~r & 0xffff, get_sr());
62
    }
63
}
64
 
65
TEST_F(SegmentRegisterFileTestFixture, sr_read_during_write)
66
{
67
    write_sr(0, 0x1234);
68
    ASSERT_EQ(0x1234, get_sr());
69
}
70
 
71
TEST_F(SegmentRegisterFileTestFixture, cs_output_during_write)
72
{
73
    write_sr(1, 0xf00f);
74
    ASSERT_EQ(0xf00f, dut.cs);
75
}
76
 
77
class CoreFixture : public RTLCPU<verilator_debug_enabled>,
78
                    public ::testing::Test
79
{
80
public:
81
    CoreFixture() : RTLCPU(current_test_name())
82
    {
83
    }
84
};
85
TEST_F(CoreFixture, SegmentRegisterFileReset)
86
{
87
    for (auto r = static_cast<int>(ES); r <= static_cast<int>(DS); ++r) {
88
        write_reg(static_cast<GPR>(r), ~r);
89
        EXPECT_EQ(read_reg(static_cast<GPR>(r)), static_cast<uint16_t>(~r));
90
    }
91
 
92
    reset();
93
 
94
    for (auto r = static_cast<int>(ES); r <= static_cast<int>(DS); ++r)
95
        EXPECT_EQ(read_reg(static_cast<GPR>(r)),
96
                  static_cast<GPR>(r) == CS ? 0xffff : 0);
97
}

powered by: WebSVN 2.1.0

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