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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/varlen.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
  2 /* Copyright (c) 2020 Facebook */
  3 
  4 #include <test_progs.h>
  5 #include <time.h>
  6 #include "test_varlen.skel.h"
  7 
  8 #define CHECK_VAL(got, exp) \
  9         CHECK((got) != (exp), "check", "got %ld != exp %ld\n", \
 10               (long)(got), (long)(exp))
 11 
 12 void test_varlen(void)
 13 {
 14         int duration = 0, err;
 15         struct test_varlen* skel;
 16         struct test_varlen__bss *bss;
 17         struct test_varlen__data *data;
 18         const char str1[] = "Hello, ";
 19         const char str2[] = "World!";
 20         const char exp_str[] = "Hello, \0World!\0";
 21         const int size1 = sizeof(str1);
 22         const int size2 = sizeof(str2);
 23 
 24         skel = test_varlen__open_and_load();
 25         if (CHECK(!skel, "skel_open", "failed to open skeleton\n"))
 26                 return;
 27         bss = skel->bss;
 28         data = skel->data;
 29 
 30         err = test_varlen__attach(skel);
 31         if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err))
 32                 goto cleanup;
 33 
 34         bss->test_pid = getpid();
 35 
 36         /* trigger everything */
 37         memcpy(bss->buf_in1, str1, size1);
 38         memcpy(bss->buf_in2, str2, size2);
 39         bss->capture = true;
 40         usleep(1);
 41         bss->capture = false;
 42 
 43         CHECK_VAL(bss->payload1_len1, size1);
 44         CHECK_VAL(bss->payload1_len2, size2);
 45         CHECK_VAL(bss->total1, size1 + size2);
 46         CHECK(memcmp(bss->payload1, exp_str, size1 + size2), "content_check",
 47               "doesn't match!\n");
 48 
 49         CHECK_VAL(data->payload2_len1, size1);
 50         CHECK_VAL(data->payload2_len2, size2);
 51         CHECK_VAL(data->total2, size1 + size2);
 52         CHECK(memcmp(data->payload2, exp_str, size1 + size2), "content_check",
 53               "doesn't match!\n");
 54 
 55         CHECK_VAL(data->payload3_len1, size1);
 56         CHECK_VAL(data->payload3_len2, size2);
 57         CHECK_VAL(data->total3, size1 + size2);
 58         CHECK(memcmp(data->payload3, exp_str, size1 + size2), "content_check",
 59               "doesn't match!\n");
 60 
 61         CHECK_VAL(data->payload4_len1, size1);
 62         CHECK_VAL(data->payload4_len2, size2);
 63         CHECK_VAL(data->total4, size1 + size2);
 64         CHECK(memcmp(data->payload4, exp_str, size1 + size2), "content_check",
 65               "doesn't match!\n");
 66 
 67         CHECK_VAL(bss->ret_bad_read, -EFAULT);
 68         CHECK_VAL(data->payload_bad[0], 0x42);
 69         CHECK_VAL(data->payload_bad[1], 0x42);
 70         CHECK_VAL(data->payload_bad[2], 0);
 71         CHECK_VAL(data->payload_bad[3], 0x42);
 72         CHECK_VAL(data->payload_bad[4], 0x42);
 73 cleanup:
 74         test_varlen__destroy(skel);
 75 }
 76 

~ [ 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