AWTK input event recording and playback

Input event recording and playback

1. Purpose

Common uses for input event recording and replay are:

  • Automatic presentation function.
  • Run stress tests for long periods of time.
  • Assisted manual testing. Sometimes when there is a crash bug, it is often forgotten how to operate before, and input event recording and replay can accurately reproduce the problem. At the same time, it can also reduce the workload of manual testing.

2.API

/**
 * @method event_recorder_player_start_record
 * 开始事件记录。
 * @annotation ["static"]
 * @param {const char*} filename 用于保存事件的文件名。
 *
 * @return {ret_t} 返回 RET_OK 表示成功,否则表示失败。
 */
ret_t event_recorder_player_start_record(const char* filename);

/**
 * @method event_recorder_player_start_play
 * 开始事件重放。
 * @annotation ["static"]
 * @param {const char*} filename 存放事件的文件名。
 * @param {uint32_t} times 循环播放的次数。
 *
 * @return {ret_t} 返回 RET_OK 表示成功,否则表示失败。
 */
ret_t event_recorder_player_start_play(const char* filename, uint32_t times);

/**
 * @method event_recorder_player_stop_record
 * 停止事件记录。
 * @annotation ["static"]
 *
 * @return {ret_t} 返回 RET_OK 表示成功,否则表示失败。
 */
ret_t event_recorder_player_stop_record(void);

/**
 * @method event_recorder_player_stop_play
 * 停止事件重放。
 * @annotation ["static"]
 *
 * @return {ret_t} 返回 RET_OK 表示成功,否则表示失败。
 */
ret_t event_recorder_player_stop_play(void);

3. Usage

There are generally two ways to enable input event recording and playback:

  • Start record or replay functions via command line arguments (examples are not currently provided).

  • Initiate record and playback functions via shortcut keys. This method is more flexible and can be started and stopped at any time, and can be recorded and played back at any time.

The macro WITH|_EVENT_RECORDER_PLAYER needs to be defined to enable the event recording and playback function. The PC version defines this macro by default.

The demoui demonstrates the use of shortcut keys to start recording and playback:

#include "base/event_recorder_player.h"
...

static ret_t on_key_record_play_events(void* ctx, event_t* e) {
  key_event_t* evt = (key_event_t*)e;

#ifdef WITH_EVENT_RECORDER_PLAYER
  if (evt->key == TK_KEY_F5) {
    event_recorder_player_start_record("event_log.bin");
    return RET_STOP;
  } else if (evt->key == TK_KEY_F6) {
    event_recorder_player_stop_record();
    return RET_STOP;
  } else if (evt->key == TK_KEY_F7) {
    event_recorder_player_start_play("event_log.bin", 0xffff);
    return RET_STOP;
  } else if (evt->key == TK_KEY_F8) {
    event_recorder_player_stop_play();
    return RET_STOP;
  }
#endif /*WITH_EVENT_RECORDER_PLAYER*/

  return RET_OK;
}

...

widget_on(wm, EVT_KEY_UP, on_key_record_play_events, wm);

In the above code:

  • F5 key to start recording.
  • F6 key to stop recording.
  • F7 key to start playback.
  • F8 key to stop playback.

4. Known Issues

  • If you want to play the recorded event repeatedly, make sure to stop recording after returning to the initial interface when recording the event.
  • Currently, the input events of the platform's native input method are not recorded.
{{o.name}}
{{m.name}}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324127517&siteId=291194637