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

Subversion Repositories ao486

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

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.ReadListener;
34
import ao486.module.memory.Test;
35
import java.util.LinkedList;
36
import java.util.Random;
37
 
38
public class TestReadNoCache extends Test implements Listener, ReadListener.ReadInterface {
39
 
40
    void go(long seed) throws Exception {
41
        random = new Random(seed);
42
 
43
        avalon = new AvalonListener(random, this);
44
        read   = new ReadListener();
45
 
46
        finish_cycle = 0;
47
        counter = 1;
48
 
49
        long address = (counter << 4) + random.nextInt(16);
50
        length  = 1 + random.nextInt(8);
51
        value   = random.nextLong();
52
        avalon.set_memory(address, value, length);
53
 
54
        read.read(4, 0, address, length, false, false, this);
55
 
56
        //----------
57
 
58
        LinkedList<Listener> listeners = new LinkedList<>();
59
        listeners.add(avalon);
60
        listeners.add(read);
61
        listeners.add(this);
62
 
63
        run_simulation(listeners);
64
    }
65
    @Override
66
    public void read(int cycle, long data) throws Exception {
67
        //System.out.printf("Read value: %x\n", data);
68
 
69
        for(int i=0; i<length; i++) {
70
            if((value & 0xFF) != (data & 0xFF)) throw new Exception(String.format("Value mismatch: value = %x, data: %x", value, data));
71
 
72
            value >>= 8;
73
            data >>= 8;
74
        }
75
 
76
        counter++;
77
 
78
        if(counter >= 100) {
79
            finish_cycle = cycle+1;
80
            return;
81
        }
82
 
83
        long address = (counter << 4) + random.nextInt(16);
84
        length  = 1 + random.nextInt(8);
85
        value   = random.nextLong();
86
        avalon.set_memory(address, value, length);
87
 
88
        read.read(cycle+1, 0, address, length, false, false, this);
89
    }
90
 
91
    @Override
92
    public void read_page_fault(int cycle, long cr2, long error_code) throws Exception {
93
        throw new Exception("read_page_fault: cr2: " + cr2 + ", error_code: " + error_code);
94
    }
95
 
96
    @Override
97
    public void read_ac_fault(int cycle) throws Exception {
98
        throw new Exception("read_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) input.finished = true;
104
    }
105
 
106
    @Override
107
    public void get_output(int cycle, Output output) throws Exception {
108
    }
109
 
110
    int  length;
111
    long value;
112
 
113
    int counter;
114
    Random random;
115
 
116
    int finish_cycle;
117
 
118
    AvalonListener avalon;
119
    ReadListener   read;
120
 
121
    //-------------
122
 
123
    public static void main(String args[]) throws Exception {
124
 
125
        TestReadNoCache test1 = new TestReadNoCache();
126
 
127
        for(int i=0; i<100; i++) {
128
            test1.go(i);
129
 
130
            System.out.println("Run " + i + " complete.");
131
        }
132
 
133
        System.out.println("[Main] thread end.");
134
    }
135
}

powered by: WebSVN 2.1.0

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