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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [module/] [memory/] [test/] [TestWriteCache.java] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/*
2
 * Copyright (c) 2014, Aleksander Osman
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * * Redistributions of source code must retain the above copyright notice, this
9
 *   list of conditions and the following disclaimer.
10
 *
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 *   this list of conditions and the following disclaimer in the documentation
13
 *   and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
 
27
package ao486.module.memory.test;
28
 
29
import ao486.module.memory.AvalonListener;
30
import ao486.module.memory.GlobalListener;
31
import ao486.module.memory.Input;
32
import ao486.module.memory.Listener;
33
import ao486.module.memory.Output;
34
import ao486.module.memory.Test;
35
import ao486.module.memory.WriteListener;
36
import java.util.HashMap;
37
import java.util.LinkedList;
38
import java.util.Random;
39
 
40
public class TestWriteCache extends Test implements Listener, WriteListener.WriteInterface {
41
    void go(long seed) throws Exception {
42
        random = new Random(seed);
43
 
44
        avalon = new AvalonListener(random, this);
45
        write  = new WriteListener();
46
        global = new GlobalListener();
47
 
48
        global.set(false, false, false, false, random.nextBoolean(), false, 0xABCDE000, false, false, false, false);
49
 
50
        expected_values = new HashMap<>();
51
 
52
        finish_cycle = 0;
53
        counter = 1;
54
 
55
        address_base = random.nextLong();
56
        address_base &= 0xFFFFFFF0L;
57
 
58
        address = address_base + random.nextInt(16);
59
        length  = 1 + random.nextInt(4);
60
        value   = random.nextLong();
61
        value &= 0xFFFFFFFF;
62
 
63
        write.write(4, 0, address, length, false, false, value, this);
64
 
65
        //----------
66
 
67
        LinkedList<Listener> listeners = new LinkedList<>();
68
        listeners.add(avalon);
69
        listeners.add(write);
70
        listeners.add(global);
71
        listeners.add(this);
72
 
73
        run_simulation(listeners);
74
    }
75
 
76
    @Override
77
    public void written(int cycle) throws Exception {
78
 
79
        for(int i=0; i<length; i++) {
80
            expected_values.put(address+i, value & 0xFF);
81
            value >>= 8;
82
        }
83
 
84
        counter++;
85
 
86
        if(counter >= 2000) {
87
            finish_cycle = cycle+20;
88
            return;
89
        }
90
 
91
        address = address_base + random.nextInt(16);
92
        length  = 1 + random.nextInt(4);
93
        value   = random.nextLong();
94
        value &= 0xFFFFFFFF;
95
 
96
        write.write(cycle+1, 0, address, length, false, false, value, this);
97
    }
98
 
99
    @Override
100
    public void write_page_fault(int cycle, long cr2, long error_code) throws Exception {
101
        throw new Exception("write page fault: " + cycle + ", cr2: " + cr2 + ", error_code: " + error_code);
102
    }
103
 
104
    @Override
105
    public void write_ac_fault(int cycle) throws Exception {
106
        throw new Exception("write ac fault.");
107
    }
108
 
109
    @Override
110
    public void set_input(int cycle, Input input) throws Exception {
111
        if(cycle >= finish_cycle && finish_cycle > 0) {
112
            input.finished = true;
113
 
114
            if(global.cr0_nw) {
115
                //check written values
116
                for(long local_address : expected_values.keySet()) {
117
                    long memory_data = avalon.get_memory(local_address);
118
                    long local_data = expected_values.get(local_address);
119
 
120
                    if((local_data & 0xFF) != (memory_data & 0xFF)) {
121
                        throw new Exception(String.format("Value mismatch: local_address: %x, memory_data: %x, local_data: %x\n", local_address, memory_data, local_data));
122
                    }
123
                }
124
            }
125
 
126
        }
127
    }
128
 
129
    @Override
130
    public void get_output(int cycle, Output output) throws Exception {
131
    }
132
 
133
    @Override
134
    public void avalon_read(int cycle, long read_address) throws Exception {
135
        if(cycle >= 350 && (read_address & 0xFFFFFFF0) == address_base) {
136
            if(address_base_read) throw new Exception("Reading double address_base_read.");
137
            address_base_read = true;
138
        }
139
        if(cycle >= 350 && (read_address & 0xFFFFFFF0) == address_base+1) {
140
            if(address_base_plus_1_read) throw new Exception("Reading double address_base_plus_1_read.");
141
            address_base_plus_1_read = true;
142
        }
143
        if(((read_address & 0xFFFFFFF0) != address_base) && ((read_address & 0xFFFFFFF0) == address_base+1)) throw new Exception("Unknown address read.");
144
    }
145
 
146
    long address_base;
147
    long address;
148
    int  length;
149
    long value;
150
 
151
    boolean address_base_read;
152
    boolean address_base_plus_1_read;
153
 
154
    int counter;
155
    Random random;
156
 
157
    int finish_cycle;
158
 
159
    HashMap<Long, Long> expected_values; //map address -> value
160
 
161
    AvalonListener avalon;
162
    WriteListener  write;
163
    GlobalListener global;
164
 
165
    //-------------
166
 
167
    public static void main(String args[]) throws Exception {
168
        TestWriteCache test1 = new TestWriteCache();
169
 
170
        for(int i=0; i<20; i++) {
171
            test1.go(i*i);
172
 
173
            System.out.println("Run " + i + " complete.");
174
        }
175
 
176
        System.out.println("[Main] thread end.");
177
    }
178
}

powered by: WebSVN 2.1.0

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