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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/cpu_mask.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 #include <test_progs.h>
  3 #include <bpf/btf.h>
  4 #include "bpf/libbpf_internal.h"
  5 
  6 static int duration = 0;
  7 
  8 static void validate_mask(int case_nr, const char *exp, bool *mask, int n)
  9 {
 10         int i;
 11 
 12         for (i = 0; exp[i]; i++) {
 13                 if (exp[i] == '1') {
 14                         if (CHECK(i + 1 > n, "mask_short",
 15                                   "case #%d: mask too short, got n=%d, need at least %d\n",
 16                                   case_nr, n, i + 1))
 17                                 return;
 18                         CHECK(!mask[i], "cpu_not_set",
 19                               "case #%d: mask differs, expected cpu#%d SET\n",
 20                               case_nr, i);
 21                 } else {
 22                         CHECK(i < n && mask[i], "cpu_set",
 23                               "case #%d: mask differs, expected cpu#%d UNSET\n",
 24                               case_nr, i);
 25                 }
 26         }
 27         CHECK(i < n, "mask_long",
 28               "case #%d: mask too long, got n=%d, expected at most %d\n",
 29               case_nr, n, i);
 30 }
 31 
 32 static struct {
 33         const char *cpu_mask;
 34         const char *expect;
 35         bool fails;
 36 } test_cases[] = {
 37         { "\n", "1", false },
 38         { "0,2\n", "101", false },
 39         { "0-2\n", "111", false },
 40         { "0-2,3-4\n", "11111", false },
 41         { "", "1", false },
 42         { "0-2", "111", false },
 43         { "0,2", "101", false },
 44         { "0,1-3", "1111", false },
 45         { "0,1,2,3", "1111", false },
 46         { "0,2-3,5", "101101", false },
 47         { "3-3", "0001", false },
 48         { "2-4,6,9-10", "00111010011", false },
 49         /* failure cases */
 50         { "", "", true },
 51         { "0-", "", true },
 52         { "0 ", "", true },
 53         { "0_1", "", true },
 54         { "1-0", "", true },
 55         { "-1", "", true },
 56 };
 57 
 58 void test_cpu_mask()
 59 {
 60         int i, err, n;
 61         bool *mask;
 62 
 63         for (i = 0; i < ARRAY_SIZE(test_cases); i++) {
 64                 mask = NULL;
 65                 err = parse_cpu_mask_str(test_cases[i].cpu_mask, &mask, &n);
 66                 if (test_cases[i].fails) {
 67                         CHECK(!err, "should_fail",
 68                               "case #%d: parsing should fail!\n", i + 1);
 69                 } else {
 70                         if (CHECK(err, "parse_err",
 71                                   "case #%d: cpu mask parsing failed: %d\n",
 72                                   i + 1, err))
 73                                 continue;
 74                         validate_mask(i + 1, test_cases[i].expect, mask, n);
 75                 }
 76                 free(mask);
 77         }
 78 }
 79 

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