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

Subversion Repositories fwrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mballance
/*
2
 * riscv_compliance_tests.cpp
3
 *
4
 *
5
 * Copyright 2018 Matthew Ballance
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in
9
 * compliance with the License.  You may obtain a copy of
10
 * the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in
15
 * writing, software distributed under the License is
16
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17
 * CONDITIONS OF ANY KIND, either express or implied.  See
18
 * the License for the specific language governing
19
 * permissions and limitations under the License.
20
 *
21
 *  Created on: Oct 24, 2018
22
 *      Author: ballance
23
 */
24
 
25
#include "riscv_compliance_tests.h"
26
#include "GoogletestVlCmdlineProcessor.h"
27
#include "ElfSymtabReader.h"
28
#include <stdlib.h>
29
#include <elf.h>
30
 
31
void riscv_compliance_tests::SetUp() {
32
        fprintf(stdout, "SetUp\n");
33
        fwrisc_instr_tests::SetUp();
34
 
35
        raiseObjection(this);
36
}
37
 
38
void riscv_compliance_tests::memwrite(uint32_t addr, uint8_t mask, uint32_t data) {
39
        if (addr == 0x80001000) {
40
                fprintf(stdout, "Note: end of test\n");
41
                dropObjection(this);
42
        } else {
43
                fwrisc_instr_tests::memwrite(addr, mask, data);
44
        }
45
}
46
 
47
void riscv_compliance_tests::runtest() {
48
        run();
49
        check();
50
}
51
 
52
void riscv_compliance_tests::check() {
53
        const GoogletestVlCmdlineProcessor &clp = GoogletestVlCmdlineProcessor::instance();
54
        FILE *ref_file_fp, *elf_file_fp;
55
        std::string elf_file, ref_file;
56
        char line[256];
57
        uint32_t addr=0x2030/4, exp, actual;
58
        uint32_t begin_signature=0, end_signature=0;
59
        char *p;
60
 
61
        clp.get_plusarg_value("+REF_FILE", ref_file);
62
        clp.get_plusarg_value("+SW_IMAGE", elf_file);
63
 
64
        ElfSymtabReader symtab;
65
 
66
        if (!symtab.read(elf_file)) {
67
                fprintf(stdout, "Error: failed to read ELF symbol table\n");
68
        }
69
 
70
        begin_signature = symtab.find_sym("begin_signature").st_value;
71
        end_signature = symtab.find_sym("end_signature").st_value;
72
 
73
 
74
        ASSERT_NE(0, begin_signature);
75
        ASSERT_NE(0, end_signature);
76
 
77
 
78
        fprintf(stdout, "REF_FILE=%s\n", ref_file.c_str());
79
 
80
        ref_file_fp = fopen(ref_file.c_str(), "rb");
81
        ASSERT_TRUE(ref_file_fp);
82
 
83
        addr = (begin_signature & 0xFFFF)/4;
84
        while (fgets(line, sizeof(line), ref_file_fp)) {
85
                char *p = line + strlen(line) - 2;
86
 
87
                while (p > line) {
88
                        char *old_p = p;
89
                        p -= 8;
90
                        *old_p = 0;
91
 
92
                        exp = strtoul(p, 0, 16);
93
 
94
                        actual = m_mem[addr].first;
95
 
96
                        fprintf(stdout, "0x%08x: exp=0x%08x actual=0x%08x\n", 4*addr, exp, actual);
97
                        ASSERT_EQ(exp, actual);
98
 
99
                        addr++;
100
                }
101
        }
102
}
103
 
104
TEST_F(riscv_compliance_tests, coretest) {
105
        runtest();
106
}
107
 
108
TEST_F(riscv_compliance_tests, smoke2) {
109
        fprintf(stdout, "smoketest2\n");
110
        run();
111
}
112
 

powered by: WebSVN 2.1.0

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