[dv] Fix wait_alert_trigger

A few update on waiting for an alert
1. `DV_SPINWAIT_EXIT doesn't report uvm_error. It creates 2 threads and any
of them finish, it kills the other. Added uvm_error if alert doesn't
occur.
2. the alert may be triggered earlier than we call this task, change to
wait for either alert_p or ack_p.
3. increase default max_wait_time to 7 cycles

Signed-off-by: Weicai Yang <weicai@google.com>
diff --git a/hw/dv/sv/alert_esc_agent/alert_esc_if.sv b/hw/dv/sv/alert_esc_agent/alert_esc_if.sv
index dc550f3..73c38a7 100644
--- a/hw/dv/sv/alert_esc_agent/alert_esc_if.sv
+++ b/hw/dv/sv/alert_esc_agent/alert_esc_if.sv
@@ -97,6 +97,10 @@
     get_alert = (alert_tx_final.alert_p === 1'b1 && alert_tx_final.alert_n === 1'b0);
   endfunction : get_alert
 
+  function automatic bit is_alert_handshaking();
+    return alert_tx_final.alert_p === 1'b1 || alert_rx_final.ack_p === 1'b1;
+  endfunction : is_alert_handshaking
+
   // this task wait for alert_ping request.
   // alert_ping request is detected by level triggered "alert_rx.ping_p/n" signals pairs
   // and no sig_int_err
diff --git a/hw/dv/sv/cip_lib/seq_lib/cip_base_vseq.sv b/hw/dv/sv/cip_lib/seq_lib/cip_base_vseq.sv
index 6f5f4fc..e045dfe 100644
--- a/hw/dv/sv/cip_lib/seq_lib/cip_base_vseq.sv
+++ b/hw/dv/sv/cip_lib/seq_lib/cip_base_vseq.sv
@@ -507,11 +507,15 @@
     end
   endtask
 
-  virtual task wait_alert_trigger(string alert_name, int max_wait_cycle = 2, bit wait_complete = 0);
-    `DV_SPINWAIT_EXIT(while (!cfg.m_alert_agent_cfg[alert_name].vif.get_alert())
+  // if alerts are triggered continuously, there are 6 cycles gap between 2 alerts. 2-3 cycles for
+  // clock domain crossing, 2 for pauses, 1 for idle state.
+  // So use 7 cycle for default max_wait_cycle.
+  virtual task wait_alert_trigger(string alert_name, int max_wait_cycle = 7, bit wait_complete = 0);
+    `DV_SPINWAIT_EXIT(while (!cfg.m_alert_agent_cfg[alert_name].vif.is_alert_handshaking())
                       cfg.clk_rst_vif.wait_clks(1);,
-                      cfg.clk_rst_vif.wait_clks(max_wait_cycle);,
-                      $sformatf("expect alert:%0s to fire", alert_name))
+                      // another thread to wait for given cycles. If timeout, report an error.
+                      cfg.clk_rst_vif.wait_clks(max_wait_cycle);
+                      `uvm_error(`gfn, $sformatf("expect alert:%0s to fire", alert_name)))
     if (wait_complete) begin
       `DV_SPINWAIT(cfg.m_alert_agent_cfg[alert_name].vif.wait_ack_complete();,
                    $sformatf("timeout wait for alert handshake:%0s", alert_name))