Tests: lttng-ust-getcpu-override-test cache and error-check sysconf()
[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 *
5 * Copyright (c) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Copyright (c) 2015 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26
27#include <stdlib.h>
28#include <time.h>
29#include <string.h>
30#include <stdio.h>
31#include <unistd.h>
32#include <lttng/ust-getcpu.h>
33
de76faf8
JG
34static long nprocessors;
35
568d7e2d
JR
36int plugin_getcpu(void)
37{
38 /* Generate a sequence based on the number of configurated processor
39 * by using sequence[i] % nb_configured_processors. Where sequence
40 * is a static random sequence.
41 * The expected cpu_id sequence can be regenerated on the test script
42 * side and compared to the extracted cpu sequence for validation.
43 * This does no guarantee in absolute the validity of the getcpu
44 * plugin but provide a strong argument of it's validity.
45 */
46 static int i = 0;
885fe378
JG
47 static int seq_seed[256] = { 100, 57, 232, 236, 42, 193, 224, 184, 216,
48 150, 92, 91, 108, 118, 55, 243, 65, 101, 209, 0, 147, 36, 29,
49 34, 49, 188, 174, 105, 253, 245, 227, 238, 112, 20, 222, 201,
50 102, 175, 119, 19, 132, 41, 78, 90, 114, 64, 138, 14, 48, 18,
51 162, 85, 204, 124, 133, 73, 172, 106, 241, 126, 28, 104, 111,
52 21, 127, 219, 9, 244, 237, 189, 59, 214, 52, 141, 107, 26, 25,
53 199, 3, 157, 117, 234, 33, 44, 46, 84, 69, 155, 122, 250, 231,
54 86, 239, 76, 190, 120, 1, 94, 206, 8, 148, 159, 167, 215, 164,
55 31, 217, 61, 71, 125, 68, 109, 195, 177, 95, 82, 142, 182, 129,
56 87, 37, 140, 134, 186, 173, 39, 116, 143, 254, 229, 131, 67,
57 121, 192, 240, 15, 221, 30, 242, 185, 80, 170, 135, 51, 187,
58 194, 246, 12, 225, 181, 137, 211, 228, 88, 218, 27, 233, 161,
59 77, 252, 123, 93, 220, 248, 205, 223, 144, 128, 196, 70, 247,
60 210, 178, 203, 154, 24, 169, 149, 163, 35, 7, 151, 103, 197,
61 139, 165, 158, 207, 72, 113, 145, 45, 183, 11, 198, 43, 81, 230,
62 97, 96, 2, 66, 213, 146, 179, 22, 58, 54, 38, 160, 200, 235,
63 226, 156, 56, 208, 249, 32, 176, 168, 110, 191, 79, 152, 115,
64 10, 74, 60, 251, 17, 83, 180, 171, 202, 40, 166, 255, 53, 212,
65 98, 5, 50, 99, 4, 89, 13, 63, 6, 136, 153, 23, 16, 47, 130, 75,
66 62 };
568d7e2d 67 int ret;
de76faf8
JG
68
69 ret = seq_seed[i] % nprocessors;
568d7e2d
JR
70 i++;
71 i = i % 256;
72 return ret;
73}
74
75void lttng_ust_getcpu_plugin_init(void)
76{
77 int ret;
78
de76faf8
JG
79 nprocessors = sysconf(_SC_NPROCESSORS_CONF);
80 if (nprocessors < 0) {
81 perror("Failed to get _SC_NPROCESSORS_CONF");
82 goto error;
83 }
84
568d7e2d
JR
85 ret = lttng_ust_getcpu_override(plugin_getcpu);
86 if (ret) {
87 fprintf(stderr, "Error enabling getcpu override: %s\n",
88 strerror(-ret));
89 goto error;
90 }
91 return;
92
93error:
94 exit(EXIT_FAILURE);
95}
This page took 0.037103 seconds and 4 git commands to generate.