|
| 1 | + |
| 2 | +== Architectural Functional Coverage |
| 3 | + |
| 4 | +In principle, a test plan could simply list a set of features to test, and a set of tests that exercise these features. Experienced verification engineers have learned that tests often have bugs and don't exercise the feature that the author intended. Many of these bugs can be caught if a different engineer independently writes functional coverpoints that measure whether the tests exercised the features. |
| 5 | + |
| 6 | +This Certification Test Plan focuses on whether a DUT implements all of the architectural features of a profile. Architectural features are those that are directly visible to the programmer, especially those defined in the unprivileged and privileged ISA specifications. |
| 7 | + |
| 8 | +[NOTE] |
| 9 | +==== |
| 10 | +Later phases of certification tests may add ratified architectural features outside the ISA spec, such as IOMMU, debug, or AIA. |
| 11 | +==== |
| 12 | + |
| 13 | +_Certification_ differs from _design verification_ in that it does not systematically test microarchitectural features. Design verification must be aware of DUT-specific features such as the pipeline design. For example, DV should test design-specific interactions of interrupt arrival time, pipeline hazards, multicycle instructions, MMU, and memory system. Design verification also should test tricky implementation issues, such as hard floating-point rounding cases. |
| 14 | + |
| 15 | +This plan uses the term _Architectural Functional Coverage_ to describe the functional coverpoints required for certification. In contrast, full design verification also has _Microarchitectural Functional Coverage_. |
| 16 | + |
| 17 | +_Functional coverage_ also differs from _code coverage_, which measures whether the test suite exercises all of the lines of code in the RTL. Each of these detects different types of bugs. Code coverage is part of DV but not certification. |
| 18 | + |
| 19 | +Architectural functional coverage requires a way to measure the architectural state of the machine after each instruction. The https://github.com/riscv-verification/RVVI[RISC-V Verification Interface] (RVVI) provides a standard way to observe this state in the DUT. This document defines Extended RVVI with additional signals to facilitate testing virtual memory. |
| 20 | + |
| 21 | +*** links to unpriv and priv specs |
| 22 | + |
| 23 | + |
| 24 | +=== Extended RVVI |
| 25 | + |
| 26 | +As compared to the base RVVI, Extended RVVI adds the following signals: |
| 27 | + |
| 28 | +[[t-extendedrvvi]] |
| 29 | +.Extended RVVI Signals |
| 30 | +[options=header] |
| 31 | +[cols="1, 1, 4" options=header] |
| 32 | +[%AUTOWIDTH] |
| 33 | +|=== |
| 34 | +|Signal|Width|Description |
| 35 | +|virt_adr_i|XLEN|Virtual address of instruction |
| 36 | +|virt_adr_d|XLEN|Virtual address of data accessed by instruction |
| 37 | +|phys_adr_i|PA_BITS|Physical address of instruction |
| 38 | +|phys_adr_d|PA_BITS|Physical address of data accessed by instruction |
| 39 | +|pte_i|XLEN|Instruction page table entry |
| 40 | +|pte_d|XLEN|Data page table entry |
| 41 | +|ppn_i|PPN_BITS|Instruction physical page number |
| 42 | +|ppn_d|PPN_BITS|Data physical page number |
| 43 | +|page_type_i|2|Instruction page type ***explain |
| 44 | +|page_type_d|2|Data page type |
| 45 | +|read_access|1|Instruction reads data (loads, AMOs, ***CMO) |
| 46 | +|write_access|1|Instruction writes data (stores, AMO, ***cbo.zero) |
| 47 | +|execute_access|1|***define - is this jumps? when asserted, and does it only affect data accesses? |
| 48 | +|=== |
| 49 | + |
| 50 | +*** PA_BITS |
| 51 | +PPN_BITS = PA_BITS - 12 |
| 52 | +*** why do we need ppn when we have phys_addr? Why not derive locally? |
| 53 | + |
| 54 | +*** do we need to add guest physical address? Such as |
| 55 | + |
| 56 | +* gpa_adr_i |
| 57 | +* gpa_adr_d |
| 58 | + |
| 59 | +maybe guest page table entries? |
| 60 | + |
| 61 | +=== riscvISACOV Signals |
| 62 | + |
| 63 | +Coverpoints are described using the open https://github.com/riscv-verification/riscvISACOV[riscvISACOV] framework. |
| 64 | + |
| 65 | +The framework collects data coming across the RVVI interface and presents it with `ins.current` and `ins.prev` data structures to allow easy access to the architectural state at the end of the current and previous instructions. For example, `ins.current.rs1` is the source register for the current instruction, and `ins.current.rd_val` is the value written to the destination register by the current instruction. |
| 66 | + |
| 67 | +[NOTE] |
| 68 | +==== |
| 69 | +Most coverpoints use `ins.current`, to measure architectural state at the end of the instruction. However, some privileged coverpoints need to know the privilege mode or values of CSRs at the start of the instruction and thus use `ins.prev`. |
| 70 | +==== |
| 71 | + |
| 72 | +The available fields are given in fcov/coverage/RISCV_coverage_rvvi.svh. Most commonly used fields are summarized in <<t-riscvISACOV>>. Other fields include floating-point and vector register IDs and values, MMU extended RVVI signals, vector type information, and pending interrupts. |
| 73 | + |
| 74 | +[[t-riscvISACOV]] |
| 75 | +.riscvISACOV Signals for Coverpoints |
| 76 | +[options=header] |
| 77 | +[cols="1, 1, 4, 2" options=header] |
| 78 | +[%AUTOWIDTH] |
| 79 | +|=== |
| 80 | +|Signal|Width|Description|Example |
| 81 | +|insn|ILEN|Instruction bit pattern|*** add x10, x11, x12 |
| 82 | +|inst_name|string|Instruction name|add |
| 83 | +|disass|string|Disassembled instruction|`add x10, x11, x12` |
| 84 | +|trap|1|Instruction trapped rather than retiring|0 |
| 85 | +|mode|2|Privilege mode 11 = machine, 01 = supervisor, 00 = user|11 |
| 86 | +|pc_rdata|XLEN|PC of current instruction|0x80000000 |
| 87 | +|pc_wdata|XLEN|PC of next instruction|0x80000004 |
| 88 | +|rs1|5|Source register 1 ID|11 |
| 89 | +|rs2|5|Source register 2 ID|12 |
| 90 | +|rd|5|Destination register ID|10 |
| 91 | +|rs1_val|XLEN|Source register 1 value|42 |
| 92 | +|rs2_val|XLEN|Source register 2 value|69 |
| 93 | +|rd_val|XLEN|Value written to destination register|111 |
| 94 | +|imm|XLEN|Value of immediate|100 |
| 95 | +|csr|XLEN x 4096|Value of CSRs| |
| 96 | +|=== |
| 97 | + |
| 98 | +*** exact meaning of trap, importance in writing test |
| 99 | +*** do we need pending interrupts, or can this be part of mip? |
| 100 | + |
| 101 | +[NOTE] |
| 102 | +==== |
| 103 | +RVVI and riscvISACOV support the notion of multiple harts that retire multiple instructions per cycle. The number of instructions retired per cycle is a microarchitectural issue irrelevant to architectural functional verification, so it is set to 1, consistent with simulators that report each instruction retiring individually. Phase 0-2 testing only involves a single hart. Later phases may need to generalize to multiple harts to exercise fences and atomic operations that relate to memory consistency. |
| 104 | +==== |
| 105 | + |
| 106 | +[NOTE] |
| 107 | +==== |
| 108 | +Our riscvISACOV implementation uses a SystemVerilog disassmbler in fcov/disassemble.svh, replacing a proprietery disassembler from Imperas. When adding new extensions, update the disassembler accordingly. |
| 109 | +==== |
| 110 | + |
| 111 | + |
| 112 | +=== Writing Coverpoints with riscvISACOV |
| 113 | + |
| 114 | +*** example of coverpoint |
| 115 | +*** organization of files |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | +=== Sail Trace Coverage Flow |
| 120 | + |
| 121 | +Coverage is measured by running tests on Sail and generating a trace file, then passing this trace file to an RVVI agent in a SystemVerilog testbench that checks coverage. |
| 122 | + |
| 123 | +[NOTE] |
| 124 | +==== |
| 125 | +The number of coverpoints and the number of tests both grow with the number of extensions, so the runtime to measure coverage can grow quadratically with the number of extensions, and becomes problematic. To avoid this, it is recommended to only enable coverpoints for one extension (or small group of extensions) at a time and to only run tests for that extension, and generate a Unified Coverage Database (UDCB) file and report for that extension. A script will kick off such tests in parallel for all extensions, and merge the coverage reports. |
| 126 | +==== |
| 127 | + |
| 128 | +Sail produces the trace file in a standard RVVI-Trace format (see Section <<RVVI-Trace Format>>). Any other simulator that implements the same trace format can also be used to cross-check coverage. |
| 129 | + |
| 130 | +*** Jordan add instructions on how to run this |
| 131 | + |
| 132 | +=== RVVI-Trace Format |
| 133 | + |
| 134 | +*** Jordan write |
| 135 | +*** how to handle instructions that change multiple CSRs, such as a write to mstatus.SIE also affecting sstatus.SIE |
0 commit comments