Skip to content

Commit 2fa85eb

Browse files
committed
add rpc_misc.py, mv test getmemoryinfo, add test mallocinfo
1 parent 4b6673d commit 2fa85eb

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

test/functional/rpc_misc.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
'wallet_txn_clone.py',
113113
'wallet_txn_clone.py --segwit',
114114
'rpc_getchaintips.py',
115+
'rpc_misc.py',
115116
'interface_rest.py',
116117
'mempool_spend_coinbase.py',
117118
'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,
@@ -85,13 +84,8 @@ def run_test(self):
8584
assert_equal(txout['value'], 50)
8685

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

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

0 commit comments

Comments
 (0)