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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [module/] [memory/] [test/] [TestWriteNoCache.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.Input;
31
import ao486.module.memory.Listener;
32
import ao486.module.memory.Output;
33
import ao486.module.memory.Test;
34
import ao486.module.memory.WriteListener;
35
import java.util.HashMap;
36
import java.util.LinkedList;
37
import java.util.Random;
38
 
39
public class TestWriteNoCache extends Test implements Listener, WriteListener.WriteInterface {
40
 
41
    void go(long seed) throws Exception {
42
        random = new Random(seed);
43
 
44
        avalon = new AvalonListener(random, this);
45
        write  = new WriteListener();
46
 
47
        expected_values = new HashMap<>();
48
 
49
        finish_cycle = 0;
50
        counter = 1;
51
 
52
        address = (counter << 5) + random.nextInt(16);
53
        length  = 1 + random.nextInt(4);
54
        value   = random.nextLong();
55
        value &= 0xFFFFFFFF;
56
 
57
        write.write(4, 0, address, length, false, false, value, this);
58
 
59
        //----------
60
 
61
        LinkedList<Listener> listeners = new LinkedList<>();
62
        listeners.add(avalon);
63
        listeners.add(write);
64
        listeners.add(this);
65
 
66
        run_simulation(listeners);
67
    }
68
 
69
    @Override
70
    public void written(int cycle) throws Exception {
71
 
72
        //check written value
73
        long key_address = address | (((long)length) << 32);
74
        expected_values.put(key_address, value);
75
        //System.out.printf("Adding: address: %x, length: %d, value: %x\n", address, length, value);
76
        counter++;
77
 
78
        if(counter >= 1000) {
79
            finish_cycle = cycle+20;
80
            return;
81
        }
82
 
83
        address = (counter << 5) + random.nextInt(16);
84
        length  = 1 + random.nextInt(4);
85
        value   = random.nextLong();
86
        value &= 0xFFFFFFFF;
87
 
88
        write.write(cycle+1, 0, address, length, false, false, value, this);
89
    }
90
 
91
    @Override
92
    public void write_page_fault(int cycle, long cr2, long error_code) throws Exception {
93
        throw new Exception("write page fault: " + cycle + ", cr2: " + cr2 + ", error_code: " + error_code);
94
    }
95
 
96
    @Override
97
    public void write_ac_fault(int cycle) throws Exception {
98
        throw new Exception("write ac fault.");
99
    }
100
 
101
    @Override
102
    public void set_input(int cycle, Input input) throws Exception {
103
        if(cycle >= finish_cycle && finish_cycle > 0) {
104
            input.finished = true;
105
 
106
            //check written values
107
            for(long key : expected_values.keySet()) {
108
                long local_address = key & 0xFFFFFFFFL;
109
                long local_length  = (key >> 32);
110
                long local_value   = expected_values.get(key);
111
 
112
                for(int i=0; i<local_length; i++) {
113
                    long data = avalon.get_memory(local_address + i);
114
                    if((local_value & 0xFF) != (data & 0xFF)) {
115
                        throw new Exception(String.format("Value mismatch: local_addr: %x, local_length: %d, i: %d, data: %x\n", local_address, local_length, i, data));
116
                    }
117
                    local_value >>= 8;
118
                }
119
            }
120
        }
121
    }
122
 
123
    @Override
124
    public void get_output(int cycle, Output output) throws Exception {
125
    }
126
 
127
    long address;
128
    int  length;
129
    long value;
130
 
131
    int counter;
132
    Random random;
133
 
134
    int finish_cycle;
135
 
136
    HashMap<Long, Long> expected_values; //map address -> value
137
 
138
    AvalonListener avalon;
139
    WriteListener  write;
140
 
141
    //-------------
142
 
143
    public static void main(String args[]) throws Exception {
144
        TestWriteNoCache test1 = new TestWriteNoCache();
145
 
146
        for(int i=0; i<10; i++) {
147
            test1.go(i);
148
 
149
            System.out.println("Run " + i + " complete.");
150
        }
151
 
152
        System.out.println("[Main] thread end.");
153
    }
154
}

powered by: WebSVN 2.1.0

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