-
Notifications
You must be signed in to change notification settings - Fork 7
/
HACKING
208 lines (136 loc) · 4.96 KB
/
HACKING
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
Create development environment
------------------------------
Defaults to Python 3.
make virtualenv
make develop
make venv=/usr/tce/packages/python/python-3.7.2/bin/virtualenv virtualenv
make develop
pythondevmode
-------------
If this environment variable is set to a non-empty string, enable
Python Development Mode, introducing additional runtime checks that
are too expensive to be enabled by default. New in version 3.7.
setenv PYTHONDEVMODE 1
Parse test
----------
Parse some strings in ``tests/check_decl.py`` and compare to reference
in ``tests/check-decl.output``.
The parse trees are compared.
make test-decl
make test-decl-diff
make test-decl-replace
Run unittest
------------
make test
The tests are in the ``tests`` directory.
Run a single unittest:
../build/temp.linux-x86_64-3.7/venv/bin/python test_declast.py CheckParse.test_inheritance
Running a single Python unit test.
# Use the Python in the virtual environment
setenv WORK .../build/temp.linux-x86_64-3.7
setenv PYTHONEXE $WORK/venv/bin/python
cd tests
$PYTHONEXE -m unittest test_ast.CheckAst.test_d_generate1
# Run a regression test
setenv PYTHONPATH $WORK/run/struct-class-c/python
cd regression/run/struct-class-c/python
$PYTHONEXE -m unittest test.Struct.test_Arrays1
Regression tests
----------------
make do-test
Run the script test/do-test.py over some yaml files.
The output is saved in build/temp.linux-x86_64-3.7/regression
Update fiducials
make do-test-replace [ do-test-args=tutorial ]
Running a single test
make do-test do-test-args=tutorial
Running a test manually (with pdb).
Run the test via do-test. Extract run line from test.log
cd $WORK/build/temp.linux-x86_64-3.7/regression/classes
$WORK/build/temp.linux-x86_64-3.7/venv/bin/shroud ... $WORK/regression/input/classes.yaml
Test generated code
-------------------
make test-all
Compile the generated code (after do-test-replace) and run some unit
tests. These tests are in tests/run and contains a small library
which is wrapped by the corresponding yaml file
(i.e. tests/tutorial.yaml wraps run/tutorial)
``regression/run/Makfile`` is top level makefile.
``regression/run/default.mk`` has compiler flags.
Compile a single test
fortran-XXX compile wrappers for XXX.yaml
test-fortran-XXX run test for XXX.yaml
test-fortran All Fortran tests
test-cfi Fortran tests with C-Fortran-Interface
py-XXX compile module for XXX.yaml
test-python-XXX run Python test for XXX.yaml
test-python All Python tests
Adding a regression test
------------------------
* Add a file ``regression/input/newtest.yaml``.
* Run the test ``make do-test do-test-args=newtest``
* Look for errors in ``$(tempdir)/regression/log.test``
``make print-tempdir``.
* Add a call to TestDesc in ``regression/do-test.py`` to run *newtest*.
* ``mkdir regression/run/newtest``
* Create files ``Makefile``, ``newtest.cpp`` and ``newtest.hpp``
* Add to variable *fortran-test-list-std* in
``regression/run/Makefile`` to run as part of ``test-all`` target.
Try ``make -n test-fortran-newtest`` to see commands which will be
run.
Several tests are run with language=c and c++. To accomplish this,
the run/pkg files have the .c suffix. The sync-cxx target copies the
files to another directory with a .cpp suffix. This directory is added
to the VPATH. For the Python tests, there is an explicit run to force
the use of CXX. The VPATH finds both the C and C++ files since they
have the same stem.
reference counting
------------------
``Python-3.9.12/Misc/valgrind-python.supp``
```
valgrind --tool=memcheck --suppressions=valgrind-python.supp \
python -E -tt ./my_python_script.py
```
Build Python with ``--with-address-sanitizer --with-pydebug``
file dependency
---------------
main.py
wrapX.py generate.py
fcfmt.py metaattrs.py
ast.py
declast.py declstr.py
whelpers.py
typemap.py statements.py todict.py
util.py visitor.py
error.py # no dependencies
metadata.py
Error with template: 'call SHROUD_copy_array_{cxx_T}({c_var_context}, {f_var}, size({f_var},kind=C_SIZE_T))'
can be debugged by changing util.wformat to remove comment to provide a backtrace.
adding a type
-------------
typemap.py
ast.py LibraryNode.create_std_names()
add to namespace
declast.py get_canonical_typemap()
Convert 'long int' into 'long'
formatting generated code
-------------------------
Always use `{nullptr}` instead of `NULL`. Helps C++.
error checking
--------------
Write a `#error` line instead of generating bad code so the
compiler will point out the error.
debugging
---------
```
import yaml
print(yaml.dump(cf_tree, default_flow_style=False))
import pprint
pp = pprint.PrettyPrinter(indent=4)
pp.pprint( dict or tuple )
```
import pdb; pdb.set_trace()
% yes c | python ... >&! out
Answer 'c' to all pdb prompts.
To start pdb on an exception, uncomment line in main.py
#sys.excepthook = info