summaryrefslogtreecommitdiffstats
path: root/storage/src/tests/common/hostreporter/cpureportertest.cpp
blob: 150362a91badf8c6689e86ff71051a8f2e9bb904 (plain) (blame)
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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/log/log.h>
#include <vespa/storage/common/hostreporter/cpureporter.h>
#include <vespa/vdstestlib/cppunit/macros.h>
#include <vespa/vespalib/data/slime/slime.h>
#include <vespa/vespalib/util/jsonstream.h>
#include "util.h"

LOG_SETUP(".test.cpureporter");

namespace storage {
namespace {
using Object = vespalib::JsonStream::Object;
using End = vespalib::JsonStream::End;
}

struct CpuReporterTest : public CppUnit::TestFixture
{
    void testCpuReporter();

    CPPUNIT_TEST_SUITE(CpuReporterTest);
    CPPUNIT_TEST(testCpuReporter);
    CPPUNIT_TEST_SUITE_END();
};

CPPUNIT_TEST_SUITE_REGISTRATION(CpuReporterTest);

void
CpuReporterTest::testCpuReporter()
{
    CpuReporter cpuReporter;
    vespalib::Slime slime;
    util::reporterToSlime(cpuReporter,  slime);
    CPPUNIT_ASSERT(1.0 <= slime.get()["cpu"]["context switches"].asDouble());
    CPPUNIT_ASSERT(1.0 <= slime.get()["cpu"]["cputotal"]["user"].asDouble());
    CPPUNIT_ASSERT(1.0 <= slime.get()["cpu"]["cputotal"]["user"].asDouble());
    CPPUNIT_ASSERT(1.0 <= slime.get()["cpu"]["cputotal"]["user"].asDouble());
}
} // storage