Giter Club home page Giter Club logo

rfuzz's Introduction

rfuzz: coverage-directed fuzzing for RTL research platform

This repository contains the rfuzz research platform which was created at UC Berkeley's ADEPT Lab to investigate the use of coverage-directed fuzzing for RTL pre-silicon testing.

The source code is release under a BSD-3-Clause license in order to allow for reproduction of experimental results as well as a basis for further research.

Instructions

Clone the Repository

git clone https://github.com/ekiwi/rfuzz.git
cd rfuzz
# switch submodules to use HTTPS instead of SSH
sed -i 's/[email protected]:/https:\/\/github.com\//'  .gitmodules
# initialize and update submodules
git submodule update --init

Install Dependencies

Note: instead of setting up your system manually you can try the Vagrantfile provided with this repository. For more information see vagrantup.com.

On a fresh installation of Ubuntu 18.04 (Bionic Beaver) the following installation steps were necessary:

  1. Install dependencies from the default repositories (requires root privileges):
apt update && apt upgrade
apt install build-essential meson pkg-config openjdk-8-jdk verilator cargo
apt install python3-toml python3-numpy python3-matplotlib graphviz
  1. Install sbt by following the official docs:
echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823
sudo apt-get update
sudo apt-get install sbt
  1. On a headless server: add the following to your ~/.config/matplotlib/matplotlibrc:
backend: agg

(more info)

Note: rfuzz is developed on Fedora Linux Workstation which thus also offers good support

Software Simulation Fuzz Server

In order to fuzz test a particular RTL design, we need to take the FIRRTL source code, instrument it and compile it into a fast RTL simulation using the verilator tool.

The exact build steps are encoded in the toplevel Makefile provided with this repository. In order to build the final binary you can use the pseudo target bin. If you also want to start the binary you can use the pseudo target run (WARNING: this will create the /tmp/fpga directory and will delete any existing directory of the same name).

Thus to start the RTL simulation (also called the fuzz server) for the default Sodor3Stage benchmark you just need to execute make run. This should provide you with the following output:

rm -rf /tmp/fpga
mkdir /tmp/fpga
/home/ubuntu/rfuzz/build/ICache_server
Fuzz Server for ICache
Allocated Bytes per Input:    40
Allocated Bytes per Coverage: 30
created tx fifo
created rx fifo

This signals that the fuzz server is ready to receive test input from the fuzzer as well as provide coverage feedback.

Fuzzer

The fuzzer is implemented in software and connects to the software simulation fuzz server or the FPGA driver through shared memory. As opposed to the fuzz server, the fuzzer itself is design agnostic and thus only needs to be compiled once. The design specific information is propagated through a TOML file generated alongside the fuzz server when executing make bin (or make run).

To build the fuzzer change to the fuzzer directory and execute:

cargo build --release

Note: the performance of release builds can be around 10x faster. Do NOT run benchmarks with debug builds (the default configuration).

To see a list of options that the fuzzer supports run:

cargo run --release -- -h

This should provide you with an output similar to this:

kfuzz 0.1.0
Kevin Laeufer <[email protected]>
AFL-style fuzzer specialized for fuzzing RTL circuits.

USAGE:
    kfuzz [FLAGS] [OPTIONS] <TOML> --output-directory <DIR>

FLAGS:
    -h, --help                      Prints help information
    -q, --print-queue               Prints queue content at the end of a fuzzing run.
    -c, --print-total-cov           Prints the union coverage at the end of a fuzzing run.
    -r, --random                    Generate independent random inputs instead of using the fuzzing algorithm.
    -d, --skip-deterministic        Skip all deterministic mutation strategies.
    -n, --skip-non-deterministic    Skip all non-deterministic mutation strategies.
    -t, --test-mode                 Test the fuzz server with known input/coverage pairs.
    -v, --version                   Prints version information

OPTIONS:
    -s, --server-id <fuzz_server_id>    The id of the fuzz server isntance to connect to. [default: 0]
    -i, --input-directory <DIR>         The output directory of a previous run from which to resume.
    -j, --jqf-level <jqf_level>         Select which level of JQF to apply. [default: 2]  [possible values: 0, 1, 2]
    -o, --output-directory <DIR>        Used to log this session. Must be empty!
        --seed-cycles <seed_cycles>     The starting seed consits of all zeros for N cycles. [default: 5]

ARGS:
    <TOML>    TOML file describing the circuit being fuzzed

To quickly fuzz the default configuration, make sure that the fuzz server is running (see previous section) and then launch the fuzzer like this:

cargo run --release -- -c -o out ../build/Sodor3Stage.toml

To terminate fuzzing use Ctrl+C and wait for the fuzzer to shut down (this can take some time depending on how fast the design under test executes).

FPGA Accelerated Fuzz Server

The FPGA acceleration is not working on the current main branch anymore. Please have a look at the iccad18 branch instead. Also, please feel free to contact the authors since the FPGA fuzzing is not very well documented.

Analysis

The scripts that were used to analyze the fuzzing results and generate graphs for our ICCAD'18 paper can be found in the analysis/ directory. Our raw results from running the fuzz server and fuzzer on the AWS cloud can be found in the rfuzz-results repository in the jack folder. In order to ignore any functional changes that were made to rfuzz after the ICCAD'18 submission, please make sure that you use the iccad18 branch in the rfuzz repository.

In order to regenerate the graphs, make sure that your installation has a graphical desktop environment (or add the appropriate code to dump graphs to disk to the end of analysis.py).
Then make sure that the appropriate binaries are available:

make FIR=FFTSmall.fir DUT=FFTSmall bin
make FIR=Sodor1Stage.fir DUT=Sodor1Stage bin
make FIR=Sodor3Stage.fir DUT=Sodor3Stage bin
make FIR=Sodor5Stage.fir DUT=Sodor5Stage bin
make FIR=TLI2C.fir DUT=TLI2C bin
make FIR=TLSPI.fir DUT=TLSPI bin

Now you can run the analysis script like this:

./analysis.py ../../rfuzz-results/jack/Sodor3Stage.jqf1.seed5.random.out ../../rfuzz-results/jack/Sodor3Stage.jqf2.seed5.out

This will display the resulting graph which should be an exact copy of the one printed in our paper (assuming you used the iccad18 branch). It will also generate a mutation history graph for each fuzzing run, e.g. 0.Sodor3Stage.out_mutations.png.

Note: the analysis.py script uses a version of the design with minimal instrumentation and restarts the RTL simulator for each test input in order to increase our confidence in the analysis results. Invalid inputs as indicated by failing assumptions in the design are automatically discarded and excluded from the coverage results. Have a look at the scripts in the analysis/ directory to learn the details.

Benchmarks

A collection of benchmarks in the form of RTL circuits in the FIRRTL format can be found in the benchmarks/ directory. Please consult the local Readme to learn more about how each individual benchmark was created.

Our Makefile takes the name of a FIRRTL (*.fir) file and the name of the corresponding RTL toplevel module as parameters, e.g.:

make FIR=TLI2C.fir DUT=TLI2C run

The following benchmarks are available, benchmarks used in our ICCAD'18 paper are listed in bold:

Name FIR DUT Description Source
FFT Small FFTSmall.fir FFTSmall FFT DSP circuit fft
ICache ICache.fir ICache instruction cache from Rocket Chip rocket-chip
ICache w/ Coverage ICacheCover.fir ICache ICache w/ user defined coverage annotations rocket-chip
Non-Blocking Data Cache NonBlockingDCache.fir NonBlockingDCache data cache from Rocket Chip rocket-chip
Rocket Chip Tile RocketTile.fir RocketTile 64-bit RISCV CPU Tile rocket-chip
Sodor 1-Stage Sodor1Stage.fir Sodor1Stage educational RISCV core with 1 pipeline stage riscv-sodor
Sodor 3-Stage Sodor3Stage.fir Sodor3Stage educational RISCV core with 3 pipeline stages riscv-sodor
Sodor 5-Stage Sodor5Stage.fir Sodor5Stage educational RISCV core with 5 pipeline stages riscv-sodor
I2C Peripheral TLI2C.fir TLI2C I2C controller connected to TileLink bus sifive-blocks
PWM Peripheral TLPWM.fir TLPWM PWM timer connected to TileLink bus sifive-blocks
SPI Peripheral TLSPI.fir TLSPI SPI controller connected to TileLink bus sifive-blocks
UART Peripheral TLUART.fir TLUART UART controller connected to TileLink bus sifive-blocks

Note: the benchmarks that were not used in our paper have not been thoroughly evaluated and thus may not work reliably or may produce spurious results.

ICCAD'18 Paper

You can learn more about rfuzz in our ICCAD'18 paper which explains how we adapted the coverage-directed fuzzing ideas from software testing to RTL verification while building the basic research platform.

In order to reproduce our results, please make sure to use the iccad18 branch of this repository.

Kevin Laeufer and Jack Koenig and Donggyu Kim and Jonathan Bachrach and Koushik Sen. RFUZZ: Coverage-Directed Fuzz Testing of RTL on FPGAs. In International Conference On Computer Aided Design, 2018 (ICCAD'18), San Diego, CA, November 2018.

Preprint PDF

rfuzz's People

Contributors

ekiwi avatar jackkoenig avatar donggyukim avatar

Stargazers

 avatar  avatar NickNick avatar  avatar  avatar daiym avatar Magnus Oksbøl Therkelsen avatar Yan  avatar  avatar wzg avatar parish avatar TommyTang avatar Tommy Wu avatar Gijs Burghoorn avatar  avatar Laurier Loiselle avatar Lin, Yong Xiang avatar  avatar Ben avatar KX.Y. avatar  avatar Heinz Riener avatar kkqq avatar Aurélien Hernandez avatar Karl Koscher avatar Peinan Li avatar Minbok Wi avatar hanyj avatar gua avatar Yang Liu avatar GGYgip avatar Dan Park avatar  avatar David A avatar Zihui Guo avatar Jeff Carpenter avatar Leway Colin avatar Painting avatar Zifei Zhang avatar Zihao Ye avatar kenan_xiao avatar Chen avatar Dian-Lun (Aaron) Lin avatar Yang Xiaoyu avatar Jinyan Xu avatar Yike Zhou avatar Shengtuo Hu avatar  avatar  avatar  avatar Benshan Mei avatar xrkk avatar  avatar Nikita avatar  avatar Minwoo (Josh) Kang avatar Yuichi Sugiyama avatar Andrew Whigham avatar  avatar Yifan Qiao avatar Wende Tan avatar Leo Langer avatar  Liu Xiaoyi avatar NULL avatar  avatar  avatar Derry Pratama avatar Colin avatar Youngsuk Kim avatar Rohan Padhye avatar Jiuyang Liu avatar Julian Lupu avatar Anmol avatar  avatar muuk avatar Ali avatar Guang Wang avatar David Hanna Jr. avatar Benjamin Brock avatar Anselm avatar  avatar Bradley Evans avatar Zhenkun avatar yama0xff avatar  avatar Rohan Bavishi avatar

Watchers

James Cloos avatar  avatar Ali avatar  avatar  avatar

rfuzz's Issues

Coverage port width mismatches number of mux in design

Hi!

I am currently working on reimplementing the rfuzz passes in yosys to make it compatible with some other tools I am working with. I have realised that the width of the coverage port does not match the total number of multiplexers in the design (after converting processes to multiplexers and registers but skipping the SparseMem transform). Are there any optimisations in the FIRRTL passes reducing the number of multiplexers that I might be missing? Or does the ProfilingTransform skip certain multiplexers if they cannot be toggled?

Thanks a lot for your help,

Tobias

Error running RFUZZ on Chisel FIR

Hello!

I am trying to apply RFUZZ to a design generated by Chisel. When passing the corresponding .fir file, I encounter the following errors:
line 1984:39 mismatched input ':' expecting {'.', '[', UnsignedInt, SignedInt, HexLit, OctalLit, BinaryLit} line 2648:2 mismatched input 'module' expecting {'.', '[', UnsignedInt, SignedInt, HexLit, OctalLit, BinaryLit} [error] (run-main-0) firrtl.SyntaxErrorsException: 2 syntax error(s) detected [error] firrtl.SyntaxErrorsException: 2 syntax error(s) detected [error] stack trace is suppressed; run last Compile / bgRunMain for the full output [error] Nonzero exit code: 1 [error] (Compile / runMain) Nonzero exit code: 1 [error] Total time: 3 s, completed Mar 28, 2023, 12:43:26 PM

Since the .fir files are generated by Chisel and should not have syntax errors, I was wondering If there might be a bug in the parser or if anyone has come across a similar issue.

Thanks,

Tobias

Error when trying to use other benchmarks

Hello,
I am trying to use this tool to fuzz other designs. I already run it for the given benchmarks and the results are really satisfiable .
What I have to do now, is use this tool , to verify the coverage of AES CIPHER Core, which is provided in both VHDL and Verilog.
My first Issue was to integrate this design to this tool, given that the RFUZZ needs a (.fir) file as input, so the intermediate representation . I already read on the official page of FIRRTL that there is a synthesizer (Yosys) that converts from Verilog to FirRtl.
I converted my design to FirRtl but it gives me an error when I try to instrument it :
make run
cd instrumentation ;
sbt -ivy /home/maku/Desktop/Fuzzing/rfuzz/.ivy2 "runMain hardwareafl.firrtltransforms.CustomTop -i /home/maku/Desktop/Fuzzing/rfuzz/benchmarks/Top_PipelinedCipher.fir -o /home/maku/Desktop/Fuzzing/rfuzz/build/Top_PipelinedCipher.v -X verilog -ll info -fct hardwareafl.firrtltransforms.NoDedupTransform,hardwareafl.firrtltransforms.ReplaceMemsTransform,hardwareafl.firrtltransforms.SplitMuxConditions,hardwareafl.firrtltransforms.ProfilingTransform,firrtl.passes.wiring.WiringTransform,hardwareafl.firrtltransforms.AddMetaResetTransform "
[info] Loading settings from plugins.sbt ...
[info] Loading project definition from /home/maku/Desktop/Fuzzing/rfuzz/instrumentation/project
[info] Loading settings from build.sbt ...
[info] Set current project to instrumentation (in build file:/home/maku/Desktop/Fuzzing/rfuzz/instrumentation/)
[info] Running hardwareafl.firrtltransforms.CustomTop -i /home/maku/Desktop/Fuzzing/rfuzz/benchmarks/Top_PipelinedCipher.fir -o /home/maku/Desktop/Fuzzing/rfuzz/build/Top_PipelinedCipher.v -X verilog -ll info -fct hardwareafl.firrtltransforms.NoDedupTransform,hardwareafl.firrtltransforms.ReplaceMemsTransform,hardwareafl.firrtltransforms.SplitMuxConditions,hardwareafl.firrtltransforms.ProfilingTransform,firrtl.passes.wiring.WiringTransform,hardwareafl.firrtltransforms.AddMetaResetTransform
[error] (run-main-0) java.lang.StackOverflowError
[error] java.lang.StackOverflowError
[error] at java.util.regex.Pattern$5.isSatisfiedBy(Pattern.java:5253)
[error] at java.util.regex.Pattern$5.isSatisfiedBy(Pattern.java:5253)
[error] at java.util.regex.Pattern$CharProperty.match(Pattern.java:3778)
[error] at java.util.regex.Pattern$Curly.match0(Pattern.java:4252)
[error] at java.util.regex.Pattern$Curly.match(Pattern.java:4236)
[error] at java.util.regex.Pattern$Ques.match(Pattern.java:4184)
[error] at java.util.regex.Pattern$GroupHead.match(Pattern.java:4660)
[error] at java.util.regex.Pattern$BmpCharProperty.match(Pattern.java:3800)
[error] at java.util.regex.Pattern$Curly.match0(Pattern.java:4274)
[error] at java.util.regex.Pattern$Curly.match(Pattern.java:4236)
[error] at java.util.regex.Matcher.match(Matcher.java:1270)
[error] at java.util.regex.Matcher.matches(Matcher.java:604)

I dont know if the problem is of synthesizer, which is not converting good the verilog file. I tried It also with small designs, but the result is the same. Maybe I should modify something to the Rfuzz ?

Thank you

Unable to run RFuzz

Hi,

I am trying to run RFuzz at my end on Ubuntu 18.04 LTS version. I have gone through the README.md file, installed all the required dependencies.

Finally, I am trying to run : make run.

I encountered an error which is shown below :

error1

I analysed the file meson.build in the folder verilator and suspected that at line number 49, that verilator_src might be of type non-array object (I am not sure as I have never used meson before ! ) Based on the comment, which you have put up, I think it would be verilator_files[0] & verilator_files[1] instead on verilator_src[0] and verilator_src[1].

Can you please help me with this issue ?

Need help with Rfuzz inputs

Hi,

I want to compare the output of rocket-chip when fuzzed with Rfuzz with SPIKE, the ISA simulator. For this, I will have to run the spike with the same inputs as the ones used on rocket-chip. In the repository where can I find the elf or binary files used as input to drive the rocket-chip? Are they output in a format that SPIKE can accept directly or does the input generated by Rfuzz have to be modified to use with SPIKE?

Any help regarding this task would be really helpful.

Thanking you in advance.

`make run` error

Hi, thanks for your excellent work. I followed the READMD to install and run RFUZZ, but when I run the command make run I met an Error as follows:

....
Total FIRRTL Compile Time: 1973.2 ms
[info] [0.000] Elaborating design...
coverage_byte_count: 190
input_byte_count: 8
coverage width: 1496
[info] [0.196] Done elaborating.
Computed transform order in: 84.6 ms
Total FIRRTL Compile Time: 618.8 ms
[success] Total time: 6 s, completed May 30, 2024, 11:10:17 AM
mv harness/VerilatorHarness.v /home/rfuzz/build/Sodor3Stage_VHarness.v
mv harness/E2ECoverageHarness.v /home/rfuzz/build/Sodor3Stage_E2EHarness.v
mkdir -p /home/rfuzz/build/vSodor3Stage
cd /home/rfuzz/build/vSodor3Stage && meson ../../verilator --buildtype=release \
                         -Dtrace=false -Dbuild_dir='/home/rfuzz/build' -Ddut='Sodor3Stage' \
                      && ninja
/bin/sh: 1: meson: not found
make: *** [Makefile:93: /home/rfuzz/build/Sodor3Stage_server] Error 127
root@50deed058db3:/home/rfuzz# ls build/
Sodor3Stage.e2e.toml  Sodor3Stage.toml	Sodor3Stage_E2EHarness.v	      Sodor3Stage_VHarness.v
Sodor3Stage.lo.fir    Sodor3Stage.v	Sodor3Stage_InstrumentationInfo.toml  vSodor3Stage
root@50deed058db3:/home/rfuzz# 

I listed the build dir but NO Sodor3Stage_server file. Should I change the Makefile?
I run make clean; make run, the problem occured again. How can I fix it?

try to use rfuzz

Hello, i am trying to use rfuzz to generate workload for some architectures. some of my architecture are combinational designs. so there is no need for concatenating the inputs through time. i see that the number of test input bits is fixed to 35 bytes. i need to change it according to the design. so how could i do that ?
also there is something printed in the screen (of fuzzer) called " Bitmap " and it have some values. i am not sure what this " Bitmap" means. I understand that if i have inputs (a(8 bits) , b(16 bits), c(1 bit)) and i want to use them. I need to assign first 8 bits to a then next 16 bits to b then 1 bit to c then next cycle use next 8 bits to a etc. am i right ?

Test with RocketTile

Hi.
Recently I'm trying rfuzz to test Rocket chip designs. (with verilator software simulation)

I followed the instructions in README.
However, it takes long time to simulate RocketTile, approximately 100 cycles per second.

Is there any way to accelerate the simulation speed?

Small README update for sbt

Hi Kevin,

Thanks for your work. I'm getting my feet wet in rfuzz so thank you for your hard work. I was following the readme, and got stuck installing sbt despite having worked with Chisel based cores before (new Ubuntu install for my computer). While the link you point to for installing sbt lists the correct steps for installation, the README is slightly out of date for it now because bintray has been sunsetted. It's pretty minor and it only took a few minutes for me to work around, but you may want to update the sbt install portion of the README to bring it up to date.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.