// SPDX-License-Identifier: GPL-2.0-only
/*
* arch/arm/kernel/kprobes-test.c
*
* Copyright (C) 2011 Jon Medhurst <tixy@yxit.co.uk>.
*/
/*
* This file contains test code for ARM kprobes.
*
* The top level function run_all_tests() executes tests for all of the
* supported instruction sets: ARM, 16-bit Thumb, and 32-bit Thumb. These tests
* fall into two categories; run_api_tests() checks basic functionality of the
* kprobes API, and run_test_cases() is a comprehensive test for kprobes
* instruction decoding and simulation.
*
* run_test_cases() first checks the kprobes decoding table for self consistency
* (using table_test()) then executes a series of test cases for each of the CPU
* instruction forms. coverage_start() and coverage_end() are used to verify
* that these test cases cover all of the possible combinations of instructions
* described by the kprobes decoding tables.
*
* The individual test cases are in kprobes-test-arm.c and kprobes-test-thumb.c
* which use the macros defined in kprobes-test.h. The rest of this
* documentation will describe the operation of the framework used by these
* test cases.
*/
/*
* TESTING METHODOLOGY
* -------------------
*
* The methodology used to test an ARM instruction 'test_insn' is to use
* inline assembler like:
*
* test_before: nop
* test_case: test_insn
* test_after: nop
*
* When the test case is run a kprobe is placed of each nop. The
* post-handler of the test_before probe is used to modify the saved CPU
* register context to that which we require for the test case. The
* pre-handler of the of the test_after probe saves a copy of the CPU
* register context. In this way we can execute test_insn with a specific
* register context and see the results afterwards.
*
* To actually test the kprobes instruction emulation we perform the above
* step a second time but with an additional kprobe on the test_case
* instruction itself. If the emulation is accurate then the results seen
* by the test_