|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) 2019 The Bitcoin Core developers |
| 3 | +# Distributed under the MIT software license, see the accompanying |
| 4 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 5 | +"""Test RPC misc output.""" |
| 6 | +import xml.etree.ElementTree as ET |
| 7 | + |
| 8 | +from test_framework.test_framework import BitcoinTestFramework |
| 9 | +from test_framework.util import ( |
| 10 | + assert_raises_rpc_error, |
| 11 | + assert_equal, |
| 12 | + assert_greater_than, |
| 13 | +) |
| 14 | + |
| 15 | +from test_framework.authproxy import JSONRPCException |
| 16 | + |
| 17 | + |
| 18 | +class RpcMiscTest(BitcoinTestFramework): |
| 19 | + def set_test_params(self): |
| 20 | + self.num_nodes = 1 |
| 21 | + |
| 22 | + def run_test(self): |
| 23 | + node = self.nodes[0] |
| 24 | + |
| 25 | + self.log.info("test getmemoryinfo") |
| 26 | + memory = node.getmemoryinfo()['locked'] |
| 27 | + assert_greater_than(memory['used'], 0) |
| 28 | + assert_greater_than(memory['free'], 0) |
| 29 | + assert_greater_than(memory['total'], 0) |
| 30 | + assert_greater_than(memory['locked'], 0) |
| 31 | + assert_greater_than(memory['chunks_used'], 0) |
| 32 | + assert_greater_than(memory['chunks_free'], 0) |
| 33 | + assert_equal(memory['used'] + memory['free'], memory['total']) |
| 34 | + |
| 35 | + self.log.info("test mallocinfo") |
| 36 | + try: |
| 37 | + mallocinfo = node.getmemoryinfo(mode="mallocinfo") |
| 38 | + self.log.info('getmemoryinfo(mode="mallocinfo") call succeeded') |
| 39 | + tree = ET.fromstring(mallocinfo) |
| 40 | + assert_equal(tree.tag, 'malloc') |
| 41 | + except JSONRPCException: |
| 42 | + self.log.info('getmemoryinfo(mode="mallocinfo") not available') |
| 43 | + assert_raises_rpc_error(-8, 'mallocinfo is only available when compiled with glibc 2.10+', node.getmemoryinfo, mode="mallocinfo") |
| 44 | + |
| 45 | + assert_raises_rpc_error(-8, "unknown mode foobar", node.getmemoryinfo, mode="foobar") |
| 46 | + |
| 47 | +if __name__ == '__main__': |
| 48 | + RpcMiscTest().main() |
0 commit comments