summaryrefslogtreecommitdiff
path: root/qa/qt/qmc_dynamic
diff options
context:
space:
mode:
Diffstat (limited to 'qa/qt/qmc_dynamic')
-rw-r--r--qa/qt/qmc_dynamic/GNUmakefile27
-rw-r--r--qa/qt/qmc_dynamic/GNUmakefile.install18
-rw-r--r--qa/qt/qmc_dynamic/qmc_dynamic.cpp351
-rw-r--r--qa/qt/qmc_dynamic/qmc_dynamic.pro13
4 files changed, 409 insertions, 0 deletions
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