summaryrefslogtreecommitdiff
path: root/qa/src/test_mmv.python
blob: 255d5c392ef4e2c24c2513c913ac9a42f7a0b9db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
""" Test creation of PCP MMV metrics via the pcp.mmv python module """
#
# Copyright (C) 2013 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#

import sys
import unittest
from pcp import mmv, pmapi
from cpmapi import PM_COUNT_ONE, PM_TIME_USEC
import cmmv

class TestSequenceFunctions(unittest.TestCase):
    """ Test driver class for pcp.mmv module verification """

    def test_mmv(self):
        """ Worker which creates mmv instances, indoms, metrics
            and ties 'em all together via the MemoryMappedValues
            class.
            Once executed, this test create an MMV file that can
            be queried using pmdammv (by a PCP test driver script).
        """

        instances = [mmv.mmv_instance(0, "zero"), mmv.mmv_instance(1, "hero")]
        woodlands = [mmv.mmv_instance(0, "bird"), mmv.mmv_instance(1, "tree"),
                     mmv.mmv_instance(2, "eggs"), mmv.mmv_instance(3, "frog")]
        indoms = [mmv.mmv_indom(serial = 1,
                            shorttext = "We can be heroes",
                            helptext = "Set of instances from zero to hero"),
                  mmv.mmv_indom(serial = 2)]
        indoms[0].set_instances(instances)
        indoms[1].set_instances(woodlands)
        metrics = [mmv.mmv_metric(name = "counter",
                              item = 1,
                              typeof = cmmv.MMV_TYPE_U32,
                              semantics = cmmv.MMV_SEM_COUNTER,
                              dimension = pmapi.pmUnits(0,0,1,0,0,PM_COUNT_ONE),
                              shorttext = "Example counter metric",
                              helptext = "Yep, a test counter metric"),
                   mmv.mmv_metric(name = "instant",
                              item = 2,
                              typeof = cmmv.MMV_TYPE_I32,
                              semantics = cmmv.MMV_SEM_INSTANT,
                              dimension = pmapi.pmUnits(0,0,0,0,0,0),
                              shorttext = "Example instant metric",
                              helptext = "Yep, a test instantaneous metric"),
                   mmv.mmv_metric(name = "indom",
                              item = 3,
                              typeof = cmmv.MMV_TYPE_U32,
                              semantics = cmmv.MMV_SEM_DISCRETE,
                              dimension = pmapi.pmUnits(0,0,0,0,0,0),
                              indom = 1),
                   mmv.mmv_metric(name = "interval",
                              item = 4,
                              typeof = cmmv.MMV_TYPE_ELAPSED,
                              semantics = cmmv.MMV_SEM_COUNTER,
                              dimension = pmapi.pmUnits(0,1,0,0,PM_TIME_USEC,0),
                              indom = 2),
                   mmv.mmv_metric(name = "string",
                              item = 5,
                              typeof = cmmv.MMV_TYPE_STRING,
                              dimension = pmapi.pmUnits(0,0,0,0,0,0),
                              semantics = cmmv.MMV_SEM_INSTANT),
                   mmv.mmv_metric(name = "strings",
                              item = 6,
                              typeof = cmmv.MMV_TYPE_STRING,
                              semantics = cmmv.MMV_SEM_INSTANT,
                              dimension = pmapi.pmUnits(0,0,0,0,0,0),
                              indom = 1,
                              shorttext = "test string metrics",
                              helptext = "Yep, string metric with instances")]

        values = mmv.MemoryMappedValues("test")
        self.assertTrue(values != None)
        self.assertTrue(values.started() == 0)
        values.add_indoms(indoms)
        self.assertTrue(values.started() == 0)
        values.add_metrics(metrics)
        self.assertTrue(values.started() == 0)

        values.start()
        self.assertTrue(values.started() == 1)
        caliper = values.lookup_interval_start("interval", "eggs")
        self.assertTrue(caliper != None)
        instant = values.lookup_mapping("instant", None)
        self.assertTrue(instant != None)
        values.add(instant, 41)
        values.inc(instant)
        values.interval_end(caliper)
        values.stop()
        self.assertTrue(values.started() == 0)

        # verification of the metrics values, semantics, indoms
        # and so on is performed in conjunction with pmdammv in
        # a driver script in the pcp/qa sources

if __name__ == '__main__':

    sys.exit(unittest.main())