-
Notifications
You must be signed in to change notification settings - Fork 2
/
instantiate
executable file
·51 lines (38 loc) · 1.01 KB
/
instantiate
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
#!/usr/bin/python3
import argparse
from string import Template
MAIN = Template('''#include "lib/syslib.h"
#include "lib/printf.h"
${defines}
int main()
{
int res;
${uses}
printf("passed\\n");
return 0;
}
''')
DEFINE = Template('int __${name}();')
USE = Template('''
res = __${name}();
if (res) {
printf("failed in ${path}: %d\\n", res);
return -1;
}''')
parser = argparse.ArgumentParser()
parser.add_argument('-o', help='output file')
parser.add_argument('case', nargs='*', help='test case')
if __name__ == "__main__":
args = parser.parse_args()
cases = []
for path in args.case:
name = path.replace('/', '_').replace('.', '_')
cases.append((path, name))
defines = '\n'.join(DEFINE.substitute(name=n) for _, n in cases)
uses = '\n'.join(USE.substitute(name=n, path=p) for p, n in cases)
text = MAIN.substitute(defines=defines, uses=uses)
if args.o:
with open(args.o, 'w') as f:
f.write(text)
else:
print(text)