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
|
//
// Test host matching algorithm with multiple groups
//
#include <errno.h>
#include <QTextStream>
#include <qmc_context.h>
#include <qmc_group.h>
#include <qmc_metric.h>
#include <qmc_indom.h>
QTextStream cerr(stderr);
QTextStream cout(stdout);
#define mesg(str) msg(__LINE__, str)
void
msg(int line, char const* str)
{
static int count = 1;
cerr << endl << "*** " << count << ": Line " << line << " - " << str
<< " ***" << endl;
count++;
}
void
quit(int err)
{
pmflush();
cerr << "Error: " << pmErrStr(err) << endl;
exit(1);
}
int
main(int argc, char* argv[])
{
int sts = 0;
int c;
QString source;
pmProgname = basename(argv[0]);
while ((c = getopt(argc, argv, "D:?")) != EOF) {
switch (c) {
case 'D':
sts = __pmParseDebug(optarg);
if (sts < 0) {
pmprintf("%s: unrecognized debug flag specification (%s)\n",
pmProgname, optarg);
sts = 1;
}
else {
pmDebug |= sts;
sts = 0;
}
break;
case '?':
default:
sts = 1;
break;
}
}
if (sts) {
pmprintf("Usage: %s\n", pmProgname);
pmflush();
exit(1);
/*NOTREACHED*/
}
mesg("Create two groups");
QmcGroup group1;
pmflush();
QmcGroup group2;
pmflush();
mesg("Create an archive context in both groups, but to different hosts");
source = "archives/oview-short";
sts = group1.use(PM_CONTEXT_ARCHIVE, source);
if (sts < 0)
quit(sts);
source = "archives/rattle";
sts = group2.use(PM_CONTEXT_ARCHIVE, source);
if (sts < 0)
quit(sts);
mesg("Try to create a host context to snort in group1");
// Should pass as it will get mapped to the archive
source = "snort";
sts = group1.use(PM_CONTEXT_HOST, source);
if (sts < 0)
quit(sts);
mesg("Try to create a host context to snort in group2");
// Should fail, this group has not seen an archive context for host snort
source = "snort";
sts = group2.use(PM_CONTEXT_HOST, source);
if (sts >= 0) {
mesg("Test failed: duplicate context created from another group");
pmflush();
exit(1);
}
pmflush();
return 0;
}
|