~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/tests/binfmt_elf_kunit.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 #include <kunit/test.h>
  3 
  4 static void total_mapping_size_test(struct kunit *test)
  5 {
  6         struct elf_phdr empty[] = {
  7                 { .p_type = PT_LOAD, .p_vaddr = 0, .p_memsz = 0, },
  8                 { .p_type = PT_INTERP, .p_vaddr = 10, .p_memsz = 999999, },
  9         };
 10         /*
 11          * readelf -lW /bin/mount | grep '^  .*0x0' | awk '{print "\t\t{ .p_type = PT_" \
 12          *                              $1 ", .p_vaddr = " $3 ", .p_memsz = " $6 ", },"}'
 13          */
 14         struct elf_phdr mount[] = {
 15                 { .p_type = PT_PHDR, .p_vaddr = 0x00000040, .p_memsz = 0x0002d8, },
 16                 { .p_type = PT_INTERP, .p_vaddr = 0x00000318, .p_memsz = 0x00001c, },
 17                 { .p_type = PT_LOAD, .p_vaddr = 0x00000000, .p_memsz = 0x0033a8, },
 18                 { .p_type = PT_LOAD, .p_vaddr = 0x00004000, .p_memsz = 0x005c91, },
 19                 { .p_type = PT_LOAD, .p_vaddr = 0x0000a000, .p_memsz = 0x0022f8, },
 20                 { .p_type = PT_LOAD, .p_vaddr = 0x0000d330, .p_memsz = 0x000d40, },
 21                 { .p_type = PT_DYNAMIC, .p_vaddr = 0x0000d928, .p_memsz = 0x000200, },
 22                 { .p_type = PT_NOTE, .p_vaddr = 0x00000338, .p_memsz = 0x000030, },
 23                 { .p_type = PT_NOTE, .p_vaddr = 0x00000368, .p_memsz = 0x000044, },
 24                 { .p_type = PT_GNU_PROPERTY, .p_vaddr = 0x00000338, .p_memsz = 0x000030, },
 25                 { .p_type = PT_GNU_EH_FRAME, .p_vaddr = 0x0000b490, .p_memsz = 0x0001ec, },
 26                 { .p_type = PT_GNU_STACK, .p_vaddr = 0x00000000, .p_memsz = 0x000000, },
 27                 { .p_type = PT_GNU_RELRO, .p_vaddr = 0x0000d330, .p_memsz = 0x000cd0, },
 28         };
 29         size_t mount_size = 0xE070;
 30         /* https://lore.kernel.org/linux-fsdevel/YfF18Dy85mCntXrx@fractal.localdomain */
 31         struct elf_phdr unordered[] = {
 32                 { .p_type = PT_LOAD, .p_vaddr = 0x00000000, .p_memsz = 0x0033a8, },
 33                 { .p_type = PT_LOAD, .p_vaddr = 0x0000d330, .p_memsz = 0x000d40, },
 34                 { .p_type = PT_LOAD, .p_vaddr = 0x00004000, .p_memsz = 0x005c91, },
 35                 { .p_type = PT_LOAD, .p_vaddr = 0x0000a000, .p_memsz = 0x0022f8, },
 36         };
 37 
 38         /* No headers, no size. */
 39         KUNIT_EXPECT_EQ(test, total_mapping_size(NULL, 0), 0);
 40         KUNIT_EXPECT_EQ(test, total_mapping_size(empty, 0), 0);
 41         /* Empty headers, no size. */
 42         KUNIT_EXPECT_EQ(test, total_mapping_size(empty, 1), 0);
 43         /* No PT_LOAD headers, no size. */
 44         KUNIT_EXPECT_EQ(test, total_mapping_size(&empty[1], 1), 0);
 45         /* Empty PT_LOAD and non-PT_LOAD headers, no size. */
 46         KUNIT_EXPECT_EQ(test, total_mapping_size(empty, 2), 0);
 47 
 48         /* Normal set of PT_LOADS, and expected size. */
 49         KUNIT_EXPECT_EQ(test, total_mapping_size(mount, ARRAY_SIZE(mount)), mount_size);
 50         /* Unordered PT_LOADs result in same size. */
 51         KUNIT_EXPECT_EQ(test, total_mapping_size(unordered, ARRAY_SIZE(unordered)), mount_size);
 52 }
 53 
 54 static struct kunit_case binfmt_elf_test_cases[] = {
 55         KUNIT_CASE(total_mapping_size_test),
 56         {},
 57 };
 58 
 59 static struct kunit_suite binfmt_elf_test_suite = {
 60         .name = KBUILD_MODNAME,
 61         .test_cases = binfmt_elf_test_cases,
 62 };
 63 
 64 kunit_test_suite(binfmt_elf_test_suite);
 65 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php