Skip to content

Commit f9dbb31

Browse files
author
MarcoFalke
committed
Merge #15485: add rpc_misc.py, mv test getmemoryinfo, add test mallocinfo
f13ad1c modify test for memory locked in case locking pages failed at some point (Adam Jonas) 2fa85eb 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
2 parents dc251de + f13ad1c commit f9dbb31

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

test/functional/rpc_misc.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
assert_greater_than_or_equal,
14+
)
15+
16+
from test_framework.authproxy import JSONRPCException
17+
18+
19+
class RpcMiscTest(BitcoinTestFramework):
20+
def set_test_params(self):
21+
self.num_nodes = 1
22+
23+
def run_test(self):
24+
node = self.nodes[0]
25+
26+
self.log.info("test getmemoryinfo")
27+
memory = node.getmemoryinfo()['locked']
28+
assert_greater_than(memory['used'], 0)
29+
assert_greater_than(memory['free'], 0)
30+
assert_greater_than(memory['total'], 0)
31+
# assert_greater_than_or_equal() for locked in case locking pages failed at some point
32+
assert_greater_than_or_equal(memory['locked'], 0)
33+
assert_greater_than(memory['chunks_used'], 0)
34+
assert_greater_than(memory['chunks_free'], 0)
35+
assert_equal(memory['used'] + memory['free'], memory['total'])
36+
37+
self.log.info("test mallocinfo")
38+
try:
39+
mallocinfo = node.getmemoryinfo(mode="mallocinfo")
40+
self.log.info('getmemoryinfo(mode="mallocinfo") call succeeded')
41+
tree = ET.fromstring(mallocinfo)
42+
assert_equal(tree.tag, 'malloc')
43+
except JSONRPCException:
44+
self.log.info('getmemoryinfo(mode="mallocinfo") not available')
45+
assert_raises_rpc_error(-8, 'mallocinfo is only available when compiled with glibc 2.10+', node.getmemoryinfo, mode="mallocinfo")
46+
47+
assert_raises_rpc_error(-8, "unknown mode foobar", node.getmemoryinfo, mode="foobar")
48+
49+
if __name__ == '__main__':
50+
RpcMiscTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
'wallet_txn_clone.py',
111111
'wallet_txn_clone.py --segwit',
112112
'rpc_getchaintips.py',
113+
'rpc_misc.py',
113114
'interface_rest.py',
114115
'mempool_spend_coinbase.py',
115116
'mempool_reorg.py',

test/functional/wallet_basic.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
assert_array_result,
1212
assert_equal,
1313
assert_fee_amount,
14-
assert_greater_than,
1514
assert_raises_rpc_error,
1615
connect_nodes_bi,
1716
sync_blocks,
@@ -84,13 +83,8 @@ def run_test(self):
8483
assert_equal(txout['value'], 50)
8584

8685
# Send 21 BTC from 0 to 2 using sendtoaddress call.
87-
# Locked memory should increase to sign transactions
88-
self.log.info("test getmemoryinfo")
89-
memory_before = self.nodes[0].getmemoryinfo()
9086
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11)
9187
mempool_txid = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)
92-
memory_after = self.nodes[0].getmemoryinfo()
93-
assert_greater_than(memory_after['locked']['used'], memory_before['locked']['used'])
9488

9589
self.log.info("test gettxout (second part)")
9690
# utxo spent in mempool should be visible if you exclude mempool

0 commit comments

Comments
 (0)