/var/lib/pcp/testsuite/src/eofarch.c is in pcp-testsuite 3.8.12ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | /*
* Copyright (c) 1997-2001 Silicon Graphics, Inc. All Rights Reserved.
*/
/*
* exercise outside feasible log range operations ... before start
* and after end
*/
#include <pcp/pmapi.h>
#include <pcp/impl.h>
static int vflag;
int
main(int argc, char **argv)
{
int c;
int sts;
int ctx;
int errflag = 0;
char *archive = "foo";
char *namespace = PM_NS_DEFAULT;
static char *usage = "[-a archive] [-n namespace] [-v]";
pmResult *resp;
int resnum = 0;
pmID pmid = 0;
struct timeval when;
struct timeval first;
struct timeval last;
__pmSetProgname(argv[0]);
while ((c = getopt(argc, argv, "a:D:n:v")) != EOF) {
switch (c) {
case 'a': /* archive */
archive = optarg;
break;
#ifdef PCP_DEBUG
case 'D': /* debug flag */
sts = __pmParseDebug(optarg);
if (sts < 0) {
fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n",
pmProgname, optarg);
errflag++;
}
else
pmDebug |= sts;
break;
#endif
case 'n': /* alternative name space file */
namespace = optarg;
break;
case 'v': /* verbose output */
vflag++;
break;
case '?':
default:
errflag++;
break;
}
}
if (errflag) {
printf("Usage: %s %s\n", pmProgname, usage);
exit(1);
}
if ((sts = pmLoadNameSpace(namespace)) < 0) {
printf("%s: Cannot load namespace from \"%s\": %s\n", pmProgname, namespace, pmErrStr(sts));
exit(1);
}
if ((ctx = pmNewContext(PM_CONTEXT_ARCHIVE, archive)) < 0) {
printf("%s: Cannot connect to archive \"%s\": %s\n", pmProgname, archive, pmErrStr(ctx));
exit(1);
}
when.tv_sec = 0;
when.tv_usec = 0;
if ((sts = pmSetMode(PM_MODE_FORW, &when, 0)) < 0) {
printf("%s: pmSetMode: %s\n", pmProgname, pmErrStr(sts));
exit(1);
}
printf("\nPass 1: forward scan\n");
for (;;) {
if ((sts = pmFetchArchive(&resp)) < 0) {
if (sts != PM_ERR_EOL)
printf("pmFetchArchive: %s\n", pmErrStr(sts));
break;
}
if (resnum == 0) {
first = resp->timestamp;
pmid = resp->vset[0]->pmid;
}
else
last = resp->timestamp;
resnum++;
if (vflag)
__pmDumpResult(stdout, resp);
pmFreeResult(resp);
}
printf("Found %d samples, with %d log reads\n", resnum, __pmLogReads);
printf("\nPass 2: before start of log scan\n");
first.tv_sec--;
printf(" 2.1: FORWARD, expect success\n");
__pmLogReads = 0;
if ((sts = pmSetMode(PM_MODE_FORW, &first, 0)) < 0) {
printf("pmSetMode: %s\n", pmErrStr(sts));
exit(1);
}
if ((sts = pmFetchArchive(&resp)) < 0) {
printf(" %s with %d log_reads\n", pmErrStr(sts), __pmLogReads);
}
else {
if (vflag)
__pmDumpResult(stdout, resp);
printf(" found 1 with %d log reads\n", __pmLogReads);
pmFreeResult(resp);
}
printf(" 2.2: BACKWARD, expect EOL\n");
__pmLogReads = 0;
if ((sts = pmSetMode(PM_MODE_BACK, &first, 0)) < 0) {
printf("pmSetMode: %s\n", pmErrStr(sts));
exit(1);
}
if ((sts = pmFetchArchive(&resp)) < 0) {
printf(" %s with %d log_reads\n", pmErrStr(sts), __pmLogReads);
}
else {
if (vflag)
__pmDumpResult(stdout, resp);
printf(" found 1 with %d log reads\n", __pmLogReads);
pmFreeResult(resp);
}
printf(" 2.3: INTERP, expect EOL\n");
__pmLogReads = 0;
if ((sts = pmSetMode(PM_MODE_INTERP, &first, 0)) < 0) {
printf("pmSetMode: %s\n", pmErrStr(sts));
exit(1);
}
if ((sts = pmFetch(1, &pmid, &resp)) < 0) {
printf(" %s with %d log_reads\n", pmErrStr(sts), __pmLogReads);
}
else {
if (vflag)
__pmDumpResult(stdout, resp);
printf(" found 1 with %d log reads\n", __pmLogReads);
pmFreeResult(resp);
}
printf("\nPass 3: after end of log scan\n");
last.tv_sec++;
printf(" 3.1: FORWARD, expect EOL\n");
__pmLogReads = 0;
if ((sts = pmSetMode(PM_MODE_FORW, &last, 0)) < 0) {
printf("pmSetMode: %s\n", pmErrStr(sts));
exit(1);
}
if ((sts = pmFetchArchive(&resp)) < 0) {
printf(" %s with %d log_reads\n", pmErrStr(sts), __pmLogReads);
}
else {
if (vflag)
__pmDumpResult(stdout, resp);
printf(" found 1 with %d log reads\n", __pmLogReads);
pmFreeResult(resp);
}
printf(" 3.2: BACKWARD, expect success\n");
__pmLogReads = 0;
if ((sts = pmSetMode(PM_MODE_BACK, &last, 0)) < 0) {
printf("pmSetMode: %s\n", pmErrStr(sts));
exit(1);
}
if ((sts = pmFetchArchive(&resp)) < 0) {
printf(" %s with %d log_reads\n", pmErrStr(sts), __pmLogReads);
}
else {
if (vflag)
__pmDumpResult(stdout, resp);
printf(" found 1 with %d log reads\n", __pmLogReads);
pmFreeResult(resp);
}
printf(" 3.3: INTERP, expect EOL\n");
__pmLogReads = 0;
if ((sts = pmSetMode(PM_MODE_INTERP, &last, 0)) < 0) {
printf("pmSetMode: %s\n", pmErrStr(sts));
exit(1);
}
if ((sts = pmFetch(1, &pmid, &resp)) < 0) {
printf(" %s with %d log_reads\n", pmErrStr(sts), __pmLogReads);
}
else {
if (vflag)
__pmDumpResult(stdout, resp);
printf(" found 1 with %d log reads\n", __pmLogReads);
pmFreeResult(resp);
}
exit(0);
}
|