• Eduard Zingerman's avatar
    selftests/bpf: Tests execution support for test_loader.c · 19a8e06f
    Eduard Zingerman authored
    Extends test_loader.c:test_loader__run_subtests() by allowing to
    execute BPF_PROG_TEST_RUN bpf command for selected programs.
    This is similar to functionality provided by test_verifier.
    
    Adds the following new attributes controlling test_loader behavior:
    
      __retval(...)
      __retval_unpriv(...)
    
    * If any of these attributes is present, the annotated program would
      be executed using libbpf's bpf_prog_test_run_opts() function.
    * If __retval is present, the test run would be done for program
      loaded in privileged mode.
    * If __retval_unpriv is present, the test run would be done for
      program loaded in unprivileged mode.
    * To mimic test_verifier behavior, the actual run is initiated in
      privileged mode.
    * The value returned by a test run is compared against retval
      parameter.
    
    The retval attribute takes one of the following parameters:
    - a decimal number
    - a hexadecimal number (must start from '0x')
    - any of a three special literals (provided for compatibility with
      test_verifier):
      - INT_MIN
      - POINTER_VALUE
      - TEST_DATA_LEN
    
    An example of the attribute usage:
    
      SEC("socket")
      __description("return 42")
      __success __success_unpriv __retval(42)
      __naked void the_42_test(void)
      {
              asm volatile ("                                 \
              r0 = 42;                                        \
              exit;                                           \
      "       ::: __clobber_all);
      }
    Signed-off-by: default avatarEduard Zingerman <eddyz87@gmail.com>
    Link: https://lore.kernel.org/r/20230325025524.144043-5-eddyz87@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    19a8e06f
bpf_misc.h 9.98 KB