diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2014-10-26 12:33:50 +0400 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2014-10-26 12:33:50 +0400 |
commit | 47e6e7c84f008a53061e661f31ae96629bc694ef (patch) | |
tree | 648a07f3b5b9d67ce19b0fd72e8caa1175c98f1a /qa/pmdas/broken | |
download | pcp-debian.tar.gz |
Debian 3.9.10debian/3.9.10debian
Diffstat (limited to 'qa/pmdas/broken')
-rw-r--r-- | qa/pmdas/broken/GNUmakefile | 83 | ||||
-rw-r--r-- | qa/pmdas/broken/GNUmakefile.install | 97 | ||||
-rwxr-xr-x | qa/pmdas/broken/broken_Install | 30 | ||||
-rwxr-xr-x | qa/pmdas/broken/broken_Remove | 24 | ||||
-rw-r--r-- | qa/pmdas/broken/broken_help | 39 | ||||
-rw-r--r-- | qa/pmdas/broken/broken_pmda.c | 387 | ||||
-rw-r--r-- | qa/pmdas/broken/broken_pmda.v1.c | 386 | ||||
-rw-r--r-- | qa/pmdas/broken/broken_pmns | 36 | ||||
-rw-r--r-- | qa/pmdas/broken/domain.h | 1 |
9 files changed, 1083 insertions, 0 deletions
diff --git a/qa/pmdas/broken/GNUmakefile b/qa/pmdas/broken/GNUmakefile new file mode 100644 index 0000000..4834cad --- /dev/null +++ b/qa/pmdas/broken/GNUmakefile @@ -0,0 +1,83 @@ +# +# Copyright (c) 2012 Red Hat. +# Copyright (c) 2009-2010 Aconex. All Rights Reserved. +# Copyright (c) 1997-2002 Silicon Graphics, Inc. All Rights Reserved. +# + +TOPDIR = ../../.. +include $(TOPDIR)/src/include/builddefs + +STDPMID = $(TOPDIR)/src/pmns/stdpmid +TESTDIR = $(PCP_VAR_DIR)/testsuite/pmdas/broken + +CFILES = broken_pmda.c +CFILES_TARGETS = $(CFILES) + +TARGETS = $(subst broken_pmda,,$(basename $(CFILES_TARGETS))) \ + broken_pmda_2_0 broken_pmda_2_1 broken_pmda_2_2 \ + broken_pmda_2_3 broken_pmda_2_4 broken_pmda_2_5 + +LLDFLAGS = $(PCP_LIBS) +LLDLIBS = $(PCPLIB) + +# all archives, except the ones checked into the source tree, +# then add executables beyond $(TARGETS) +# +LDIRT = *.log help.pag help.dir $(subst .c,.o,$(CFILES)) \ + broken_pmda_*.c real_broken_pmns broken_v?.dir broken_v?.pag \ + $(TARGETS) + +default default_pcp setup: $(CFILES_TARGETS) $(TARGETS) + +MYFILES = broken_help broken_pmns domain.h +MYSCRIPTS = broken_Install broken_Remove +LSRCFILES += $(MYFILES) $(MYSCRIPTS) GNUmakefile.install + +include $(BUILDRULES) + +$(TARGETS): + +install install_pcp: + $(INSTALL) -m 755 -d $(TESTDIR) + $(INSTALL) -m 644 $(CFILES) $(MYFILES) $(TESTDIR) + $(INSTALL) -m 755 $(MYSCRIPTS) $(TARGETS) $(TESTDIR) + $(INSTALL) -m 644 GNUmakefile.install $(TESTDIR)/GNUmakefile + +real_broken_pmns: domain.h broken_pmns + cat domain.h >real_broken_pmns + echo >>real_broken_pmns + echo 'root {' >>real_broken_pmns + echo ' broken' >>real_broken_pmns + echo '}' >>real_broken_pmns + echo >>real_broken_pmns + cat broken_pmns >>real_broken_pmns + +broken_pmda_2_0: broken_pmda.c domain.h + rm -f $@ $@.c + ln -s broken_pmda.c $@.c + $(CCF) $(CDEFS) -DVERSION_2 -o $@ $@.c -lpcp_pmda $(LDLIBS) $(LDFLAGS) + +broken_pmda_2_1: broken_pmda.c domain.h + rm -f $@ $@.c + ln -s broken_pmda.c $@.c + $(CCF) $(CDEFS) -DVERSION_2 -DBUG_1 -o $@ $@.c -lpcp_pmda $(LDLIBS) $(LDFLAGS) + +broken_pmda_2_2: broken_pmda.c domain.h + rm -f $@ $@.c + ln -s broken_pmda.c $@.c + $(CCF) $(CDEFS) -DVERSION_2 -DBUG_2 -o $@ $@.c -lpcp_pmda $(LDLIBS) $(LDFLAGS) + +broken_pmda_2_3: broken_pmda.c domain.h + rm -f $@ $@.c + ln -s broken_pmda.c $@.c + $(CCF) $(CDEFS) -DVERSION_2 -DBUG_3 -o $@ $@.c -lpcp_pmda $(LDLIBS) $(LDFLAGS) + +broken_pmda_2_4: broken_pmda.c domain.h + rm -f $@ $@.c + ln -s broken_pmda.c $@.c + $(CCF) $(CDEFS) -DVERSION_2 -DBUG_4 -o $@ $@.c -lpcp_pmda $(LDLIBS) $(LDFLAGS) + +broken_pmda_2_5: broken_pmda.c domain.h + rm -f $@ $@.c + ln -s broken_pmda.c $@.c + $(CCF) $(CDEFS) -DVERSION_2 -DBUG_5 -o $@ $@.c -lpcp_pmda $(LDLIBS) $(LDFLAGS) diff --git a/qa/pmdas/broken/GNUmakefile.install b/qa/pmdas/broken/GNUmakefile.install new file mode 100644 index 0000000..44f7722 --- /dev/null +++ b/qa/pmdas/broken/GNUmakefile.install @@ -0,0 +1,97 @@ +#!gmake +# +# Copyright (c) 2009-2010 Aconex. All Rights Reserved. +# Copyright (c) 1997-2002 Silicon Graphics, Inc. All Rights Reserved. +# + +ifdef PCP_CONF +include $(PCP_CONF) +else +include $(PCP_DIR)/etc/pcp.conf +endif +PATH = $(shell . $(PCP_DIR)/etc/pcp.env; echo $$PATH) +include $(PCP_INC_DIR)/builddefs + +STDPMID = $(PCP_VAR_DIR)/pmns/stdpmid + +# remove -Lpath and -Ipath options from builddefs CFLAGS value +# +PCP_LIBS = +TMP := $(CFLAGS:-I%=) +ifdef PCP_DIR +# put -Ipath and -Lpath back but use paths for run-time environment +# +CFLAGS = $(TMP) -I$(PCP_INC_DIR)/.. -L$(PCP_LIB_DIR) +else +CFLAGS = $(TMP) +endif +CFILES = broken_pmda.c +CFILES_TARGETS = $(CFILES) + +TARGETS = $(subst broken_pmda,,$(basename $(CFILES_TARGETS))) \ + broken_pmda_2_0 broken_v2.dir broken_pmda_2_1 broken_pmda_2_2 \ + broken_pmda_2_3 broken_pmda_2_4 broken_pmda_2_5 + +LLDLIBS = -lpcp $(LIB_FOR_MATH) $(LIB_FOR_DLOPEN) $(LIB_FOR_PTHREADS) + + +# all archives, except the ones checked into the source tree, +# then add executables beyond $(TARGETS) +# +LDIRT = *.log help.pag help.dir $(subst .c,.o,$(CFILES)) \ + broken_pmda_*.c real_broken_pmns broken_v?.dir broken_v?.pag \ + $(TARGETS) + +default default_pcp setup: $(CFILES_TARGETS) $(TARGETS) + +MYFILES = broken_help broken_pmns +MYSCRIPTS = broken_Install broken_Remove + +include $(PCP_INC_DIR)/buildrules + +$(TARGETS): + +install install_pcp: + +broken_v2.dir: broken_help real_broken_pmns + rm -f broken_v2.pag broken_v2.dir + newhelp -n real_broken_pmns -v 2 -o broken_v2 broken_help + +real_broken_pmns: domain.h broken_pmns + cat domain.h >real_broken_pmns + echo >>real_broken_pmns + echo 'root {' >>real_broken_pmns + echo ' broken' >>real_broken_pmns + echo '}' >>real_broken_pmns + echo >>real_broken_pmns + cat broken_pmns >>real_broken_pmns + +broken_pmda_2_0: broken_pmda.c domain.h + rm -f $@ $@.c + ln -s broken_pmda.c $@.c + $(CCF) $(CDEFS) -DVERSION_2 -o $@ $@.c -lpcp_pmda $(LDLIBS) + +broken_pmda_2_1: broken_pmda.c domain.h + rm -f $@ $@.c + ln -s broken_pmda.c $@.c + $(CCF) $(CDEFS) -DVERSION_2 -DBUG_1 -o $@ $@.c -lpcp_pmda $(LDLIBS) + +broken_pmda_2_2: broken_pmda.c domain.h + rm -f $@ $@.c + ln -s broken_pmda.c $@.c + $(CCF) $(CDEFS) -DVERSION_2 -DBUG_2 -o $@ $@.c -lpcp_pmda $(LDLIBS) + +broken_pmda_2_3: broken_pmda.c domain.h + rm -f $@ $@.c + ln -s broken_pmda.c $@.c + $(CCF) $(CDEFS) -DVERSION_2 -DBUG_3 -o $@ $@.c -lpcp_pmda $(LDLIBS) + +broken_pmda_2_4: broken_pmda.c domain.h + rm -f $@ $@.c + ln -s broken_pmda.c $@.c + $(CCF) $(CDEFS) -DVERSION_2 -DBUG_4 -o $@ $@.c -lpcp_pmda $(LDLIBS) + +broken_pmda_2_5: broken_pmda.c domain.h + rm -f $@ $@.c + ln -s broken_pmda.c $@.c + $(CCF) $(CDEFS) -DVERSION_2 -DBUG_5 -o $@ $@.c -lpcp_pmda $(LDLIBS) diff --git a/qa/pmdas/broken/broken_Install b/qa/pmdas/broken/broken_Install new file mode 100755 index 0000000..32fa109 --- /dev/null +++ b/qa/pmdas/broken/broken_Install @@ -0,0 +1,30 @@ +#!/bin/sh +# +# Copyright (c) 1997-2002 Silicon Graphics, Inc. All Rights Reserved. +# +# Install the broken PMDA and/or PMNS +# + +# source the PCP configuration environment variables +. $PCP_DIR/etc/pcp.env + +# Get the common procedures and variable assignments +# +. $PCP_SHARE_DIR/lib/pmdaproc.sh + +# The name of the PMDA +# +iam=broken + +# Do it +# +_setup + +dso_opt=false +daemon_opt=false +pmns_source=broken_pmns +help_source=broken_help + +_install + +exit 0 diff --git a/qa/pmdas/broken/broken_Remove b/qa/pmdas/broken/broken_Remove new file mode 100755 index 0000000..9d264ff --- /dev/null +++ b/qa/pmdas/broken/broken_Remove @@ -0,0 +1,24 @@ +#!/bin/sh +# +# Copyright (c) 1997-2002 Silicon Graphics, Inc. All Rights Reserved. +# +# Remove the broken PMDA +# + +# source the PCP configuration environment variables +. $PCP_DIR/etc/pcp.env + +# Get the common procedures and variable assignments +# +. $PCP_SHARE_DIR/lib/pmdaproc.sh + +# The name of the PMDA +# +iam=broken + +# Do it +# +_setup +_remove + +exit 0 diff --git a/qa/pmdas/broken/broken_help b/qa/pmdas/broken/broken_help new file mode 100644 index 0000000..684c4c0 --- /dev/null +++ b/qa/pmdas/broken/broken_help @@ -0,0 +1,39 @@ +# +# broken help file +# help is provided for all metrics except broken.bad.help +# + +@ broken.valid.one calls to fetch callback +The number of calls to the PMDA-supplied fetch callback function. + +@ broken.valid.two has instance domain +Valid metric with an instance domain. + +@ broken.valid.three has another instance domain +Valid instance domain with non-sequential serial number. + +@ broken.bad.type illegal data type +Data type in pmDesc is set to PM_TYPE_NOSUPPORT. + +@ broken.bad.semantics semantics too high +Metric semantics set to -1. + +@ broken.bad.scale scale too high +Scale of metrics beyond defined range. + +@ broken.bad.indom undefined indom +The indom is set beyond the bounds of the indom table. + +@ broken.no.fetch no fetch method implemented +The fetch callback does not handle this metric. + +@ broken.no.shorthelp +There is no short help for the metric + +@ broken.no.longhelp no long help + +@ broken.no.instfetch missing fetch for one instance +One instance is not supported by fetch callback + +@ broken.no.instances empty inst list +The inst list is empty diff --git a/qa/pmdas/broken/broken_pmda.c b/qa/pmdas/broken/broken_pmda.c new file mode 100644 index 0000000..c6c3e43 --- /dev/null +++ b/qa/pmdas/broken/broken_pmda.c @@ -0,0 +1,387 @@ +/* + * Broken, a PMDA which is broken in several ways + * + * Copyright (c) 1995-2001 Silicon Graphics, Inc. All Rights Reserved. + */ + +#include <stdio.h> +#include <time.h> +#include <pcp/pmapi.h> +#include <pcp/impl.h> +#include <pcp/pmda.h> +#include "domain.h" + +/* + * Broken PMDA + * + * This PMDA is broken in several ways. This is used to test libpcp_pmda + * error recovery and messages to the user. Not all the metrics are invalid, + * and the metric id's are intentionally sparse to force non-direct mapping. + * + * The macro BUG_? can be used to turn certain bad things on which may + * be fatal. + * + * BUG Metrics + * * broken.valid.one - returns num calls to fetch callback + * * broken.valid.two - has instance domain, fixed values + * * broken.bad.type - illegal data type + * * broken.valid.three - normal, fixed value + * * broken.no.fetch - no fetch method implemented for this metric + * * broken.no.help - no help text for this metric + * * broken.no.shorthelp - no short help on metric + * * broken.no.longhelp - no long help on metric + * * broken.bad.semantics - illegal semantics + * * broken.bad.scale - illegal scale + * * broken.no.pmns - not defined in pmns + * * broken.no.instfetch - one instance not handled by fetch + * * broken.no.instances - instance domain with no instances + * + * 1 broken.bad.indom - metric with undefined instance + * 2 - no instance domain supplied + * 3 - no metrics supplied + * 4 - bad help file path + * + * The macro VERSION_? can be used to force this to be a PCP 1.X or 2.0 PMDA + * + * 1 - use pcp1.X headers and link with compat libs + * 2 - use pcp2.o headers and latest libs + */ + +/* + * list of instances + */ + +#ifndef BUG_2 +static pmdaInstid _indom0[] = { + { 0, "a" }, { 1, "b" }, { 2, "c" } +}; +#endif + +static pmdaInstid _indom1[] = { + { 50, "x" }, { 10, "y" }, { 9, "z" } +}; + +/* + * list of instace domains + */ + +static pmdaIndom indomtab[] = { +#define INDOM_0 0 +#ifndef BUG_2 + { INDOM_0, 3, _indom0 }, +#endif +#define INDOM_1 7 + { INDOM_1, 3, _indom1 }, +#define INDOM_2 8 + { INDOM_2, 0, (pmdaInstid *)0 } +}; + + + +#ifndef BUG_3 + +/* + * all metrics supported in this PMDA - one table entry for each + */ + +static pmdaMetric metrictab[] = { +/* valid.one */ + { (void *)0, + { PMDA_PMID(0,0), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* valid.two */ + { (void *)0, + { PMDA_PMID(0,1), PM_TYPE_U32, INDOM_0, PM_SEM_INSTANT, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* bad.type */ + { (void *)0, + { PMDA_PMID(0,5), PM_TYPE_NOSUPPORT, PM_INDOM_NULL, PM_SEM_COUNTER, + { 0, 0, 0, 0, 0, 0 } }, }, +/* valid.three */ + { (void *)0, + { PMDA_PMID(0,7), PM_TYPE_U32, INDOM_1, PM_SEM_INSTANT, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* no.fetch */ + { (void *)0, + { PMDA_PMID(0,9), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* no.help */ + { (void *)0, + { PMDA_PMID(0,10), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* no.shorthelp */ + { (void *)0, + { PMDA_PMID(0,11), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* no.longhelp */ + { (void *)0, + { PMDA_PMID(0,12), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* no.isntfetch */ + { (void *)0, + { PMDA_PMID(0,13), PM_TYPE_U32, INDOM_1, PM_SEM_INSTANT, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* bad.semantics */ + { (void *)0, + { PMDA_PMID(1,1), PM_TYPE_U32, PM_INDOM_NULL, -1, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* bad.scale */ + { (void *)0, + { PMDA_PMID(1,2), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER, + { 1, 0, 0, 10, 0, 0 } }, }, +/* no.pmns */ + { (void *)0, + { PMDA_PMID(1,3), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER, + { 1, 0, 0, 10, 0, 0 } }, }, +#ifdef BUG_1 +/* bad.indom */ + { (void *)0, + { PMDA_PMID(1,4), PM_TYPE_U32, 17, PM_SEM_COUNTER, + { 1, 0, 0, 10, 0, 0 } }, }, +#endif +/* no.instances */ + { (void *)0, + { PMDA_PMID(0,14), PM_TYPE_U32, INDOM_2, PM_SEM_COUNTER, + { 1, 0, 0, 10, 0, 0 } }, }, +}; + +#endif + +static int _isDSO = 1; /* =0 I am a daemon */ +static char *_logFile = "broken.log"; +#if defined(VERSION_1) +static char *_helpText = "pmdas/broken/broken_v1"; +#else +static char *_helpText = "pmdas/broken/broken_v2"; +#endif + +/* + * callback provided to pmdaFetch + */ + +static int +broken_fetchCallBack(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom) +{ + static int count = 0; + __pmID_int *idp = (__pmID_int *)&(mdesc->m_desc.pmid); + + switch (idp->cluster) { + case 0: + switch (idp->item) { + case 0: + atom->l = ++count; + break; + case 1: + switch (inst) { + case 0: + atom->l = 1; + break; + case 1: + atom->l = 2; + break; + case 2: + atom->l = 3; + break; + default: + return PM_ERR_INST; + } + break; + /* broken.bogus.one: metric not defined in table but is in pmns */ + case 2: + fprintf(stderr, + "%s: Fetching metric 0.2 which does not exist\n", + pmProgname); + atom->l = 42; + break; + /* metric not defined in table or pmns */ + case 3: + fprintf(stderr, + "%s: Fetching metric 0.3 which does not exist\n", + pmProgname); + atom->l = -1; + break; + case 5: + atom->d = 3.14; + break; + case 7: + switch (inst) { + case 50: + atom->l = 44; + break; + case 10: + atom->l = 45; + break; + case 9: + atom->l = 46; + break; + default: + return PM_ERR_INST; + } + break; + case 10: + atom->l = 55; + break; + case 11: + atom->l = 66; + break; + case 12: + atom->l = 77; + break; + case 13: + switch (inst) { + case 50: + atom->l = 44; + break; + case 9: + atom->l = 46; + break; + default: + return PM_ERR_INST; + } + break; + case 14: + fprintf(stderr, "PMID %s requested with inst = %d\n", + pmIDStr(mdesc->m_desc.pmid), inst); + return PM_ERR_VALUE; + default: + return PM_ERR_PMID; + } + break; + case 1: + switch (idp->item) { + case 1: + atom->l = 333; + break; + case 2: + atom->l = 12345; + break; + case 3: + atom->l = 4321; + break; +#ifdef BUG_4 + case 4: + fprintf(stderr, "Eeek! Should not be trying to get PMID %s\n", + pmIDStr(mdesc->m_desc.pmid)); + break; +#endif + default: + return PM_ERR_PMID; + } + break; + default: + return PM_ERR_PMID; + } + + return 0; +} + +/* + * Initialise the agent (both daemon and DSO). + */ + +void +broken_init(pmdaInterface *dp) +{ +#if defined(BUG_5) + if (_isDSO) + /* + * we don't grok PMDA_INTERFACE_77 ... 77 is arbitrary, just needs + * to be bigger than currently validand supported + */ +#if defined(VERSION_1) + pmdaDSO(dp, 77, "broken DSO", BROKEN, _helpText); +#else + pmdaDSO(dp, 77, "broken DSO", _helpText); +#endif +#elif defined(VERSION_1) + if (_isDSO) + pmdaDSO(dp, PMDA_PROTOCOL_2, "broken DSO", BROKEN, _helpText); +#else + if (_isDSO) + pmdaDSO(dp, PMDA_INTERFACE_2, "broken DSO", _helpText); +#endif + + if (dp->status != 0) + return; + + pmdaSetFetchCallBack(dp, broken_fetchCallBack); + +#if defined(BUG_2) + pmdaInit(dp, indomtab, sizeof(indomtab)/sizeof(indomtab[0]), + metrictab, sizeof(metrictab)/sizeof(metrictab[0])); +#elif defined(BUG_3) + pmdaInit(dp, indomtab, sizeof(indomtab)/sizeof(indomtab[0]), + (pmdaMetric *)0, -1); +#elif defined(BUG_4) + pmdaInit(dp, indomtab, sizeof(indomtab)/sizeof(indomtab[0]), + metrictab, sizeof(metrictab)/sizeof(metrictab[0])); +#else + pmdaInit(dp, indomtab, sizeof(indomtab)/sizeof(indomtab[0]), + metrictab, sizeof(metrictab)/sizeof(metrictab[0])); +#endif +} + +static void +usage(void) +{ + fprintf(stderr, "Usage: %s [options]\n\n", pmProgname); + fputs("Options:\n" + " -d N set pmDebug debugging flag to N\n" + " -D domain use domain (numeric) for metrics domain of PMDA\n" + " -h helpfile get help text from helpfile rather then default path\n" + " -l logfile write log into logfile rather than using default log name\n" + "\nExactly one of the following options may appear:\n" + " -i port expect PMCD to connect on given inet port (number or name)\n" + " -p expect PMCD to supply stdin/stdout (pipe)\n" + " -u socket expect PMCD to connect on given unix domain socket\n" + " -6 port expect PMCD to connect on given ipv6 port (number or name)\n", + stderr); + exit(1); +} + +/* + * Set up the agent if running as a daemon. + */ + +int +main(int argc, char **argv) +{ + int err = 0; + pmdaInterface desc; + + __pmSetProgname(argv[0]); + _isDSO = 0; + +#if defined(BUG_5) + /* + * we don't grok PMDA_INTERFACE_77 ... 77 is arbitrary, just needs + * to be bigger than currently valid and supported + */ + pmdaDaemon(&desc, 77, pmProgname, BROKEN, _logFile, + _helpText); +#elif defined(VERSION_1) + pmdaDaemon(&desc, PMDA_PROTOCOL_2, pmProgname, BROKEN, _logFile, + _helpText); +#else + pmdaDaemon(&desc, PMDA_INTERFACE_2, pmProgname, BROKEN, _logFile, + _helpText); +#endif + + if (desc.status != 0) { + fprintf(stderr, "pmdaDaemon() failed!\n"); + exit(1); + } + + if (pmdaGetOpt(argc, argv, "D:d:h:i:l:pu:6:", &desc, &err) != EOF) + err++; + + if (err) + usage(); + + pmdaOpenLog(&desc); + broken_init(&desc); + pmdaConnect(&desc); + pmdaMain(&desc); + + exit(0); +} diff --git a/qa/pmdas/broken/broken_pmda.v1.c b/qa/pmdas/broken/broken_pmda.v1.c new file mode 100644 index 0000000..00cda3e --- /dev/null +++ b/qa/pmdas/broken/broken_pmda.v1.c @@ -0,0 +1,386 @@ +/* + * Broken, a PMDA which is broken in several ways + * + * Copyright (c) 1995-2002 Silicon Graphics, Inc. All Rights Reserved. + */ + +#include <stdio.h> +#include <time.h> +#include <pcp/pmapi.h> +#include <pcp/impl.h> +#include <pcp/pmda.h> +#include "domain.h" + +/* + * Broken PMDA + * + * This PMDA is broken in several ways. This is used to test libpcp_pmda + * error recovery and messages to the user. Not all the metrics are invalid, + * and the metric id's are intentionally sparse to force non-direct mapping. + * + * The macro BUG_? can be used to turn certain bad things on which may + * be fatal. + * + * BUG Metrics + * * broken.valid.one - returns num calls to fetch callback + * * broken.valid.two - has instance domain, fixed values + * * broken.bad.type - illegal data type + * * broken.valid.three - normal, fixed value + * * broken.no.fetch - no fetch method implemented for this metric + * * broken.no.help - no help text for this metric + * * broken.no.shorthelp - no short help on metric + * * broken.no.longhelp - no long help on metric + * * broken.bad.semantics - illegal semantics + * * broken.bad.scale - illegal scale + * * broken.no.pmns - not defined in pmns + * * broken.no.instfetch - one instance not handled by fetch + * * broken.no.instances - instance domain with no instances + * + * 1 broken.bad.indom - metric with undefined instance + * 2 - no instance domain supplied + * 3 - no metrics supplied + * 4 - bad help file path + * + * The macro VERSION_? can be used to force this to be a PCP 1.X or 2.0 PMDA + * + * 1 - use pcp1.X headers and link with compat libs + * 2 - use pcp2.o headers and latest libs + */ + +#ifndef BUG_2 + +/* + * list of instances + */ + +static pmdaInstid _indom0[] = { + { 0, "a" }, { 1, "b" }, { 2, "c" } +}; + +static pmdaInstid _indom1[] = { + { 50, "x" }, { 10, "y" }, { 9, "z" } +}; + +/* + * list of instace domains + */ + +static pmdaIndom indomtab[] = { +#define INDOM_0 0 + { INDOM_0, 3, _indom0 }, +#define INDOM_1 7 + { INDOM_1, 3, _indom1 }, +#define INDOM_2 8 + { INDOM_2, 0, (pmdaInstid *)0 } +}; + +#else + +#define INDOM_0 0 +#define INDOM_1 7 +#define INDOM_2 8 + +#endif + + +#ifndef BUG_3 + +/* + * all metrics supported in this PMDA - one table entry for each + */ + +static pmdaMetric metrictab[] = { +/* valid.one */ + { (void *)0, + { PMDA_PMID(0,0), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* valid.two */ + { (void *)0, + { PMDA_PMID(0,1), PM_TYPE_U32, INDOM_0, PM_SEM_INSTANT, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* bad.type */ + { (void *)0, + { PMDA_PMID(0,5), PM_TYPE_NOSUPPORT, PM_INDOM_NULL, PM_SEM_COUNTER, + { 0, 0, 0, 0, 0, 0 } }, }, +/* valid.three */ + { (void *)0, + { PMDA_PMID(0,7), PM_TYPE_U32, INDOM_1, PM_SEM_INSTANT, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* no.fetch */ + { (void *)0, + { PMDA_PMID(0,9), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* no.help */ + { (void *)0, + { PMDA_PMID(0,10), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* no.shorthelp */ + { (void *)0, + { PMDA_PMID(0,11), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* no.longhelp */ + { (void *)0, + { PMDA_PMID(0,12), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* no.isntfetch */ + { (void *)0, + { PMDA_PMID(0,13), PM_TYPE_U32, INDOM_1, PM_SEM_INSTANT, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* bad.semantics */ + { (void *)0, + { PMDA_PMID(1,1), PM_TYPE_U32, PM_INDOM_NULL, -1, + { 0, 1, 0, 0, PM_TIME_SEC, 0 } }, }, +/* bad.scale */ + { (void *)0, + { PMDA_PMID(1,2), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER, + { 1, 0, 0, 10, 0, 0 } }, }, +/* no.pmns */ + { (void *)0, + { PMDA_PMID(1,3), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER, + { 1, 0, 0, 10, 0, 0 } }, }, +#ifdef BUG_1 +/* bad.indom */ + { (void *)0, + { PMDA_PMID(1,4), PM_TYPE_U32, 17, PM_SEM_COUNTER, + { 1, 0, 0, 10, 0, 0 } }, }, +#endif +/* no.instances */ + { (void *)0, + { PMDA_PMID(0,14), PM_TYPE_U32, INDOM_2, PM_SEM_COUNTER, + { 1, 0, 0, 10, 0, 0 } }, }, +}; + +#endif + +static int _isDSO = 1; /* =0 I am a daemon */ +static char *_logFile = "broken.log"; +#if defined(VERSION_1) +static char *_helpText = "pmdas/broken/broken_v1"; +#else +static char *_helpText = "pmdas/broken/broken_v2"; +#endif + +/* + * callback provided to pmdaFetch + */ + +static int +broken_fetchCallBack(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom) +{ + static int count = 0; + _pmID_int *idp = (_pmID_int *)&(mdesc->m_desc.pmid); + + switch (idp->cluster) { + case 0: + switch (idp->item) { + case 0: + atom->l = ++count; + break; + case 1: + switch (inst) { + case 0: + atom->l = 1; + break; + case 1: + atom->l = 2; + break; + case 2: + atom->l = 3; + break; + default: + return PM_ERR_INST; + } + break; + /* broken.bogus.one: metric not defined in table but is in pmns */ + case 2: + fprintf(stderr, + "%s: Fetching metric 0.2 which does not exist\n", + pmProgname); + atom->l = 42; + break; + /* metric not defined in table or pmns */ + case 3: + fprintf(stderr, + "%s: Fetching metric 0.3 which does not exist\n", + pmProgname); + atom->l = -1; + break; + case 5: + atom->d = 3.14; + break; + case 7: + switch (inst) { + case 50: + atom->l = 44; + break; + case 10: + atom->l = 45; + break; + case 9: + atom->l = 46; + break; + default: + return PM_ERR_INST; + } + break; + case 10: + atom->l = 55; + break; + case 11: + atom->l = 66; + break; + case 12: + atom->l = 77; + break; + case 13: + switch (inst) { + case 50: + atom->l = 44; + break; + case 9: + atom->l = 46; + break; + default: + return PM_ERR_INST; + } + break; + case 14: + fprintf(stderr, "PMID %s requested with inst = %d\n", + pmIDStr(mdesc->m_desc.pmid), inst); + return PM_ERR_VALUE; + default: + return PM_ERR_PMID; + } + break; + case 1: + switch (idp->item) { + case 1: + atom->l = 333; + break; + case 2: + atom->l = 12345; + break; + case 3: + atom->l = 4321; + break; +#ifdef BUG_4 + case 4: + fprintf(stderr, "Eeek! Should not be trying to get PMID %s\n", + pmIDStr(mdesc->m_desc.pmid)); + break; +#endif + default: + return PM_ERR_PMID; + } + break; + default: + return PM_ERR_PMID; + } + + return 0; +} + +/* + * Initialise the agent (both daemon and DSO). + */ + +void +broken_init(pmdaInterface *dp) +{ +#if defined(BUG_5) + if (_isDSO) + /* we don't grok PMDA_INTERFACE_4 ... */ +#if defined(VERSION_1) + pmdaDSO(dp, 4, "broken DSO", BROKEN, _helpText); +#else + pmdaDSO(dp, 4, "broken DSO", _helpText); +#endif +#elif defined(VERSION_1) + if (_isDSO) + pmdaDSO(dp, PMDA_PROTOCOL_2, "broken DSO", BROKEN, _helpText); +#else + if (_isDSO) + pmdaDSO(dp, PMDA_INTERFACE_2, "broken DSO", _helpText); +#endif + + if (dp->status != 0) + return; + + pmdaSetFetchCallBack(dp, broken_fetchCallBack); + +#if defined(BUG_2) + pmdaInit(dp, (pmdaIndom *)0, 0, metrictab, + sizeof(metrictab)/sizeof(metrictab[0])); +#elif defined(BUG_3) + pmdaInit(dp, indomtab, sizeof(indomtab)/sizeof(indomtab[0]), + (pmdaMetric *)0, -1); +#elif defined(BUG_4) + pmdaInit(dp, indomtab, sizeof(indomtab)/sizeof(indomtab[0]), + metrictab, sizeof(metrictab)/sizeof(metrictab[0])); +#else + pmdaInit(dp, indomtab, sizeof(indomtab)/sizeof(indomtab[0]), + metrictab, sizeof(metrictab)/sizeof(metrictab[0])); +#endif +} + +static void +usage(void) +{ + fprintf(stderr, "Usage: %s [options]\n\n", pmProgname); + fputs("Options:\n" + " -d N set pmDebug debugging flag to N\n" + " -D domain use domain (numeric) for metrics domain of PMDA\n" + " -h helpfile get help text from helpfile rather then default path\n" + " -l logfile write log into logfile rather than using default log name\n" + "\nExactly one of the following options may appear:\n" + " -i port expect PMCD to connect on given inet port (number or name)\n" + " -p expect PMCD to supply stdin/stdout (pipe)\n" + " -u socket expect PMCD to connect on given unix domain socket\n" + " -6 port expect PMCD to connect on given ipv6 port (number or name)\n", + stderr); + exit(1); +} + +/* + * Set up the agent if running as a daemon. + */ + +int +main(int argc, char **argv) +{ + int err = 0; + pmdaInterface desc; + + __pmSetProgname(argv[0]); + _isDSO = 0; + +#if defined(BUG_5) + /* we don't grok PMDA_INTERFACE_4 ... */ + pmdaDaemon(&desc, 4, pmProgname, BROKEN, _logFile, + _helpText); +#elif defined(VERSION_1) + pmdaDaemon(&desc, PMDA_PROTOCOL_2, pmProgname, BROKEN, _logFile, + _helpText); +#else + pmdaDaemon(&desc, PMDA_INTERFACE_2, pmProgname, BROKEN, _logFile, + _helpText); +#endif + + if (desc.status != 0) { + fprintf(stderr, "pmdaDaemon() failed!\n"); + exit(1); + } + + if (pmdaGetOpt(argc, argv, "D:d:h:i:l:pu:6:", &desc, &err) != EOF) + err++; + + if (err) + usage(); + + pmdaOpenLog(&desc); + broken_init(&desc); + pmdaConnect(&desc); + pmdaMain(&desc); + + exit(0); +} diff --git a/qa/pmdas/broken/broken_pmns b/qa/pmdas/broken/broken_pmns new file mode 100644 index 0000000..926ab3f --- /dev/null +++ b/qa/pmdas/broken/broken_pmns @@ -0,0 +1,36 @@ +/* + * Metrics for a broken PMDA + */ + +broken { + valid + bad + no + bogus +} + +broken.valid { + one BROKEN:0:0 + two BROKEN:0:1 + three BROKEN:0:7 +} + +broken.bad { + type BROKEN:0:5 + semantics BROKEN:1:1 + scale BROKEN:1:2 + indom BROKEN:1:4 +} + +broken.no { + fetch BROKEN:0:9 + help BROKEN:0:10 + shorthelp BROKEN:0:11 + longhelp BROKEN:0:12 + instfetch BROKEN:0:13 + instances BROKEN:0:14 +} + +broken.bogus { + one BROKEN:0:2 +} diff --git a/qa/pmdas/broken/domain.h b/qa/pmdas/broken/domain.h new file mode 100644 index 0000000..3de61ee --- /dev/null +++ b/qa/pmdas/broken/domain.h @@ -0,0 +1 @@ +#define BROKEN 249 |