Coverage Tanımları

Gün 7: Bitirme Projesi - Bölüm 2 | ALU projesi için covergroup ve cross coverage

Kaynak Kod

// =============================================================================
// GUN 7 - Konu 5: Covergroup - Fonksiyonel Kapsam Tanimlari
// =============================================================================

class ALU_Coverage;

  covergroup alu_cg with function sample(
    ALU_Transaction::opcode_e opcode,
    logic [7:0] a, logic [7:0] b,
    logic [15:0] result, logic [3:0] flags
  );
    option.per_instance = 1;

    // Islem kodu kapsami
    cp_opcode: coverpoint opcode {
      bins add = {ALU_Transaction::OP_ADD};
      bins sub = {ALU_Transaction::OP_SUB};
      bins and_op = {ALU_Transaction::OP_AND};
      bins or_op  = {ALU_Transaction::OP_OR};
      bins xor_op = {ALU_Transaction::OP_XOR};
      bins not_op = {ALU_Transaction::OP_NOT};
      bins shl = {ALU_Transaction::OP_SHL};
      bins shr = {ALU_Transaction::OP_SHR};
    }

    // Operand A kose durumlari
    cp_op_a: coverpoint a {
      bins zero = {0};
      bins one  = {1};
      bins mid  = {8'h7F, 8'h80};
      bins max_minus_one = {8'hFE};
      bins max  = {8'hFF};
      bins low  = {[2:8'h7E]};
      bins high = {[8'h81:8'hFD]};
    }

    // Operand B kose durumlari
    cp_op_b: coverpoint b {
      bins zero = {0};
      bins one  = {1};
      bins mid  = {8'h7F, 8'h80};
      bins max_minus_one = {8'hFE};
      bins max  = {8'hFF};
      bins low  = {[2:8'h7E]};
      bins high = {[8'h81:8'hFD]};
    }

    // Bayrak kapsami
    cp_flags: coverpoint flags {
      bins no_flags   = {4'b0000};
      bins zero_flag  = {4'b0001};
      bins neg_flag   = {4'b0010};
      bins carry_flag = {4'b0100};
      bins ovf_flag   = {4'b1000};
      wildcard bins any_flag = {4'b???1, 4'b??1?, 4'b?1??, 4'b1???};
    }

    // Sonuc araliklari
    cp_result: coverpoint result {
      bins zero     = {0};
      bins small    = {[1:255]};
      bins medium   = {[256:65534]};
      bins max_val  = {65535};
    }

    // Cross coverage: Islem x Operand araliklari
    cx_opcode_a: cross cp_opcode, cp_op_a;
    cx_opcode_b: cross cp_opcode, cp_op_b;
    cx_opcode_flags: cross cp_opcode, cp_flags {
      ignore_bins not_applicable = binsof(cp_opcode) intersect {ALU_Transaction::OP_AND, 
        ALU_Transaction::OP_OR, ALU_Transaction::OP_XOR, ALU_Transaction::OP_NOT} &&
        binsof(cp_flags) intersect {4'b0100, 4'b1000};
    }
  endgroup

  alu_cg cg;

  function new();
    cg = new();
  endfunction

  function void sample(ALU_Transaction txn);
    cg.sample(txn.opcode, txn.operand_a, txn.operand_b, txn.result, txn.flags);
  endfunction

  function void report();
    $display("\n  ========== KAPSAM RAPORU ==========");
    $display("  Toplam Kapsam : %.1f%%", cg.get_coverage());
    $display("  cp_opcode     : %.1f%%", cg.cp_opcode.get_coverage());
    $display("  cp_op_a       : %.1f%%", cg.cp_op_a.get_coverage());
    $display("  cp_op_b       : %.1f%%", cg.cp_op_b.get_coverage());
    $display("  cp_flags      : %.1f%%", cg.cp_flags.get_coverage());
    $display("  cp_result     : %.1f%%", cg.cp_result.get_coverage());
    $display("  =====================================");
  endfunction
endclass