qa: update 660 to generate index.html, fixing pcp-testsuite runs
[pcp.git] / qa / src / chkctx2.c
blob4fc5a05c5d767fb4b437f7b31ac7850527f56091
1 /*
2 * Copyright (c) 1997-2001 Silicon Graphics, Inc. All Rights Reserved.
3 */
5 #define SOURCE handle == 0 ? "host" : ( type == PM_CONTEXT_ARCHIVE ? "archive" : "host" )
6 #define HOST handle == 0 ? "localhost" : host
8 /*
9 * context and profile exerciser
12 #include <pcp/pmapi.h>
13 #include <pcp/impl.h>
15 static int inst_bin[] = { 100, 200, 300, 400, 500, 600, 700, 800, 900 };
17 static int xpect_bin[] = { 1 };
18 static int xpect_colour[] = { 0 };
20 static char *namelist[] = {
21 "sampledso.bin",
22 "sampledso.colour"
26 * handle profile values expected
27 * 0 bin=500, no colour 1 bin 0 colour
30 int
31 main(int argc, char **argv)
33 int c;
34 int sts;
35 int errflag = 0;
36 int type = 0;
37 char *host = "localhost";
38 char *namespace = PM_NS_DEFAULT;
39 pmInDom indom_bin, indom_colour;
40 pmID metrics[2];
41 pmResult *resp;
42 pmDesc desc;
43 int handle;
44 #ifdef PCP_DEBUG
45 static char *debug = "[-D N] ";
46 #else
47 static char *debug = "";
48 #endif
49 static char *usage = "[-a archive] [-h hostname] [-L] [-n namespace]";
51 __pmSetProgname(argv[0]);
53 while ((c = getopt(argc, argv, "a:D:h:Ln:")) != EOF) {
54 switch (c) {
56 case 'a': /* archive name */
57 if (type != 0) {
58 fprintf(stderr, "%s: at most one of -a, -h and -L allowed\n", pmProgname);
59 errflag++;
61 type = PM_CONTEXT_ARCHIVE;
62 host = optarg;
63 break;
65 #ifdef PCP_DEBUG
66 case 'D': /* debug flag */
67 sts = __pmParseDebug(optarg);
68 if (sts < 0) {
69 fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n",
70 pmProgname, optarg);
71 errflag++;
73 else
74 pmDebug |= sts;
75 break;
76 #endif
78 case 'h': /* hostname for PMCD to contact */
79 if (type != 0) {
80 fprintf(stderr, "%s: at most one of -a, -h and -L allowed\n", pmProgname);
81 errflag++;
83 host = optarg;
84 type = PM_CONTEXT_HOST;
85 break;
87 case 'L': /* local mode, no PMCD */
88 if (type != 0) {
89 fprintf(stderr, "%s: at most one of -a, -h and -L allowed\n", pmProgname);
90 errflag++;
92 host = NULL;
93 type = PM_CONTEXT_LOCAL;
94 break;
96 case 'n': /* alternative name space file */
97 namespace = optarg;
98 break;
100 case '?':
101 default:
102 errflag++;
103 break;
107 if (errflag) {
108 fprintf(stderr, "Usage: %s %s%s\n", pmProgname, debug, usage);
109 exit(1);
112 if ((sts = pmLoadASCIINameSpace(namespace, 1)) < 0) {
113 printf("%s: Cannot load namespace from \"%s\": %s\n", pmProgname, namespace, pmErrStr(sts));
114 exit(1);
116 if ((sts = pmLookupName(2, namelist, metrics)) < 0) {
117 fprintf(stderr, "pmLookupName: %s\n", pmErrStr(sts));
118 fprintf(stderr, "pmids: 0x%x 0x%x\n", metrics[0], metrics[1]);
119 exit(1);
122 /* make context 0 the default localhost one */
123 if ((sts = pmNewContext(PM_CONTEXT_HOST, "localhost")) < 0) {
124 fprintf(stderr, "pmNewContext(..., \"localhost\"): %s\n",
125 pmErrStr(sts));
126 exit(1);
129 if (type == 0)
130 type = PM_CONTEXT_HOST; /* default */
132 if (type == PM_CONTEXT_HOST) {
133 if ((sts = pmNewContext(PM_CONTEXT_HOST, host)) < 0) {
134 fprintf(stderr, "handle: pmNewContext(host=%s): %s\n", host, pmErrStr(sts));
135 exit(1);
138 else if (type == PM_CONTEXT_LOCAL) {
139 if ((sts = pmNewContext(PM_CONTEXT_LOCAL, host)) < 0) {
140 fprintf(stderr, "handle: pmNewContext(local): %s\n", pmErrStr(sts));
141 exit(1);
144 else {
145 if ((sts = pmNewContext(PM_CONTEXT_ARCHIVE, host)) < 0) {
146 fprintf(stderr, "handle: pmNewContext(archive=%s): %s\n", host, pmErrStr(sts));
147 exit(1);
150 handle = sts;
152 while (handle >= 0) {
153 pmUseContext(handle);
155 if ((sts = pmLookupDesc(metrics[0], &desc)) < 0) {
156 fprintf(stderr, "pmLookupDesc: context=%d %s=%s %s: %s\n",
157 handle, SOURCE, HOST, namelist[0], pmErrStr(sts));
158 exit(1);
160 indom_bin = desc.indom;
161 if ((sts = pmLookupDesc(metrics[1], &desc)) < 0) {
162 fprintf(stderr, "pmLookupDesc: context=%d %s=%s %s: %s\n",
163 handle, SOURCE, HOST, namelist[1], pmErrStr(sts));
164 exit(1);
166 indom_colour = desc.indom;
168 pmDelProfile(indom_bin, 0, (int *)0);
169 pmAddProfile(indom_bin, 1, &inst_bin[4]);
170 pmDelProfile(indom_colour, 0, (int *)0);
172 sts = pmFetch(2, metrics, &resp);
173 if (sts < 0) {
174 fprintf(stderr, "botch @ context=%d %s=%s: pmFetch: %s\n",
175 handle, SOURCE, HOST, pmErrStr(sts));
177 else {
178 if (resp->numpmid != 2) {
179 fprintf(stderr, "botch @ context=%d %s=%s: numpmid %d != 2\n",
180 handle, SOURCE, HOST, resp->numpmid);
182 else {
183 if (resp->vset[0]->numval != xpect_bin[0]) {
184 fprintf(stderr, "botch @ context=%d %s=%s: [indom %s] numval got: %d expect: %d\n",
185 handle, SOURCE, HOST, pmInDomStr(indom_bin),
186 resp->vset[0]->numval, xpect_bin[0]);
188 if (resp->vset[1]->numval != xpect_colour[0]) {
189 fprintf(stderr, "botch @ context=%d %s=%s: [indom %s] numval got: %d expect: %d\n",
190 handle, SOURCE, HOST, pmInDomStr(indom_colour),
191 resp->vset[1]->numval, xpect_colour[0]);
194 pmFreeResult(resp);
196 if (handle) {
197 if ((sts = pmDestroyContext(handle)) < 0)
198 fprintf(stderr, "pmDestroyContext %d %s=%s: %s\n",
199 handle, SOURCE, HOST, pmErrStr(sts));
201 handle--;
204 exit(0);