-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Script to generate signature from test ELFs #466
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c5c4985
Support ELF running with signature section dump
piotro888 8041a96
Support running with cocotb
piotro888 6c63e7a
fixes
piotro888 da912ca
Fix error reporting
piotro888 c4acb21
Fix segment loading
piotro888 dd1b762
Add RVTEST enviorment configuration
piotro888 11a9391
Merge branch 'master' into piotro888/riscof
piotro888 8901051
Merge branch 'master' into piotro888/riscof
piotro888 fdac4fd
Remove debug line
piotro888 202512b
Merge branch 'master' into piotro888/riscof
piotro888 14aa970
fix typing
piotro888 2dd30d5
Align instruction sections to ICache lane size
piotro888 23cf60c
Sync coreblocks env directory
piotro888 be074c4
Move align to utils, change align assignments
piotro888 3d24f88
Merge branch 'master' into piotro888/riscof
tilk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import asyncio | ||
import argparse | ||
import sys | ||
import os | ||
import subprocess | ||
from typing import Literal | ||
|
||
if __name__ == "__main__": | ||
parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
sys.path.insert(0, parent) | ||
|
||
import test.regression.signature # noqa: E402 | ||
from test.regression.pysim import PySimulation # noqa: E402 | ||
|
||
|
||
def run_with_cocotb(test_name: str, traces: bool, output: str) -> bool: | ||
arglist = [ | ||
"make", | ||
"-C", | ||
parent + "/" if parent else "" + "test/regression/cocotb", | ||
"-f", | ||
"signature.Makefile", | ||
"--no-print-directory", | ||
] | ||
|
||
if os.path.isfile(output): | ||
os.remove(output) | ||
|
||
arglist += [f"TESTNAME={test_name}"] | ||
arglist += [f"OUTPUT={output}"] | ||
|
||
if traces: | ||
arglist += ["TRACES=1"] | ||
|
||
subprocess.run(arglist) | ||
|
||
return os.path.isfile(output) # completed successfully if signature file was created | ||
|
||
|
||
def run_with_pysim(test_name: str, traces: bool, verbose: bool, output: str) -> bool: | ||
traces_file = None | ||
if traces: | ||
traces_file = os.path.basename(test_name) | ||
try: | ||
asyncio.run( | ||
test.regression.signature.run_test(PySimulation(verbose, traces_file=traces_file), test_name, output) | ||
) | ||
except RuntimeError as e: | ||
print("RuntimeError:", e) | ||
return False | ||
return True | ||
|
||
|
||
def run_test(test: str, backend: Literal["pysim", "cocotb"], traces: bool, verbose: bool, output: str) -> bool: | ||
if backend == "cocotb": | ||
return run_with_cocotb(test, traces, output) | ||
elif backend == "pysim": | ||
return run_with_pysim(test, traces, verbose, output) | ||
return False | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-t", "--trace", action="store_true", help="Dump waveforms") | ||
parser.add_argument("-v", "--verbose", action="store_true", help="Verbose output") | ||
parser.add_argument("-b", "--backend", default="pysim", choices=["cocotb", "pysim"], help="Simulation backend") | ||
parser.add_argument("-o", "--output", default=None, help="Selects output file to write test signature to") | ||
parser.add_argument("path") | ||
|
||
args = parser.parse_args() | ||
|
||
output = args.output if args.output else args.path + ".signature" | ||
|
||
success = run_test(args.path, args.backend, args.trace, args.verbose, output) | ||
if not success: | ||
print(f"{args.path}: Program execution failed") | ||
|
||
if output is not None: # create empty file on failure for checker scripts | ||
with open(output, "w"): | ||
pass | ||
|
||
sys.exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
OUTPUT_ARCH( "riscv" ) | ||
ENTRY(rvtest_entry_point) | ||
|
||
MEMORY | ||
{ | ||
text (rxai!w) : ORIGIN = 0x00000000, LENGTH = 2M | ||
data (wxa!ri) : ORIGIN = 0x10000000, LENGTH = 1M | ||
mmio (wa!rxi) : ORIGIN = 0x80000000, LENGTH = 1K | ||
signature (wa!rxi) : ORIGIN = 0x81000000, LENGTH = 16K | ||
|
||
} | ||
|
||
PHDRS | ||
{ | ||
text PT_LOAD; | ||
data_init PT_LOAD; | ||
data PT_NULL; | ||
mmio PT_LOAD; | ||
signature PT_LOAD; | ||
} | ||
|
||
SECTIONS | ||
{ | ||
.text.init : { *(.text.init) } >text AT>text :text | ||
. = ALIGN(0x1000); | ||
.text : { *(.text) } >text AT>text :text | ||
|
||
. = ALIGN(0x1000); | ||
.data : { *(.data) } >data AT>data :data_init | ||
.data.string : { *(.data.string)} >data AT>data :data_init | ||
.bss : { *(.bss) } >data AT>data :data | ||
|
||
. = ALIGN(0x1000); | ||
.hostmmio : { *(.hostmmio) } >mmio AT>mmio :mmio | ||
|
||
. = ALIGN(0x1000); | ||
.signature : { *(.signature) } >signature AT>signature :signature | ||
|
||
_end = .; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#ifndef _COMPLIANCE_MODEL_H | ||
#define _COMPLIANCE_MODEL_H | ||
#define RVMODEL_DATA_SECTION \ | ||
.pushsection .hostmmio,"aw",@progbits; \ | ||
.align 8; .global tohost; tohost: .dword 0; \ | ||
.align 8; .global fromhost; fromhost: .dword 0; \ | ||
.popsection; \ | ||
.align 8; .global begin_regstate; begin_regstate: \ | ||
.word 128; \ | ||
.align 8; .global end_regstate; end_regstate: \ | ||
.word 4; | ||
|
||
//RV_COMPLIANCE_HALT | ||
#define RVMODEL_HALT \ | ||
li x1, 1; \ | ||
write_tohost: \ | ||
sw x1, tohost, t5; \ | ||
j write_tohost; | ||
|
||
#define RVMODEL_BOOT | ||
|
||
//RV_COMPLIANCE_DATA_BEGIN | ||
#define RVMODEL_DATA_BEGIN \ | ||
RVMODEL_DATA_SECTION \ | ||
.pushsection .signature,"aw",@progbits; \ | ||
.align 2; \ | ||
.global begin_signature; begin_signature: | ||
|
||
//RV_COMPLIANCE_DATA_END | ||
#define RVMODEL_DATA_END \ | ||
.global end_signature; end_signature: \ | ||
.popsection; | ||
|
||
//RVTEST_IO_INIT | ||
#define RVMODEL_IO_INIT | ||
//RVTEST_IO_WRITE_STR | ||
#define RVMODEL_IO_WRITE_STR(_R, _STR) | ||
//RVTEST_IO_CHECK | ||
#define RVMODEL_IO_CHECK() | ||
//RVTEST_IO_ASSERT_GPR_EQ | ||
#define RVMODEL_IO_ASSERT_GPR_EQ(_S, _R, _I) | ||
//RVTEST_IO_ASSERT_SFPR_EQ | ||
#define RVMODEL_IO_ASSERT_SFPR_EQ(_F, _R, _I) | ||
//RVTEST_IO_ASSERT_DFPR_EQ | ||
#define RVMODEL_IO_ASSERT_DFPR_EQ(_D, _R, _I) | ||
|
||
// empty macros to supress warnings | ||
#define RVMODEL_SET_MSW_INT | ||
#define RVMODEL_CLEAR_MSW_INT | ||
#define RVMODEL_CLEAR_MTIMER_INT | ||
#define RVMODEL_CLEAR_MEXT_INT | ||
#define RVMODEL_CLR_MSW_INT | ||
#define RVMODEL_CLR_MTIMER_INT | ||
#define RVMODEL_CLR_MEXT_INT | ||
#define RVMODEL_SET_SSW_INT | ||
#define RVMODEL_CLR_SSW_INT | ||
#define RVMODEL_CLR_STIMER_INT | ||
#define RVMODEL_CLR_SEXT_INT | ||
#define RVMODEL_SET_VSW_INT | ||
#define RVMODEL_CLR_VSW_INT | ||
#define RVMODEL_CLR_VTIMER_INT | ||
#define RVMODEL_CLR_VEXT_INT | ||
|
||
#endif // _COMPLIANCE_MODEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Makefile | ||
|
||
# defaults | ||
SIM ?= verilator | ||
TOPLEVEL_LANG ?= verilog | ||
|
||
VERILOG_SOURCES += $(PWD)/../../../core.v | ||
# use VHDL_SOURCES for VHDL files | ||
|
||
# TOPLEVEL is the name of the toplevel module in your Verilog or VHDL file | ||
TOPLEVEL = top | ||
|
||
# MODULE is the basename of the Python test file | ||
MODULE = signature_entrypoint | ||
|
||
SIM_BUILD = build/signature | ||
|
||
# Yosys/Amaranth borkedness workaround | ||
ifeq ($(SIM),verilator) | ||
EXTRA_ARGS += -Wno-CASEINCOMPLETE -Wno-CASEOVERLAP -Wno-WIDTHEXPAND -Wno-WIDTHTRUNC | ||
endif | ||
|
||
ifeq ($(TRACES),1) | ||
EXTRA_ARGS += --trace-fst --trace-structs | ||
endif | ||
|
||
# include cocotb's make rules to take care of the simulator setup | ||
include $(shell cocotb-config --makefiles)/Makefile.sim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
import sys | ||
import cocotb | ||
from pathlib import Path | ||
|
||
top_dir = Path(__file__).parent.parent.parent.parent | ||
sys.path.insert(0, str(top_dir)) | ||
|
||
from test.regression.cocotb import CocotbSimulation # noqa: E402 | ||
from test.regression.signature import run_test # noqa: E402 | ||
|
||
|
||
@cocotb.test() | ||
async def do_test(dut): | ||
cocotb.logging.getLogger().setLevel(cocotb.logging.INFO) | ||
|
||
test_name = os.environ["TESTNAME"] | ||
if test_name is None: | ||
raise RuntimeError("No ELF file provided") | ||
|
||
output = os.environ["OUTPUT"] | ||
if output is None: | ||
output = test_name + ".signature" | ||
|
||
await run_test(CocotbSimulation(dut), test_name, output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
os.path.join()
?