SlideShare a Scribd company logo
Practical RISC-V Random Test Generation using Constraint
Programming
Edmond A. Cote – http://www.edmondcote.com
ABSTRACT
A proof-of-concept random test generator for RISC-V ISA is
presented. The test generator uses constraint programming for
specification of relationships between instructions and operands.
Example scenarios to cover basic instruction randomization, data
hazards, and non-sharing are presented. The tool integrates the
RISC-V instruction set simulator to enable the generation of self-
checking tests. The tool is implemented in Python using a freely-
available constraint solver library. A summary of problems
encountered is provided and next steps are discussed.
BACKGROUND
Constrained random verification is an important and effective tool
for functional verification of microprocessors. Simple random
stimulus is not sufficient to verify a processor fully [1]. The use of
constraint programming for functional verification has
traditionally been limited to domain-specific languages such as e,
OpenVera, and SystemVerilog. In the context of a lean
semiconductor development model, the cost to acquire licenses of
such tools may be prohibitive. The freely-available SystemC
Verification Library offers limited supports for constraints. Python
verification frameworks exist such as cocotb [2] and Migen [3] but
do not offer support for constraint programming. This project
aims to explore the possibility of extending Python-based
hardware verification frameworks with support for constrained
random verification.
OBJECTIVES
• Learn about RISC-V architecture ahead of workshop
• Learn about low-level constraint programming
• Demonstrate proof-of-concept random test generator
• Complete interesting technical project outside of work
METHODS CONCLUSIONS AND NEXT STEPS
REFERENCES
• [1] Applying Constrained-Random Verification to
Microprocessors - Jason C. Chen, Synopsys Inc.
• [2] cocoTB documentation -
https://media.readthedocs.org/pdf/cocotb/latest/cocotb.pdf
• [3] Migen manual http://m-labs.hk/migen.pdf
• [4] Constraint Satisfaction Problem Wiki -
http://en.wikipedia.org/wiki/Constraint_satisfaction_problem
Constraint Programming
• Used Python language and python-constraint CSP solver library
• CSPs defined by triple {X,D,C} [4]:
X = {X1,…, Xn} is a set of variables
D = {D1,…,Dn} is a set of respective domain values
C = {C1,…,Cm} is a set of constraints
• Problem is input to tool using this paradigm
• MinConflictSolver in library provides a single valid random
solution
Examples
• Define 10 variables (instructions) and their domain
(set of all instructions)
i_var = ["i[{}]".format(x) for _ in range(10)]
i_dom = ['sw','lw','add','sub', …] # RISC-V instrs
csp.addVariables(i_var, i_dom)
• Constrain instruction 0 and 2 to be either load or store
csp.addConstraint(InSetConstraint(['sw','lw']),
['i[0]','i[2]'])
• Constrain for probable WAW hazard
rd_var = ["rd[{}]".format(x) for _ in range(10)]
rd_dom = ['ra','s0','s1', …] # RISC-V registers
csp.addVariables(rd_vars, rd_dom)
# At least 5 values of rd are in set
csp.addConstraint(SomeInSetConstraint(['s1'], 5), rd_var)
• Use of anonymous functions non shared addresses
csp.addVariable('addr', range(256)) # fixed domain issue
csp.addConstraint(lambda addr: # non sharing
addr > cpu*256/ncpu and addr <= (cpu+1)*256/ncpu))
Test Generation
• Generate random initial values for all registers
• Solve CSP; use csp.getSolution()
• Generate instruction sequence based on instruction type, save to
temporary file, and compile.
Self Checking
• Test generator instructs ISS to execute ELF
p = Popen('spike -d /path/to/elf'.split(' '),
stdin=subprocess.PIPE, stderr=subprocess.PIPE)
• ISS runs until magic number reached
until reg 0 gp DEADBEEF
• Test generator inserts reg commands to ISS and captures values of
registers
• Self checking code appended to test
• Generated self checking tests pass on RISC-V ISS
• Random stability checked by varying random seed
• Low level constraint programming is difficult, but
interesting exercise
• Fixed domains are problematic for integer space
• Access to alternative solvers can provide the entire
solution space. This presents interesting opportunities
for functional verification (e.g. analysis of state space,
creation of exhaustive tests, etc.).
• Use of Python subprocess module to communicate with
ISS was effective, but required patch for tool to accept
commands from stdin
• Explore Google or-tools and SystemC Verification Library
• Find a project to apply such a methodology to
Example test case :
RVTEST_CODE_BEGIN
// Randomly generated initial values (subset shown)
li s0, 0x8e73c
li s1, 0xa46d6
// Random instructions
or s0 , s0, s1
// Magic number register write
li gp, 0xDEADBEEF
// Generated self checking code, values from ISS
li gp, 0xAE7FE
bne s0, gp, fail
li gp, 0xa46d6
bne s1, gp, fail
TEST_PASSFAIL
RVTEST_CODE_END

More Related Content

What's hot (20)

PPTX
How to Connect SystemVerilog with Octave
Amiq Consulting
 
PDF
Return oriented programming
hybr1s
 
PPTX
Clang compiler `
Rabin BK
 
PDF
Efficient Bytecode Analysis: Linespeed Shellcode Detection
Georg Wicherski
 
PPTX
Linux binary analysis and exploitation
Dharmalingam Ganesan
 
PPTX
Mixing d ps building architecture on the cross cutting example
corehard_by
 
PDF
HIS 2015: Alastair F. Donaldson - Fighting for Software Correctness in a Mass...
AdaCore
 
PDF
Pinpointing Vulnerabilities (Ravel)
Yue Chen
 
PDF
Design for Testability
Stanislav Tiurikov
 
PPT
system verilog
Vinchipsytm Vlsitraining
 
PDF
GPCE16 Poster: Automatic Non-functional Testing of Code Generators Families
Mohamed BOUSSAA
 
PDF
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
OpenEBS
 
PDF
Deterministic Galois: On-demand, Portable and Parameterless
Donald Nguyen
 
PPTX
Scan insertion
kumar gavanurmath
 
PPTX
LLVM Compiler
Chayan Pathak
 
PDF
BKK16-302: Android Optimizing Compiler: New Member Assimilation Guide
Linaro
 
PPT
Introduction to llvm
Tao He
 
PDF
Survey of Program Transformation Technologies
Chunhua Liao
 
PDF
TMPA-2017: Vellvm - Verifying the LLVM
Iosif Itkin
 
PDF
TMPA-2017: Stemming Architectural Decay in Software Systems
Iosif Itkin
 
How to Connect SystemVerilog with Octave
Amiq Consulting
 
Return oriented programming
hybr1s
 
Clang compiler `
Rabin BK
 
Efficient Bytecode Analysis: Linespeed Shellcode Detection
Georg Wicherski
 
Linux binary analysis and exploitation
Dharmalingam Ganesan
 
Mixing d ps building architecture on the cross cutting example
corehard_by
 
HIS 2015: Alastair F. Donaldson - Fighting for Software Correctness in a Mass...
AdaCore
 
Pinpointing Vulnerabilities (Ravel)
Yue Chen
 
Design for Testability
Stanislav Tiurikov
 
system verilog
Vinchipsytm Vlsitraining
 
GPCE16 Poster: Automatic Non-functional Testing of Code Generators Families
Mohamed BOUSSAA
 
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
OpenEBS
 
Deterministic Galois: On-demand, Portable and Parameterless
Donald Nguyen
 
Scan insertion
kumar gavanurmath
 
LLVM Compiler
Chayan Pathak
 
BKK16-302: Android Optimizing Compiler: New Member Assimilation Guide
Linaro
 
Introduction to llvm
Tao He
 
Survey of Program Transformation Technologies
Chunhua Liao
 
TMPA-2017: Vellvm - Verifying the LLVM
Iosif Itkin
 
TMPA-2017: Stemming Architectural Decay in Software Systems
Iosif Itkin
 

Viewers also liked (7)

PDF
Программно-аппаратная разработка с использованием FPGA на примере поддержки п...
CEE-SEC(R)
 
PDF
Instruction: dev environment
Soshi Nemoto
 
PDF
Scaling python to_hpc_big_data-maidanov
Denis Nagorny
 
PDF
Sql Injection 0wning Enterprise
n|u - The Open Security Community
 
PPTX
Sour Pickles
SensePost
 
PDF
Common technique in Bypassing Stuff in Python.
Shahriman .
 
PDF
Guru01 13 15
Krishna's Calling
 
Программно-аппаратная разработка с использованием FPGA на примере поддержки п...
CEE-SEC(R)
 
Instruction: dev environment
Soshi Nemoto
 
Scaling python to_hpc_big_data-maidanov
Denis Nagorny
 
Sql Injection 0wning Enterprise
n|u - The Open Security Community
 
Sour Pickles
SensePost
 
Common technique in Bypassing Stuff in Python.
Shahriman .
 
Guru01 13 15
Krishna's Calling
 
Ad

Similar to Practical RISC-V Random Test Generation using Constraint Programming (20)

PPTX
Online test program generator for RISC-V processors
RISC-V International
 
PDF
Functional Verification of Large-integers Circuits using a Cosimulation-base...
IJECEIAES
 
PPTX
Is Advanced Verification for FPGA based Logic needed
chiportal
 
PDF
Poster: Contract-Based Integration of Cyber-Physical Analyses
Ivan Ruchkin
 
PDF
Reconfigurable Model for RISC Processors
Thiago Lima
 
PPTX
module5 notes on random zation techniques.pptx
smiritisms
 
PDF
Appsec obfuscator reloaded
Cyber Security Alliance
 
PPTX
Crossing the Boundaries: Development Strategies for (P)SoCs
Andreas Koschak
 
PDF
Fpga Verification Methodology and case studies - Semisrael Expo2014
Avi Caspi
 
PPTX
ASIC design verification
Gireesh Kallihal
 
PPT
Dill may-2008
Obsidian Software
 
PDF
Session 6 sv_randomization
Nirav Desai
 
PDF
Getting started with RISC-V verification what's next after compliance testing
RISC-V International
 
PDF
DARPA CGC and DEFCON CTF: Automatic Attack and Defense Technique
Chong-Kuan Chen
 
PPTX
Trusted Automatic Programming - November 2024
Abhik Roychoudhury
 
PDF
The Cortex-A15 Verification Story
DVClub
 
DOCX
Assignment 1 Hypothetical Machine SimulatorCSci 430 Int.docx
jane3dyson92312
 
PDF
Verification Challenges and Methodologies
Dr. Shivananda Koteshwar
 
DOCX
OverviewAssignment 1 Hypothetical Machine SimulatorCSci 43.docx
honey690131
 
Online test program generator for RISC-V processors
RISC-V International
 
Functional Verification of Large-integers Circuits using a Cosimulation-base...
IJECEIAES
 
Is Advanced Verification for FPGA based Logic needed
chiportal
 
Poster: Contract-Based Integration of Cyber-Physical Analyses
Ivan Ruchkin
 
Reconfigurable Model for RISC Processors
Thiago Lima
 
module5 notes on random zation techniques.pptx
smiritisms
 
Appsec obfuscator reloaded
Cyber Security Alliance
 
Crossing the Boundaries: Development Strategies for (P)SoCs
Andreas Koschak
 
Fpga Verification Methodology and case studies - Semisrael Expo2014
Avi Caspi
 
ASIC design verification
Gireesh Kallihal
 
Dill may-2008
Obsidian Software
 
Session 6 sv_randomization
Nirav Desai
 
Getting started with RISC-V verification what's next after compliance testing
RISC-V International
 
DARPA CGC and DEFCON CTF: Automatic Attack and Defense Technique
Chong-Kuan Chen
 
Trusted Automatic Programming - November 2024
Abhik Roychoudhury
 
The Cortex-A15 Verification Story
DVClub
 
Assignment 1 Hypothetical Machine SimulatorCSci 430 Int.docx
jane3dyson92312
 
Verification Challenges and Methodologies
Dr. Shivananda Koteshwar
 
OverviewAssignment 1 Hypothetical Machine SimulatorCSci 43.docx
honey690131
 
Ad

Recently uploaded (20)

PPTX
Comparison of Flexible and Rigid Pavements in Bangladesh
Arifur Rahman
 
PDF
Python Mini Project: Command-Line Quiz Game for School/College Students
MPREETHI7
 
PDF
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Mark Billinghurst
 
PPTX
Kel.3_A_Review_on_Internet_of_Things_for_Defense_v3.pptx
Endang Saefullah
 
PPT
SF 9_Unit 1.ppt software engineering ppt
AmarrKannthh
 
PPTX
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
 
PPTX
WHO And BIS std- for water quality .pptx
dhanashree78
 
PDF
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
PPTX
Precooling and Refrigerated storage.pptx
ThongamSunita
 
PPT
دراسة حاله لقرية تقع في جنوب غرب السودان
محمد قصص فتوتة
 
PDF
01-introduction to the ProcessDesign.pdf
StiveBrack
 
PPTX
Functions in Python Programming Language
BeulahS2
 
PDF
輪読会資料_Miipher and Miipher2 .
NABLAS株式会社
 
PDF
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Mark Billinghurst
 
PDF
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
PPSX
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
PDF
How to Buy Verified CashApp Accounts IN 2025
Buy Verified CashApp Accounts
 
PPTX
Computer network Computer network Computer network Computer network
Shrikant317689
 
PDF
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
 
PDF
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
Comparison of Flexible and Rigid Pavements in Bangladesh
Arifur Rahman
 
Python Mini Project: Command-Line Quiz Game for School/College Students
MPREETHI7
 
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Mark Billinghurst
 
Kel.3_A_Review_on_Internet_of_Things_for_Defense_v3.pptx
Endang Saefullah
 
SF 9_Unit 1.ppt software engineering ppt
AmarrKannthh
 
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
 
WHO And BIS std- for water quality .pptx
dhanashree78
 
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
Precooling and Refrigerated storage.pptx
ThongamSunita
 
دراسة حاله لقرية تقع في جنوب غرب السودان
محمد قصص فتوتة
 
01-introduction to the ProcessDesign.pdf
StiveBrack
 
Functions in Python Programming Language
BeulahS2
 
輪読会資料_Miipher and Miipher2 .
NABLAS株式会社
 
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Mark Billinghurst
 
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
How to Buy Verified CashApp Accounts IN 2025
Buy Verified CashApp Accounts
 
Computer network Computer network Computer network Computer network
Shrikant317689
 
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
 
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 

Practical RISC-V Random Test Generation using Constraint Programming

  • 1. Practical RISC-V Random Test Generation using Constraint Programming Edmond A. Cote – http://www.edmondcote.com ABSTRACT A proof-of-concept random test generator for RISC-V ISA is presented. The test generator uses constraint programming for specification of relationships between instructions and operands. Example scenarios to cover basic instruction randomization, data hazards, and non-sharing are presented. The tool integrates the RISC-V instruction set simulator to enable the generation of self- checking tests. The tool is implemented in Python using a freely- available constraint solver library. A summary of problems encountered is provided and next steps are discussed. BACKGROUND Constrained random verification is an important and effective tool for functional verification of microprocessors. Simple random stimulus is not sufficient to verify a processor fully [1]. The use of constraint programming for functional verification has traditionally been limited to domain-specific languages such as e, OpenVera, and SystemVerilog. In the context of a lean semiconductor development model, the cost to acquire licenses of such tools may be prohibitive. The freely-available SystemC Verification Library offers limited supports for constraints. Python verification frameworks exist such as cocotb [2] and Migen [3] but do not offer support for constraint programming. This project aims to explore the possibility of extending Python-based hardware verification frameworks with support for constrained random verification. OBJECTIVES • Learn about RISC-V architecture ahead of workshop • Learn about low-level constraint programming • Demonstrate proof-of-concept random test generator • Complete interesting technical project outside of work METHODS CONCLUSIONS AND NEXT STEPS REFERENCES • [1] Applying Constrained-Random Verification to Microprocessors - Jason C. Chen, Synopsys Inc. • [2] cocoTB documentation - https://media.readthedocs.org/pdf/cocotb/latest/cocotb.pdf • [3] Migen manual http://m-labs.hk/migen.pdf • [4] Constraint Satisfaction Problem Wiki - http://en.wikipedia.org/wiki/Constraint_satisfaction_problem Constraint Programming • Used Python language and python-constraint CSP solver library • CSPs defined by triple {X,D,C} [4]: X = {X1,…, Xn} is a set of variables D = {D1,…,Dn} is a set of respective domain values C = {C1,…,Cm} is a set of constraints • Problem is input to tool using this paradigm • MinConflictSolver in library provides a single valid random solution Examples • Define 10 variables (instructions) and their domain (set of all instructions) i_var = ["i[{}]".format(x) for _ in range(10)] i_dom = ['sw','lw','add','sub', …] # RISC-V instrs csp.addVariables(i_var, i_dom) • Constrain instruction 0 and 2 to be either load or store csp.addConstraint(InSetConstraint(['sw','lw']), ['i[0]','i[2]']) • Constrain for probable WAW hazard rd_var = ["rd[{}]".format(x) for _ in range(10)] rd_dom = ['ra','s0','s1', …] # RISC-V registers csp.addVariables(rd_vars, rd_dom) # At least 5 values of rd are in set csp.addConstraint(SomeInSetConstraint(['s1'], 5), rd_var) • Use of anonymous functions non shared addresses csp.addVariable('addr', range(256)) # fixed domain issue csp.addConstraint(lambda addr: # non sharing addr > cpu*256/ncpu and addr <= (cpu+1)*256/ncpu)) Test Generation • Generate random initial values for all registers • Solve CSP; use csp.getSolution() • Generate instruction sequence based on instruction type, save to temporary file, and compile. Self Checking • Test generator instructs ISS to execute ELF p = Popen('spike -d /path/to/elf'.split(' '), stdin=subprocess.PIPE, stderr=subprocess.PIPE) • ISS runs until magic number reached until reg 0 gp DEADBEEF • Test generator inserts reg commands to ISS and captures values of registers • Self checking code appended to test • Generated self checking tests pass on RISC-V ISS • Random stability checked by varying random seed • Low level constraint programming is difficult, but interesting exercise • Fixed domains are problematic for integer space • Access to alternative solvers can provide the entire solution space. This presents interesting opportunities for functional verification (e.g. analysis of state space, creation of exhaustive tests, etc.). • Use of Python subprocess module to communicate with ISS was effective, but required patch for tool to accept commands from stdin • Explore Google or-tools and SystemC Verification Library • Find a project to apply such a methodology to Example test case : RVTEST_CODE_BEGIN // Randomly generated initial values (subset shown) li s0, 0x8e73c li s1, 0xa46d6 // Random instructions or s0 , s0, s1 // Magic number register write li gp, 0xDEADBEEF // Generated self checking code, values from ISS li gp, 0xAE7FE bne s0, gp, fail li gp, 0xa46d6 bne s1, gp, fail TEST_PASSFAIL RVTEST_CODE_END