美文网首页
[CAPL] TestWaitForAllJoinedEvent

[CAPL] TestWaitForAllJoinedEvent

作者: welder77 | 来源:发表于2020-01-22 08:09 被阅读0次

今天介绍下CAPL的测试函数TestWaitForAllJoinedEvents 和 TestWaitForAnyJoinedEvent

引子:
通常在CANoe中,测试脚本是一个序列执行的顺序,那么对于不确定的触发事件,我们应该如何对其判断呢?

举例:
我们有一个诊断功能寻址的测试Case,需要我们测试诊断仪发出功能寻址请求后的一段时间内收到2个不同节点的诊断反馈。但是我们无法确定哪个节点先回哪个后会。(我们在config中已经将这两个不同节点的诊断反馈数据关联到了两个系统变量)

解答:
答案是使用TestJoinXXXXXX函数+TestWaitForAllJoinedEvents函数的组合。

image.png

testJoinSysVarEvent+TestWaitForAllJoinedEvents使用流程示意图:

TestWaitForAllJoinedEvents使用流程.png

p.s.

  1. 经过测试,这里所说的触发是指系统变量有变化时,而不是更新时。如果需要更新时也触发,可以使用TestJoinTextEvent来实现(后文会有介绍)。
  2. 另外TestWaitForAnyJoinedEvent(任意事件触发)与TestWaitForAllJoinedEvents使用方法一致,只是在判断时有任意事件触发即Pass。

代码示例:
下面这段代码,是一个WaitForAllEvents的示例,

testcase WaitForAllEvents()
{
  const  dword waitDuration = 15000; // [ms]
  long eventHandle1, eventHandle2;
  int64 eventTime1 , eventTime2 ;
  long res;

 TestCaseTitle("Demo", "WaitForAllEvents");

 eventHandle1 = testJoinSysVarEvent(sysvar::test::Sysvar1); 
//首先注册想要判断的触发事件1(这里是一个系统变量1)

 eventHandle2 = testJoinSysVarEvent(sysvar::test::Sysvar2); 
//首先注册想要判断的触发事件2(这里是一个系统变量2)

 res = TestWaitForAllJoinedEvents(waitDuration); 
//设置TestWaitForAllJoinedEvents并添加等待时间,当两个事件都被触发时(不分顺序),
//TestWaitForAllJoinedEvents会返回一个大于0的数,反之则为0(具体返回值可以查询帮助文档)。

  if (res > 0) // all events ocurred, last one is stored in res
 {
   write("All expected events occured");
   testStepPass("All expected events occured");
 }
  else
 {
   write("Timeout after %d ms: Not all expected events occured", waitDuration);
 }

//testGetJoinedEventOccured 用于获取某个触发事件的触发时间。
  if (testGetJoinedEventOccured(eventHandle1, eventTime1) == 1)
 {
   write("SysVar1 changed at %I64d", eventTime1);
 }
  else
 {
   write("SysVar1 unchanged");
 }

//testGetJoinedEventOccured 用于获取某个触发事件的触发时间。
  if (testGetJoinedEventOccured(eventHandle2, eventTime2) == 1)
 {
   write("SysVar2 changed at %I64d", eventTime2);
 }
  else
 {
   write("SysVar2 unchanged");
 }

}

最后,我们来介绍下TestJoinTextEvent的使用方法,TestJoinTextEvent相对来说也是一种最为自由的添加事件触发的方式,我们可以把TestJoinTextEvent认为是一种用户自定义的触发事件。理论上我们可以通过此方法,实现CAPL中任意事件的触发和收集。
下面是一个使用TestJoinTextEvent的小例子,在这个例子中,我们预期一段时间内,两个系统变量中的任意一个系统变量有更新,如果没有则报错。

//待触发的系统变量1
on sysvar_update Device::JDS2900_Check
{
  TestSupplyTextEvent("JDS2900_Check sysvar update!");  //发出特定文字信号
}

//待触发的系统变量2
on sysvar_update Device::JDS2900_CH1_Freq
{
  TestSupplyTextEvent("JDS2900_CH1_Freq sysvar update!"); //发出特定文字信号
}


testcase WaitForAnyEvents()
{
  const  dword waitDuration = 15000; // [ms]
  long eventHandle1, eventHandle2;
  int64 eventTime1 , eventTime2 ;
  long res;

  TestCaseTitle("Demo", "WaitForAnyEvents");


  eventHandle1 = TestJoinTextEvent("JDS2900_Check sysvar update!");  //将特定文字信号注册为触发事件1
  eventHandle2 = TestJoinTextEvent("JDS2900_CH1_Freq sysvar update!"); //将特定文字信号注册为触发事件2

  res = TestWaitForAnyJoinedEvent(waitDuration); //等待以上任意触发事件被触发

  if (res > 0) // any events ocurred, last one is stored in res
 {
   write("any expected events occured");
   testStepPass("any expected events occured");
 }
  else
 {
   write("Timeout after %d ms: Not any expected events occured", waitDuration);
 }

//testGetJoinedEventOccured 用于获取某个触发事件的触发时间。
  if (testGetJoinedEventOccured(eventHandle1, eventTime1) == 1)
 {
   write("SysVar1 changed at %I64d", eventTime1);
 }
  else
 {
   write("SysVar1 unchanged");
 }

//testGetJoinedEventOccured 用于获取某个触发事件的触发时间。
  if (testGetJoinedEventOccured(eventHandle2, eventTime2) == 1)
 {
   write("SysVar2 changed at %I64d", eventTime2);
 }
  else
 {
   write("SysVar2 unchanged");
 }

}

希望此文可以帮助你理解CANoe中TestWaitForAllJoinedEvents/TestWaitForAnyJoinedEvent,从事件注册到函数调用,最后事件触发的使用流程。

相关文章

  • [CAPL] TestWaitForAllJoinedEvent

    今天介绍下CAPL的测试函数TestWaitForAllJoinedEvents 和 TestWaitForAny...

  • CAPL尝试

    CAPL是CANoe的脚本。当系统变量发生变化时触发逻辑: 这里,如果设置的sysvar要生效,需要设置为anal...

  • 2019-08-13 karabiner新配置备份 - capl

    之前写的太乱了,映射了caplocks为command,导致出现了很多问题,现在简化一下,并成功做出来了调度中心的...

网友评论

      本文标题:[CAPL] TestWaitForAllJoinedEvent

      本文链接:https://www.haomeiwen.com/subject/blzpoctx.html