File: ns_shared1.cpp

package info (click to toggle)
pcp 7.1.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 252,748 kB
  • sloc: ansic: 1,483,656; sh: 182,366; xml: 160,462; cpp: 83,813; python: 24,980; perl: 18,327; yacc: 6,877; lex: 2,864; makefile: 2,738; awk: 165; fortran: 60; java: 52
file content (145 lines) | stat: -rw-r--r-- 3,847 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// SPDX-License-Identifier: BSD-2-Clause
#include <cstdio>
#include "common.h"
#include "../usdt.h"
#include "ns_shared.h"

/* Alright, USDT and USDT semaphores have global visibility and naming, but
 * C++ has its own quirks, so we'll test various cases with USDTs in global
 * and namespaced context. As opposed to ns_simple test, this time we have
 * multiple files in main executable and the library.
 */

namespace main_ns
{
	USDT_DEFINE_SEMA(main_sema); /* definition */

	/* We don't have to put these declarations inside the namespace (they
	 * would work in global namespace just as fine, as demonstrated by
	 * ns_simple test), but we are doing this here anyways just to test
	 * that putting declarations inside namespaces also work
	 */
	USDT_DECLARE_SEMA(sub_sema); /* declaration */
#ifndef SHARED
	USDT_DECLARE_SEMA(lib_sema); /* declaration */
#endif

	__weak __optimize void main_func(int x)
	{
		USDT_WITH_EXPLICIT_SEMA(main_sema, test, main_main, x);
		USDT_WITH_EXPLICIT_SEMA(sub_sema, test, main_sub, x);
#ifndef SHARED
		USDT_WITH_EXPLICIT_SEMA(lib_sema, test, main_lib, x);
#endif

		printf("main: main_sema is %s.\n", USDT_SEMA_IS_ACTIVE(main_sema) ? "ACTIVE" : "INACTIVE");
		printf("main: sub_sema is %s.\n", USDT_SEMA_IS_ACTIVE(sub_sema) ? "ACTIVE" : "INACTIVE");
#ifndef SHARED
		printf("main: lib_sema is %s.\n", USDT_SEMA_IS_ACTIVE(lib_sema) ? "ACTIVE" : "INACTIVE");
#endif
	}
}

int main(int argc, char **argv)
{
	if (handle_args(argc, argv))
		return 0;

	main_ns::main_func(1);
	sub_ns::sub_func(2);
	lib_ns::lib_func(3);

	return 0;
}

const char *USDT_SPECS =
"test:main_main base=BASE1 sema=SEMA1 argn=1 args=-4@*.\n"
"test:main_sub base=BASE1 sema=SEMA2 argn=1 args=-4@*.\n"
#ifndef SHARED
"test:main_lib base=BASE1 sema=SEMA3 argn=1 args=-4@*.\n"
#endif
"test:sub_main base=BASE1 sema=SEMA1 argn=1 args=-4@*.\n"
"test:sub_sub base=BASE1 sema=SEMA2 argn=1 args=-4@*.\n"
#ifndef SHARED
"test:sub_lib base=BASE1 sema=SEMA3 argn=1 args=-4@*.\n"
#endif
#ifdef SHARED
"test:lib_lib base=BASE2 sema=SEMA3 argn=1 args=-4@*.\n"
#else /* !SHARED */
"test:lib_main base=BASE1 sema=SEMA1 argn=1 args=-4@*.\n"
"test:lib_sub base=BASE1 sema=SEMA2 argn=1 args=-4@*.\n"
"test:lib_lib base=BASE1 sema=SEMA3 argn=1 args=-4@*.\n"
#endif /* SHARED */
;

const char *UNTRACED_OUTPUT =
"main: main_sema is INACTIVE.\n"
"main: sub_sema is INACTIVE.\n"
#ifndef SHARED
"main: lib_sema is INACTIVE.\n"
#endif
"sub: main_sema is INACTIVE.\n"
"sub: sub_sema is INACTIVE.\n"
#ifndef SHARED
"sub: lib_sema is INACTIVE.\n"
"lib: main_sema is INACTIVE.\n"
"lib: sub_sema is INACTIVE.\n"
#endif
"lib: lib_sema is INACTIVE.\n"
;

const char *BPFTRACE_SCRIPT =
"test:main_main { x=%d -> arg0 }\n"
"test:main_sub { x=%d -> arg0 }\n"
#ifndef SHARED
"test:main_lib { x=%d -> arg0 }\n"
#endif /* SHARED */
"test:sub_main { x=%d -> arg0 }\n"
"test:sub_sub { x=%d -> arg0 }\n"
#ifndef SHARED
"test:sub_lib { x=%d -> arg0 }\n"
#endif /* SHARED */
#ifdef SHARED
"lib:test:lib_lib { x=%d -> arg0 }\n"
#else /* !SHARED */
"test:lib_main { x=%d -> arg0 }\n"
"test:lib_sub { x=%d -> arg0 }\n"
"test:lib_lib { x=%d -> arg0 }\n"
#endif
;

const char *BPFTRACE_OUTPUT =
"test:main_main: x=1\n"
"test:main_sub: x=1\n"
#ifndef SHARED
"test:main_lib: x=1\n"
#endif /* SHARED */
"test:sub_main: x=2\n"
"test:sub_sub: x=2\n"
#ifndef SHARED
"test:sub_lib: x=2\n"
#endif /* SHARED */
#ifdef SHARED
"lib:test:lib_lib: x=3\n"
#else /* !SHARED */
"test:lib_main: x=3\n"
"test:lib_sub: x=3\n"
"test:lib_lib: x=3\n"
#endif
;

const char *TRACED_OUTPUT = ""
"main: main_sema is ACTIVE.\n"
"main: sub_sema is ACTIVE.\n"
#ifndef SHARED
"main: lib_sema is ACTIVE.\n"
#endif
"sub: main_sema is ACTIVE.\n"
"sub: sub_sema is ACTIVE.\n"
#ifndef SHARED
"sub: lib_sema is ACTIVE.\n"
"lib: main_sema is ACTIVE.\n"
"lib: sub_sema is ACTIVE.\n"
#endif
"lib: lib_sema is ACTIVE.\n"
;