Commit graph

9 commits

Author SHA1 Message Date
Junbo Zheng
2968b2c587 monkey: add missing blank lines after declarations
The nxstyle check on CI flagged three spots in monkey_main.c where a
declaration block runs directly into the following statement. Insert a
blank line after the declarations at each location; no logic change.

Fixes the Check job failure on PR #3784:
https://github.com/apache/nuttx-apps/actions/runs/34935981535/job/104273851956?pr=3784

Before:
```
graphics/input/monkey/monkey_main.c:223:2: error: Missing blank line after declarations
graphics/input/monkey/monkey_main.c:363:2: error: Missing blank line after declarations
graphics/input/monkey/monkey_main.c:526:6: error: Missing blank line after declarations
```

After:
```
nxstyle monkey_main.c -> exit 0
```

Assisted-by: Claude Code (GLM-5.3) <claude@anthropic.com>
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2026-09-15 09:16:23 -03:00
Junbo Zheng
6e79ea2d85 monkey: block SIGTERM and consume it in sigtimedwait() for a clean exit
Block SIGTERM at startup and add it to the sigtimedwait() set in
monkey_wait(): a blocked signal is never swallowed by the handler, it
either wakes the in-progress wait or stays pending on the task until
the next sigtimedwait() returns it immediately, so the exit through
the regular monkey_delete() cleanup path is deterministic. Because
the kernel keeps the signal mask and pending queue per task, sibling
monkey instances (e.g. multiple instances started for different
input devices) each stop independently, and no shared state is
involved.

Also add a signal_handler() that logs the received signal and
register it for SIGTSTP/SIGCONT/SIGTERM, so these signals never fall
back to their default actions and stay consumable by sigtimedwait()
/ sigwaitinfo().

Before:
kill -15 <pid> terminates the task via the default SIGTERM action
with no cleanup: no "monkey_delete: OK" is ever printed.

After:
kill -15 <pid> exits within one loop iteration (<= one event period,
100-500ms by default) via monkey_delete(), independently for each
running instance, and restarting monkey works.

Testing:

Built and verified on the NuttX simulator (host: Ubuntu 22.04):

  cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
  # enable in build/.config:
  #   CONFIG_INPUT=y
  #   CONFIG_GRAPHICS_INPUT_MONKEY=y
  #   CONFIG_NSH_MAXARGUMENTS=16
  ninja -C build olddefconfig && ninja -C build
  ./build/nuttx

Run in the nsh prompt (uinput injection mode):

  nsh> monkey -t 0x11 -p 100-300 -s 454x454 &   (uinput touch)
  nsh> monkey -t 0x12 -p 100-300 -s 454x454 -b 0 &  (uinput button)
  nsh> ps
  nsh> kill -15 <pid>

ps with both instances running (each monkey task shows "Waiting
Signal" with SIGMASK 0x8000, i.e. SIGTERM blocked while sitting in
sigtimedwait):

  TID   PID  PPID PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK            STACK COMMAND
    0     0     0   0 FIFO     Kthread   - Ready              0000000000000000 0069584 Idle_Task
    1     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067456 sim_loop_wq 0x71204b2003f0 0x71204b200478
    2     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067464 hpwork 0x40188860 0x401888e8
    4     4     0 100 FIFO     Task      - Waiting  Semaphore 0000000000000000 0067496 init_main
    9     9     4 100 FIFO     Task      - Running            0000000000000000 0067504 sh
   10    10     9 110 FIFO     Task      - Waiting  Signal    0000000000008000 0069472 monkey -t 0x11 -p 100-300 -s 454x454
   11    11     9 110 FIFO     Task      - Waiting  Signal    0000000000008000 0069448 monkey -t 0x12 -p 100-300 -s 454x454 -b 0

After "kill -15 10" (touch instance exits, button instance
unaffected):

  nsh> kill -15 10
  [monkey] monkey_wait: Recv sig: SIGTERM
  [monkey] monkey_delete: OK
  nsh> ps
  TID   PID  PPID PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK            STACK COMMAND
    0     0     0   0 FIFO     Kthread   - Ready              0000000000000000 0069584 Idle_Task
    1     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067456 sim_loop_wq 0x71204b2003f0 0x71204b200478
    2     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067464 hpwork 0x40188860 0x401888e8
    4     4     0 100 FIFO     Task      - Waiting  Semaphore 0000000000000000 0067496 init_main
    9     9     4 100 FIFO     Task      - Running            0000000000000000 0067504 sh
   11    11     9 110 FIFO     Task      - Waiting  Signal    0000000000008000 0069448 monkey -t 0x12 -p 100-300 -s 454x454 -b 0

After "kill -15 11" (second instance exits the same way, no monkey
task left):

  nsh> kill -15 11
  [monkey] monkey_wait: Recv sig: SIGTERM
  [monkey] monkey_delete: OK
  nsh> ps
  TID   PID  PPID PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK            STACK COMMAND
    0     0     0   0 FIFO     Kthread   - Ready              0000000000000000 0069584 Idle_Task
    1     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067456 sim_loop_wq 0x71204b2003f0 0x71204b200478
    2     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067464 hpwork 0x40188860 0x401888e8
    4     4     0 100 FIFO     Task      - Waiting  Semaphore 0000000000000000 0067496 init_main
    9     9     4 100 FIFO     Task      - Running            0000000000000000 0067504 sh

A new instance started after both kills (PID 12) runs normally and
is again stopped cleanly by kill -15.

Note: on the simulator the uinput devices register as /dev/utouch
and /dev/ubutton, while monkey opens /dev/input0 and /dev/buttons;
the run above used a local (uncommitted) path patch to work around
this. On a board where the device paths match, no patch is needed.

Assisted-by: Claude Code (glm-5.3) <claude@anthropic.com>
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2026-09-15 09:16:23 -03:00
Piyush Patle
9d849adfab include/debug.h: Use <nuttx/debug.h> in apps
Replace app-side includes of <debug.h> with <nuttx/debug.h> to use the
header from the NuttX tree explicitly after the header move.

Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
2026-04-11 10:39:27 -03:00
liuhongchao
a6286ee0ea graphics/input: Add getevent input event monitor tool.
Add getevent utility for monitoring input events including
mouse clicks/movement, multi-touch coordinates/pressure,
and keyboard key presses. Supports automatic device detection
in /dev and command-line device path specification with
non-blocking I/O.

Signed-off-by: liuhongchao <liuhongchao@xiaomi.com>
2026-04-09 11:59:19 +02:00
liuchan3
fdf6f57d6c graphics/input: Adjust input tool priority and sampling rate
Align to monkey's priority, with a sampling rate similar to a real touch.

Signed-off-by: liuchan3 <liuchan3@xiaomi.com>
2025-08-12 20:20:01 +08:00
liuchan3
6f93e401aa apps/graphics: Refactor the input tool using input generator library
Signed-off-by: liuchan3 <liuchan3@xiaomi.com>
2025-08-12 20:20:01 +08:00
liuchan3
36b117c00a apps/graphics: Refactor monkey using input generator library
Signed-off-by: liuchan3 <liuchan3@xiaomi.com>
2025-08-12 20:20:01 +08:00
Zhe Weng
7bfd5e5790 apps/system: Move input/monkey to apps/graphics/input
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-08-12 20:20:01 +08:00
Zhe Weng
7a2d5bbc64 apps/graphics: Add input generator library
We can use it to unify our monkey / input tools, and for other input
generation purposes easily.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-08-12 20:20:01 +08:00