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

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/mem2node.c

Version: ~ [ linux-6.2-rc3 ] ~ [ linux-6.1.5 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.87 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.162 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.228 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.269 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.302 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ 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 <linux/compiler.h>
  3 #include <linux/bitmap.h>
  4 #include <linux/kernel.h>
  5 #include <linux/zalloc.h>
  6 #include <perf/cpumap.h>
  7 #include <internal/cpumap.h>
  8 #include "debug.h"
  9 #include "env.h"
 10 #include "mem2node.h"
 11 #include "tests.h"
 12 
 13 static struct node {
 14         int              node;
 15         const char      *map;
 16 } test_nodes[] = {
 17         { .node = 0, .map = ""     },
 18         { .node = 1, .map = "1-2"   },
 19         { .node = 3, .map = "5-7,9" },
 20 };
 21 
 22 #define T TEST_ASSERT_VAL
 23 
 24 static unsigned long *get_bitmap(const char *str, int nbits)
 25 {
 26         struct perf_cpu_map *map = perf_cpu_map__new(str);
 27         unsigned long *bm = NULL;
 28         int i;
 29 
 30         bm = bitmap_zalloc(nbits);
 31 
 32         if (map && bm) {
 33                 for (i = 0; i < map->nr; i++) {
 34                         set_bit(map->map[i], bm);
 35                 }
 36         }
 37 
 38         if (map)
 39                 perf_cpu_map__put(map);
 40         else
 41                 free(bm);
 42 
 43         return bm && map ? bm : NULL;
 44 }
 45 
 46 static int test__mem2node(struct test_suite *t __maybe_unused, int subtest __maybe_unused)
 47 {
 48         struct mem2node map;
 49         struct memory_node nodes[3];
 50         struct perf_env env = {
 51                 .memory_nodes    = (struct memory_node *) &nodes[0],
 52                 .nr_memory_nodes = ARRAY_SIZE(nodes),
 53                 .memory_bsize    = 0x100,
 54         };
 55         unsigned int i;
 56 
 57         for (i = 0; i < ARRAY_SIZE(nodes); i++) {
 58                 nodes[i].node = test_nodes[i].node;
 59                 nodes[i].size = 10;
 60 
 61                 T("failed: alloc bitmap",
 62                   (nodes[i].set = get_bitmap(test_nodes[i].map, 10)));
 63         }
 64 
 65         T("failed: mem2node__init", !mem2node__init(&map, &env));
 66         T("failed: mem2node__node",  0 == mem2node__node(&map,   0x50));
 67         T("failed: mem2node__node",  1 == mem2node__node(&map,  0x100));
 68         T("failed: mem2node__node",  1 == mem2node__node(&map,  0x250));
 69         T("failed: mem2node__node",  3 == mem2node__node(&map,  0x500));
 70         T("failed: mem2node__node",  3 == mem2node__node(&map,  0x650));
 71         T("failed: mem2node__node", -1 == mem2node__node(&map,  0x450));
 72         T("failed: mem2node__node", -1 == mem2node__node(&map, 0x1050));
 73 
 74         for (i = 0; i < ARRAY_SIZE(nodes); i++)
 75                 zfree(&nodes[i].set);
 76 
 77         mem2node__exit(&map);
 78         return 0;
 79 }
 80 
 81 DEFINE_SUITE("mem2node", mem2node);
 82 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp