# SPDX-License-Identifier: GPL-2.0

config SELFTEST
	bool "Self-tests"
	help
	  Configures support for in-barebox testing

if SELFTEST

config CMD_SELFTEST
	bool "selftest command"
	depends on COMMAND_SUPPORT
	default y
	help
	  Command to run enabled barebox self-tests.
	  If run without arguments, all tests are run

	  Usage: selftest [-l] [tests...]

	  Options:
	    -l     list available tests

config SELFTEST_AUTORUN
	bool "Run self-tests on startup"
	help
	  Self tests are run automatically after initcalls are done,
	  but before barebox_main (shell or board-specific startup).

config SELFTEST_ENABLE_ALL
	bool "Enable all self-tests"
	select SELFTEST_BASE64
	select SELFTEST_RANGE
	select SELFTEST_PRINTF
	select SELFTEST_MALLOC
	select SELFTEST_CLEANUP
	select SELFTEST_PROGRESS_NOTIFIER
	select SELFTEST_OF_MANIPULATION
	select SELFTEST_OF_OVERLAY
	select SELFTEST_ENVIRONMENT_VARIABLES if ENVIRONMENT_VARIABLES
	select SELFTEST_FS_RAMFS if FS_RAMFS
	select SELFTEST_DIRFD if FS_RAMFS && FS_DEVFS
	select SELFTEST_JSON if JSMN
	select SELFTEST_JWT if JWT
	select SELFTEST_DIGEST if DIGEST
	select SELFTEST_MMU if MMU
	select SELFTEST_STRING
	select SELFTEST_SETJMP if ARCH_HAS_SJLJ
	select SELFTEST_REGULATOR if REGULATOR_FIXED
	select SELFTEST_RESOURCE
	select SELFTEST_TEST_COMMAND if CMD_TEST
	select SELFTEST_IDR
	select SELFTEST_TLV
	select SELFTEST_DM
	select SELFTEST_LVM if BLOCK
	select SELFTEST_UBI if MTD_UBI && MTD_WRITE
	select SELFTEST_TALLOC
	select SELFTEST_BLSPEC if BLSPEC && DEFAULT_ENVIRONMENT
	help
	  Selects all self-tests compatible with current configuration

config SELFTEST_BASE64
	bool "base64 selftest"
	select BASE64
	help
	  Tests base64 implementation

config SELFTEST_RANGE
	bool "range.h selftest"
	help
	  Tests range functions

config SELFTEST_MALLOC
	bool "malloc() selftest"
	help
	  Tests barebox memory allocator

config SELFTEST_CLEANUP
	bool "scope-based cleanup selftest"
	help
	  Tests the __free() cleanup handlers the barebox allocators define,
	  i.e. that leaving a scope frees the buffer, that NULL and error
	  pointers are never freed and that no_free_ptr() inhibits cleanup.

	  If unsure, say n.

config SELFTEST_TALLOC
	bool "talloc() selftest"
	help
	  Tests barebox talloc allocator

config SELFTEST_PRINTF
	bool "printf selftest"
	help
	  Tests barebox vsnprintf() functionality

config SELFTEST_OF_MANIPULATION
	bool "OF manipulation selftest"
	select OFTREE
	help
	  Tests barebox device tree manipulation functionality

config SELFTEST_OF_OVERLAY
	bool "OF overlay selftest"
	select OF_OVERLAY
	help
	  Tests devicetree overlay application

config SELFTEST_PROGRESS_NOTIFIER
	bool "progress notifier selftest"

config SELFTEST_ENVIRONMENT_VARIABLES
	bool "environment variable selftest"

config SELFTEST_FS_RAMFS
	bool "ramfs selftest"
	depends on FS_RAMFS

config SELFTEST_DIRFD
	bool "dirfd selftest"
	depends on FS_RAMFS && FS_DEVFS

config SELFTEST_JSON
	bool "JSON selftest"
	depends on JSMN

config SELFTEST_JWT
	bool "JSON Web Token selftest"
	depends on JWT
	select TEST_KEY_RSA4096

config SELFTEST_MMU
	bool "MMU remapping selftest"
	select MEMTEST
	depends on MMU

config SELFTEST_DIGEST
	bool "Digest selftest"
	depends on DIGEST
	select PRINTF_HEXSTR

config SELFTEST_STRING
	bool "String library selftest"
	select VERSION_CMP

config SELFTEST_SETJMP
	bool "setjmp/longjmp library selftest"
	depends on ARCH_HAS_SJLJ

config SELFTEST_BLSPEC
	bool "bootloader spec selftest"
	depends on BLSPEC && DEFAULT_ENVIRONMENT

config SELFTEST_REGULATOR
	bool "Regulator selftest"
	depends on REGULATOR_FIXED
	select OF_OVERLAY

config SELFTEST_RESOURCE
	bool "Resource selftest"

config SELFTEST_TEST_COMMAND
	bool "test command selftest"
	depends on CMD_TEST

config SELFTEST_IDR
	bool "idr selftest"
	select IDR

config SELFTEST_TLV
	bool "TLV selftest"
	select TLV
	select BASE64
	select BOARD_LXA

config SELFTEST_LVM
	bool "LVM selftest"
	depends on BLOCK
	select DM_LVM
	select RAMDISK_BLK
	help
	  Tests the parsing of LVM2 metadata, using physical volume
	  images that are assembled in memory and backed by ramdisks.
	  This covers the tokenizer, the recovery from damaged labels
	  and metadata areas, the selection of the most recent metadata
	  when the physical volumes of a group disagree, and the mapping
	  of logical volumes onto the extents they are made of.

config SELFTEST_UBI
	bool "UBI selftest"
	depends on MTD_UBI && MTD_WRITE
	help
	  Tests attaching UBI to images that UBI itself wrote to an
	  in-memory NAND device and that were then changed in one field:
	  a static volume's last LEB larger than the usable LEB size and,
	  with fastmap support, PEB numbers in the fastmap outside the
	  device.

config SELFTEST_DM
	bool "Device mapper selftest"
	select DISK
	select DM_BLK
	select DM_BLK_LINEAR
	select RAMDISK_BLK
	help
	  Tests the available device mapper targets

endif
