Friday, October 7, 2016

OVM 101.

Test Environment Structure
diagram
// Top level "module" contains class based test environment
//        and structural interface that drives DUT (module)
module top;

import ovm_pkg::*;
import my_pkg::*;

...
dut_if dut_if_inst0 ();
dut dut_inst0 (._if (dut_if_inst0) );

initial
begin
    run_test ("my_test_set");
end

endmodule : top

// ovm classes
// usually classes of test environment that includes fixed test bench
// and variable test sets

`include "ovm_macros.svh"

package my_package;
import ovm_pkg::*;

// Fixed test environment
class my_test_env extends ovm_env;
    `ovm_component_utils (my_test_env)

    // constructor
    function new (string s, ovm_component inst_parent);
        super.new (s, inst_parent);
    endfunction : new

    function void build;
        super.build ();
    endfunction : build

    task run;
        #10 ovm_top.stop_request();
    endtask : run

endclass : my_test_env

class my_test_set extends ovm_test;
    `ovm_component_utils (my_test_set)

    my_test_env my_test_env_handle;

    // constructor
    function new(string s, ovm_component inst_parent); 
        super.new(s, inst_parent);
    endfunction : new

    function void build;
        super.build();
        my_test_env_handle = my_test_env::type_id::create 
            ("my_test_env_handle", this);
    endfunction : build

endclass : my_test_set

// interface dut_if(); -> between test components and DUT
interface dut_if ();
...
endinterface : dut_if

// Design under test
module DUT (dut_if _if); 
endmodule : dut


UVM/OVM primer.


Basic Concepts:
  • Constrained random, coverage-driven verification
  • Configurable, flexible, test benches
  • Verification IP reuse
  • Separation of tests from test bench
  • TLM communication
  • Layered sequential stimulus
  • Standardized messaging
  • Register layer (UVM)

UVM Class Hierarchy
  • uvm_object

OVM Class Hierarchy
  • ovm_object
    • obm_report_object
      • ovm_component
        • ovm_env
        • ovm_test
        • ovm_agent
        • ovm_sequencer
        • ovm_driver
        • ovm_monitor
        • ovm_scoreboard
  • ovm_agent usually contains driver / monitor and sequencer

Prerequisite:
  • Verification Planning
  • Constrained Random Verification
  • SystemVerilog
  • UVM/OVM Class Library, OOP, TLM

Useful Links:


Sunday, October 2, 2016

Java Math.

Math
  • Math.round()

BigDecimal

   java.math.BigDecimal
  • BigDecimal (int)
  • BigDecimal (double)
  • BigDecimal (long)
  • BigDecimal (String) // better
  • Methods
    • add (value)
    • compareTo(value)
    • divide(value, scale, rounding-mode)
    • multiply(value)
    • setScale(scale, rounding-mode)
    • subtract(value)
    • toString()

   java.math.RoundingMode
  • HALF_UP
  • HALF_EVEN
import java.math.*; // imports all classes and 
                    // enumerations in java.math

// convert subtotal and discount percent to 
BigDecimal BigDecimal decimalSubtotal =
    new BigDecimal(Double.toString(subtotal)); 
decimalSubtotal =
    decimalSubtotal.setScale(2, RoundingMode.HALF_UP); 
BigDecimal decimalDiscountPercent =
    new BigDecimal(Double.toString(discountPercent));

// calculate discount amount 
BigDecimal discountAmount =
    decimalSubtotal.multiply(decimalDiscountPercent); 
discountAmount = discountAmount.setScale(
    2, RoundingMode.HALF_UP);
// calculate total before tax, sales tax, and total
BigDecimal totalBeforeTax =
   decimalSubtotal.subtract(discountAmount);
BigDecimal salesTaxPercent =
   new BigDecimal(SALES_TAX_PCT);
BigDecimal salesTax =
   salesTaxPercent.multiply(totalBeforeTax);
salesTax = salesTax.setScale(2, RoundingMode.HALF_UP);
BigDecimal total = totalBeforeTax.add(salesTax);

// Create another BigDecimal object from existing BigDecimal Object
BigDecimal total2 = new BigDecimal(total.toString());

Java OOP.


  • Java String is immutable object

Using "this"
public class MyClass {
     private final String value;
     private final String type;

     public MyClass(int x){
         this(Integer.toString(x), "int");
     }

     public MyClass(boolean x){
         this(Boolean.toString(x), "boolean");
     }

     public String toString(){
         return value;
     }

     public String getType(){
         return type;
     }

     private MyClass(String value, String type){
         this.value = value;
         this.type = type;
     }
}

Java Exceptions.


Exception Basics

Order of Catch Matters
userChoice = 0; //initialize it
    try {
        userChoice = getInput(inputReader); 
    }// order of catch is important

    catch (NullPointerException e) { 
        System.out.println("Message:"+e.getMessage());
    }
    catch (MyOutOfRangeException e) {
        System.out.println("Message: " + e.getMessage()); 
    }
    catch (Exception e) {
        System.out.println("Catch all Exception"); 
    }

    finally { //always exectued with our without catch
        if (userChoice==0) //still has initial value
            System.out.println("Please try again ..."); 
        else
            System.out.println("Your choice is:"+ userChoice); 
    }
 

Prevent Exceptions As Possible
// Get valid numeric format
public static double getDouble(Scanner sc, String prompt) {
          double d = 0.0;
          boolean isValid = false;
          while (isValid == false)
          {
              System.out.print(prompt);
              if (sc.hasNextDouble())
              {
                  d = sc.nextDouble();
                  isValid = true;
              }
              else {
                  System.out.println(
                      "Error! Invalid number. Try again.");
              }
              sc.nextLine(); // discard any other data
           }
           return d; 
}

// Get valid numeric format
public static double getDoubleWithin (
        Scanner sc,
        String prompt,
        double min, double max )
{
    double d = 0.0;
    boolean isValid = false;
    while (isValid == false) {
        d = getDouble(sc, prompt);
        if (d <= min) {
            System.out.println(
                "Error! Number must be greater than " + 
                min + ".");
        }
        else if (d >= max){
            System.out.println(
                "Error! Number must be less than " +
                max + ".");
        } 
        else
            isValid = true;
    }
    return d; 
}

Scanner sc = new Scanner(System.in);
double subtotal1 = getDouble(sc, "Enter subtotal: "); 
double subtotal2 = getDoubleWithinRange(
                              sc,
                             "Enter subtotal: ",
                             0,
                             10000);


From Git to GitHub.


Create Folders in GitHub
  1. When upload files, pull the whole directory to the area.
  2. Add "dir/" in front of files to be committed.
  3. Use "git add folder/filename" or "git add file_path" and then "git commit" and "git push"
  4. In GitHub, click "Create new files", in the file name box, add "path_name / file_name"

Clone GitHub Repository
# git clone github_url local_directory
1. git clone https://github.com/changanna/java.git local_java_dir
2. git clong git@github.com:changanna/java.git # SSH protocol
3. git add file_path
4. git add .
5. git commit
6. git push

Check in Folders/Files For First Time
1.git init
2.git config user.name "someone"
3.git config user.email "someone@someplace.com"
4.git add *
5.git commit -m "some init msg"
6.git push
Check in Folders/Files Settings
1. using sourcetree: 
   Repository -> Repository Settings --> Advanced --> uncheck "Use global user settings" box

2. Repository > Repository Settings > Edit config file.
   Check if the [user] section exists. If the user section is missing, add it.

   [user]
   name = "your name"
   email = "your email"

3. Don't use "git pull" to skip settings
   % git fetch
   % git reset --hard origin/master
   % git fetch && git reset --hard HEAD


Git Quick Guides


Saturday, October 1, 2016

Git 101.

Basics:
  • help / man 
    • man git
    • man git-log / man git-commit
    • git help log
  • git config --global user.name <your_name>
  • git config --global user.email you@yourdomain.com
  • git config --get remote.origin.ur /home/amy/project
  • git config -l # 
  • git init
  • git status
  • git log (more)
  • git add <filename> (more)
  • git commit -m "message" <filename> (more)
  • git branch <branch_name> (more)
  • git checkout master 
  • git checkout -b <branch_name>
  • git branch (check branch is created)
  • git merge (more)
  • git branch -d <branch-to-delete> # but git ensure the changes is in current branch
  • git branch -D <branch-to-remove> # no changes are reserved
  • git branch -r origin/master # keeps a pristine copy of original branch
  • git revert (more)
  • git clone <directory> <new cloned directory>
    • git commit -a # to commit the new cloned directory in repository
  • ex: git clone amy.org:/home/amy/project  my_repo_directory # ssh protocol
  • git pull <new cloned directory>
    • git fetch <new cloned directory> # to inspect new changes and decide whether to merge
    • git log -p HEAD..FETCH_HEAD
    • gitk HEAD..FETCH_HEAD
    • gitk HEAD...FETCH_HEAD  # show everything reachable from either one but not both
  • git remote add <new directory> <from directory>
    • git fetch <new directory> # inspect without merging
    • git log -p master..new_directory/master # show a list of changes
    • git merge new_directory/master
  • git pull . remotes/new_directory/master # same as above commands, merge without checking
  • git pull # update all changes to local files
  • git push # update files in remote github repository
  • git show <commit number>
  • git show HEAD # tip of current branch
    • git show HEAD^    # parent
    • git show HEAD^^  # grandparent
  • git show experiment1 # tip of experiment1 branch
  • more...
    • git rm [-n][-q][-r] <dir to be removed>
    • git tag v2.5 <your own commit name.
    • git diff v2.5 HEAD
    • git branch new_branch v2.5
    • git reset --hard HEAD^
    • git grep "key_word" v2.5
    • git log v2.5..v2.7
    • git log --since="2 days ago"
    • git log v2.5..  Makefile
    • git log master .. child # commit in child but not master
    • gitk --since="2 days ago"  codec/
    • git diff  v2.5:Makefile  HEAD:Makefile.in
    • git show v2.5:Makefile
  • git docs
  • git tutorial files

EXAMPLE
% tar xzf project.tar.gz
% cd project
% git init
% git add .
% git commit
% git add file1 file2
% git diff --cached
% git status
% git commit -a -m "new changes"
% git log -p
% git log --stat --summary
% git branch experiment1
% git branch
% git checkout experiment1
    ... (edit files)
% git commit -a
% git checkout master
    ... (edit files)
% git commit -a
% git merge experiment1
% git diff
% git commit -a
% (git push to update files in remote github repository)
% git branch -d experiment1
% git branch -D crazy-idea-to-remove

GitHub:
  • git remote add origin https://github.com/myaccount/mynewrepository.git
  • git push -u origin master_branch_name
  • git hash object - use hash code as an identifier for a specific commit
  • git revert <has code number> - to backtrack
  • git pull origin master_branch_name - get most recent changes to local computer