Merge #15485: add rpc_misc.py, mv test getmemoryinfo, add test mallocinfo

f13ad1cae0 modify test for memory locked in case locking pages failed at some point (Adam Jonas)
2fa85ebd1c add rpc_misc.py, mv test getmemoryinfo, add test mallocinfo (Adam Jonas)

Pull request description:

  Creating the `rpc_misc.py` functional test file to add space for adding tests to a file that doesn't have a lot of coverage.
    - Removing the `getmemoryinfo()` smoke test from wallet basic rather than moving it to keep the wallet decoupled. Feel like testing for reasonable memory allocation values should suffice.
    - Adding coverage for `mallocinfo()`. Introduced standard lib XML parser since the function exports an XML string that describes the current state of the memory-allocation implementation in the caller.

Tree-SHA512: ced30115622916c88d1e729969ee331272ec9f2881eb36dee4bb7331bf633a6810a57fed63a0cfaf86de698edb5162e6a035efd07c89ece1df56b69d61288072
This commit is contained in:
MarcoFalke 2019-03-01 13:54:15 -05:00 committed by Odysseas Gabrielides
parent 6619124787
commit 1b75f4f1d7
2 changed files with 51 additions and 0 deletions

50
test/functional/rpc_misc.py Executable file
View File

@ -0,0 +1,50 @@
#!/usr/bin/env python3
# Copyright (c) 2019 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test RPC misc output."""
import xml.etree.ElementTree as ET
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_raises_rpc_error,
assert_equal,
assert_greater_than,
assert_greater_than_or_equal,
)
from test_framework.authproxy import JSONRPCException
class RpcMiscTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
def run_test(self):
node = self.nodes[0]
self.log.info("test getmemoryinfo")
memory = node.getmemoryinfo()['locked']
assert_greater_than(memory['used'], 0)
assert_greater_than(memory['free'], 0)
assert_greater_than(memory['total'], 0)
# assert_greater_than_or_equal() for locked in case locking pages failed at some point
assert_greater_than_or_equal(memory['locked'], 0)
assert_greater_than(memory['chunks_used'], 0)
assert_greater_than(memory['chunks_free'], 0)
assert_equal(memory['used'] + memory['free'], memory['total'])
self.log.info("test mallocinfo")
try:
mallocinfo = node.getmemoryinfo(mode="mallocinfo")
self.log.info('getmemoryinfo(mode="mallocinfo") call succeeded')
tree = ET.fromstring(mallocinfo)
assert_equal(tree.tag, 'malloc')
except JSONRPCException:
self.log.info('getmemoryinfo(mode="mallocinfo") not available')
assert_raises_rpc_error(-8, 'mallocinfo is only available when compiled with glibc 2.10+', node.getmemoryinfo, mode="mallocinfo")
assert_raises_rpc_error(-8, "unknown mode foobar", node.getmemoryinfo, mode="foobar")
if __name__ == '__main__':
RpcMiscTest().main()

View File

@ -106,6 +106,7 @@ BASE_SCRIPTS = [
'wallet_txn_doublespend.py --mineblock', 'wallet_txn_doublespend.py --mineblock',
'wallet_txn_clone.py', 'wallet_txn_clone.py',
'rpc_getchaintips.py', 'rpc_getchaintips.py',
'rpc_misc.py',
'interface_rest.py', 'interface_rest.py',
'mempool_spend_coinbase.py', 'mempool_spend_coinbase.py',
'mempool_reorg.py', 'mempool_reorg.py',