File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed
Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 3232 - name : Run unit tests
3333 run :
3434 make test-unit
35+ - name : Run unit tests with bounded parser cache
36+ run :
37+ make test-cache-size-bound
3538 - name : Run integration tests
3639 run :
3740 make test-integration
Original file line number Diff line number Diff line change @@ -47,6 +47,11 @@ test-unit: venv/bin/activate $(UNIT_TESTS)
4747 . $< && python3 -m unittest $(UNIT_TESTS )
4848test : test-unit
4949
50+ .PHONY : test-cache-size-bound
51+ test-cache-size-bound : venv/bin/activate $(UNIT_TESTS )
52+ PYDEVICETREE_CACHE_SIZE_BOUND=128 . $< && python3 -m unittest $(UNIT_TESTS )
53+ test : test-cache-size-bound
54+
5055INTEGRATION_TESTS = tests/test_full_trees.py
5156
5257.PHONY : test-integration
Original file line number Diff line number Diff line change 22# Copyright (c) 2019 SiFive Inc.
33# SPDX-License-Identifier: Apache-2.0
44
5+ import os
6+ import sys
7+
58import pyparsing as p # type: ignore
69
7- p .ParserElement .enablePackrat ()
10+ ENV_CACHE_OPTION = "PYDEVICETREE_CACHE_SIZE_BOUND"
11+
12+ cache_bound = None
13+ if ENV_CACHE_OPTION in os .environ :
14+ option = os .environ [ENV_CACHE_OPTION ]
15+ if option != "None" :
16+ try :
17+ cache_bound = int (option )
18+ except ValueError :
19+ print ("%s requires a valid integer" % ENV_CACHE_OPTION , file = sys .stderr )
20+ p .ParserElement .enablePackrat (cache_bound )
821
922node_name = p .Word (p .alphanums + ",.-+_" ) ^ p .Literal ("/" )
1023integer = p .pyparsing_common .integer ^ (p .Literal ("0x" ).suppress () + p .pyparsing_common .hex_integer )
5972devicetree .ignore ("//" + p .SkipTo (p .lineEnd ))
6073
6174if __name__ == "__main__" :
62- import sys
6375 if len (sys .argv ) > 1 :
6476 devicetree .parseFile (sys .argv [1 ]).pprint ()
You can’t perform that action at this time.
0 commit comments