summaryrefslogtreecommitdiff
path: root/qa/qt/qmc_context
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2014-10-26 12:33:50 +0400
committerIgor Pashev <pashev.igor@gmail.com>2014-10-26 12:33:50 +0400
commit47e6e7c84f008a53061e661f31ae96629bc694ef (patch)
tree648a07f3b5b9d67ce19b0fd72e8caa1175c98f1a /qa/qt/qmc_context
downloadpcp-debian.tar.gz
Debian 3.9.10debian/3.9.10debian
Diffstat (limited to 'qa/qt/qmc_context')
-rw-r--r--qa/qt/qmc_context/GNUmakefile27
-rw-r--r--qa/qt/qmc_context/GNUmakefile.install18
-rw-r--r--qa/qt/qmc_context/qmc_context.cpp241
-rw-r--r--qa/qt/qmc_context/qmc_context.pro13
4 files changed, 299 insertions, 0 deletions
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