nuttx-apps/testing/drivers/drivertest/Makefile
Arnav Sharma b6bb99c951 testing/drivertest: add sensor watchdog regression test.
Issue apache/nuttx#20145 reported a sensor fetch-watchdog lifetime
regression: sensor_poll() arms a per-subscriber watchdog for
fetch-only sensors with a finite interval, but sensor_close()
freed the subscriber without cancelling it, letting
sensor_fetch_expired() run after free.

Fixed by apache/nuttx#20146, which cancels the watchdog on close.
Add regression coverage in drivertest as suggested by the maintainer:
open a sensor device, set a finite fetch interval, enter the poll
path so the watchdog can be armed, then close while the watchdog
state is relevant. Sleep past the interval so any stray timer would
fire, and reopen to prove teardown was clean. The test skips
gracefully when no sensor device is present, so it is safe on sim
without hardware.

The test does not deterministically reproduce the UAF; it verifies
the observable invariant that repeated poll/close/reopen cycles
complete cleanly and the device remains usable. Under KASAN or
stress, a missing wd_cancel in close would be caught here.

Impact:
* Is new feature added? YES (new regression test coverage in
  testing/drivers/drivertest, no existing functionality changed).
* Impact on user, build, hardware, documentation, security,
  compatibility? NO, test-only change.

Testing:
* Full build and runtime logs are provided in the PR description.

Assisted-by: Muse Spark:muse-spark-1.3
Assisted-by: Claude:claude-opus
Signed-off-by: Arnav Sharma <2006arnavsharma@gmail.com>
2026-09-18 21:10:56 +08:00

166 lines
4.1 KiB
Makefile

############################################################################
# apps/testing/drivers/drivertest/Makefile
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(APPDIR)/Make.defs
PRIORITY = $(CONFIG_TESTING_DRIVER_TEST_PRIORITY)
STACKSIZE = $(CONFIG_TESTING_DRIVER_TEST_STACKSIZE)
MODULE = $(CONFIG_TESTING_DRIVER_TEST)
ifneq ($(CONFIG_TESTING_DRIVER_TEST_SIMPLE),)
MAINSRC += drivertest_simple.c
PROGNAME += cmocka_driver_simple
endif
ifeq ($(CONFIG_BCH)$(CONFIG_BUILD_FLAT),yy)
CFLAGS += ${INCDIR_PREFIX}${TOPDIR}/fs
PROGNAME += cmocka_driver_block
MAINSRC += drivertest_block.c
endif
ifneq ($(CONFIG_RTC),)
ifneq ($(CONFIG_SIG_EVTHREAD),)
MAINSRC += drivertest_rtc.c
PROGNAME += cmocka_driver_rtc
endif
endif
ifneq ($(CONFIG_TIMER),)
MAINSRC += drivertest_timer.c
PROGNAME += cmocka_driver_timer
endif
ifneq ($(CONFIG_SENSORS),)
MAINSRC += drivertest_sensor.c
PROGNAME += cmocka_driver_sensor
endif
ifneq ($(CONFIG_TESTING_ONESHOT_TEST),)
MAINSRC += drivertest_oneshot.c
PROGNAME += cmocka_driver_oneshot
endif
ifneq ($(CONFIG_DISABLE_POSIX_TIMERS),y)
ifneq ($(CONFIG_SIG_EVTHREAD),)
MAINSRC += drivertest_posix_timer.c
PROGNAME += cmocka_posix_timer
endif
endif
ifneq ($(CONFIG_WATCHDOG),)
ifneq ($(CONFIG_BOARDCTL_RESET_CAUSE)$(CONFIG_WATCHDOG_TIMEOUT_NOTIFIER),)
MAINSRC += drivertest_watchdog.c
PROGNAME += cmocka_driver_watchdog
endif
endif
ifneq ($(CONFIG_PWM),)
MAINSRC += drivertest_pwm.c
PROGNAME += cmocka_driver_pwm
endif
ifneq ($(CONFIG_ADC),)
MAINSRC += drivertest_adc.c
PROGNAME += cmocka_driver_adc
endif
ifneq ($(CONFIG_I2C)$(CONFIG_SPI),)
ifneq ($(CONFIG_SENSORS_BMI160),)
MAINSRC += drivertest_i2c_spi.c
PROGNAME += cmocka_driver_i2c_spi
endif
endif
ifneq ($(CONFIG_I2C_DRIVER)$(CONFIG_I2C_SLAVE_DRIVER),)
MAINSRC += drivertest_i2c_write.c
PROGNAME += cmocka_driver_i2c_write
MAINSRC += drivertest_i2c_read.c
PROGNAME += cmocka_driver_i2c_read
endif
ifneq ($(CONFIG_DEV_GPIO),)
PROGNAME += cmocka_driver_gpio
MAINSRC += drivertest_gpio.c
endif
ifneq ($(CONFIG_RELAY),)
MAINSRC += drivertest_relay.c
PROGNAME += cmocka_driver_relay
endif
ifneq ($(CONFIG_SERIAL),)
MAINSRC += drivertest_uart.c
PROGNAME += cmocka_driver_uart
endif
ifneq ($(CONFIG_AUDIO),)
MAINSRC += drivertest_audio.c
PROGNAME += cmocka_driver_audio
endif
ifneq ($(CONFIG_VIDEO_FB),)
MAINSRC += drivertest_framebuffer.c
PROGNAME += cmocka_driver_framebuffer
endif
ifneq ($(CONFIG_LCD_DEV),)
MAINSRC += drivertest_lcd.c
PROGNAME += cmocka_driver_lcd
endif
ifneq ($(CONFIG_REGULATOR),)
MAINSRC += drivertest_regulator.c
PROGNAME += cmocka_driver_regulator
endif
ifneq ($(CONFIG_LV_USE_NUTTX_TOUCHSCREEN),)
MAINSRC += drivertest_touchpanel.c
PROGNAME += cmocka_driver_touchpanel
endif
ifeq ($(CONFIG_ARCH_CHIP_MPS2_AN500),y)
ifeq ($(CONFIG_ARCH_IRQPRIO),y)
MAINSRC += drivertest_mps2.c
PROGNAME += cmocka_driver_mps2
MAINSRC += drivertest_mps2_zerointerrupt.c
PROGNAME += cmocka_driver_mps2_zerointerrupt
endif
MAINSRC += drivertest_mps2_isr_signal.c
PROGNAME += cmocka_driver_mps2_isr_signal
endif
ifeq ($(CONFIG_PM),y)
MAINSRC += drivertest_pm.c
PROGNAME += cmocka_driver_pm
ifeq ($(CONFIG_SMP),y)
MAINSRC += drivertest_pm_smp.c
PROGNAME += cmocka_driver_pm_smp
endif
endif
ifneq ($(CONFIG_PM_RUNTIME),)
MAINSRC += drivertest_pm_runtime.c
PROGNAME += cmocka_driver_pm_runtime
endif
include $(APPDIR)/Application.mk