Skip to content

Commit

Permalink
Merge pull request #2113 from ThalesSiliconSecurity/dev/cvxif
Browse files Browse the repository at this point in the history
CVXIF : Integrate cvxif tests into CI
  • Loading branch information
ASintzoff authored Aug 11, 2023
2 parents dfdcefe + 8148bbb commit 0da8e08
Show file tree
Hide file tree
Showing 15 changed files with 609 additions and 50 deletions.
72 changes: 63 additions & 9 deletions .gitlab-ci/cva6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -447,19 +447,22 @@ pub_generated_tests:
matrix:
- list_num: 1
DASHBOARD_JOB_TITLE: "Generated Random Arithmetic tests"
DASHBOARD_JOB_DESCRIPTION: "Generate Random Arithmetic tests using the RISCV-DV"
DASHBOARD_JOB_DESCRIPTION: "Generate Random Arithmetic tests using CVA6-DV"
- list_num: 2
DASHBOARD_JOB_TITLE: "Generated CSR tests"
DASHBOARD_JOB_DESCRIPTION: "Generate Random CSR tests using the RISCV-DV"
DASHBOARD_JOB_TITLE: "Generated Hazard Arithmetic tests"
DASHBOARD_JOB_DESCRIPTION: "Generate Hazard register (RAW) Arithmetic tests using CVA6-DV"
- list_num: 3
DASHBOARD_JOB_TITLE: "Generated MMU tests"
DASHBOARD_JOB_DESCRIPTION: "Generate Random MMU tests using the RISCV-DV"
DASHBOARD_JOB_TITLE: "Generated CSR tests"
DASHBOARD_JOB_DESCRIPTION: "Generate Random CSR tests using CVA6-DV"
- list_num: 4
DASHBOARD_JOB_TITLE: "Generated Random Load_store tests"
DASHBOARD_JOB_DESCRIPTION: "Generate Random Load_store tests using the RISCV-DV"
DASHBOARD_JOB_TITLE: "Generated MMU tests"
DASHBOARD_JOB_DESCRIPTION: "Generate Random MMU tests using CVA6-DV"
- list_num: 5
DASHBOARD_JOB_TITLE: "Generated Random Load_store tests"
DASHBOARD_JOB_DESCRIPTION: "Generate Random Load_store tests using CVA6-DV"
- list_num: 6
DASHBOARD_JOB_TITLE: "Generated Jump tests"
DASHBOARD_JOB_DESCRIPTION: "Generate Random Arithmetic Jump tests using the RISCV-DV"
DASHBOARD_JOB_DESCRIPTION: "Generate Random Arithmetic Jump tests using CVA6-DV"
script:
- mkdir -p artifacts/coverage
- source ./cva6/regress/dv-generated-tests.sh
Expand All @@ -473,6 +476,31 @@ pub_generated_tests:
artifacts:
expire_in: 3 week

pub_generated_xif_tests:
tags: [$TAGS_RUNNER]
extends:
- .verif_test
variables:
DASHBOARD_SORT_INDEX: 12
DASHBOARD_JOB_CATEGORY: "Code Coverage"
parallel:
matrix:
- list_num: 1
DASHBOARD_JOB_TITLE: "Generated Random xif tests"
DASHBOARD_JOB_DESCRIPTION: "Generate Random tests for cvxif using CVA6-DV"
script:
- mkdir -p artifacts/coverage
- source ./cva6/regress/dv-generated-xif-tests.sh
- mv cva6/sim/vcs_results/default/vcs.d/simv.vdb artifacts/coverage
- mv cva6/sim/seedlist.yaml artifacts/coverage
- python3 .gitlab-ci/scripts/report_pass.py
rules:
- when: manual
allow_failure: true
timeout: 4h
artifacts:
expire_in: 3 week

pub_directed_isacov-tests:
tags: [$TAGS_RUNNER]
extends:
Expand All @@ -497,6 +525,30 @@ pub_directed_isacov-tests:
artifacts:
expire_in: 3 week

pub_directed_xif-tests:
tags: [$TAGS_RUNNER]
extends:
- .verif_test
variables:
DASHBOARD_SORT_INDEX: 15
DASHBOARD_JOB_CATEGORY: "Functional Coverage"
parallel:
matrix:
- list_num: 0
DASHBOARD_JOB_TITLE: "Directed tests"
DASHBOARD_JOB_DESCRIPTION: "Execute directed tests to improve functional coverage of cvxif"
script:
- mkdir -p artifacts/coverage
- source ./cva6/regress/dv-generated-xif-tests.sh
- mv cva6/sim/vcs_results/default/vcs.d/simv.vdb artifacts/coverage
- python3 .gitlab-ci/scripts/report_pass.py
rules:
- when: manual
allow_failure: true
timeout: 4h
artifacts:
expire_in: 3 week

pub_fpga-boot:
tags: [fpga,shell]
extends:
Expand Down Expand Up @@ -530,10 +582,12 @@ code_coverage-report:
- *initjob
- pub_generated_tests
- pub_directed_isacov-tests
- pub_generated_xif_tests
- pub_directed_xif-tests
variables:
DASHBOARD_JOB_TITLE: "Report merge coverage"
DASHBOARD_JOB_DESCRIPTION: "Report merge coverage of generated tests"
DASHBOARD_SORT_INDEX: 12
DASHBOARD_SORT_INDEX: 14
DASHBOARD_JOB_CATEGORY: "Code Coverage"
script:
- echo $SYN_VCS_BASHRC; source $SYN_VCS_BASHRC
Expand Down
18 changes: 17 additions & 1 deletion cva6/env/corev-dv/cva6_instr_gen_config.sv
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,31 @@ class cva6_instr_gen_config_c extends riscv_instr_gen_config;
//-----------------------------------------------------------------------------

// cvxif extension support
bit enable_x_extension ;
bit enable_x_extension;
bit enable_rdrs1_hazard;
bit enable_rdrs2_hazard;
bit enable_same_reg;

constraint hazard_reg_c {
if (enable_same_reg) {
enable_rdrs1_hazard == 1'b0;
enable_rdrs2_hazard == 1'b0;
}
}

`uvm_object_utils_begin(cva6_instr_gen_config_c)
`uvm_field_int(enable_x_extension, UVM_DEFAULT)
`uvm_field_int(enable_rdrs1_hazard, UVM_DEFAULT)
`uvm_field_int(enable_rdrs2_hazard, UVM_DEFAULT)
`uvm_field_int(enable_same_reg, UVM_DEFAULT)
`uvm_object_utils_end

function new (string name = "");
super.new(name);
get_bool_arg_value("+enable_x_extension=", enable_x_extension);
get_bool_arg_value("+enable_rdrs1_hazard=", enable_rdrs1_hazard);
get_bool_arg_value("+enable_rdrs2_hazard=", enable_rdrs2_hazard);
get_bool_arg_value("+enable_same_reg=", enable_same_reg);
endfunction

endclass : cva6_instr_gen_config_c
61 changes: 61 additions & 0 deletions cva6/env/corev-dv/cva6_instr_hazard_test.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2018 Google LLC
* Copyright 2020 OpenHW Group
* Copyright 2023 Thales
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

//------------------------------------------------------------------------------
// CORE-V instruction generator base test:
// - extension of the RISC-V instruction generator base test.
//
//------------------------------------------------------------------------------

class cva6_instr_hazard_test_c extends riscv_instr_base_test;

`uvm_component_utils(cva6_instr_hazard_test_c)

function new(string name="", uvm_component parent=null);
super.new(name, parent);
endfunction

virtual function void build_phase(uvm_phase phase);
override_asm_program_gen();
override_gen_config();
override_rand_stream();
super.build_phase(phase);
endfunction

virtual function void override_asm_program_gen();
`uvm_info("CVA6_DV", $sformatf("Overriding ..."), UVM_LOW)
uvm_factory::get().set_type_override_by_type(riscv_asm_program_gen::get_type(),
cva6_asm_program_gen_c::get_type());
`uvm_info("CVA6_DV", $sformatf("Overrid done "), UVM_LOW)
endfunction

virtual function void override_gen_config();
`uvm_info("CVA6_DV", $sformatf("Overriding ..."), UVM_LOW)
uvm_factory::get().set_type_override_by_type(riscv_instr_gen_config::get_type(),
cva6_instr_gen_config_c::get_type());
`uvm_info("CVA6_DV", $sformatf("Overrid done "), UVM_LOW)
endfunction

virtual function void override_rand_stream();
`uvm_info("CVA6_DV", $sformatf("Overriding ..."), UVM_LOW)
uvm_factory::get().set_type_override_by_type(riscv_rand_instr_stream::get_type(),
cva6_reg_hazard_stream_c::get_type());
`uvm_info("CVA6_DV", $sformatf("Overrid done "), UVM_LOW)
endfunction

endclass : cva6_instr_hazard_test_c
2 changes: 2 additions & 0 deletions cva6/env/corev-dv/cva6_instr_test_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ package cva6_instr_test_pkg;
import cva6_signature_pkg::*;

`include "cva6_instr_gen_config.sv"
`include "cva6_reg_hazard_stream.sv"
`include "cva6_asm_program_gen.sv"
`include "cva6_instr_base_test.sv"
`include "cva6_instr_hazard_test.sv"
`include "cvxif_custom_instr.sv"
`include "rv32x_instr.sv"

Expand Down
62 changes: 62 additions & 0 deletions cva6/env/corev-dv/cva6_reg_hazard_stream.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// class for hazard instruction stream (RAW)
// that means destination register of previous instruction is the same source register of the current instruction

class cva6_reg_hazard_stream_c extends riscv_rand_instr_stream;

`uvm_object_utils(cva6_reg_hazard_stream_c)

string label;

function new(string name = "");
super.new(name);
endfunction

virtual function void gen_instr(bit no_branch = 1'b0, bit no_load_store = 1'b1,
bit is_debug_program = 1'b0);
riscv_reg_t prev_reg;
cva6_instr_gen_config_c cfg_cva6;
`DV_CHECK_FATAL($cast(cfg_cva6, cfg), "Could not cast cfg into cfg_cva6")
setup_allowed_instr(no_branch, no_load_store);
foreach(instr_list[i]) begin
if (i == 0) begin
randomize_instr(instr_list[i], is_debug_program);
prev_reg = instr_list[i].rd;
end
else if (i >= 1) begin
randomize_instr(instr_list[i], is_debug_program);
if (!instr_list[i].is_compressed) begin
`DV_CHECK_RANDOMIZE_WITH_FATAL(instr_list[i],
if (has_rs1 && cfg_cva6.enable_rdrs1_hazard) {
instr_list[i].rs1 == prev_reg;
}
if (has_rs2 && cfg_cva6.enable_rdrs2_hazard) {
instr_list[i].rs2 == prev_reg;
}
if (cfg_cva6.enable_same_reg) {
instr_list[i].rd == instr_list[i].rs1;
instr_list[i].rs1 == instr_list[i].rs2;
})
prev_reg = instr_list[i].rd;
end
else begin
`DV_CHECK_RANDOMIZE_WITH_FATAL(instr_list[i],
if (instr_list[i-1].rd inside {[S0:A5]}) {
if (has_rs1 && cfg_cva6.enable_rdrs1_hazard) {
instr_list[i].rs1 == prev_reg;
}
if (has_rs2 && cfg_cva6.enable_rdrs2_hazard) {
instr_list[i].rs2 == prev_reg;
}})
prev_reg = instr_list[i].rd;
end
end
end
// Do not allow branch instruction as the last instruction because there's no
// forward branch target
while (instr_list[$].category == BRANCH) begin
void'(instr_list.pop_back());
if (instr_list.size() == 0) break;
end
endfunction

endclass
2 changes: 1 addition & 1 deletion cva6/env/corev-dv/target/rv32imc/riscv_core_setting.sv
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ parameter int XLEN = 32;
parameter satp_mode_t SATP_MODE = BARE;

// Supported Privileged mode
privileged_mode_t supported_privileged_mode[] = {USER_MODE, SUPERVISOR_MODE, MACHINE_MODE};
privileged_mode_t supported_privileged_mode[] = {MACHINE_MODE};

// Unsupported instructions
riscv_instr_name_t unsupported_instr[];
Expand Down
29 changes: 18 additions & 11 deletions cva6/regress/dv-generated-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fi
# install the required tools
source ./cva6/regress/install-cva6.sh
source ./cva6/regress/install-riscv-dv.sh
source ./cva6/regress/install-spike.sh

if ! [ -n "$DV_TARGET" ]; then
DV_TARGET=cv32a60x
Expand Down Expand Up @@ -51,41 +52,48 @@ if [[ "$list_num" = 1 ]];then
);
I=(100 100 20 100 20 20);
elif [[ "$list_num" = 2 ]];then
TEST_NAME=(
"riscv_arithmetic_basic_same_reg_test"
"riscv_arithmetic_basic_hazard_rdrs1_test"
"riscv_arithmetic_basic_hazard_rdrs2_test"
);
I=(100 100 100);
elif [[ "$list_num" = 3 ]];then
TEST_NAME=(
"riscv_arithmetic_basic_csr_dummy"
"riscv_arithmetic_basic_Randcsr_test"
"riscv_arithmetic_basic_ebreak_dret_test"
"riscv_arithmetic_basic_illegal_csr"
);
I=(20 20 20 20);
elif [[ "$list_num" = 3 ]];then
elif [[ "$list_num" = 4 ]];then
TEST_NAME=(
"riscv_mmu_stress_hint_test"
"riscv_mmu_stress_test"
);
I=(100 100);
elif [[ "$list_num" = 4 ]];then
elif [[ "$list_num" = 5 ]];then
TEST_NAME=(
"riscv_load_store_test"
"riscv_load_store_cmp_test"
"riscv_load_store_hint_test"
"riscv_load_store_hazard_test"
"riscv_unaligned_load_store_test"
);
I=(50 50 50 50);
elif [[ "$list_num" = 5 ]];then
elif [[ "$list_num" = 6 ]];then
TEST_NAME=(
"riscv_rand_jump_hint_comp_test"
"riscv_rand_jump_no_cmp_test"
"riscv_rand_jump_illegal_test"
"riscv_arithmetic_basic_sub_prog_test"
);
I=(75 75 50 30);
I=(75 75 50 20);
fi

if [[ "$list_num" != 0 ]];then
if [[ ${#TEST_NAME[@]} != ${#I[@]} ]];then
echo "***********ERROR***************"
echo "The length of TEST_NAME and I should be equal !!!!"
echo "The length of TEST_NAME and Iteration should be equal !!!!"
echo "Fix the length of one of the arrays"
exit
fi
Expand All @@ -106,16 +114,16 @@ while [[ $j -lt ${#TEST_NAME[@]} ]];do
cp ../env/corev-dv/custom/riscv_custom_instr_enum.sv ./dv/src/isa/custom/
python3 cva6.py --testlist=$TESTLIST_FILE --test ${TEST_NAME[j]} --iss_yaml cva6.yaml --target $DV_TARGET -cs ../env/corev-dv/target/rv32imac/ --mabi ilp32 --isa rv32imac --simulator_yaml ../env/corev-dv/simulator.yaml --iss=vcs-uvm,spike -i ${I[j]} -bz 1 --iss_timeout 300
n=0
echo "Generate the test : ${TEST_NAME[j]}"
echo "Generate the test: ${TEST_NAME[j]}"
#this while loop detects the failed tests from the log file and remove them
echo "Deleting failed tests : "
echo "Deleting failed tests: "
while read line;do
if [[ "$line" = "" ]];then
n=$((n+1))
fi
for word in $line;do
if [[ "$word" = "$key_word" ]];then
echo -e ""${TEST_NAME[j]}"_"$n" : Failed"
echo -e ""${TEST_NAME[j]}"_"$n": Failed"
rm -rf vcs_results/default/vcs.d/simv.vdb/snps/coverage/db/testdata/"${TEST_NAME[j]}"_"$n"/
fi
done
Expand All @@ -126,8 +134,7 @@ done
#Execute directed tests to improve functional coverage of ISA
j=0
elif [[ "$list_num" = 0 ]];then
printf "==== Execute Directed tests to improve functional coverage of isa, by hiting some corners !!! ====\n\n"
printf "==== These tests are generated by RISCV-DV before modify to hit some specific values ====\n\n"
printf "==== Execute Directed tests to improve functional coverage of isa, by hitting corners !!! ====\n\n"
python3 cva6.py --testlist=$DIRECTED_TESTLIST --iss_yaml cva6.yaml --target $DV_TARGET --iss=vcs-uvm,spike
fi
cd -
Loading

0 comments on commit 0da8e08

Please sign in to comment.