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/qt | |
download | pcp-debian.tar.gz |
Debian 3.9.10debian/3.9.10debian
Diffstat (limited to 'qa/qt')
43 files changed, 2987 insertions, 0 deletions
diff --git a/qa/qt/GNUmakefile b/qa/qt/GNUmakefile new file mode 100644 index 0000000..151ed77 --- /dev/null +++ b/qa/qt/GNUmakefile @@ -0,0 +1,22 @@ +# +# Copyright (c) 2014 Red Hat. +# + +TOPDIR = ../.. +include $(TOPDIR)/src/include/builddefs + +TESTDIR = $(PCP_VAR_DIR)/testsuite/qt +SUBDIRS = qmc_context qmc_desc qmc_dynamic qmc_event qmc_format \ + qmc_group qmc_hosts qmc_indom qmc_metric qmc_source +LSRCFILES = GNUmakefile.install setup-executables + +default setup default_pcp: $(SUBDIRS) + $(SUBDIRS_MAKERULE) + +install install_pcp: $(SUBDIRS) + $(INSTALL) -m 755 -d $(TESTDIR) + $(INSTALL) -m 644 GNUmakefile.install $(TESTDIR)/GNUmakefile + $(INSTALL) -m 755 setup-executables $(TESTDIR)/setup-executables + $(SUBDIRS_MAKERULE) + +include $(BUILDRULES) diff --git a/qa/qt/GNUmakefile.install b/qa/qt/GNUmakefile.install new file mode 100644 index 0000000..42bf49a --- /dev/null +++ b/qa/qt/GNUmakefile.install @@ -0,0 +1,41 @@ +#!gmake +# +# Copyright (c) 2012 Red Hat. +# Copyright (c) 2010 Aconex. 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 + +# special variant of SUBDIRS_MAKERULE for running QA in the tree +# +SUBDIRS_MAKERULE = \ + @for d in `echo $^ `; do \ + if test -d "$$d" ; then \ + $(ECHO) === $$d ===; \ + if test -f "$$d/GNUmakefile.install"; then \ + $(MAKE) -C $$d -f GNUmakefile.install $@ || exit $$?; \ + else \ + $(MAKE) -C $$d $@ || exit $$?; \ + fi; \ + fi; \ + done + +SUBDIRS = qmc_context qmc_desc qmc_dynamic qmc_event qmc_format \ + qmc_group qmc_hosts qmc_indom qmc_metric qmc_source + +default default_pcp: $(SUBDIRS) + $(SUBDIRS_MAKERULE) + +setup: $(SUBDIRS) + $(SUBDIRS_MAKERULE) + +install install_pcp: $(SUBDIRS) + $(SUBDIRS_MAKERULE) + +include $(BUILDRULES) diff --git a/qa/qt/qmc_context/GNUmakefile b/qa/qt/qmc_context/GNUmakefile new file mode 100644 index 0000000..ee55cb0 --- /dev/null +++ b/qa/qt/qmc_context/GNUmakefile @@ -0,0 +1,27 @@ +TOPDIR = ../../.. +include $(TOPDIR)/src/include/builddefs + +COMMAND = qmc_context +PROJECT = $(COMMAND).pro +SOURCES = $(COMMAND).cpp +TESTDIR = $(PCP_VAR_DIR)/testsuite/qt/$(COMMAND) + +LSRCFILES = $(PROJECT) $(SOURCES) +LDIRDIRT = build $(COMMAND).xcodeproj +LDIRT = $(COMMAND) *.o Makefile + +default default_pcp: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +install install_pcp: default + $(INSTALL) -m 755 -d $(TESTDIR) + $(INSTALL) -m 644 GNUmakefile.install $(TESTDIR)/GNUmakefile + $(INSTALL) -m 644 $(PROJECT) $(SOURCES) $(TESTDIR) +ifeq "$(ENABLE_QT)" "true" + $(INSTALL) -m 755 $(BINARY) $(TESTDIR)/$(COMMAND) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_context/GNUmakefile.install b/qa/qt/qmc_context/GNUmakefile.install new file mode 100644 index 0000000..d173e64 --- /dev/null +++ b/qa/qt/qmc_context/GNUmakefile.install @@ -0,0 +1,18 @@ +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 + +COMMAND = qmc_context +PROJECT = $(COMMAND).pro + +default setup install: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_context/qmc_context.cpp b/qa/qt/qmc_context/qmc_context.cpp new file mode 100644 index 0000000..d7b7909 --- /dev/null +++ b/qa/qt/qmc_context/qmc_context.cpp @@ -0,0 +1,241 @@ +// +// Test QmcContext class +// + +#include <QTextStream> +#include <qmc_context.h> + +QTextStream cerr(stderr); +QTextStream cout(stdout); + +int +main(int argc, char* argv[]) +{ + int fail = 0, sts = 0; + int c; + char buf[MAXHOSTNAMELEN]; + 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); + fail = 1; + } + else { + pmDebug |= sts; + } + break; + case '?': + default: + sts = 1; + break; + } + } + + if (fail) { + pmprintf("Usage: %s\n", pmProgname); + pmflush(); + exit(1); + } + + (void)gethostname(buf, MAXHOSTNAMELEN); + buf[MAXHOSTNAMELEN-1] = '\0'; + + fprintf(stderr, "*** Simple connection ***\n"); + source = QString("oview-short"); + + QmcSource *src1 = QmcSource::getSource(PM_CONTEXT_ARCHIVE, source, false); + if (src1->status() < 0) { + pmprintf("%s: Error: Unable to create context to \"%s\": %s\n", + pmProgname, (const char *)source.toAscii(), + pmErrStr(src1->status())); + pmflush(); + fail = 1; + } + + QmcContext context1(src1); + if (context1.handle() < 0) { + pmflush(); + fail = 1; + } + + context1.dump(cout); + + pmID pmid; + uint_t indomIndex; + + fprintf(stderr, "\n*** Cacheing of descriptors and indoms ***\n"); + QmcDesc *desc; + QmcIndom *indom = NULL; + + sts = context1.lookupInDom("hinv.ncpu", indomIndex); + if (sts < 0) { + pmprintf("%s: Error: hinv.ncpu: %s\n", + pmProgname, pmErrStr(sts)); + pmflush(); + fail = 1; + } + else { + sts = context1.lookupPMID("hinv.ncpu", pmid); + if (sts < 0) { + pmprintf("%s: Error: hinv.ncpu PMID: %s\n", + pmProgname, pmErrStr(sts)); + pmflush(); + fail = 1; + } + desc = &context1.desc(pmid); + if (desc->status() < 0) { + pmprintf("%s: Error: hinv.ncpu descriptor: %s\n", + pmProgname, pmErrStr(desc->status())); + pmflush(); + fail = 1; + } + else if (indomIndex < UINT_MAX) { + pmprintf("%s: Error: hinv.ncpu indom is not NULL\n", + pmProgname); + pmflush(); + fail = 1; + } + } + + sts = context1.lookupInDom("hinv.cputype", indomIndex); + if (sts < 0) { + pmprintf("%s: Error: hinv.cputype: %s\n", + pmProgname, pmErrStr(sts)); + pmflush(); + fail = 1; + } + else { + sts = context1.lookupPMID("hinv.cputype", pmid); + if (sts < 0) { + pmprintf("%s: Error: hinv.cputype PMID: %s\n", + pmProgname, pmErrStr(sts)); + pmflush(); + fail = 1; + } + desc = &context1.desc(pmid); + indom = &context1.indom(indomIndex); + if (desc->status() < 0) { + pmprintf("%s: Error: hinv.cputype descriptor: %s\n", + pmProgname, pmErrStr(desc->status())); + pmflush(); + fail = 1; + } + else if (indom->status() < 0) { + pmprintf("%s: Error: hinv.cputype indom: %s\n", + pmProgname, pmErrStr(indom->status())); + pmflush(); + fail = 1; + } + } + + QmcIndom *indom2; + + sts = context1.lookupInDom("hinv.map.cpu", indomIndex); + if (sts < 0) { + pmprintf("%s: Error: hinv.map.cpu: %s\n", + pmProgname, pmErrStr(sts)); + pmflush(); + fail = 1; + } + else { + sts = context1.lookupPMID("hinv.map.cpu", pmid); + if (sts < 0) { + pmprintf("%s: Error: hinv.map.cpu PMID: %s\n", + pmProgname, pmErrStr(sts)); + pmflush(); + fail = 1; + } + + desc = &context1.desc(pmid); + indom2 = &context1.indom(indomIndex); + + if (desc->status() < 0) { + pmprintf("%s: Error: hinv.map.cpu descriptor: %s\n", + pmProgname, pmErrStr(desc->status())); + pmflush(); + fail = 1; + } + else if (indom2->status() < 0) { + pmprintf("%s: Error: hinv.map.cpu indom: %s\n", + pmProgname, pmErrStr(indom2->status())); + pmflush(); + fail = 1; + } + else if (indom != indom2) { + pmprintf("%s: Error: hinv.cputype and hinv.map.cpu indoms are not the same\n", + pmProgname); + pmflush(); + fail = 1; + } + } + + sts = context1.lookupInDom("hinv.ncpu", indomIndex); + if (sts < 0) { + pmprintf("%s: Error: hinv.ncpu: %s\n", + pmProgname, pmErrStr(sts)); + pmflush(); + fail = 1; + } + else { + sts = context1.lookupPMID("hinv.ncpu", pmid); + if (sts < 0) { + pmprintf("%s: Error: hinv.ncpu PMID: %s\n", + pmProgname, pmErrStr(sts)); + pmflush(); + fail = 1; + } + + desc = &context1.desc(pmid); + + if (desc->status() < 0) { + pmprintf("%s: Error: hinv.ncpu descriptor: %s\n", + pmProgname, pmErrStr(desc->status())); + pmflush(); + fail = 1; + } + else if (indomIndex < UINT_MAX) { + pmprintf("%s: Error: hinv.ncpu indom is not NULL\n", + pmProgname); + pmflush(); + fail = 1; + } + } + + context1.dump(cout); + + fprintf(stderr, "\n*** Bad Context ***\n"); + source = QString("no-such-host"); + QmcSource *src2 = QmcSource::getSource(PM_CONTEXT_HOST, source); + + if (src2->status() >= 0) { + pmprintf("%s: Error: Able to create context to \"%s\": %s\n", + pmProgname, (const char *)source.toAscii(), + pmErrStr(src1->status())); + pmflush(); + fail = 1; + } + + QmcContext context2(src2); + + if (context2.handle() >= 0) { + pmprintf("%s: Error: Created a valid context to an invalid host\n", + pmProgname); + fail = 1; + } + + pmflush(); + + context2.dump(cout); + + fprintf(stderr, "\n*** Exiting ***\n"); + + pmflush(); + return fail; +} diff --git a/qa/qt/qmc_context/qmc_context.pro b/qa/qt/qmc_context/qmc_context.pro new file mode 100644 index 0000000..89d4d06 --- /dev/null +++ b/qa/qt/qmc_context/qmc_context.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +LANGUAGE = C++ +SOURCES = qmc_context.cpp +CONFIG += qt console warn_on +INCLUDEPATH += ../../../src/include +INCLUDEPATH += ../../../src/libpcp_qmc/src +release:DESTDIR = build/debug +debug:DESTDIR = build/release +LIBS += -L../../../src/libpcp/src +LIBS += -L../../../src/libpcp_qmc/src +LIBS += -L../../../src/libpcp_qmc/src/$$DESTDIR +LIBS += -lpcp_qmc -lpcp +QT -= gui diff --git a/qa/qt/qmc_desc/GNUmakefile b/qa/qt/qmc_desc/GNUmakefile new file mode 100644 index 0000000..f535da2 --- /dev/null +++ b/qa/qt/qmc_desc/GNUmakefile @@ -0,0 +1,27 @@ +TOPDIR = ../../.. +include $(TOPDIR)/src/include/builddefs + +COMMAND = qmc_desc +PROJECT = $(COMMAND).pro +SOURCES = $(COMMAND).cpp +TESTDIR = $(PCP_VAR_DIR)/testsuite/qt/$(COMMAND) + +LSRCFILES = $(PROJECT) $(SOURCES) +LDIRDIRT = build $(COMMAND).xcodeproj +LDIRT = $(COMMAND) *.o Makefile + +default default_pcp: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +install install_pcp: default + $(INSTALL) -m 755 -d $(TESTDIR) + $(INSTALL) -m 644 GNUmakefile.install $(TESTDIR)/GNUmakefile + $(INSTALL) -m 644 $(PROJECT) $(SOURCES) $(TESTDIR) +ifeq "$(ENABLE_QT)" "true" + $(INSTALL) -m 755 $(BINARY) $(TESTDIR)/$(COMMAND) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_desc/GNUmakefile.install b/qa/qt/qmc_desc/GNUmakefile.install new file mode 100644 index 0000000..42a3c92 --- /dev/null +++ b/qa/qt/qmc_desc/GNUmakefile.install @@ -0,0 +1,18 @@ +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 + +COMMAND = qmc_desc +PROJECT = $(COMMAND).pro + +default setup install: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_desc/qmc_desc.cpp b/qa/qt/qmc_desc/qmc_desc.cpp new file mode 100644 index 0000000..fcce0b4 --- /dev/null +++ b/qa/qt/qmc_desc/qmc_desc.cpp @@ -0,0 +1,102 @@ +// +// Test QmcDesc class +// + +#include <QTextStream> +#include <qmc_source.h> +#include <qmc_desc.h> + +QTextStream cerr(stderr); +QTextStream cout(stdout); + +int +main(int argc, char* argv[]) +{ + int sts = 0; + int c; + char buf[MAXHOSTNAMELEN]; + 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*/ + } + + (void)gethostname(buf, MAXHOSTNAMELEN); + buf[MAXHOSTNAMELEN-1] = '\0'; + source = buf; + + fprintf(stderr,"*** Compare metric descriptor with pminfo output ***\n"); + QmcSource *src = QmcSource::getSource(PM_CONTEXT_HOST, source, false); + + if (src->status() < 0) { + pmprintf("%s: Error: Unable to create context to \"%s\": %s\n", + pmProgname, buf, pmErrStr(src->status())); + pmflush(); + return 1; + } + + /* Linux hinv.ncpu PMID: 60.0.32 */ + pmID hinv_ncpu = pmid_build(60, 0, 32); + QmcDesc hinv_ncpu_pmc(hinv_ncpu); + pmDesc hinv_ncpu_desc = hinv_ncpu_pmc.desc(); + + if (hinv_ncpu_pmc.status() < 0) { + pmprintf("\n%s: Error: hinv.ncpu: %s\n", + pmProgname, pmErrStr(hinv_ncpu_pmc.status())); + pmflush(); + sts = 1; + } + + printf("hinv.ncpu\n"); + __pmPrintDesc(stdout, &hinv_ncpu_desc); + fflush(stdout); + fflush(stderr); + if (system("pminfo -d hinv.ncpu") < 0) { + pmprintf("%s: Error: Unable to run pminfo\n", pmProgname); + pmflush(); + sts = 1; + } + fflush(stdout); + fflush(stderr); + + fprintf(stderr, "\n*** Fetch a bad descriptor ***\n"); + pmID bad = pmid_build(42,42,42); + QmcDesc bad_pmc(bad); + + if (bad_pmc.status() < 0) { + pmprintf("%s: Error: Bogus metric: %s\n", + pmProgname, pmErrStr(bad_pmc.status())); + pmflush(); + } + else + sts = 1; + + return sts; +} + diff --git a/qa/qt/qmc_desc/qmc_desc.pro b/qa/qt/qmc_desc/qmc_desc.pro new file mode 100644 index 0000000..5d1e68d --- /dev/null +++ b/qa/qt/qmc_desc/qmc_desc.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +LANGUAGE = C++ +SOURCES = qmc_desc.cpp +CONFIG += qt warn_on +INCLUDEPATH += ../../../src/include +INCLUDEPATH += ../../../src/libpcp_qmc/src +release:DESTDIR = build/debug +debug:DESTDIR = build/release +LIBS += -L../../../src/libpcp/src +LIBS += -L../../../src/libpcp_qmc/src +LIBS += -L../../../src/libpcp_qmc/src/$$DESTDIR +LIBS += -lpcp_qmc -lpcp +QT -= gui diff --git a/qa/qt/qmc_dynamic/GNUmakefile b/qa/qt/qmc_dynamic/GNUmakefile new file mode 100644 index 0000000..0ed50e6 --- /dev/null +++ b/qa/qt/qmc_dynamic/GNUmakefile @@ -0,0 +1,27 @@ +TOPDIR = ../../.. +include $(TOPDIR)/src/include/builddefs + +COMMAND = qmc_dynamic +PROJECT = $(COMMAND).pro +SOURCES = $(COMMAND).cpp +TESTDIR = $(PCP_VAR_DIR)/testsuite/qt/$(COMMAND) + +LSRCFILES = $(PROJECT) $(SOURCES) +LDIRDIRT = build $(COMMAND).xcodeproj +LDIRT = $(COMMAND) *.o Makefile + +default default_pcp: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +install install_pcp: default + $(INSTALL) -m 755 -d $(TESTDIR) + $(INSTALL) -m 644 GNUmakefile.install $(TESTDIR)/GNUmakefile + $(INSTALL) -m 644 $(PROJECT) $(SOURCES) $(TESTDIR) +ifeq "$(ENABLE_QT)" "true" + $(INSTALL) -m 755 $(BINARY) $(TESTDIR)/$(COMMAND) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_dynamic/GNUmakefile.install b/qa/qt/qmc_dynamic/GNUmakefile.install new file mode 100644 index 0000000..827b780 --- /dev/null +++ b/qa/qt/qmc_dynamic/GNUmakefile.install @@ -0,0 +1,18 @@ +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 + +COMMAND = qmc_dynamic +PROJECT = $(COMMAND).pro + +default setup install: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_dynamic/qmc_dynamic.cpp b/qa/qt/qmc_dynamic/qmc_dynamic.cpp new file mode 100644 index 0000000..98b55d0 --- /dev/null +++ b/qa/qt/qmc_dynamic/qmc_dynamic.cpp @@ -0,0 +1,351 @@ +// +// Test Qt Metrics Class dynamic indom support +// + +#include <errno.h> +#include <QTextStream> +#include <qmc_context.h> +#include <qmc_group.h> +#include <qmc_metric.h> +#include <qmc_indom.h> + +#define ADD_INST "dynamic.control.add" +#define DEL_INST "dynamic.control.del" +#define mesg(str) msg(__LINE__, str) + +QTextStream cerr(stderr); +QTextStream cout(stdout); + +void +store(char const* name, char const* inst) +{ + char buf[128]; + + sprintf(buf, "pmstore %s %s > /dev/null\n", name, inst); + cout << name << ' ' << inst << endl; + if (system(buf) < 0) { + pmprintf("%s: cannot run system(%s)\n", pmProgname, buf); + pmflush(); + exit(1); + } +} + +void +dump(QmcMetric const* num, QmcMetric const* discrete, + QmcMetric const* instant, QmcMetric const* counter) +{ + cout << "dynamic.numinsts = " << num->value(0) << endl << endl; + for (int i = 0; i < discrete->numInst(); i++) { + cout << '[' << discrete->instName(i) << "] = "; + if (discrete->error(i) < 0) { + cout << pmErrStr(discrete->error(i)) << endl; + } + else { + cout << '\"' << discrete->stringValue(i) << "\" = " + << instant->value(i) << " ("; + if (counter->error(i) < 0) + cout << pmErrStr(counter->error(i)) << ")" << endl; + else + cout << counter->currentValue(i) << ")" << endl; + } + } + cout << endl; + discrete->indom()->dump(cout); +} + +void +update(QmcMetric* discrete, QmcMetric* instant, + QmcMetric* counter) +{ + if (discrete->indom()->changed()) + discrete->updateIndom(); + if (instant->indom()->changed()) + instant->updateIndom(); + if (counter->indom()->changed()) + counter->updateIndom(); +} + +void +msg(int line, char const* str) +{ + static int count = 1; + + cout << endl << "*** " << count << ": Line " << line << " - " << str + << " ***" << endl; + cerr << endl << "*** " << count << ": Line " << line << " - " << str + << " ***" << endl; + count++; +} + +int +main(int argc, char* argv[]) +{ + int sts = 0; + int c; + char buf[MAXHOSTNAMELEN]; + + 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*/ + } + + (void)gethostname(buf, MAXHOSTNAMELEN); + buf[MAXHOSTNAMELEN-1] = '\0'; + + mesg("Create two fetch groups"); + QmcGroup group1; + pmflush(); + QmcGroup group2; + pmflush(); + + mesg("Add number of instances to both groups"); + QmcMetric* numinsts1 = group1.addMetric("dynamic.numinsts"); + pmflush(); + if (numinsts1->status() < 0) + exit(1); + else + numinsts1->dump(cout); + + QmcMetric* numinsts2 = group2.addMetric("dynamic.numinsts"); + pmflush(); + if (numinsts2->status() < 0) + exit(1); + else + numinsts2->dump(cout); + + mesg("Fetch both groups"); + group1.fetch(); + numinsts1->dump(cout); + group2.fetch(); + numinsts2->dump(cout); + + mesg("Add dynamic metrics to both groups"); + QmcMetric* discrete1 = group1.addMetric("dynamic.discrete", 0.0, true); + pmflush(); + if (discrete1->status() < 0) + exit(1); + else + discrete1->dump(cout); + + QmcMetric* instant1 = group1.addMetric("dynamic.instant", 0.0, true); + pmflush(); + if (instant1->status() < 0) + exit(1); + else + instant1->dump(cout); + + QmcMetric* counter1 = group1.addMetric("dynamic.counter", 0.0, true); + pmflush(); + if (counter1->status() < 0) + exit(1); + else + counter1->dump(cout); + + QmcMetric* discrete2 = group2.addMetric("dynamic.discrete"); + pmflush(); + if (discrete2->status() < 0) + exit(1); + else + discrete2->dump(cout); + + QmcMetric* instant2 = group2.addMetric("dynamic.instant"); + pmflush(); + if (instant2->status() < 0) + exit(1); + else + instant2->dump(cout); + + QmcMetric* counter2 = group2.addMetric("dynamic.counter"); + pmflush(); + if (counter2->status() < 0) + exit(1); + else + counter2->dump(cout); + + mesg("Fetch both groups"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + group2.fetch(); + dump(numinsts2, discrete2, instant2, counter2); + + mesg("Add an instance"); + store(ADD_INST, "1"); + + mesg("Fetch first group"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + + mesg("Update indom for first group"); + update(discrete1, instant1, counter1); + + mesg("Fetch first group"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + + mesg("Fetch first group"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + + mesg("Fetch first group"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + + mesg("Add another instance"); + store(ADD_INST, "5"); + + mesg("Fetch first group"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + + mesg("Update indom for first group"); + update(discrete1, instant1, counter1); + + mesg("Fetch first group"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + + mesg("Fetch first group"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + + mesg("Delete first instance"); + store(DEL_INST, "1"); + + mesg("Fetch first group"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + + mesg("Update indom for first group"); + update(discrete1, instant1, counter1); + + mesg("Fetch first group"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + + mesg("Fetch second group"); + group2.fetch(); + dump(numinsts2, discrete2, instant2, counter2); + + mesg("Update indom for second group"); + update(discrete2, instant2, counter2); + + mesg("Fetch second group"); + group2.fetch(); + dump(numinsts2, discrete2, instant2, counter2); + + mesg("Fetch second group"); + group2.fetch(); + dump(numinsts2, discrete2, instant2, counter2); + + mesg("Delete second instance, add new instance"); + store(DEL_INST, "5"); + store(ADD_INST, "3"); + + mesg("Fetch first group"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + + mesg("Update indom for first group"); + update(discrete1, instant1, counter1); + + mesg("Fetch first group"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + + mesg("Fetch first group"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + + mesg("Fetch second group"); + group2.fetch(); + dump(numinsts2, discrete2, instant2, counter2); + + mesg("Update indom for second group"); + update(discrete2, instant2, counter2); + + mesg("Fetch second group"); + group2.fetch(); + dump(numinsts2, discrete2, instant2, counter2); + + mesg("Fetch second group"); + group2.fetch(); + dump(numinsts2, discrete2, instant2, counter2); + + mesg("Delete third instance"); + store(DEL_INST, "3"); + + mesg("Fetch first group"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + + mesg("Update indom for first group"); + update(discrete1, instant1, counter1); + + mesg("Fetch first group"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + + mesg("Fetch second group"); + group2.fetch(); + dump(numinsts2, discrete2, instant2, counter2); + + mesg("Update indom for second group"); + update(discrete2, instant2, counter2); + + mesg("Fetch second group"); + group2.fetch(); + dump(numinsts2, discrete2, instant2, counter2); + + mesg("Add second instance again"); + store(ADD_INST, "5"); + + mesg("Fetch first group"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + + mesg("Update indom for first group"); + update(discrete1, instant1, counter1); + + mesg("Fetch first group"); + group1.fetch(); + dump(numinsts1, discrete1, instant1, counter1); + + mesg("Fetch second group"); + group2.fetch(); + dump(numinsts2, discrete2, instant2, counter2); + + mesg("Update indom for second group"); + update(discrete2, instant2, counter2); + + mesg("Fetch second group"); + group2.fetch(); + dump(numinsts2, discrete2, instant2, counter2); + + return 0; +} + diff --git a/qa/qt/qmc_dynamic/qmc_dynamic.pro b/qa/qt/qmc_dynamic/qmc_dynamic.pro new file mode 100644 index 0000000..ca9ff2e --- /dev/null +++ b/qa/qt/qmc_dynamic/qmc_dynamic.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +LANGUAGE = C++ +SOURCES = qmc_dynamic.cpp +CONFIG += qt warn_on +INCLUDEPATH += ../../../src/include +INCLUDEPATH += ../../../src/libpcp_qmc/src +release:DESTDIR = build/debug +debug:DESTDIR = build/release +LIBS += -L../../../src/libpcp/src +LIBS += -L../../../src/libpcp_qmc/src +LIBS += -L../../../src/libpcp_qmc/src/$$DESTDIR +LIBS += -lpcp_qmc -lpcp +QT -= gui diff --git a/qa/qt/qmc_event/GNUmakefile b/qa/qt/qmc_event/GNUmakefile new file mode 100644 index 0000000..b125bca --- /dev/null +++ b/qa/qt/qmc_event/GNUmakefile @@ -0,0 +1,27 @@ +TOPDIR = ../../.. +include $(TOPDIR)/src/include/builddefs + +COMMAND = qmc_event +PROJECT = $(COMMAND).pro +SOURCES = $(COMMAND).cpp +TESTDIR = $(PCP_VAR_DIR)/testsuite/qt/$(COMMAND) + +LSRCFILES = $(PROJECT) $(SOURCES) +LDIRDIRT = build $(COMMAND).xcodeproj +LDIRT = $(COMMAND) *.o Makefile + +default default_pcp: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +install install_pcp: default + $(INSTALL) -m 755 -d $(TESTDIR) + $(INSTALL) -m 644 GNUmakefile.install $(TESTDIR)/GNUmakefile + $(INSTALL) -m 644 $(PROJECT) $(SOURCES) $(TESTDIR) +ifeq "$(ENABLE_QT)" "true" + $(INSTALL) -m 755 $(BINARY) $(TESTDIR)/$(COMMAND) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_event/GNUmakefile.install b/qa/qt/qmc_event/GNUmakefile.install new file mode 100644 index 0000000..35c201c --- /dev/null +++ b/qa/qt/qmc_event/GNUmakefile.install @@ -0,0 +1,18 @@ +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 + +COMMAND = qmc_event +PROJECT = $(COMMAND).pro + +default setup install: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_event/qmc_event.cpp b/qa/qt/qmc_event/qmc_event.cpp new file mode 100644 index 0000000..3b32e57 --- /dev/null +++ b/qa/qt/qmc_event/qmc_event.cpp @@ -0,0 +1,85 @@ +// +// Test event tracing functionality in libqmc +// +// Caller can setup deterministic output by calling +// "pmstore sample.event.reset 1" beforehand. +// + +#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); + +int +main(int argc, char* argv[]) +{ + int sts = 0; + int c; + + __pmSetProgname(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*/ + } + + cerr << "*** Create a single fetch group ***" << endl; + QmcGroup group; + pmflush(); + + cerr << endl << "*** Event metric ***" << endl; + QmcMetric* sample_records = group.addMetric("sample.event.records"); + if (sample_records->status() < 0) + sts = 1; + else + sample_records->dump(cerr); + pmflush(); + + QmcMetric* sample_seconds = group.addMetric("sample.seconds"); + if (sample_seconds->status() < 0) + sts = 1; + else + sample_seconds->dump(cerr); + pmflush(); + + // + // pmdasample provides a 4-phase fetch pattern for sample.event + // + for (int i = 0; i < 4; i++) { + sleep(1); + cerr << endl << "*** Group Fetch " << i << " ***" << endl; + group.fetch(); + sample_records->dump(cerr); + sample_seconds->dump(cerr); + } + + cerr << endl << "*** Exiting ***" << endl; + return sts; +} diff --git a/qa/qt/qmc_event/qmc_event.pro b/qa/qt/qmc_event/qmc_event.pro new file mode 100644 index 0000000..0f3c1e8 --- /dev/null +++ b/qa/qt/qmc_event/qmc_event.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +LANGUAGE = C++ +SOURCES = qmc_event.cpp +CONFIG += qt warn_on +INCLUDEPATH += ../../../src/include +INCLUDEPATH += ../../../src/libpcp_qmc/src +release:DESTDIR = build/debug +debug:DESTDIR = build/release +LIBS += -L../../../src/libpcp/src +LIBS += -L../../../src/libpcp_qmc/src +LIBS += -L../../../src/libpcp_qmc/src/$$DESTDIR +LIBS += -lpcp_qmc -lpcp +QT -= gui diff --git a/qa/qt/qmc_format/GNUmakefile b/qa/qt/qmc_format/GNUmakefile new file mode 100644 index 0000000..2350f48 --- /dev/null +++ b/qa/qt/qmc_format/GNUmakefile @@ -0,0 +1,27 @@ +TOPDIR = ../../.. +include $(TOPDIR)/src/include/builddefs + +COMMAND = qmc_format +PROJECT = $(COMMAND).pro +SOURCES = $(COMMAND).cpp +TESTDIR = $(PCP_VAR_DIR)/testsuite/qt/$(COMMAND) + +LSRCFILES = $(PROJECT) $(SOURCES) +LDIRDIRT = build $(COMMAND).xcodeproj +LDIRT = $(COMMAND) *.o Makefile + +default default_pcp: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +install install_pcp: default + $(INSTALL) -m 755 -d $(TESTDIR) + $(INSTALL) -m 644 GNUmakefile.install $(TESTDIR)/GNUmakefile + $(INSTALL) -m 644 $(PROJECT) $(SOURCES) $(TESTDIR) +ifeq "$(ENABLE_QT)" "true" + $(INSTALL) -m 755 $(BINARY) $(TESTDIR)/$(COMMAND) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_format/GNUmakefile.install b/qa/qt/qmc_format/GNUmakefile.install new file mode 100644 index 0000000..1e53804 --- /dev/null +++ b/qa/qt/qmc_format/GNUmakefile.install @@ -0,0 +1,18 @@ +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 + +COMMAND = qmc_format +PROJECT = $(COMMAND).pro + +default setup install: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_format/qmc_format.cpp b/qa/qt/qmc_format/qmc_format.cpp new file mode 100644 index 0000000..1387e31 --- /dev/null +++ b/qa/qt/qmc_format/qmc_format.cpp @@ -0,0 +1,37 @@ +// +// Test QmcMetric::formatValue routines +// + +#include <QTextStream> +#include <qmc.h> +#include <qmc_context.h> +#include <qmc_metric.h> + +QTextStream cerr(stderr); +QTextStream cout(stdout); + +int +main(int argc, char *argv[]) +{ + double d; + char *endptr; + + pmProgname = basename(argv[0]); + if (argc != 2) { + cerr << "Usage: " << pmProgname << " double" << endl; + exit(1); + /*NOTREACHED*/ + } + + d = strtod(argv[1], &endptr); + if (endptr != NULL && endptr[0] != '\0') { + cerr << pmProgname << ": argument \"" << argv[1] + << "\" must be a double (\"" << endptr << "\")" << endl; + exit(1); + /*NOTREACHED*/ + } + + cout << QmcMetric::formatNumber(d) << endl; + + return 0; +} diff --git a/qa/qt/qmc_format/qmc_format.pro b/qa/qt/qmc_format/qmc_format.pro new file mode 100644 index 0000000..5cf4561 --- /dev/null +++ b/qa/qt/qmc_format/qmc_format.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +LANGUAGE = C++ +SOURCES = qmc_format.cpp +CONFIG += qt warn_on +INCLUDEPATH += ../../../src/include +INCLUDEPATH += ../../../src/libpcp_qmc/src +release:DESTDIR = build/debug +debug:DESTDIR = build/release +LIBS += -L../../../src/libpcp/src +LIBS += -L../../../src/libpcp_qmc/src +LIBS += -L../../../src/libpcp_qmc/src/build/Default +LIBS += -lpcp_qmc -lpcp +QT -= gui diff --git a/qa/qt/qmc_group/GNUmakefile b/qa/qt/qmc_group/GNUmakefile new file mode 100644 index 0000000..518d807 --- /dev/null +++ b/qa/qt/qmc_group/GNUmakefile @@ -0,0 +1,27 @@ +TOPDIR = ../../.. +include $(TOPDIR)/src/include/builddefs + +COMMAND = qmc_group +PROJECT = $(COMMAND).pro +SOURCES = $(COMMAND).cpp +TESTDIR = $(PCP_VAR_DIR)/testsuite/qt/$(COMMAND) + +LSRCFILES = $(PROJECT) $(SOURCES) +LDIRDIRT = build $(COMMAND).xcodeproj +LDIRT = $(COMMAND) *.o Makefile + +default default_pcp: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +install install_pcp: default + $(INSTALL) -m 755 -d $(TESTDIR) + $(INSTALL) -m 644 GNUmakefile.install $(TESTDIR)/GNUmakefile + $(INSTALL) -m 644 $(PROJECT) $(SOURCES) $(TESTDIR) +ifeq "$(ENABLE_QT)" "true" + $(INSTALL) -m 755 $(BINARY) $(TESTDIR)/$(COMMAND) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_group/GNUmakefile.install b/qa/qt/qmc_group/GNUmakefile.install new file mode 100644 index 0000000..df5f994 --- /dev/null +++ b/qa/qt/qmc_group/GNUmakefile.install @@ -0,0 +1,18 @@ +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 + +COMMAND = qmc_group +PROJECT = $(COMMAND).pro + +default setup install: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_group/qmc_group.cpp b/qa/qt/qmc_group/qmc_group.cpp new file mode 100644 index 0000000..8d6992e --- /dev/null +++ b/qa/qt/qmc_group/qmc_group.cpp @@ -0,0 +1,835 @@ +// +// Test QmcGroup class +// It creates three groups representing three clients +// Two groups are using live contexts, one group is using archives. +// + +#include <QTextStream> +#include <QStringList> +#include <qmc_context.h> +#include <qmc_group.h> +#include <qmc_source.h> +#include <qmc_metric.h> + +QTextStream cerr(stderr); +QTextStream cout(stdout); + +#define mesg(str) msg(__LINE__, str) +#define checksts() pmflush(); if (sts < 0) fail(__LINE__, sts); + +class Client +{ +private: + + QmcGroup* _group; + QList<QmcMetric*> _metrics; + + enum KeyWords { keyArch, keyContext, keyDesc, keyError, keyFetch, + keyHost, keyIndom, keyJump, keyList, keyMetric, + keyName, keyReal, keyString, keyEvent, + keyText, keyUpdate, keyWipe }; + + static char const* keywords[]; + static char const* terminator; + static char const sep; + static char const cont; + +public: + + ~Client() + { delete _group; } + + Client() + { _group = new QmcGroup; } + + QmcGroup const& group() const + { return *_group; } + + // Represents a request for a context handle + int context(int type, char const* source); + + // Represents a namespace lookup + int name(int context, char const* metric); + + // Represents a help text lookup + int text(int context, char const* metric); + + // Represents a list of specs + int list(QStringList const& list); + + // Represents a jump to a time and interval for archives + int jump(int interval, int startSec, int startMSec); + + // Represents a fetch + int fetch(); + + // Represents a wipe + int wipe(); + + // Represents an update of dynamic indoms + int update(QList<int> const& list); + + // Dump out some debug stuff + void dump(QTextStream& os) + { _group->dump(os); } + + friend QTextStream& operator<<(QTextStream& os, struct timeval const& tv); +}; + +QTextStream& +operator<<(QTextStream& os, struct timeval const& tv) +{ + os << tv.tv_sec << Client::sep << tv.tv_usec; + return os; +} + +char const* Client::keywords[] = { "ARCH", "CONTEXT", "DESC", "ERROR", + "FETCH", "HOST", "INDOM", "JUMP", "LIST", + "METRIC", "NAME", "REAL", "STRING", "EVENT", + "TEXT", "UPDATE", "WIPE" }; + +char const* Client::terminator = ".\n"; +char const Client::sep = ' '; +char const Client::cont = '-'; + +int +Client::context(int type, char const* source) +{ + uint_t numContexts = _group->numContexts(); + QString qsource = source; + int sts = _group->use(type, qsource); + + if (sts >= 0) { + sts = _group->contextIndex(); + cout << keywords[keyContext] << sep << sts; + // We created a new context + if (_group->numContexts() > numContexts) { + QmcContext *context = _group->context(sts); + cout << sep << context->numIndoms() << sep << context->numIDs() + << sep << context->numMetrics() << sep; + if (context->source().type() == PM_CONTEXT_HOST) + cout << keywords[keyHost] << sep << context->source().host() + << sep << context->source().timezone() << endl; + else + cout << keywords[keyArch] << sep << context->source().host() + << sep << context->source().source() << sep + << context->source().start() << sep + << context->source().end() << sep + << context->source().timezone() << endl; + } + cout << terminator; + } + else { + cout << "ERROR " << sts << endl << terminator; + } + return sts; +} + +int +Client::name(int context, char const* metric) +{ + int sts = 0; + QStringList list; + + if (context < 0 || context >= (int)_group->numContexts()) + sts = PM_ERR_NOCONTEXT; + + if (sts >= 0) + sts = _group->use(context); + + if (sts >= 0) + sts = _group->context()->traverse(metric, list); + + if (sts < 0) + cout << keywords[keyError] << sep << sts << endl << terminator; + else { + cout << keywords[keyName] << sep << list.size() << endl; + for (int i = 0; i < list.size(); i++) + cout << cont << sep << list[i] << endl; + cout << terminator; + } + + return sts; +} + +int +Client::text(int context, char const* metric) +{ + int sts = 0; + pmID id; + char* buf; + + if (context < 0 || context >= (int)_group->numContexts()) + sts = PM_ERR_NOCONTEXT; + + if (sts >= 0) + sts = _group->use(context); + + if (sts >= 0) + sts = _group->context()->lookupPMID(metric, id); + + if (sts >= 0) + sts = pmLookupText(id, PM_TEXT_HELP, &buf); + + if (sts >= 0) { + cout << keywords[keyText] << sep << strlen(buf) << endl; + cout << buf << endl; + cout << terminator; + free(buf); + } + else + cout << keywords[keyError] << sep << sts << endl << terminator; + + _group->useDefault(); + + return sts; +} + +int +Client::list(QStringList const& list) +{ + int l, sts = 0; + uint_t i; + uint_t j; + uint_t k; + uint_t numContexts = _group->numContexts(); + uint_t numMetrics = _metrics.size(); + + _group->useDefault(); + + for (l = 0; l < list.size(); l++) + _metrics.append(_group->addMetric(list[l].toAscii().constData(), 0.0, false)); + + cout << keywords[keyList] << sep << _group->numContexts() << endl; + + for (i = 0; i < _group->numContexts(); i++) { + + QmcContext const *context = _group->context(i); + + cout << keywords[keyContext] << sep << i << sep + << context->numIndoms() << sep << context->numIDs() << sep + << context->numMetrics(); + + // Client has not seen this context before + if (i >= numContexts) { + if (context->source().type() == PM_CONTEXT_HOST) + cout << sep << keywords[keyHost] << sep + << context->source().host() << sep + << context->source().timezone() << endl; + else + cout << sep << keywords[keyArch] << sep + << context->source().host() << sep + << context->source().source() << sep + << context->source().start() << sep + << context->source().end() << sep + << context->source().timezone() << endl; + } + else + cout << endl; + + // Dump all indoms in context, but only list instances in use + for (j = 0; j < context->numIndoms(); j++) { + + QmcIndom const& indom = context->indom(j); + + cout << keywords[keyIndom] << sep << j << sep << indom.refCount() + << endl; + for (k = 0; k < (uint_t)indom.listLen(); k++) { + if (!indom.nullInst(k) && indom.refInst(k)) + cout << cont << sep << k << sep << indom.name(k) << endl; + } + } + + // Dump all descriptors in use + for (j = 0; j < context->numIDs(); j++) { + + pmID id = context->id(j); + QmcDesc const& desc = context->desc(id); + + cout << keywords[keyDesc] << sep << j << sep; + if (desc.desc().type == PM_TYPE_STRING) + cout << keywords[keyString]; + else if (desc.desc().type == PM_TYPE_EVENT) + cout << keywords[keyEvent]; + else + cout << keywords[keyReal]; + cout << sep << desc.units() << endl; + } + } + + // Dump new metrics listed by client + for (i = numMetrics; i < (uint_t)_metrics.size(); i++) { + + QmcMetric const& metric = *_metrics[i]; + + cout << keywords[keyMetric] << sep << i << sep; + + if (metric.status() < 0) { + cout << metric.status() << endl; + } + else { + cout << metric.numValues() << sep << metric.name() << sep + << metric.contextIndex() + << sep << metric.idIndex() << sep; + if (metric.indomIndex() == UINT_MAX) + cout << "-1" << endl; + else + cout << metric.indomIndex() << endl; + for (j = 0; j < (uint_t)metric.numInst(); j++) + cout << cont << sep << metric.instIndex(j) << endl; + } + + } + + cout << terminator; + + return sts; +} + +int +Client::jump(int interval, int startSec, int startMSec) +{ + int sts; + struct timeval start; + + start.tv_sec = startSec; + start.tv_usec = startMSec; + + sts = _group->setArchiveMode(PM_MODE_INTERP, &start, interval); + + if (sts < 0) + cout << keywords[keyError] << sts << endl << terminator; + else + cout << keywords[keyJump] << endl << terminator; + + return sts; +} + +int +Client::fetch() +{ + int sts, i, j; + + sts = _group->fetch(); + + cout << keywords[keyFetch] << sep << _group->numContexts() << sep + << _metrics.size() << endl; + + for (i = 0; i < (int)_group->numContexts(); i++) { + + QmcContext const *context = _group->context(i); + + cout << keywords[keyContext] << sep << i << sep + << (long long)(context->timeDelta() * 1000.0) << sep + << context->timeStamp() << endl; + } + + for (i = 0; i < _metrics.size(); i++) { + + QmcMetric const& metric = *_metrics[i]; + + cout << keywords[keyMetric] << sep << i << sep; + + if (metric.status() < 0) { + cout << metric.status() << endl; + } + else { + cout << metric.numValues(); + if (metric.hasInstances() && metric.indom()->changed()) + cout << sep << keywords[keyUpdate]; + cout << endl; + for (j = 0; j < metric.numValues(); j++) { + cout << cont << sep; + if (metric.error(j) < 0) + cout << '?' << endl; + else { + int type = metric.desc().desc().type; + if (QmcMetric::real(type)) + cout << metric.value(j); + else if (QmcMetric::event(type)) + metric.dump(cout, j); + else + cout << metric.stringValue(j); + cout << endl; + } + } + } + } + + cout << terminator; + + return sts; +} + +int +Client::wipe() +{ + _metrics.clear(); + + delete _group; + _group = new QmcGroup; + + cout << keywords[keyWipe] << endl << terminator; + + return 0; +} + +int +Client::update(QList<int> const& list) +{ + int sts = 0; + QList<int> contexts; + QList<int> indoms; + QList<int> metrics; + int i, j, k; + + // Generate unique list of contexts for updated metrics + for (i = 0; i < list.size(); i++) { + int index = list[i]; + + if (index < 0 || index >= _metrics.size()) { + sts = PM_ERR_PMID; + break; + } + + int ctx = _metrics[index]->contextIndex(); + + for (j = 0; j < contexts.size(); j++) + if (contexts[j] == ctx) + break; + if (j == contexts.size()) + contexts.append(ctx); + } + + if (sts >= 0) { + cout << keywords[keyUpdate] << sep << contexts.size() << endl; + + for (i = 0; i < contexts.size(); i++) { + uint_t cntx = contexts[i]; + QmcContext *context = _group->context(cntx); + + // Generate unique list of updated metrics for this context + metrics.clear(); + for (j = 0; j < list.size(); j++) { + uint_t index = list[j]; + if (_metrics[index]->status() >= 0 && + _metrics[index]->contextIndex() == cntx) + metrics.append(index); + } + + // Generate unique list of updated indoms for this context + indoms.clear(); + + for (j = 0; j < metrics.size(); j++) { + + int indom = _metrics[metrics[j]]->indomIndex(); + for (k = 0; k < indoms.size(); k++) + if (indoms[k] == indom) + break; + if (k == indoms.size()) + indoms.append(indom); + + _metrics[metrics[j]]->updateIndom(); + } + + cout << keywords[keyContext] << sep << cntx << sep + << indoms.size() << sep << list.size() << endl; + + for (j = 0; j < indoms.size(); j++) { + QmcIndom const& indom = context->indom(indoms[j]); + + cout << keywords[keyIndom] << sep << indoms[j] << sep + << indom.refCount() << endl; + for (k = 0; k < indom.listLen(); k++) { + if (!indom.nullInst(k) && indom.refInst(k)) + cout << cont << sep << k << sep << indom.name(k) << endl; + } + } + } + + for (i = 0; i < list.size(); i++) { + QmcMetric const& metric = *_metrics[list[i]]; + + cout << keywords[keyMetric] << sep << list[i] << sep; + + if (metric.status() < 0) { + cout << metric.status() << endl; + } + else { + cout << metric.numValues() << endl; + for (j = 0; j < metric.numInst(); j++) + cout << cont << sep << metric.instIndex(j) << endl; + } + } + } + else + cout << keywords[keyError] << sep << sts << endl; + + cout << terminator; + + return sts; +} + +void +store(char const* name, char const* inst) +{ + char buf[128]; + + sprintf(buf, "pmstore %s %s > /dev/null\n", name, inst); + cout << name << ' ' << inst << endl; + if (system(buf) < 0) { + pmprintf("%s: system(%s) failed\n", pmProgname, buf); + pmflush(); + exit(1); + } + if (system("pminfo -f dynamic") < 0) { + pmprintf("%s: system(pminfo) failed\n", pmProgname); + pmflush(); + exit(1); + } +} + +static int msgCount = 1; + +void +msg(int line, char const* str) +{ + cout << endl << "*** " << msgCount << ": Line " << line << " - " << str + << " ***" << endl; + cerr << endl << "*** " << msgCount << ": Line " << line << " - " << str + << " ***" << endl; + msgCount++; +} + +void +fail(int line, int err) +{ + cout << endl << "*** " << msgCount << ": Testing failed at line " << line + << " - " << pmErrStr(err) << " ***" << endl; + cerr << endl << "*** " << msgCount << ": Testing failed at line " << line + << " - " << pmErrStr(err) << " ***" << endl; + + pmflush(); + + exit(1); + /*NOTREACHED*/ +} + +int +main(int argc, char* argv[]) +{ + int sts = 0; + int c; + const char *string; + QString archive1 = "archives/snort-disks"; + // snort-disks timestamps + // 1117075022.613953 ... 1117075050.309912 + QString archive2 = "archives/vldb-disks"; + // vldb-disks timestamps + // 869629190.357184 ... 869629210.660548 + QString archive3 = "archives/moomba.pmkstat"; + QStringList metrics; + QList<int> metricIds; + + 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 || optind != argc) { + pmprintf("Usage: %s\n", pmProgname); + pmflush(); + exit(1); + /*NOTREACHED*/ + } + + store("dynamic.control.del", "-1"); + + // + // Client 1 uses live contexts to the same host as pmjd + // + + mesg("Client1: VERSION version"); + Client* client1 = new Client; + + mesg("Client1: LIST 2 hinv.ncpu kernel.all.load[1,15]"); + metrics.clear(); + metrics.append("hinv.ncpu"); + metrics.append("kernel.all.load[1,15]"); + sts = client1->list(metrics); + + checksts(); + + mesg("Client1: FETCH"); + sts = client1->fetch(); + + checksts(); + + // + // Client 2 uses live contexts to multiple hosts + // Client 2 does some namespace and helptext lookups first + // + + mesg("Client2: VERSION version"); + Client* client2 = new Client; + + + mesg("Client2: CONTEXT HOST localhost"); + sts = client2->context(PM_CONTEXT_HOST, "localhost"); + + checksts(); + + int ctx = sts; + + mesg("Client2: NAME 0 dynamic"); + sts = client2->name(ctx, "dynamic"); + + checksts(); + + mesg("Client2: TEXT 0 dynamic.numinsts"); + client2->text(ctx, "dynamic.numinsts"); + + checksts(); + + // + // Another fetch from Client 1 + // + + mesg("Client1: FETCH"); + sts = client1->fetch(); + + checksts(); + + // + // Client 3 uses archives contexts + // + + mesg("Client3: VERSION version"); + Client* client3 = new Client; + + mesg("Client3: CONTEXT ARCH archive1"); + string = archive1.toAscii().constData(); + sts = client3->context(PM_CONTEXT_ARCHIVE, string); + + checksts(); + + mesg("Client3: CONTEXT ARCH archive2"); + string = archive2.toAscii().constData(); + sts = client3->context(PM_CONTEXT_ARCHIVE, string); + + checksts(); + + // + // Client 1 does a fetch + // + + mesg("Client1: FETCH"); + sts = client1->fetch(); + + checksts(); + + // + // Client 2 sets up its metrics + // + + mesg("Client2: LIST 4 dynamic.numinsts dynamic.discrete dynamic.instant dynamic.counter"); + metrics.clear(); + metrics.append("dynamic.numinsts"); + metrics.append("dynamic.discrete"); + metrics.append("dynamic.instant"); + metrics.append("dynamic.counter"); + sts = client2->list(metrics); + + checksts(); + + mesg("Client2: FETCH"); + sts = client2->fetch(); + + checksts(); + + // + // Client 3 specifies some metrics using the archive host and source + // names + // + + mesg("Client3: LIST 4 snort:disk.dev.read[dks0d1,dks1d1,dks9d1] archives/vldb-disks/disk.dev.total[dks17d8,dks11d3,dks45d2] disk.dev.write[dks1d1,dks0d4] vldb.engr:disk.dev.total[dks18d6,dks11d3]"); + + metrics.clear(); + metrics.append("snort:disk.dev.read[dks0d1,dks1d1,dks9d1]"); + metrics.append("archives/vldb-disks/disk.dev.total[dks17d8,dks11d3,dks45d2]"); + metrics.append("disk.dev.write[dks1d1,dks0d4]"); + metrics.append("vldb.engr:disk.dev.total[dks18d6,dks11d3]"); + + sts = client3->list(metrics); + + checksts(); + + mesg("Client3: JUMP 5000 869629200 0"); + sts = client3->jump(5000, 869629200, 0); + + checksts(); + + mesg("Client3: FETCH"); + sts = client3->fetch(); + + checksts(); + + mesg("Client3: FETCH"); + sts = client3->fetch(); + + checksts(); + + // + // Client 1 now wants to add some more metrics + // + + mesg("Client1: LIST 2 hinv.ndisk disk.all.total"); + metrics.clear(); + metrics.append("hinv.ndisk"); + metrics.append("disk.all.total"); + sts = client1->list(metrics); + + checksts(); + + mesg("Client1: FETCH"); + sts = client1->fetch(); + + checksts(); + + mesg("Client1: FETCH"); + sts = client1->fetch(); + + checksts(); + + // + // Client 3 jumps into the next archive + // + + mesg("Client3: JUMP 2000 1117075022 0 "); + sts = client3->jump(2000, 1117075022, 0); + + checksts(); + + mesg("Client3: FETCH"); + sts = client3->fetch(); + + checksts(); + + mesg("Client3: FETCH"); + sts = client3->fetch(); + + checksts(); + + mesg("Client3: FETCH"); + sts = client3->fetch(); + + checksts(); + + // + // Client 1 wants to start afresh with some archive contexts + // + + mesg("Client1: WIPE"); + sts = client1->wipe(); + + checksts(); + + mesg("Client1: FETCH"); + sts = client1->fetch(); + + checksts(); + + // + // Client 2 gets a fetch in but the indom has changed + // + + mesg("Dynamic Indom Changes"); + store("dynamic.control.add", "2"); + store("dynamic.control.add", "4"); + + mesg("Client2: FETCH"); + sts = client2->fetch(); + + checksts(); + + mesg("Client2: UPDATE 3 1 2 3"); + metricIds.clear(); + metricIds.append(1); + metricIds.append(2); + metricIds.append(3); + sts = client2->update(metricIds); + + checksts(); + + mesg("Client2: FETCH"); + sts = client2->fetch(); + + checksts(); + + mesg("Client2: FETCH"); + sts = client2->fetch(); + + checksts(); + + // + // Client 1 adds some archive metrics + // + + mesg("Client1: CONTEXT ARCH moomba.pmkstat"); + string = archive3.toAscii().constData(); + sts = client1->context(PM_CONTEXT_ARCHIVE, string); + + checksts(); + + mesg("Client1: LIST 2 kernel.all.idle localhost:kernel.all.cpu.user"); + metrics.clear(); + metrics.append("irix.kernel.all.cpu.idle"); + metrics.append("moomba:irix.kernel.all.cpu.user"); + sts = client1->list(metrics); + + checksts(); + + mesg("Client1: JUMP 5000 885849650 0"); + sts = client1->jump(5000, 885849650, 0); + + checksts(); + + mesg("Client1: FETCH"); + sts = client1->fetch(); + + checksts(); + + mesg("Client1: FETCH"); + sts = client1->fetch(); + + checksts(); + + // Client 3 gets a fetch in + mesg("Client3: FETCH"); + sts = client3->fetch(); + + checksts(); + + + mesg("Exiting"); + pmflush(); + return sts; +} diff --git a/qa/qt/qmc_group/qmc_group.pro b/qa/qt/qmc_group/qmc_group.pro new file mode 100644 index 0000000..145909a --- /dev/null +++ b/qa/qt/qmc_group/qmc_group.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +LANGUAGE = C++ +SOURCES = qmc_group.cpp +CONFIG += qt warn_on +release:DESTDIR = build/debug +debug:DESTDIR = build/release +INCLUDEPATH += ../../../src/include +INCLUDEPATH += ../../../src/libpcp_qmc/src +LIBS += -L../../../src/libpcp/src +LIBS += -L../../../src/libpcp_qmc/src +LIBS += -L../../../src/libpcp_qmc/src/$$DESTDIR +LIBS += -lpcp_qmc -lpcp +QT -= gui diff --git a/qa/qt/qmc_hosts/GNUmakefile b/qa/qt/qmc_hosts/GNUmakefile new file mode 100644 index 0000000..22150a8 --- /dev/null +++ b/qa/qt/qmc_hosts/GNUmakefile @@ -0,0 +1,27 @@ +TOPDIR = ../../.. +include $(TOPDIR)/src/include/builddefs + +COMMAND = qmc_hosts +PROJECT = $(COMMAND).pro +SOURCES = $(COMMAND).cpp +TESTDIR = $(PCP_VAR_DIR)/testsuite/qt/$(COMMAND) + +LSRCFILES = $(PROJECT) $(SOURCES) +LDIRDIRT = build $(COMMAND).xcodeproj +LDIRT = $(COMMAND) *.o Makefile + +default default_pcp: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +install install_pcp: default + $(INSTALL) -m 755 -d $(TESTDIR) + $(INSTALL) -m 644 GNUmakefile.install $(TESTDIR)/GNUmakefile + $(INSTALL) -m 644 $(PROJECT) $(SOURCES) $(TESTDIR) +ifeq "$(ENABLE_QT)" "true" + $(INSTALL) -m 755 $(BINARY) $(TESTDIR)/$(COMMAND) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_hosts/GNUmakefile.install b/qa/qt/qmc_hosts/GNUmakefile.install new file mode 100644 index 0000000..5a0f3f6 --- /dev/null +++ b/qa/qt/qmc_hosts/GNUmakefile.install @@ -0,0 +1,18 @@ +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 + +COMMAND = qmc_hosts +PROJECT = $(COMMAND).pro + +default setup install: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_hosts/qmc_hosts.cpp b/qa/qt/qmc_hosts/qmc_hosts.cpp new file mode 100644 index 0000000..c1d8939 --- /dev/null +++ b/qa/qt/qmc_hosts/qmc_hosts.cpp @@ -0,0 +1,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; +} + diff --git a/qa/qt/qmc_hosts/qmc_hosts.pro b/qa/qt/qmc_hosts/qmc_hosts.pro new file mode 100644 index 0000000..52634c6 --- /dev/null +++ b/qa/qt/qmc_hosts/qmc_hosts.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +LANGUAGE = C++ +SOURCES = qmc_hosts.cpp +CONFIG += qt warn_on +release:DESTDIR = build/debug +debug:DESTDIR = build/release +INCLUDEPATH += ../../../src/include +INCLUDEPATH += ../../../src/libpcp_qmc/src +LIBS += -L../../../src/libpcp/src +LIBS += -L../../../src/libpcp_qmc/src +LIBS += -L../../../src/libpcp_qmc/src/$$DESTDIR +LIBS += -lpcp_qmc -lpcp +QT -= gui diff --git a/qa/qt/qmc_indom/GNUmakefile b/qa/qt/qmc_indom/GNUmakefile new file mode 100644 index 0000000..6ac877f --- /dev/null +++ b/qa/qt/qmc_indom/GNUmakefile @@ -0,0 +1,27 @@ +TOPDIR = ../../.. +include $(TOPDIR)/src/include/builddefs + +COMMAND = qmc_indom +PROJECT = $(COMMAND).pro +SOURCES = $(COMMAND).cpp +TESTDIR = $(PCP_VAR_DIR)/testsuite/qt/$(COMMAND) + +LSRCFILES = $(PROJECT) $(SOURCES) +LDIRDIRT = build $(COMMAND).xcodeproj +LDIRT = $(COMMAND) *.o Makefile + +default default_pcp: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +install install_pcp: default + $(INSTALL) -m 755 -d $(TESTDIR) + $(INSTALL) -m 644 GNUmakefile.install $(TESTDIR)/GNUmakefile + $(INSTALL) -m 644 $(PROJECT) $(SOURCES) $(TESTDIR) +ifeq "$(ENABLE_QT)" "true" + $(INSTALL) -m 755 $(BINARY) $(TESTDIR)/$(COMMAND) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_indom/GNUmakefile.install b/qa/qt/qmc_indom/GNUmakefile.install new file mode 100644 index 0000000..90709fc --- /dev/null +++ b/qa/qt/qmc_indom/GNUmakefile.install @@ -0,0 +1,18 @@ +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 + +COMMAND = qmc_indom +PROJECT = $(COMMAND).pro + +default setup install: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_indom/qmc_indom.cpp b/qa/qt/qmc_indom/qmc_indom.cpp new file mode 100644 index 0000000..6b82913 --- /dev/null +++ b/qa/qt/qmc_indom/qmc_indom.cpp @@ -0,0 +1,133 @@ +// +// Test QmcIndom class +// + +#include <QTextStream> +#include <qmc_context.h> +#include <qmc_source.h> +#include <qmc_desc.h> +#include <qmc_indom.h> + +QTextStream cerr(stderr); +QTextStream cout(stdout); + +int +main(int argc, char* argv[]) +{ + int sts = 0; + int c; + + 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*/ + } + + fprintf(stderr, "*** Lookup an indom ***\n"); + QString source = QString("archives/oview-short"); + QmcSource *src = QmcSource::getSource(PM_CONTEXT_ARCHIVE, source, false); + + if (src->status() < 0) { + pmprintf("%s: Error: Unable to create context to \"%s\": %s\n", + pmProgname, (const char *)source.toAscii(), + pmErrStr(src->status())); + pmflush(); + return 1; + } + + pmID hinv_map_cpu = pmid_build(1, 26, 9); + QmcDesc hinv_map_cpu_pmc(hinv_map_cpu); + + if (hinv_map_cpu_pmc.status() < 0) { + pmprintf("\n%s: Error: hinv.map.cpu: %s\n", + pmProgname, pmErrStr(hinv_map_cpu_pmc.status())); + pmflush(); + return 1; + } + + QmcIndom indom(PM_CONTEXT_ARCHIVE, hinv_map_cpu_pmc); + + if (indom.status() < 0) { + pmprintf("%s: Error: hinv.map.cpu: %s\n", + pmProgname, pmErrStr(indom.status())); + pmflush(); + return 1; + } + + indom.dump(cout); + + if (indom.diffProfile()) { + pmprintf("%s: Error: Profile requires updating but there is nothing in it\n", + pmProgname); + sts = 1; + } + + fprintf(stderr, "\n*** Reference one instance ***\n"); + indom.lookup("cpu:1.3.a"); + + if (!indom.diffProfile()) { + pmprintf("%s: Error: Profile should require updating but flag not set\n", + pmProgname); + sts = 1; + } + + indom.dump(cout); + indom.genProfile(); + + __pmProfile* profile = __pmHandleToPtr(pmWhichContext())->c_instprof; + __pmDumpProfile(stderr, PM_INDOM_NULL, profile); + + if (indom.diffProfile()) { + pmprintf("%s: Error: Profile just generated but flag still set\n", + pmProgname); + sts = 1; + } + + fprintf(stderr, "\n*** Reference all instances ***\n"); + indom.refAll(); + + if (!indom.diffProfile()) { + pmprintf("%s: Error: All instances referenced but profile flag unset\n", + pmProgname); + sts = 1; + } + + indom.dump(cout); + indom.genProfile(); + + profile = __pmHandleToPtr(pmWhichContext())->c_instprof; + __pmDumpProfile(stderr, PM_INDOM_NULL, profile); + + if (indom.diffProfile()) { + pmprintf("%s: Error: Profile just generated but flag still set\n", + pmProgname); + sts = 1; + } + + pmflush(); + return sts; +} diff --git a/qa/qt/qmc_indom/qmc_indom.pro b/qa/qt/qmc_indom/qmc_indom.pro new file mode 100644 index 0000000..bdf8cdb --- /dev/null +++ b/qa/qt/qmc_indom/qmc_indom.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +LANGUAGE = C++ +SOURCES = qmc_indom.cpp +CONFIG += qt warn_on +release:DESTDIR = build/debug +debug:DESTDIR = build/release +INCLUDEPATH += ../../../src/include +INCLUDEPATH += ../../../src/libpcp_qmc/src +LIBS += -L../../../src/libpcp/src +LIBS += -L../../../src/libpcp_qmc/src +LIBS += -L../../../src/libpcp_qmc/src/$$DESTDIR +LIBS += -lpcp_qmc -lpcp +QT -= gui diff --git a/qa/qt/qmc_metric/GNUmakefile b/qa/qt/qmc_metric/GNUmakefile new file mode 100644 index 0000000..3be53f3 --- /dev/null +++ b/qa/qt/qmc_metric/GNUmakefile @@ -0,0 +1,27 @@ +TOPDIR = ../../.. +include $(TOPDIR)/src/include/builddefs + +COMMAND = qmc_metric +PROJECT = $(COMMAND).pro +SOURCES = $(COMMAND).cpp +TESTDIR = $(PCP_VAR_DIR)/testsuite/qt/$(COMMAND) + +LSRCFILES = $(PROJECT) $(SOURCES) +LDIRDIRT = build $(COMMAND).xcodeproj +LDIRT = $(COMMAND) *.o Makefile + +default default_pcp: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +install install_pcp: default + $(INSTALL) -m 755 -d $(TESTDIR) + $(INSTALL) -m 644 GNUmakefile.install $(TESTDIR)/GNUmakefile + $(INSTALL) -m 644 $(PROJECT) $(SOURCES) $(TESTDIR) +ifeq "$(ENABLE_QT)" "true" + $(INSTALL) -m 755 $(BINARY) $(TESTDIR)/$(COMMAND) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_metric/GNUmakefile.install b/qa/qt/qmc_metric/GNUmakefile.install new file mode 100644 index 0000000..daf4be2 --- /dev/null +++ b/qa/qt/qmc_metric/GNUmakefile.install @@ -0,0 +1,18 @@ +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 + +COMMAND = qmc_metric +PROJECT = $(COMMAND).pro + +default setup install: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_metric/qmc_metric.cpp b/qa/qt/qmc_metric/qmc_metric.cpp new file mode 100644 index 0000000..3df5487 --- /dev/null +++ b/qa/qt/qmc_metric/qmc_metric.cpp @@ -0,0 +1,280 @@ +// +// Test QmcMetric class +// + +#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); + +void +changeConf(const char* str) +{ + char name[MAXPATHLEN]; + FILE *fp; + + sprintf(name, "%s/pmdas/simple/simple.conf", pmGetConfig("PCP_VAR_DIR")); + fp = fopen(name, "w"); + if (fp == NULL) { + cerr << pmProgname << ": /var/pcp/pmdas/simple/simple.conf: " + << strerror(errno) << endl; + exit(1); + /*NOTREACHED*/ + } + + fprintf(fp, "%s\n", str); + fclose(fp); +} + +int +main(int argc, char* argv[]) +{ + int sts = 0; + int c; + + 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*/ + } + + cerr << "*** Create a single fetch group ***" << endl; + QmcGroup group1; + pmflush(); + + cerr << endl << "*** Simple metric ***" << endl; + QmcMetric* hinv_ncpu = group1.addMetric("hinv.ncpu"); + pmflush(); + + if (hinv_ncpu->status() < 0) + sts = 1; + else + hinv_ncpu->dump(cerr); + + cerr << endl << "*** Metric with an Indom ***" << endl; + QmcMetric* percpu_user = group1.addMetric("sample.bin"); + pmflush(); + + if (percpu_user->status() < 0) + sts = 1; + else + percpu_user->dump(cerr); + + cerr << endl << "*** proc style specific instance ***" << endl; + QmcMetric* load_avg = group1.addMetric("kernel.all.load[1,5]"); + pmflush(); + + if (load_avg->status() < 0) + sts = 1; + else + load_avg->dump(cerr); + + cerr << endl << "*** String metric ***" << endl; + QmcMetric* sample_hullo = group1.addMetric("sample.string.hullo"); + + if (sample_hullo->status() < 0) + sts = 1; + else + sample_hullo->dump(cerr); + + cerr << endl << "*** Rate converted metric ***" << endl; + QmcMetric* sample_seconds = group1.addMetric("sample.seconds"); + + if (sample_seconds->status() < 0) + sts = 1; + else + sample_seconds->dump(cerr); + + cerr << endl << "*** Bogus metric ***" << endl; + QmcMetric* bogus_metric = group1.addMetric("bogus.metric"); + pmflush(); + + if (bogus_metric->status() >= 0) { + pmprintf("%s: Error: bogus.metric was not invalid!\n", + pmProgname); + pmflush(); + sts = 1; + } + + cerr << endl << "*** Bogus instance ***" << endl; + QmcMetric* bogus_inst = group1.addMetric("kernel.all.load[2]"); + pmflush(); + + if (bogus_inst->status() >= 0) { + pmprintf("%s: Error: kernel.all.load[2] was not invalid!\n", + pmProgname); + pmflush(); + sts = 1; + } + + pmflush(); + + sleep(1); + + cerr << endl << "*** Group 1 Fetch 1 ***" << endl; + group1.fetch(); + hinv_ncpu->dump(cerr); + percpu_user->dump(cerr); + load_avg->dump(cerr); + sample_hullo->dump(cerr); + sample_seconds->dump(cerr); + + sleep(1); + + cerr << endl << "*** Group 1 Fetch 2 ***" << endl; + group1.fetch(); + hinv_ncpu->dump(cerr); + percpu_user->dump(cerr); + load_avg->dump(cerr); + sample_hullo->dump(cerr); + sample_seconds->dump(cerr); + + cerr << endl << "*** Remove an instance ***" << endl; + load_avg->removeInst(0); + load_avg->dump(cerr); + + sleep(1); + + cerr << endl << "*** Group 1 Fetch 3 ***" << endl; + group1.fetch(); + hinv_ncpu->dump(cerr); + percpu_user->dump(cerr); + load_avg->dump(cerr); + sample_hullo->dump(cerr); + sample_seconds->dump(cerr); + + cerr << endl << "*** Add an instance ***" << endl; + load_avg->addInst("15"); + load_avg->dump(cerr); + + sleep(1); + + cerr << endl << "*** Group 1 Fetch 4 ***" << endl; + group1.fetch(); + hinv_ncpu->dump(cerr); + percpu_user->dump(cerr); + load_avg->dump(cerr); + sample_hullo->dump(cerr); + sample_seconds->dump(cerr); + + cerr << endl << "*** Creating a new group ***" << endl; + QmcGroup group2; + + cerr << endl << "*** Adding a metric with a dynamic indom ***" << endl; + QmcMetric* simple_now = group2.addMetric("simple.now"); + pmflush(); + simple_now->dump(cerr); + + cerr << endl << "*** Group 2 Fetch 1 ***" << endl; + group2.fetch(); + simple_now->dump(cerr); + + cerr << endl << "*** Change the indom ***" << endl; + changeConf("sec,min,hour"); + + cerr << endl << "*** Group 2 Fetch 2 ***" << endl; + group2.fetch(); + simple_now->dump(cerr); + + cerr << endl << "*** Updating indom ***" << endl; + if (simple_now->indom()->changed()) + simple_now->updateIndom(); + else + cerr << "Nothing to update!" << endl; + + simple_now->dump(cerr); + simple_now->indom()->dump(cerr); + + cerr << endl << "*** Group 2 Fetch 3 ***" << endl; + group2.fetch(); + simple_now->dump(cerr); + + cerr << endl << "*** Remove instance from PMDA ***" << endl; + changeConf("sec,hour"); + + cerr << endl << "*** Group 2 Fetch 4 ***" << endl; + group2.fetch(); + simple_now->dump(cerr); + + cerr << endl << "*** Remove an instance ***" << endl; + simple_now->removeInst(1); + simple_now->dump(cerr); + simple_now->indom()->dump(cerr); + + cerr << endl << "*** Updating indom ***" << endl; + if (simple_now->indom()->changed()) + simple_now->updateIndom(); + else + cerr << "Nothing to update!" << endl; + + simple_now->dump(cerr); + simple_now->indom()->dump(cerr); + + cerr << endl << "*** Group 2 Fetch 5 ***" << endl; + group2.fetch(); + simple_now->dump(cerr); + + cerr << endl << "*** Add another metric with the same indom ***" << endl; + QmcMetric* simple_now2 = group2.addMetric("simple.now"); + simple_now2->dump(cerr); + simple_now2->indom()->dump(cerr); + + cerr << endl << "*** Group 2 Fetch 6 ***" << endl; + group2.fetch(); + simple_now->dump(cerr); + simple_now2->dump(cerr); + + cerr << endl << "*** Add an instance to the PMDA ***" << endl; + changeConf("sec,min,hour"); + + cerr << endl << "*** Group 2 Fetch 7 ***" << endl; + group2.fetch(); + simple_now->dump(cerr); + simple_now2->dump(cerr); + + cerr << endl << "*** Updating indom ***" << endl; + if (simple_now2->indom()->changed()) + simple_now2->updateIndom(); + else + cerr << "Nothing to update!" << endl; + + simple_now2->dump(cerr); + simple_now2->indom()->dump(cerr); + + cerr << endl << "*** Group 2 Fetch 8 ***" << endl; + group2.fetch(); + simple_now->dump(cerr); + simple_now2->dump(cerr); + + cerr << endl << "*** Exiting ***" << endl; + return sts; +} diff --git a/qa/qt/qmc_metric/qmc_metric.pro b/qa/qt/qmc_metric/qmc_metric.pro new file mode 100644 index 0000000..49262c9 --- /dev/null +++ b/qa/qt/qmc_metric/qmc_metric.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +LANGUAGE = C++ +SOURCES = qmc_metric.cpp +CONFIG += qt warn_on +release:DESTDIR = build/debug +debug:DESTDIR = build/release +INCLUDEPATH += ../../../src/include +INCLUDEPATH += ../../../src/libpcp_qmc/src +LIBS += -L../../../src/libpcp/src +LIBS += -L../../../src/libpcp_qmc/src +LIBS += -L../../../src/libpcp_qmc/src/$$DESTDIR +LIBS += -lpcp_qmc -lpcp +QT -= gui diff --git a/qa/qt/qmc_source/GNUmakefile b/qa/qt/qmc_source/GNUmakefile new file mode 100644 index 0000000..f6f1023 --- /dev/null +++ b/qa/qt/qmc_source/GNUmakefile @@ -0,0 +1,27 @@ +TOPDIR = ../../.. +include $(TOPDIR)/src/include/builddefs + +COMMAND = qmc_source +PROJECT = $(COMMAND).pro +SOURCES = $(COMMAND).cpp +TESTDIR = $(PCP_VAR_DIR)/testsuite/qt/$(COMMAND) + +LSRCFILES = $(PROJECT) $(SOURCES) +LDIRDIRT = build $(COMMAND).xcodeproj +LDIRT = $(COMMAND) *.o Makefile + +default default_pcp: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +install install_pcp: default + $(INSTALL) -m 755 -d $(TESTDIR) + $(INSTALL) -m 644 GNUmakefile.install $(TESTDIR)/GNUmakefile + $(INSTALL) -m 644 $(PROJECT) $(SOURCES) $(TESTDIR) +ifeq "$(ENABLE_QT)" "true" + $(INSTALL) -m 755 $(BINARY) $(TESTDIR)/$(COMMAND) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_source/GNUmakefile.install b/qa/qt/qmc_source/GNUmakefile.install new file mode 100644 index 0000000..13b7a03 --- /dev/null +++ b/qa/qt/qmc_source/GNUmakefile.install @@ -0,0 +1,18 @@ +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 + +COMMAND = qmc_source +PROJECT = $(COMMAND).pro + +default setup install: +ifeq "$(ENABLE_QT)" "true" + $(QTMAKE) + $(LNMAKE) +endif + +include $(BUILDRULES) diff --git a/qa/qt/qmc_source/qmc_source.cpp b/qa/qt/qmc_source/qmc_source.cpp new file mode 100644 index 0000000..ea753f7 --- /dev/null +++ b/qa/qt/qmc_source/qmc_source.cpp @@ -0,0 +1,126 @@ +// +// Test QmcSource class +// + +#include <QTextStream> +#include <qmc_source.h> + +QTextStream cerr(stderr); +QTextStream cout(stdout); + +int +main(int argc, char* argv[]) +{ + int sts = 0; + int c; + char buf[MAXHOSTNAMELEN]; + 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*/ + } + + (void)gethostname(buf, MAXHOSTNAMELEN); + buf[MAXHOSTNAMELEN-1] = '\0'; + + fprintf(stderr,"*** Create an archive context ***\n"); + source = "archives/oview-short"; + QmcSource* src1 = QmcSource::getSource(PM_CONTEXT_ARCHIVE, source, false); + + if (src1->status() < 0) { + pmprintf("%s: Error: Unable to create context to \"oview-short\": %s\n", + pmProgname, pmErrStr(src1->status())); + pmflush(); + sts = 1; + } + + fprintf(stderr,"\n*** Create an archive context using the host name ***\n"); + source = QString("snort"); + QmcSource* src2 = QmcSource::getSource(PM_CONTEXT_HOST, source, true); + + if (src2->status() < 0) { + pmprintf("%s: Error: Unable to create context to \"%s\": %s\n", + pmProgname, (const char *)source.toAscii(), + pmErrStr(src2->status())); + pmflush(); + sts = 1; + } + + if (src1 != src2) { + pmprintf("%s: Error: Matching host to an archive failed: src1 = %s, src2 = %s\n", + pmProgname, (const char *)src1->desc().toAscii(), + (const char *)src2->desc().toAscii()); + pmflush(); + QmcSource::dumpList(cerr); + sts = 1; + } + + fprintf(stderr,"\n*** Create two live contexts to the local host ***\n"); + source = buf; + QmcSource* src3 = QmcSource::getSource(PM_CONTEXT_HOST, source); + QmcSource* src4 = QmcSource::getSource(PM_CONTEXT_HOST, source); + + if (src3->status() < 0) { + pmprintf("%s: Error: Unable to create context to \"%s\": %s\n", + pmProgname, buf, pmErrStr(src3->status())); + pmflush(); + } + + if (src4->status() < 0) { + pmprintf("%s: Error: Unable to create context to \"%s\": %s\n", + pmProgname, buf, pmErrStr(src4->status())); + pmflush(); + } + + if (src3 != src4) { + pmprintf("%s: Error: Identical host test failed: src3 = %s, src4 = %s\n", + pmProgname, (const char *)src3->desc().toAscii(), + (const char *)src4->desc().toAscii()); + pmflush(); + QmcSource::dumpList(cerr); + sts = 1; + } + + fprintf(stderr,"\n*** Create a local context ***\n"); + source = QString::null; + QmcSource* src5 = QmcSource::getSource(PM_CONTEXT_LOCAL, source); + + if (src5->status() < 0) { + pmprintf("%s: Error: Unable to create context to localhost: %s\n", + pmProgname, pmErrStr(src5->status())); + pmflush(); + sts = 1; + } + + fprintf(stderr,"\n*** List all known sources ***\n"); + QmcSource::dumpList(cout); + + pmflush(); + return sts; +} diff --git a/qa/qt/qmc_source/qmc_source.pro b/qa/qt/qmc_source/qmc_source.pro new file mode 100644 index 0000000..e0ed9f8 --- /dev/null +++ b/qa/qt/qmc_source/qmc_source.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +LANGUAGE = C++ +SOURCES = qmc_source.cpp +CONFIG += qt warn_on +release:DESTDIR = build/debug +debug:DESTDIR = build/release +INCLUDEPATH += ../../../src/include +INCLUDEPATH += ../../../src/libpcp_qmc/src +LIBS += -L../../../src/libpcp/src +LIBS += -L../../../src/libpcp_qmc/src +LIBS += -L../../../src/libpcp_qmc/src/$$DESTDIR +LIBS += -lpcp_qmc -lpcp +QT -= gui diff --git a/qa/qt/setup-executables b/qa/qt/setup-executables new file mode 100755 index 0000000..2751da1 --- /dev/null +++ b/qa/qt/setup-executables @@ -0,0 +1,39 @@ +#!/bin/sh +# +# Very ugly picker for executables from a build. +# +# Problem is that /var/lib/pcp/testsuite/qa is populated from the +# packaging, but in a build context the qmc headers are defined in +# ../../src/libpcp_qmc/src but the qmc library and the standard +# PCP headers are not in ../../src they are out in the build area +# c/o Makepkgs +# + +if [ -z "$PCP_DIR" ] +then + . /etc/pcp.conf +else + . "$PCP_DIR"/etc/pcp.conf +fi + +builddir='' +for builddir in ../../build/deb/pcp-$PCP_VERSION/qa/qt $PCP_VAR_DIR/testsuite/qt '' +do + [ -n "$builddir" -a -d "$builddir" ] && break +done + +for x in qmc_* +do + [ -x $x/$x ] && continue + echo -n "Hunting for $x executable ... " + if [ -z "$builddir" ] + then + echo "no build dir, not found" + elif [ -x $builddir/$x/$x ] + then + cp $builddir/$x/$x $x/$x + echo OK + else + echo "not found" + fi +done |