[keymgr/dv] Fix keymgr_tl_intg_err

1. don't check sw_share in CSR tests as it's hw-update
2. add checking working_state after regfile_intg and shadow storage error

Signed-off-by: Weicai Yang <weicai@google.com>
diff --git a/hw/ip/keymgr/data/keymgr.hjson b/hw/ip/keymgr/data/keymgr.hjson
index f00e2df..09412d4 100644
--- a/hw/ip/keymgr/data/keymgr.hjson
+++ b/hw/ip/keymgr/data/keymgr.hjson
@@ -705,6 +705,8 @@
               resval: "0"
             },
         ],
+        tags: [// HW-update reg
+               "excl:CsrNonInitTests:CsrExclCheck"]
       },
     },
 
@@ -729,6 +731,8 @@
               resval: "0"
             },
         ],
+        tags: [// HW-update reg
+               "excl:CsrNonInitTests:CsrExclCheck"]
       },
     },
 
diff --git a/hw/ip/keymgr/dv/env/keymgr_env_cfg.sv b/hw/ip/keymgr/dv/env/keymgr_env_cfg.sv
index ce6973f..84babfc 100644
--- a/hw/ip/keymgr/dv/env/keymgr_env_cfg.sv
+++ b/hw/ip/keymgr/dv/env/keymgr_env_cfg.sv
@@ -19,11 +19,9 @@
     tl_intg_alert_name = "fatal_fault_err";
     has_edn = 1;
     super.initialize(csr_base_addr);
-    //tl_intg_alert_fields[ral.err_code.invalid_states] = 1;
     tl_intg_alert_fields[ral.fault_status.regfile_intg] = 1;
     shadow_update_err_status_fields[ral.err_code.invalid_shadow_update] = 1;
     shadow_storage_err_status_fields[ral.fault_status.shadow] = 1;
-    //shadow_storage_err_status_fields[ral.err_code.invalid_states] = 1;
 
     m_keymgr_kmac_agent_cfg = kmac_app_agent_cfg::type_id::create("m_keymgr_kmac_agent_cfg");
     m_keymgr_kmac_agent_cfg.if_mode = dv_utils_pkg::Device;
diff --git a/hw/ip/keymgr/dv/env/seq_lib/keymgr_common_vseq.sv b/hw/ip/keymgr/dv/env/seq_lib/keymgr_common_vseq.sv
index 3e1a884..ea3da99 100644
--- a/hw/ip/keymgr/dv/env/seq_lib/keymgr_common_vseq.sv
+++ b/hw/ip/keymgr/dv/env/seq_lib/keymgr_common_vseq.sv
@@ -5,6 +5,8 @@
 class keymgr_common_vseq extends keymgr_base_vseq;
   `uvm_object_utils(keymgr_common_vseq)
 
+  bit csr_vseq_done;
+
   constraint num_trans_c {
     num_trans inside {[1:2]};
   }
@@ -37,4 +39,39 @@
     super.read_and_check_all_csrs_after_reset();
   endtask
 
+  virtual task run_csr_vseq(string csr_test_type = "",
+                            int    num_test_csrs = 0,
+                            bit    do_rand_wr_and_reset = 1);
+    csr_vseq_done = 0;
+    super.run_csr_vseq(csr_test_type, num_test_csrs, do_rand_wr_and_reset);
+    csr_vseq_done = 1;
+  endtask
+
+  virtual task check_tl_intg_error_response();
+    super.check_tl_intg_error_response();
+    check_state_after_non_operation_fault();
+  endtask
+
+  virtual task read_check_shadow_reg_status(string msg_id);
+    super.read_check_shadow_reg_status(msg_id);
+
+    if (`gmv(ral.fault_status.shadow)) begin
+      check_state_after_non_operation_fault();
+    end
+  endtask
+
+  // Check state is StInvalid when there is an non-operation fault like integrity error, storage
+  // error.
+  virtual task check_state_after_non_operation_fault();
+    // wait until csr_rw seq is done, as below operation may affect csr_rw to predict CSR values
+    wait(csr_vseq_done);
+
+    // issue an advance operation and check that state enters StInvalid
+    keymgr_advance(.wait_done(0));
+    // waiting for done is called separately as this one expects to be failed
+    csr_spinwait(.ptr(ral.op_status.status), .exp_data(keymgr_pkg::OpDoneFail),
+                 .spinwait_delay_ns($urandom_range(0, 100)));
+    read_current_state();
+    `DV_CHECK_EQ(current_state, keymgr_pkg::StInvalid)
+  endtask
 endclass