Clean-up: sessiond: cmd_enable_channel_internal
[lttng-tools.git] / tests / regression / ust / getcpu-override / lttng-ust-getcpu-override-test.c
CommitLineData
568d7e2d
JR
1/*
2 * lttng-ust-getcpu-override-test.c
3 * Based on lttng-getcpu-override-example.c from LTTng-ust exemple
4 *
9d16b343
MJ
5 * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Copyright (C) 2015 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
568d7e2d 7 *
9d16b343 8 * SPDX-License-Identifier: MIT
568d7e2d 9 *
568d7e2d
JR
10 */
11
12#include <stdlib.h>
389fbf04 13#include <common/compat/time.h>
568d7e2d
JR
14#include <string.h>
15#include <stdio.h>
16#include <unistd.h>
4bd69c5f 17#include <lttng/lttng-export.h>
568d7e2d
JR
18#include <lttng/ust-getcpu.h>
19
de76faf8
JG
20static long nprocessors;
21
f12eb9c1 22static
568d7e2d
JR
23int plugin_getcpu(void)
24{
25 /* Generate a sequence based on the number of configurated processor
26 * by using sequence[i] % nb_configured_processors. Where sequence
27 * is a static random sequence.
28 * The expected cpu_id sequence can be regenerated on the test script
29 * side and compared to the extracted cpu sequence for validation.
30 * This does no guarantee in absolute the validity of the getcpu
31 * plugin but provide a strong argument of it's validity.
32 */
33 static int i = 0;
885fe378
JG
34 static int seq_seed[256] = { 100, 57, 232, 236, 42, 193, 224, 184, 216,
35 150, 92, 91, 108, 118, 55, 243, 65, 101, 209, 0, 147, 36, 29,
36 34, 49, 188, 174, 105, 253, 245, 227, 238, 112, 20, 222, 201,
37 102, 175, 119, 19, 132, 41, 78, 90, 114, 64, 138, 14, 48, 18,
38 162, 85, 204, 124, 133, 73, 172, 106, 241, 126, 28, 104, 111,
39 21, 127, 219, 9, 244, 237, 189, 59, 214, 52, 141, 107, 26, 25,
40 199, 3, 157, 117, 234, 33, 44, 46, 84, 69, 155, 122, 250, 231,
41 86, 239, 76, 190, 120, 1, 94, 206, 8, 148, 159, 167, 215, 164,
42 31, 217, 61, 71, 125, 68, 109, 195, 177, 95, 82, 142, 182, 129,
43 87, 37, 140, 134, 186, 173, 39, 116, 143, 254, 229, 131, 67,
44 121, 192, 240, 15, 221, 30, 242, 185, 80, 170, 135, 51, 187,
45 194, 246, 12, 225, 181, 137, 211, 228, 88, 218, 27, 233, 161,
46 77, 252, 123, 93, 220, 248, 205, 223, 144, 128, 196, 70, 247,
47 210, 178, 203, 154, 24, 169, 149, 163, 35, 7, 151, 103, 197,
48 139, 165, 158, 207, 72, 113, 145, 45, 183, 11, 198, 43, 81, 230,
49 97, 96, 2, 66, 213, 146, 179, 22, 58, 54, 38, 160, 200, 235,
50 226, 156, 56, 208, 249, 32, 176, 168, 110, 191, 79, 152, 115,
51 10, 74, 60, 251, 17, 83, 180, 171, 202, 40, 166, 255, 53, 212,
52 98, 5, 50, 99, 4, 89, 13, 63, 6, 136, 153, 23, 16, 47, 130, 75,
53 62 };
568d7e2d 54 int ret;
de76faf8
JG
55
56 ret = seq_seed[i] % nprocessors;
568d7e2d
JR
57 i++;
58 i = i % 256;
59 return ret;
60}
61
4bd69c5f 62LTTNG_EXPORT void lttng_ust_getcpu_plugin_init(void);
568d7e2d
JR
63void lttng_ust_getcpu_plugin_init(void)
64{
65 int ret;
66
de76faf8
JG
67 nprocessors = sysconf(_SC_NPROCESSORS_CONF);
68 if (nprocessors < 0) {
69 perror("Failed to get _SC_NPROCESSORS_CONF");
70 goto error;
71 }
72
568d7e2d
JR
73 ret = lttng_ust_getcpu_override(plugin_getcpu);
74 if (ret) {
75 fprintf(stderr, "Error enabling getcpu override: %s\n",
76 strerror(-ret));
77 goto error;
78 }
79 return;
80
81error:
82 exit(EXIT_FAILURE);
83}
This page took 0.043878 seconds and 4 git commands to generate.