diff --git a/contrib/crave/CMakeLists.txt b/contrib/crave/CMakeLists.txt new file mode 100644 index 00000000..befe4886 --- /dev/null +++ b/contrib/crave/CMakeLists.txt @@ -0,0 +1,23 @@ +project ( crave2uvm ) +cmake_minimum_required(VERSION 2.8) + +set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build/bin) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build/lib) +set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) + +#SystemC +find_package(SystemC REQUIRED) + +#CRAVE +find_package(CRAVE REQUIRED) + +#UVM-SystemC +find_package(UVM-SystemC REQUIRED) + +#Includes setzen +include_directories (${SystemC_INCLUDE_DIRS} ${CRAVE_INCLUDE_DIRS} ${UVM_SystemC_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/src/include) + +#Compiler flags +SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -g -ggdb") + +add_subdirectory (examples) \ No newline at end of file diff --git a/contrib/crave/README.md b/contrib/crave/README.md new file mode 100644 index 00000000..b9dcd5a6 --- /dev/null +++ b/contrib/crave/README.md @@ -0,0 +1,45 @@ +# CRAVE2UVM prototype + +This projects contains a prototypical integration of CRAVE with UVM-SystemC to provide access to constrained randomization and coverage. +For demonstration, we ported the SystemVerilog example CandyLovers (UVM Tutorial for CandyLovers, see http://cluelogic.com/2011/07/uvm-tutorial-for-candy-lovers-overview/) to UVM-SystemC and included it in this distribution. + +## Requirements + +Make sure all pre-install requirements of CRAVE and UVM-SystemC are met: + +* CMake (at least v2.8.9) +* GNU Make +* g++ (at least v4.7.2) +* SystemC (the environment variable SYSTEMC_HOME must be set accordingly) +* Boost (at least v1.50.0 and the environment variable BOOST_ROOT must be set accordingly, e.g. BOOST_ROOT=/usr) +* zlib development libraries (e.g. zlib1g-dev). + +The version of CRAVE included in this distribution by default will build a minimal configuration (Glog and 2 solver backends: CUDD and SWORD). +The pre-compiled SWORD library does not work on some platforms. +In this case, the user can replace SWORD with STP by setting the environment variable CRAVE_USE_STP to ON. +If download is permitted, CRAVE can automatically download and build these backends. +Otherwise, these will be unpacked from pre-packaged archives. +Other configurations with additional backends (e.g. Boolector, Z3, CVC4, etc.) are also possible. +For more detailed instructions , please refer to the CRAVE README or contact us. + +## Installation + +To install and run the example, use the buildscript on the top-level of this repository. It currently executes three common tasks: + +1. ./buildscript install: this will install CRAVE (shipped with this distribution) into ./crave, locally compiles UVM-SystemC into ../.. and setup the Makefile for the example "CandyLovers". + +2. ./buildscript compile: this will compile the example and put the executables into build/bin. + +3. ./buildscript run: this will run the CandyLovers example. + +## Tested OS + +This distribution has been tested on the following 64-bit Linux (x86_64) systems: + +* Fedora 22 with g++-5.3.1 +* Ubuntu 14.04.4 LTS with g++-4.8.4 +* Debian 7.0 with g++-4.7.2 + +## Contact +For bug report and feedback: crave@informatik.uni-bremen.de + diff --git a/contrib/crave/buildscript b/contrib/crave/buildscript new file mode 100755 index 00000000..7e62de52 --- /dev/null +++ b/contrib/crave/buildscript @@ -0,0 +1,167 @@ +#!/bin/bash + +NUM_THREADS=1 + +install_dependencies () { + echo "Install dependencies using $NUM_THREADS thread(s)" + + #SystemC + echo -n "SystemC: " + if [ -z "$SYSTEMC_HOME" ] + then + echo "NOT FOUND - Please set SYSTEMC_HOME to a valid SystemC installation" + echo -n "Type "y" to install SystemC now: " + read line + if [ "$line" = "y" ] + then + echo "Installing SystemC (or just setting the SYSTEMC_HOME variable for installation)" + if [ ! -d systemc-2.3.1 ] + then + wget http://accellera.org/images/downloads/standards/systemc/systemc-2.3.1.tgz + mv systemc-2.3.1.tgz systemc-2.3.1.tar + tar xvf systemc-2.3.1.tar + cd systemc-2.3.1 + mkdir objdir + cd objdir + ../configure + make + make install + cd ../.. + fi + cd systemc-2.3.1 + export SYSTEMC_HOME=`pwd` + cd .. + else + exit 1 + fi + else + echo "found" + fi + + #crave + echo -n "CRAVE: " + if [ ! -d crave ] + then + : ${CRAVE_USE_STP:=OFF} + if [ "$CRAVE_USE_STP" = "ON" ]; then + CRAVE_DEPS_ARCHIVE=crave_package_deps_stp.tar.gz + export CRAVE_SOLVERS='cudd stp' + else + CRAVE_DEPS_ARCHIVE=crave_package_deps.tar.gz + export CRAVE_SOLVERS='cudd sword' + fi + echo "install" + CRAVE_ARCHIVE=`ls ./crave-*.tar.gz -t | head -1` + echo "Extract CRAVE from $CRAVE_ARCHIVE" + tar -xzf $CRAVE_ARCHIVE + CRAVE_DIR=`basename $CRAVE_ARCHIVE .tar.gz` + mv $CRAVE_DIR crave + cd crave + echo -n "Type "y" to install CRAVE in offline mode, anything else for online mode. " + echo -n "Make sure "$CRAVE_DEPS_ARCHIVE" is in "contrib/crave" in case of offline build: " + read line + if [ "$line" = "y" ] + then + echo "Build CRAVE offline using $NUM_THREADS thread(s)" + cp ../$CRAVE_DEPS_ARCHIVE crave_package_deps.tar.gz + if ! CRAVE_OFFLINE_BUILD=ON make -j $NUM_THREADS; then + echo "Building CRAVE failed. Please see above for error" + exit 3 + fi + else + echo "Build CRAVE online using $NUM_THREADS thread(s)" + if ! make -j $NUM_THREADS; then + echo "Building CRAVE failed. Please see above for error" + exit 3 + fi + fi + make install -j $NUM_THREADS + cd .. + else + echo "found" + fi + + #uvm-systemc + echo -n "uvm-systemc-1.0-alpha1: " + if [ ! -d ../../include ] + then + echo "install" + cd ../.. + #sudo apt-get install automake autoconf libtool + config/bootstrap + mkdir objdir + cd objdir + ../configure --enable-debug + echo "Build UVM-SystemC using $NUM_THREADS thread(s)" + make -j $NUM_THREADS + make install -j $NUM_THREADS + cd .. + #rm -rf objdir + cd contrib/crave + else + echo "found" + fi + +} + +if [ "$1" = '' ] + then + echo " Usage: ./buildscript [Options]" + echo " Tasks: " + echo -e " install [-j n]\t - Install the CandyLovers example and all dependencies" + echo -e " compile [-j n]\t - (Re)compile the example after changes (You may use -j n to be faster with make)" + echo -e " run \t - Run the CandyLovers example" + echo -e " tarball \t - Create a tarball of the repository" + else + if [ "$2" == "-j" ] + then + case $3 in + ''|*[!0-9]*) ;; + *) NUM_THREADS=$3 ;; + esac + fi + case "$1" in + install) + install_dependencies + if [ -d build ] + then + rm -r build + fi + mkdir build + cd build + cmake -G "Unix Makefiles" .. + cd .. + ;; + compile) + cd build + make -j $NUM_THREADS + cd .. + ;; + run) + build/bin/CandyLovers + ;; + tarball) + name_date=crave2uvm_$(date +"%Y%m%d_%H%M") + name=contrib/crave + mkdir -p $name + mkdir -p $name/cmake + mkdir -p $name/examples + mkdir -p $name/src + mkdir -p $name/presentation + + cp -R cmake/* $name/cmake + cp -R examples/* $name/examples + cp -R src/* $name/src + cp presentation/UVM-CRAVE.pdf $name/presentation/UVM-CRAVE.pdf + cp CMakeLists.txt $name/CMakeLists.txt + CRAVE_ARCHIVE=`ls crave-*.tar.gz -t | head -1` + cp $CRAVE_ARCHIVE $name/$CRAVE_ARCHIVE + cp crave_package_deps*.tar.gz $name + cp buildscript $name/buildscript + cp README.md $name/README.md + + tar -cvzf $name_date.tar.gz $name + rm -r $name + ;; + esac +fi diff --git a/contrib/crave/cmake/FindCRAVE.cmake b/contrib/crave/cmake/FindCRAVE.cmake new file mode 100644 index 00000000..9ab7cc7f --- /dev/null +++ b/contrib/crave/cmake/FindCRAVE.cmake @@ -0,0 +1,29 @@ +#______________________________________________________________________________ +# +# This CMake package creates a CRAVE target with all its dependencies +#______________________________________________________________________________ +# +# CRAVE_FOUND - system has CRAVE +# CRAVE_INCLUDE_DIRS - the CRAVE include directory and include directories of all dependencies +# CRAVE_LIBRARIES - Link these to use CRAVE. Contains CRAVE and dependencies + +SET(crave_DIR ${PROJECT_SOURCE_DIR}/crave/build/root/share/crave/) +find_package(crave QUIET) +IF(crave_FOUND) + SET(CRAVE_FOUND TRUE) + SET(CRAVE_INCLUDE_DIRS ${crave_INCLUDE_DIR}) + SET(CRAVE_LIBRARIES ${crave_LIBRARIES}) +ENDIF() + +IF(CRAVE_FOUND) + IF(NOT CRAVE_FIND_QUIETLY) + MESSAGE(STATUS "Found CRAVE: ${CRAVE_LIBRARIES}") + ENDIF(NOT CRAVE_FIND_QUIETLY) +ELSE(CRAVE_FOUND) + IF(CRAVE_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find CRAVE") + ENDIF(CRAVE_FIND_REQUIRED) +ENDIF(CRAVE_FOUND) + +MARK_AS_ADVANCED(CRAVE_INCLUDE_DIRS CRAVE_LIBRARIES) + diff --git a/contrib/crave/cmake/FindSystemC.cmake b/contrib/crave/cmake/FindSystemC.cmake new file mode 100644 index 00000000..759d7524 --- /dev/null +++ b/contrib/crave/cmake/FindSystemC.cmake @@ -0,0 +1,55 @@ +#______________________________________________________________________________ +# +# This CMake package creates a SystemC target +#______________________________________________________________________________ +# +# SystemC_FOUND - system has SystemC +# SystemC_INCLUDE_DIRS - the SystemC include directory +# SystemC_LIBRARIES - Link these to use SystemC + +IF(SystemC_LIBRARIES AND SystemC_INCLUDE_DIRS) + SET(SystemC_FOUND TRUE) +ELSE(SystemC_LIBRARIES AND SystemC_INCLUDE_DIRS) + FIND_PATH(SystemC_INCLUDE_DIR + HINTS + ${SYSTEMC_HOME}/include + $ENV{SYSTEMC_HOME}/include + NAMES + systemc.h + ) + + FIND_LIBRARY(SystemC_LIBRARY + HINTS + ${SYSTEMC_HOME}/lib + ${SYSTEMC_HOME}/lib-linux + ${SYSTEMC_HOME}/lib-linux64 + ${SYSTEMC_HOME}/lib-macos + $ENV{SYSTEMC_HOME}/lib + $ENV{SYSTEMC_HOME}/lib-linux + $ENV{SYSTEMC_HOME}/lib-linux64 + $ENV{SYSTEMC_HOME}/lib-macos + NAMES + libsystemc.a + ) + +SET(SystemC_INCLUDE_DIRS ${SystemC_INCLUDE_DIR}) +SET(SystemC_LIBRARIES ${SystemC_LIBRARY}) + +IF(SystemC_INCLUDE_DIRS AND SystemC_LIBRARIES) + SET(SystemC_FOUND TRUE) +ENDIF(SystemC_INCLUDE_DIRS AND SystemC_LIBRARIES) + +IF(SystemC_FOUND) + IF(NOT SystemC_FIND_QUIETLY) + MESSAGE(STATUS "Found SystemC: ${SystemC_LIBRARIES}") + ENDIF(NOT SystemC_FIND_QUIETLY) +ELSE(SystemC_FOUND) + IF(SystemC_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find SystemC") + ENDIF(SystemC_FIND_REQUIRED) +ENDIF(SystemC_FOUND) + +# show the SystemC_INCLUDE_DIRS and SystemC_LIBRARIES variables only in the advanced view +MARK_AS_ADVANCED(SystemC_INCLUDE_DIRS SystemC_LIBRARIES) + +ENDIF(SystemC_LIBRARIES AND SystemC_INCLUDE_DIRS) diff --git a/contrib/crave/cmake/FindUVM-SystemC.cmake b/contrib/crave/cmake/FindUVM-SystemC.cmake new file mode 100644 index 00000000..9641db5c --- /dev/null +++ b/contrib/crave/cmake/FindUVM-SystemC.cmake @@ -0,0 +1,51 @@ +#______________________________________________________________________________ +# +# This CMake package creates a UVM-SystemC target +#______________________________________________________________________________ +# +# UVM_SystemC_FOUND - system has UVM-SystemC +# UVM_SystemC_INCLUDE_DIRS - the UVM-SystemC include directory +# UVM_SystemC_LIBRARIES - Link these to use UVM-SystemC + +SET(UVM_SYSTEMC_HOME ${PROJECT_SOURCE_DIR}/../../) + +IF(UVM_SystemC_LIBRARIES AND UVM_SystemC_INCLUDE_DIRS) + SET(UVM_SystemC_FOUND TRUE) +ELSE(UVM_SystemC_LIBRARIES AND UVM_SystemC_INCLUDE_DIRS) + FIND_PATH(UVM_SystemC_INCLUDE_DIR + HINTS + ${UVM_SYSTEMC_HOME}/include + NAMES + uvm.h + ) + + FIND_LIBRARY(UVM_SystemC_LIBRARY + HINTS + ${UVM_SYSTEMC_HOME}/lib + ${UVM_SYSTEMC_HOME}/lib-linux + ${UVM_SYSTEMC_HOME}/lib-linux64 + ${UVM_SYSTEMC_HOME}/lib-macos + NAMES + libuvm-systemc.a + ) + +SET(UVM_SystemC_INCLUDE_DIRS ${UVM_SystemC_INCLUDE_DIR}) +SET(UVM_SystemC_LIBRARIES ${UVM_SystemC_LIBRARY}) + +IF(UVM_SystemC_INCLUDE_DIRS AND UVM_SystemC_LIBRARIES) + SET(UVM_SystemC_FOUND TRUE) +ENDIF(UVM_SystemC_INCLUDE_DIRS AND UVM_SystemC_LIBRARIES) + +IF(UVM_SystemC_FOUND) + IF(NOT UVM_SystemC_FIND_QUIETLY) + MESSAGE(STATUS "Found UVM_SystemC: ${UVM_SystemC_LIBRARIES}") + ENDIF(NOT UVM_SystemC_FIND_QUIETLY) +ELSE(UVM_SystemC_FOUND) + IF(UVM_SystemC_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find UVM_SystemC") + ENDIF(UVM_SystemC_FIND_REQUIRED) +ENDIF(UVM_SystemC_FOUND) + +MARK_AS_ADVANCED(UVM_SystemC_INCLUDE_DIRS UVM_SystemC_LIBRARIES) + +ENDIF(UVM_SystemC_LIBRARIES AND UVM_SystemC_INCLUDE_DIRS) diff --git a/contrib/crave/crave-2017-03-09.tar.gz b/contrib/crave/crave-2017-03-09.tar.gz new file mode 100644 index 00000000..b789582b Binary files /dev/null and b/contrib/crave/crave-2017-03-09.tar.gz differ diff --git a/contrib/crave/crave_package_deps.tar.gz b/contrib/crave/crave_package_deps.tar.gz new file mode 100644 index 00000000..9786fd16 Binary files /dev/null and b/contrib/crave/crave_package_deps.tar.gz differ diff --git a/contrib/crave/crave_package_deps_stp.tar.gz b/contrib/crave/crave_package_deps_stp.tar.gz new file mode 100644 index 00000000..d18bfa60 Binary files /dev/null and b/contrib/crave/crave_package_deps_stp.tar.gz differ diff --git a/contrib/crave/examples/CMakeLists.txt b/contrib/crave/examples/CMakeLists.txt new file mode 100644 index 00000000..ff431aa3 --- /dev/null +++ b/contrib/crave/examples/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(CandyLovers) \ No newline at end of file diff --git a/contrib/crave/examples/CandyLovers/CMakeLists.txt b/contrib/crave/examples/CandyLovers/CMakeLists.txt new file mode 100644 index 00000000..258d2c4f --- /dev/null +++ b/contrib/crave/examples/CandyLovers/CMakeLists.txt @@ -0,0 +1,5 @@ +add_definitions(-std=c++11) + +add_executable(CandyLovers sc_main.cpp verification/subscribers/jelly_bean_sb_subscriber.cpp verification/subscribers/jelly_bean_scoreboard.cpp verification/subscribers/jelly_bean_fc_subscriber.cpp) +target_link_libraries(CandyLovers ${SystemC_LIBRARIES} ${CRAVE_LIBRARIES} + ${UVM_SystemC_LIBRARIES} ${SystemC_LIBRARIES}) \ No newline at end of file diff --git a/contrib/crave/examples/CandyLovers/dut/jelly_bean_if.h b/contrib/crave/examples/CandyLovers/dut/jelly_bean_if.h new file mode 100644 index 00000000..36f393a4 --- /dev/null +++ b/contrib/crave/examples/CandyLovers/dut/jelly_bean_if.h @@ -0,0 +1,17 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once +#include +#include + +using namespace uvm; + +class jelly_bean_if { +public: + sc_core::sc_signal > color; + sc_core::sc_signal > flavor; + sc_core::sc_signal sugar_free; + sc_core::sc_signal sour; + sc_core::sc_clock clk; + sc_core::sc_signal > taste; +}; diff --git a/contrib/crave/examples/CandyLovers/dut/jelly_bean_taster.h b/contrib/crave/examples/CandyLovers/dut/jelly_bean_taster.h new file mode 100644 index 00000000..22fe4c9d --- /dev/null +++ b/contrib/crave/examples/CandyLovers/dut/jelly_bean_taster.h @@ -0,0 +1,32 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once +#include +#include + +using namespace uvm; + +//The taster gets a bean by its color and flavor. Also if its sour or even sugar free. +//As a result the taster decides if the bean is tasty or not. +SC_MODULE(jelly_bean_taster) { + sc_in > color; + sc_in > flavor; + sc_in sugar_free; + sc_in sour; + sc_in clk; + sc_out > taste; + + void taste_bean() { + if (flavor.read() == 0x4 && sour.read()) { //Chocolate and sour + taste.write(0x2); //Yucky + } else { + taste.write(0x1); //Yummy + } + } + + SC_CTOR(jelly_bean_taster) : color("color"), flavor("flavor"), sugar_free("sugar_free"), + sour("sour"), clk("clk"), taste("taste") { + SC_METHOD(taste_bean); + sensitive << clk; + } +}; diff --git a/contrib/crave/examples/CandyLovers/sc_main.cpp b/contrib/crave/examples/CandyLovers/sc_main.cpp new file mode 100644 index 00000000..036a0c81 --- /dev/null +++ b/contrib/crave/examples/CandyLovers/sc_main.cpp @@ -0,0 +1,29 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#include +#include +#include + +#include "dut/jelly_bean_if.h" +#include "dut/jelly_bean_taster.h" +#include "verification/jelly_bean_test.h" + +int sc_main(int, char*[]) +{ + crave::init("crave.cfg"); + jelly_bean_taster* jb_taster = new jelly_bean_taster("jb_taster"); + jelly_bean_if* jb_if = new jelly_bean_if(); + + jb_taster->taste(jb_if->taste); + jb_taster->sour(jb_if->sour); + jb_taster->sugar_free(jb_if->sugar_free); + jb_taster->flavor(jb_if->flavor); + jb_taster->color(jb_if->color); + jb_taster->clk(jb_if->clk); + + //uvm_config_db_options::turn_on_tracing(); + uvm_config_db::set(0, "*", "interface", jb_if); + uvm::run_test("jelly_bean_test"); + uvm::print_topology(); + return 0; +} diff --git a/contrib/crave/examples/CandyLovers/verification/jelly_bean_agent.h b/contrib/crave/examples/CandyLovers/verification/jelly_bean_agent.h new file mode 100644 index 00000000..82d34453 --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/jelly_bean_agent.h @@ -0,0 +1,45 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include +#include + +#include "jelly_bean_driver.h" +#include "jelly_bean_sequencer.h" +#include "jelly_bean_monitor.h" +#include "transactions/jelly_bean_transaction.h" + +using uvm::uvm_agent; +using uvm::uvm_component_name; +using uvm::uvm_phase; +using uvm::uvm_analysis_port; + +class jelly_bean_agent : public uvm_agent { +public: + uvm_analysis_port jb_ap; + jelly_bean_sequencer* jb_seqr; + jelly_bean_driver* jb_drvr; + jelly_bean_monitor* jb_mon; + + jelly_bean_agent(uvm_component_name name) : uvm_agent(name), jb_seqr(0), jb_drvr(0), jb_mon(0) { + }; + + virtual ~jelly_bean_agent() { + }; + + void build_phase(uvm_phase& phase) { + uvm_agent::build_phase(phase); + jb_seqr = jelly_bean_sequencer::type_id::create("jb_seqr", this); + jb_mon = jelly_bean_monitor::type_id::create("jb_mon", this); + jb_drvr = jelly_bean_driver::type_id::create("jb_drvr", this); + } + + void connect_phase(uvm_phase& phase) { + uvm_agent::connect_phase(phase); + jb_drvr->seq_item_port.connect(jb_seqr->seq_item_export); + jb_mon->analyse.connect(jb_ap); + } + + UVM_COMPONENT_UTILS(jelly_bean_agent); +}; diff --git a/contrib/crave/examples/CandyLovers/verification/jelly_bean_configuration.h b/contrib/crave/examples/CandyLovers/verification/jelly_bean_configuration.h new file mode 100644 index 00000000..14bed82a --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/jelly_bean_configuration.h @@ -0,0 +1,17 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include +#include + +class jelly_bean_configuration : public uvm::uvm_object { +public: + UVM_OBJECT_UTILS(jelly_bean_configuration); + + jelly_bean_configuration(const std::string& name_ = "") : uvm::uvm_object(name_) { + }; + + virtual ~jelly_bean_configuration() { + }; +}; diff --git a/contrib/crave/examples/CandyLovers/verification/jelly_bean_driver.h b/contrib/crave/examples/CandyLovers/verification/jelly_bean_driver.h new file mode 100644 index 00000000..78346b8d --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/jelly_bean_driver.h @@ -0,0 +1,56 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include +#include +#include +#include +#include + +#include "transactions/jelly_bean_transaction.h" +#include "../dut/jelly_bean_taster.h" +#include "../dut/jelly_bean_if.h" + +using uvm::uvm_driver; +using uvm::uvm_component_name; +using uvm::uvm_phase; + +template +class jelly_bean_driver : public uvm_driver { +private: + jelly_bean_if* interface; + +public: + + jelly_bean_driver(uvm_component_name name) : uvm_driver(name), interface(0) { + }; + UVM_COMPONENT_PARAM_UTILS(jelly_bean_driver); + + virtual ~jelly_bean_driver() { + }; + + void build_phase(uvm_phase& phase) { + uvm_driver::build_phase(phase); + if (!uvm_config_db::get(this, "", "interface", interface)) + UVM_FATAL(this->name(), "Virtual interface not defined! Simulation aborted!"); + } + + void run_phase(uvm_phase& phase) { + uvm_driver::run_phase(phase); + REQ req, rsp; + while (true) { + sc_core::wait(interface->clk.posedge_event()); + interface->flavor.write(0x0); + this->seq_item_port->get_next_item(req); + sc_core::wait(interface->clk.posedge_event()); + interface->flavor.write(req.flavor._to_integral()); + interface->color.write(req.color._to_integral()); + interface->sour.write(req.sour); + interface->sugar_free.write(req.sugar_free); + rsp.set_id_info(req); + this->seq_item_port->item_done(); + this->seq_item_port->put(rsp); + } + } +}; diff --git a/contrib/crave/examples/CandyLovers/verification/jelly_bean_env.h b/contrib/crave/examples/CandyLovers/verification/jelly_bean_env.h new file mode 100644 index 00000000..7d3ae377 --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/jelly_bean_env.h @@ -0,0 +1,40 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include + +#include "jelly_bean_agent.h" +#include "subscribers/jelly_bean_scoreboard.h" +#include "subscribers/jelly_bean_fc_subscriber.h" + +using uvm::uvm_env; +using uvm::uvm_component_name; +using uvm::uvm_phase; + +class jelly_bean_env : public uvm_env { +public: + jelly_bean_agent* jb_agent; + jelly_bean_fc_subscriber* jb_fc_sub; + jelly_bean_scoreboard* jb_sb; + UVM_COMPONENT_UTILS(jelly_bean_env); + + jelly_bean_env(uvm_component_name name) : uvm_env(name), jb_agent(0), jb_sb(0), jb_fc_sub(0) { + }; + + virtual ~jelly_bean_env() { + }; + + void build_phase(uvm_phase& phase) { + uvm_env::build_phase(phase); + jb_agent = jelly_bean_agent::type_id::create("jb_agent", this); + jb_fc_sub = jelly_bean_fc_subscriber::type_id::create("jb_fc_sub", this); + jb_sb = jelly_bean_scoreboard::type_id::create("jb_sb", this); + } + + void connect_phase(uvm_phase& phase) { + uvm_env::connect_phase(phase); + jb_agent->jb_ap.connect(jb_fc_sub->analysis_export); + jb_agent->jb_ap.connect(jb_sb->jb_analysis_export); + } +}; diff --git a/contrib/crave/examples/CandyLovers/verification/jelly_bean_monitor.h b/contrib/crave/examples/CandyLovers/verification/jelly_bean_monitor.h new file mode 100644 index 00000000..f91ff432 --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/jelly_bean_monitor.h @@ -0,0 +1,55 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include + +#include "transactions/jelly_bean_transaction.h" +#include "../dut/jelly_bean_if.h" + +using uvm::uvm_monitor; +using uvm::uvm_phase; +using uvm::uvm_component_name; +using uvm::uvm_config_db; +using uvm::uvm_analysis_port; + +class jelly_bean_monitor : public uvm_monitor { +private: + jelly_bean_if* interface; + +public: + uvm_analysis_port analyse; + + jelly_bean_monitor(uvm_component_name name) : uvm_monitor(name), analyse("jba_port"), interface(0) { + }; + UVM_COMPONENT_UTILS(jelly_bean_monitor); + + virtual ~jelly_bean_monitor() { + }; + + void build_phase(uvm_phase& phase) { + uvm_monitor::build_phase(phase); + + if (!uvm_config_db::get(this, "", "interface", interface)) + UVM_FATAL(this->get_name(), "Virtual interface not defined! Simulation aborted!"); + } + + void run_phase(uvm::uvm_phase& phase) { + uvm_monitor::run_phase(phase); + while (true) { + jelly_bean_transaction trans; + sc_core::wait(interface->flavor.default_event()); + if (interface->flavor.read() != flavor_e::NO_FLAVOR) { + // TODO possible to eliminate _unchecked in the following? + trans = jelly_bean_transaction(); + trans.color = color_e::_from_integral_unchecked(interface->color.read().to_int()); + trans.sour = interface->sour.read(); + trans.sugar_free = interface->sugar_free.read(); + trans.flavor = flavor_e::_from_integral_unchecked(interface->flavor.read().to_int()); + sc_core::wait(interface->clk.posedge_event()); + trans.taste = taste_e::_from_integral_unchecked(interface->taste.read().to_int()); + analyse.write(trans); + } + } + } +}; diff --git a/contrib/crave/examples/CandyLovers/verification/jelly_bean_sequencer.h b/contrib/crave/examples/CandyLovers/verification/jelly_bean_sequencer.h new file mode 100644 index 00000000..52ff6fac --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/jelly_bean_sequencer.h @@ -0,0 +1,21 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include +#include + +using uvm::uvm_sequencer; +using uvm::uvm_component_name; + +template +class jelly_bean_sequencer : public uvm_sequencer { +public: + + jelly_bean_sequencer(uvm_component_name name) : uvm_sequencer(name) { + }; + UVM_COMPONENT_PARAM_UTILS(jelly_bean_sequencer); + + virtual ~jelly_bean_sequencer() { + }; +}; diff --git a/contrib/crave/examples/CandyLovers/verification/jelly_bean_test.h b/contrib/crave/examples/CandyLovers/verification/jelly_bean_test.h new file mode 100644 index 00000000..4aba12b2 --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/jelly_bean_test.h @@ -0,0 +1,82 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include +#include + +#include "jelly_bean_env.h" +#include "transactions/jelly_bean_transaction.h" +#include "transactions/sugar_free_jelly_bean_transaction.h" +#include "sequences/one_jelly_bean_sequence.h" +#include "sequences/same_flavored_jelly_beans_sequence.h" +#include "sequences/gift_boxed_jelly_beans_sequence.h" +#include "jelly_bean_configuration.h" + +using uvm::uvm_test; +using uvm::uvm_component_name; +using uvm::uvm_phase; +using uvm::uvm_config_db; +using std::cout; +using std::endl; + +class jelly_bean_test : public uvm_test { +private: + jelly_bean_env* jb_env; + +public: + UVM_COMPONENT_UTILS(jelly_bean_test); + + jelly_bean_test(uvm_component_name name) : uvm_test(name), jb_env(0) { + }; + + virtual ~jelly_bean_test() { + }; + + void build_phase(uvm_phase& phase) { + uvm_test::build_phase(phase); + jelly_bean_configuration jb_cfg("jb_cf"); + //assert(jb_cfg.randomize()); TODO: Randomized config? + uvm_config_db::set(this, "*", "config", jb_cfg); + jelly_bean_transaction::type_id::set_type_override(sugar_free_jelly_bean_transaction::get_type()); + jb_env = jelly_bean_env::type_id::create("jb_env", this); + } + + void run_phase(uvm_phase& phase) { + UVM_INFO("jelly_bean_test", "Test is running!", UVM_LOW); + + cout << std::endl << "######### One jelly bean ##########" << endl << endl; + + //Start with a "sequence" of one single bean + one_jelly_bean_sequence* jb_seq; + phase.raise_objection(this); + jb_seq = one_jelly_bean_sequence::type_id::create("jb_seq", this); + jb_seq->start(jb_env->jb_agent->jb_seqr); + sc_core::wait(10, SC_NS); + + cout << "############## Same flavored jelly beans ###############" << endl << endl; + + //Now test a sequence of two to four beans that will have the same flavor + same_flavored_jelly_beans_sequence* jb_sf_seq; + jb_sf_seq = same_flavored_jelly_beans_sequence::type_id::create("jb_sf_seq", this); + jb_sf_seq->start(jb_env->jb_agent->jb_seqr); + sc_core::wait(10, SC_NS); + + cout << "############## Gift boxed jelly beans ################" << endl << endl; + + //Finally test a gift box: A sequence of two or three independent same flavored + //sequences with two to four beens each + gift_boxed_jelly_beans_sequence* jb_gb_seq; + jb_gb_seq = gift_boxed_jelly_beans_sequence::type_id::create("jb_gb_seq", this); + jb_gb_seq->start(jb_env->jb_agent->jb_seqr); + sc_core::wait(10, SC_NS); + + phase.drop_objection(this); + } + + void final_phase(uvm_phase& phase) { + uvm_test::final_phase(phase); + //Needed to stop the clock properly + sc_core::sc_stop(); + } +}; diff --git a/contrib/crave/examples/CandyLovers/verification/sequences/gift_boxed_jelly_beans_sequence.h b/contrib/crave/examples/CandyLovers/verification/sequences/gift_boxed_jelly_beans_sequence.h new file mode 100644 index 00000000..91abf636 --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/sequences/gift_boxed_jelly_beans_sequence.h @@ -0,0 +1,38 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include +#include + +#include "same_flavored_jelly_beans_sequence.h" + +template +class gift_boxed_jelly_beans_sequence : public uvm_randomized_sequence { +public: + crv_variable num_jelly_bean_flavors; + crv_constraint c_num_flavors{2 <= num_jelly_bean_flavors(), num_jelly_bean_flavors() <= 3}; + + gift_boxed_jelly_beans_sequence(crave::crv_object_name name) : uvm_randomized_sequence(name) { + }; + UVM_OBJECT_PARAM_UTILS(gift_boxed_jelly_beans_sequence); + + void body() { + this->randomize(); + same_flavored_jelly_beans_sequence* jb_seq; + string output = "jelly_bean_seq length: " + std::to_string(num_jelly_bean_flavors); + UVM_INFO("gift_boxed_jelly_beans_sequence", output, UVM_LOW); + + REQ* req = new REQ(); + RSP* rsp = new RSP(); + + for (unsigned int i = 0; i < num_jelly_bean_flavors; i++) { + jb_seq = same_flavored_jelly_beans_sequence::type_id::create("jb_sf_seq_gb", 0, this->get_full_name()); + assert(jb_seq->randomize()); + UVM_DO(jb_seq); + } + } + + virtual ~gift_boxed_jelly_beans_sequence() { + }; +}; diff --git a/contrib/crave/examples/CandyLovers/verification/sequences/one_jelly_bean_sequence.h b/contrib/crave/examples/CandyLovers/verification/sequences/one_jelly_bean_sequence.h new file mode 100644 index 00000000..9d003338 --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/sequences/one_jelly_bean_sequence.h @@ -0,0 +1,24 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include + +template +class one_jelly_bean_sequence : public uvm::uvm_sequence { +public: + + one_jelly_bean_sequence(const std::string& name_) : uvm_sequence(name_) { + }; + UVM_OBJECT_PARAM_UTILS(one_jelly_bean_sequence); + + void body() { + REQ* req = new REQ(); + RSP* rsp = new RSP(); + UVM_DO(req); + this->get_response(rsp); + } + + virtual ~one_jelly_bean_sequence() { + }; +}; diff --git a/contrib/crave/examples/CandyLovers/verification/sequences/same_flavored_jelly_beans_sequence.h b/contrib/crave/examples/CandyLovers/verification/sequences/same_flavored_jelly_beans_sequence.h new file mode 100644 index 00000000..aeb84a2d --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/sequences/same_flavored_jelly_beans_sequence.h @@ -0,0 +1,41 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include +#include + +template + +//Use CRAVE in a sequence, hence inherit from uvm_randomized_sequence +class same_flavored_jelly_beans_sequence : public uvm_randomized_sequence { +public: + //Again define some randomizable attributes + crv_variable length; + crv_variable flavor; + + //The length of the sequence may differ between two and four + crv_constraint c_length{2 <= length(), length() <= 4}; + //Make sure the flavor that persits in this sequence is not flavorless + crv_constraint c_no_no_flavor{flavor() != flavor_e::NO_FLAVOR}; + + void body() { + //Randomize the sequence once to get its flavor and length + this->randomize(); + REQ* req = new REQ(); + RSP* rsp = new RSP(); + for (unsigned int i = 0; i < length; i++) { + //Create transactions and rerandomize them to have the flavor of the sequence + //The makro UVM_DO_WITH of UVM_SystemC can be used for this + UVM_DO_WITH(req, req->flavor() == flavor._to_integral()); + this->get_response(rsp); + } + } + + same_flavored_jelly_beans_sequence(crave::crv_object_name name) : uvm_randomized_sequence(name) { + }; + UVM_OBJECT_PARAM_UTILS(same_flavored_jelly_beans_sequence); + + virtual ~same_flavored_jelly_beans_sequence() { + }; +}; diff --git a/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_fc_subscriber.cpp b/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_fc_subscriber.cpp new file mode 100644 index 00000000..b13740ec --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_fc_subscriber.cpp @@ -0,0 +1,8 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#include "jelly_bean_fc_subscriber.h" + +void jelly_bean_fc_subscriber::write(const jelly_bean_transaction& t){ + jb_tx = t; + jb_cg.sample(); +} diff --git a/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_fc_subscriber.h b/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_fc_subscriber.h new file mode 100644 index 00000000..ea625bff --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_fc_subscriber.h @@ -0,0 +1,78 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include +#include +#include + +#include "../transactions/jelly_bean_transaction.h" + +using crave::crv_variable; +using crave::crv_coverpoint; +using crave::crv_object_name; + +//First define a covergroup +class jelly_bean_cg : public crave::crv_covergroup { +public: + //These variables represent the values + crv_variable cover_color; + crv_variable cover_flavor; + crv_variable cover_sugar_free; + crv_variable cover_sour; + + //These coverpoints actual measure coverage + crv_coverpoint cp_color{"cp_color"}; + crv_coverpoint cp_flavor{"cp_flavor"}; + crv_coverpoint cp_sugar_free{"cp_sugar_free"}; + crv_coverpoint cp_sour{"cp_sour"}; + + jelly_bean_cg(crv_object_name) { + //Each coverpoint has a bin that is described by a constraint + //If a measured value matches the constraint, the bin is increased by one + cp_sugar_free.bins(cover_sugar_free() == true); + cp_sour.bins(cover_sour() == true); + cp_sugar_free.bins(cover_sugar_free() == false); + cp_sour.bins(cover_sour() == false); + + //A bin for each color/flavor + for (int i = 0; i < 3; i++) { + cp_color.bins(cover_color() == i); + } + for (int i = 1; i < flavor_e::_size(); i++) { + cp_flavor.bins(cover_flavor() == i); + } + } + + jelly_bean_cg(const jelly_bean_cg&) { + } + + virtual ~jelly_bean_cg() { + } +}; + +class jelly_bean_fc_subscriber : public uvm::uvm_subscriber { +public: + UVM_COMPONENT_UTILS(jelly_bean_fc_subscriber); + + jelly_bean_transaction jb_tx; + jelly_bean_cg jb_cg = jelly_bean_cg("jb_cg"); + + jelly_bean_fc_subscriber(uvm::uvm_component_name name) : uvm::uvm_subscriber(name) { + //The last action needed is to bind transaction variables to its corresponding coverpoint + jb_cg.cover_color.bind(jb_tx.color); + jb_cg.cover_flavor.bind(jb_tx.flavor); + jb_cg.cover_sugar_free.bind(jb_tx.sugar_free); + jb_cg.cover_sour.bind(jb_tx.sour); + }; + + virtual ~jelly_bean_fc_subscriber() { + }; + + void write(const jelly_bean_transaction& t); + + void report_phase(uvm::uvm_phase& phase) { + uvm_subscriber::report_phase(phase); + jb_cg.report(); + } +}; diff --git a/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_sb_subscriber.cpp b/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_sb_subscriber.cpp new file mode 100644 index 00000000..f5f3d3c9 --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_sb_subscriber.cpp @@ -0,0 +1,8 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#include "jelly_bean_sb_subscriber.h" + +void jelly_bean_sb_subscriber::write(const jelly_bean_transaction& t){ + jelly_bean_scoreboard* jb_sb = dynamic_cast(this->m_comp_parent); + jb_sb->check_jelly_bean_taste(t); +} diff --git a/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_sb_subscriber.h b/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_sb_subscriber.h new file mode 100644 index 00000000..482b734f --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_sb_subscriber.h @@ -0,0 +1,24 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include + +#include "../transactions/jelly_bean_transaction.h" +#include "jelly_bean_scoreboard.h" + +using uvm::uvm_subscriber; +using uvm::uvm_component_name; + +class jelly_bean_sb_subscriber : public uvm_subscriber { +public: + UVM_COMPONENT_UTILS(jelly_bean_sb_subscriber); + + jelly_bean_sb_subscriber(uvm_component_name name) : uvm_subscriber(name) { + }; + + virtual ~jelly_bean_sb_subscriber() { + }; + + void write(const jelly_bean_transaction& t); +}; diff --git a/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_scoreboard.cpp b/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_scoreboard.cpp new file mode 100644 index 00000000..188927c5 --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_scoreboard.cpp @@ -0,0 +1,37 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#include "jelly_bean_scoreboard.h" + +using uvm::uvm_table_printer; + +void jelly_bean_scoreboard::build_phase(uvm::uvm_phase& phase){ + uvm_scoreboard::build_phase(phase); + jb_sb_sub = jelly_bean_sb_subscriber::type_id::create("jb_sb_sub", this); +} + +void jelly_bean_scoreboard::connect_phase(uvm::uvm_phase& phase){ + uvm_scoreboard::connect_phase(phase); + jb_analysis_export.connect(jb_sb_sub->analysis_export); +} + +void jelly_bean_scoreboard::check_jelly_bean_taste( + jelly_bean_transaction jb_tx){ + uvm_table_printer* p = new uvm_table_printer(); + std::stringstream concat; + if (jb_tx.flavor == flavor_e::CHOCOLATE && jb_tx.sour) { + if (jb_tx.taste == taste_e::YUCKY) { + concat << "You have a good sense of taste." << std::endl << jb_tx.sprint(p); + UVM_INFO("jelly_bean_scoreboard", concat.str(), uvm::UVM_LOW); + } else { + concat << "You lost sense of taste!" << std::endl << jb_tx.sprint(p); + UVM_ERROR("jelly_bean_scoreboard", concat.str()); + } + } else + if (jb_tx.taste == taste_e::YUMMY) { + concat << "You have a good sense of taste." << std::endl << jb_tx.sprint(p); + UVM_INFO("jelly_bean_scoreboard", concat.str(), uvm::UVM_LOW); + } else { + concat << "You lost sense of taste!" << std::endl << jb_tx.sprint(p); + UVM_ERROR("jelly_bean_scoreboard", concat.str()); + } +} diff --git a/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_scoreboard.h b/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_scoreboard.h new file mode 100644 index 00000000..98aa44c8 --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/subscribers/jelly_bean_scoreboard.h @@ -0,0 +1,36 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include +#include + +#include "jelly_bean_sb_subscriber.h" +#include "../transactions/jelly_bean_transaction.h" + +using uvm::uvm_scoreboard; +using uvm::uvm_component_name; +using uvm::uvm_phase; + +class jelly_bean_sb_subscriber; + +class jelly_bean_scoreboard : public uvm_scoreboard { +private: + jelly_bean_sb_subscriber* jb_sb_sub; +public: + uvm::uvm_analysis_export jb_analysis_export; + + UVM_COMPONENT_UTILS(jelly_bean_scoreboard) + jelly_bean_scoreboard(uvm_component_name name) : uvm_scoreboard(name), jb_sb_sub(0) { + }; + + virtual ~jelly_bean_scoreboard() { + }; + + void build_phase(uvm_phase& phase); + + void connect_phase(uvm_phase& phase); + + void check_jelly_bean_taste(jelly_bean_transaction jb_tx); + +}; diff --git a/contrib/crave/examples/CandyLovers/verification/transactions/jelly_bean_transaction.h b/contrib/crave/examples/CandyLovers/verification/transactions/jelly_bean_transaction.h new file mode 100644 index 00000000..f37b122c --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/transactions/jelly_bean_transaction.h @@ -0,0 +1,61 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using crave::crv_variable; +using crave::crv_constraint; +using crave::if_then; +using crave::crv_object_name; + +CRAVE_BETTER_ENUM(color_e, RED = 0, GREEN = 1, BLUE = 2); +CRAVE_BETTER_ENUM(flavor_e, NO_FLAVOR = 0, APPLE = 1, BLUEBERRY = 2, + BUBBLE_GUM = 3, CHOCOLATE = 4); +CRAVE_BETTER_ENUM(taste_e, UNKNOWN = 0, YUMMY = 1, YUCKY = 2); + +//Include CRAVE into a sequence_item by using uvm_randomized_sequence_item for inheritence +class jelly_bean_transaction : public uvm_randomized_sequence_item { +public: + UVM_OBJECT_UTILS(jelly_bean_transaction); + + //Define some randomziable attributes of a bean + crv_variable color; + crv_variable flavor; + crv_variable taste; + crv_variable sugar_free; + crv_variable sour; + + //A bean must have a flavor + crv_constraint c_flavor{flavor() != flavor_e::NO_FLAVOR}; + //A apple flavored bean implies it cannot be blue + crv_constraint c_color1{if_then(flavor() == flavor_e::APPLE, color() != color_e::BLUE)}; + //A blueberry flavored bean implies it must be blue + crv_constraint c_color2{if_then(flavor() == flavor_e::BLUEBERRY, color() == color_e::BLUE)}; + //And finally, a green bean must be sour + crv_constraint c_sour{if_then(color() == color_e::GREEN, sour() == true)}; + + jelly_bean_transaction(crv_object_name name = "jelly_beans_trans") : uvm_randomized_sequence_item(name) { + }; + + virtual ~jelly_bean_transaction() { + }; + + virtual void do_print(const uvm::uvm_printer& printer) const { + printer.print_string("color", color._to_string()); + printer.print_string("flavor", flavor._to_string()); + printer.print_string("taste", taste._to_string()); + printer.print_field_int("sugar_free", (int) sugar_free); + printer.print_field_int("sour", (int) sour); + } +}; + diff --git a/contrib/crave/examples/CandyLovers/verification/transactions/sugar_free_jelly_bean_transaction.h b/contrib/crave/examples/CandyLovers/verification/transactions/sugar_free_jelly_bean_transaction.h new file mode 100644 index 00000000..12c428cf --- /dev/null +++ b/contrib/crave/examples/CandyLovers/verification/transactions/sugar_free_jelly_bean_transaction.h @@ -0,0 +1,23 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include + +#include "jelly_bean_transaction.h" + +using crave::crv_constraint; +using std::string; + +class sugar_free_jelly_bean_transaction : public jelly_bean_transaction { +public: + crv_constraint c_sugarFree{sugar_free() == true}; + + UVM_OBJECT_UTILS(sugar_free_jelly_bean_transaction); + + sugar_free_jelly_bean_transaction(const string& name = "sugar_free_transaction") : jelly_bean_transaction(name) { + }; + + virtual ~sugar_free_jelly_bean_transaction() { + }; +}; diff --git a/contrib/crave/presentation/UVM-CRAVE.pdf b/contrib/crave/presentation/UVM-CRAVE.pdf new file mode 100644 index 00000000..637b95dd Binary files /dev/null and b/contrib/crave/presentation/UVM-CRAVE.pdf differ diff --git a/contrib/crave/src/include/crave2uvm.h b/contrib/crave/src/include/crave2uvm.h new file mode 100644 index 00000000..6830d9fc --- /dev/null +++ b/contrib/crave/src/include/crave2uvm.h @@ -0,0 +1,44 @@ +/*! \file crave2uvm.h + \brief Include this file to get all Crave2UVM functionality. + + This file contains all includes and macros you need to get started with Crave2UVM. + It includes the two adapter classes and redefines UVM_DO_ON_PRI_WITH in order to + * add random verification with constraints. + */ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once +#include "uvm_randomized_sequence_item.h" +#include "uvm_randomized_sequence.h" + +#undef UVM_DO +#define UVM_DO(SEQ_OR_ITEM) \ + UVM_DO_ON_PRI_WITH(SEQ_OR_ITEM, this->m_sequencer, -1,) + +#undef UVM_DO_PRI +#define UVM_DO_PRI(SEQ_OR_ITEM, PRIORITY) \ + UVM_DO_ON_PRI_WITH(SEQ_OR_ITEM, this->m_sequencer, PRIORITY,) + +#undef UVM_DO_ON +#define UVM_DO_ON(SEQ_OR_ITEM, SEQR) \ + UVM_DO_ON_PRI_WITH(SEQ_OR_ITEM, SEQR, -1,) + +#undef UVM_DO_ON_PRI +#define UVM_DO_ON_PRI(SEQ_OR_ITEM, SEQR, PRIORITY) \ + UVM_DO_ON_PRI_WITH(SEQ_OR_ITEM, SEQR, PRIORITY,) + +/*! \def UVM_DO_ON_PRI_WITH(SEQ_OR_ITEM, SEQR, PRIORITY, CONSTRAINTS) + \brief Redefine UVM_DO_ON_PRI_WITH to use in \a CONSTRAINTS with CRAVE. + */ +#undef UVM_DO_ON_PRI_WITH +#define UVM_DO_ON_PRI_WITH(SEQ_OR_ITEM, SEQR, PRIORITY, CONSTRAINTS) \ + { \ + ::uvm::uvm_sequence_base* seq__; \ + seq__ = dynamic_cast(SEQ_OR_ITEM); \ + if (seq__ == NULL) this->start_item(SEQ_OR_ITEM, PRIORITY); \ + if (seq__ == NULL && !SEQ_OR_ITEM->randomize_with(CONSTRAINTS)) \ + UVM_WARNING("RNDFLD", "Randomization failed in uvm_do_with action"); \ + if (seq__ == NULL) this->finish_item(SEQ_OR_ITEM, PRIORITY); \ + else seq__->start(SEQR, this, PRIORITY, 0); \ + } \ + diff --git a/contrib/crave/src/include/uvm_randomized_sequence.h b/contrib/crave/src/include/uvm_randomized_sequence.h new file mode 100644 index 00000000..852aad83 --- /dev/null +++ b/contrib/crave/src/include/uvm_randomized_sequence.h @@ -0,0 +1,55 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include +#include +#include +#include +#include + +/** + * \brief Overrides uvm_sequence and crv_sequence_item to merge its functionality. + * + * This class is intendant as an adapter to merge CRAVE functionality into UVM-SystemC + * processes without harming them. To use it, simply inherit from this class instead from + * uvm_sequence. You may now use CRAVE variables and constraints in your UVM-Sequence. + */ + +template +class uvm_randomized_sequence : public uvm::uvm_sequence, public crave::crv_sequence_item { +public: + /** + * \brief Register uvm_randomized_sequence with UVM-SystemC. + */ + UVM_OBJECT_UTILS(uvm_randomized_sequence); + + /** + * \brief Creates a new sequence with given name. + * + * Since both CRAVE and UVM-SystemC are using some kind of name for theier objects + * , both parent will be named the same. std::string is the lowest common denominator + * between the nameing type of CRAVE and of UVM-SystemC. Therefore you may pass a + * std::string or a crave::crv_object_name as argument. + * + * \param name Name of this sequence. + */ + uvm_randomized_sequence(crave::crv_object_name name = "crv_seq") + : uvm::uvm_sequence(name()) { + }; + + virtual ~uvm_randomized_sequence() { + }; +}; + +/** + * \example same_flavored_jelly_beans_sequence.h + * + * Demonstrates how to inherit from this class and use CRAVE to ensure that a special + * attribute remains the same wihthin this sequence. + */ +/** + * \example gift_boxed_jelly_beans_sequence.h + * + * Shows how to randomize the amount of sequences within a sequence with CRAVE. + */ \ No newline at end of file diff --git a/contrib/crave/src/include/uvm_randomized_sequence_item.h b/contrib/crave/src/include/uvm_randomized_sequence_item.h new file mode 100644 index 00000000..74160106 --- /dev/null +++ b/contrib/crave/src/include/uvm_randomized_sequence_item.h @@ -0,0 +1,49 @@ +// Copyright 2015-2016 The CRAVE developers, University of Bremen, Germany. All rights reserved.// + +#pragma once + +#include +#include +#include +#include +#include + +/** + * \brief Overrides uvm_sequence_item and crv_sequence_item to merge its functionality. + * + * This class is intendant as an adapter to merge CRAVE functionality into UVM-SystemC + * processes without harming them. To use it, simply inherit from this class instead from + * uvm_sequence_item. You may now use CRAVE variables and constraints in your UVM-Sequence-Item. + */ + +class uvm_randomized_sequence_item : public uvm::uvm_sequence_item, public crave::crv_sequence_item { +public: + /** + * \brief Register uvm_randomized_sequence_item with UVM-SystemC. + */ + UVM_OBJECT_UTILS(uvm_randomized_sequence_item); + + /** + * \brief Creates a new sequence_item with given name. + * + * Since both CRAVE and UVM-SystemC are using some kind of name for theier objects + * , both parent will be named the same. std::string is the lowest common denominator + * between the nameing type of CRAVE and of UVM-SystemC. Therefore you may pass a + * std::string or a crave::crv_object_name as argument. + * + * \param name Name of this sequence. + */ + uvm_randomized_sequence_item(crave::crv_object_name name = "crv_uvm_seq_item") + : uvm::uvm_sequence_item(name()) { + } + + virtual ~uvm_randomized_sequence_item() { + }; +}; + +/** + * \example jelly_bean_transaction.h + * + * Demonstrates basic randomizsation of UVM-Transactions using + * uvm_randomized_sequence_item. + */