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

Subversion Repositories fwrisc

[/] [fwrisc/] [trunk/] [ve/] [fwrisc/] [tests/] [fwrisc_zephyr_tests.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mballance
/*
2
 * fwrisc_zephyr_tests.cpp
3
 *
4
 * Copyright 2018 Matthew Ballance
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in
8
 * compliance with the License.  You may obtain a copy of
9
 * the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in
14
 * writing, software distributed under the License is
15
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
16
 * CONDITIONS OF ANY KIND, either express or implied.  See
17
 * the License for the specific language governing
18
 * permissions and limitations under the License.
19
 *
20
 *
21
 *  Created on: Nov 16, 2018
22
 *      Author: ballance
23
 */
24
 
25
#include "fwrisc_zephyr_tests.h"
26
#include "ElfSymtabReader.h"
27
#include "GoogletestVlCmdlineProcessor.h"
28
#include <stdio.h>
29
 
30
fwrisc_zephyr_tests::fwrisc_zephyr_tests() : fwrisc_ctest_base(10000000) {
31
        m_ram_console = 0;
32
        m_raw_console = false;
33
        m_halt_addr = 0; // Don't halt
34
        m_msg_listener = [&](const std::string &msg) { }; // Empty
35
}
36
 
37
fwrisc_zephyr_tests::~fwrisc_zephyr_tests() {
38
        // TODO Auto-generated destructor stub
39
}
40
 
41
void fwrisc_zephyr_tests::SetUp() {
42
        fwrisc_ctest_base::SetUp();
43
 
44
        m_ram_console = m_symtab.find_sym("ram_console").st_value;
45
        // _Fault is called when the main function returns
46
        m_halt_addr = m_symtab.find_sym("_Fault").st_value;
47
        filter_func("char_out");
48
        filter_func("ram_console_out");
49
        filter_func("__udivsi3");
50
        filter_func("__umodsi3");
51
        filter_func("__mulsi3");
52
        fprintf(stdout, "Ram Console: 0x%08x\n", m_ram_console);
53
}
54
 
55
void fwrisc_zephyr_tests::regwrite(uint32_t raddr, uint32_t rdata) {
56
 
57
}
58
 
59
void fwrisc_zephyr_tests::exec(uint32_t addr, uint32_t instr) {
60
        fwrisc_ctest_base::exec(addr, instr);
61
//      std::string sym;
62
//      if (m_trace_funcs) {
63
//              if (m_symtab.find_sym(addr, sym)) {
64
//                      fprintf(stdout, "EXEC: %s (0x%08x)\n", sym.c_str(), addr);
65
//              }
66
//      }
67
//      if (m_trace_instr) {
68
//              fprintf(stdout, "EXEC: 0x%08x\n", addr);
69
//      }
70
//
71
//      if (addr == m_halt_addr) {
72
//              fprintf(stdout, "hit halt address 0x%08x\n", m_halt_addr);
73
//              m_end_of_test = true;
74
//              dropObjection(this);
75
//      }
76
}
77
 
78
void fwrisc_zephyr_tests::memwrite(uint32_t addr, uint8_t mask, uint32_t data) {
79
//      fprintf(stdout, "WRITE: 0x%08x\n", addr);
80
        if (addr >= m_ram_console && addr < (m_ram_console+1024)) {
81
                char ch;
82
                switch (mask) {
83
                case 1: ch = ((data >> 0) & 0xFF); break;
84
                case 2: ch = ((data >> 8) & 0xFF); break;
85
                case 4: ch = ((data >> 16) & 0xFF); break;
86
                case 8: ch = ((data >> 24) & 0xFF); break;
87
                }
88
 
89
                if (ch) {
90
                        if (m_raw_console) {
91
                                fputc(ch, stdout);
92
                                fflush(stdout);
93
                        }
94
                        if (ch == '\n') {
95
                                if (!m_raw_console) {
96
                                        fputs("# ", stdout);
97
                                        fputs(m_buffer.c_str(), stdout);
98
                                        fputs("\n", stdout);
99
                                        fflush(stdout);
100
                                }
101
 
102
                                m_msg_listener(m_buffer);
103
                                m_console_out.push_back(m_buffer);
104
                                m_buffer.clear();
105
                        } else {
106
                                m_buffer.push_back(ch);
107
                        }
108
                }
109
        }
110
}
111
 
112
void fwrisc_zephyr_tests::check(const char *exp[], uint32_t exp_sz) {
113
        ASSERT_EQ(m_end_of_test, true);
114
 
115
        for (uint32_t i=0; i<exp_sz; i++) {
116
                const char *msg = exp[i];
117
                bool found = false;
118
 
119
                for (std::vector<std::string>::const_iterator it=m_console_out.begin();
120
                                it!=m_console_out.end(); it++) {
121
                        std::string line = (*it);
122
 
123
                        if (line == msg) {
124
                                found = true;
125
                                break;
126
                        }
127
                }
128
 
129
                if (!found) {
130
                        fprintf(stdout, "Error: Failed to find msg \"%s\"\n", msg);
131
                }
132
                ASSERT_EQ(true, found);
133
        }
134
}
135
 
136
TEST_F(fwrisc_zephyr_tests, dhrystone) {
137
        const char *exp[] = {
138
                        "Hello World! fwrisc_sim"
139
        };
140
 
141
        m_msg_listener = [&](const std::string &msg) {
142
                if (msg == "Hello World! fwrisc_sim") {
143
                        m_end_of_test = true;
144
                        dropObjection(this);
145
                }
146
        };
147
 
148
        run(100000000);
149
 
150
        check(exp, sizeof(exp)/sizeof(const char *));
151
}
152
 
153
TEST_F(fwrisc_zephyr_tests, hello_world) {
154
        const char *exp[] = {
155
                        "Hello World! fwrisc_sim"
156
        };
157
 
158
        m_msg_listener = [&](const std::string &msg) {
159
                if (msg == "Hello World! fwrisc_sim") {
160
                        m_end_of_test = true;
161
                        dropObjection(this);
162
                }
163
        };
164
 
165
        run(100000);
166
 
167
        check(exp, sizeof(exp)/sizeof(const char *));
168
}
169
 
170
TEST_F(fwrisc_zephyr_tests, synchronization) {
171
        int threadB_count = 0;
172
        const char *exp[] = {
173
                        "threadA: Hello World from fwrisc_sim!",
174
                        "threadB: Hello World from fwrisc_sim!"
175
        };
176
 
177
        m_msg_listener = [&](const std::string &msg) {
178
                if (msg.substr(0, strlen("threadB")) == "threadB") {
179
                        threadB_count++;
180
                }
181
 
182
                if (threadB_count >= 2) {
183
                        m_end_of_test = true;
184
                        dropObjection(this);
185
                }
186
        };
187
 
188
        run(100000000);
189
 
190
        check(exp, sizeof(exp)/sizeof(const char *));
191
}
192
 
193
TEST_F(fwrisc_zephyr_tests, philosophers) {
194
        const char *exp[] = {
195
                        "An implementation of a solution to the Dining Philosophers"
196
        };
197
 
198
        m_raw_console = true;
199
 
200
        run(100000000);
201
 
202
        check(exp, sizeof(exp)/sizeof(const char *));
203
}
204
 
205
TEST_F(fwrisc_zephyr_tests, coretest) {
206
        run(100000);
207
 
208
        ASSERT_EQ(m_end_of_test, true);
209
}
210
 

powered by: WebSVN 2.1.0

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