55
66from pixie .tests .support import PixieTestCase
77
8+ example_config = """
9+ {
10+ "translation_unit": [
11+ {
12+ "name": "llvm_foo_double_double",
13+ "source": "int _Z3fooPdS_(double* a, double* b, double* c) {
14+ *c = *a + *b;
15+ }"
16+ },
17+ {
18+ "name": "llvm_foo_float_float",
19+ "path": "llvm_foo_float_float.c",
20+ "extra_flags": []
21+ },
22+ ],
23+ "export_config": {
24+ "symbols": [
25+ {
26+ "python_name": "foo",
27+ "symbol_name": "_Z3fooPdS_",
28+ "signature": "void(double*, double*, double*)"
29+ }
30+ ]
31+ }
32+ }"""
33+
834
935class TestCLI (PixieTestCase ):
1036
@@ -28,6 +54,41 @@ def test_pixie_cc_basic(self):
2854 self .assertEqual (files [0 ], cfile_name )
2955 self .assertTrue (files [1 ].startswith (testlib_name ))
3056
57+ def test_pixie_cc_config (self ):
58+ cfile_name = "test.c"
59+ cfile_source = textwrap .dedent (
60+ """
61+ int f(x) {
62+ return x + 1;
63+ }
64+ """ )
65+ json_file_name = "config.json"
66+ json_file_source = example_config
67+ tu_cfile_name = "llvm_foo_float_float.c"
68+ tu_cfile_source = textwrap .dedent (
69+ """
70+ int foo(float* a, float* b, float* c) { *c = *a + *b; }
71+ """ )
72+ with TemporaryDirectory (prefix = self .tmpdir .name ) as tmpdir :
73+ cfile_path = os .path .join (tmpdir , cfile_name )
74+ with open (cfile_path , "wt" ) as f :
75+ f .write (cfile_source )
76+ json_file_path = os .path .join (tmpdir , json_file_name )
77+ with open (json_file_path , "wt" ) as f :
78+ f .write (json_file_source )
79+ with open (os .path .join (tmpdir , tu_cfile_name ), "wt" ) as f :
80+ f .write (tu_cfile_source )
81+ testlib_name = "testclib"
82+ command = ["pixie-cc" , cfile_name , "-g" , "-O0" , "-o" ,
83+ testlib_name , "-C" , json_file_name ]
84+ subprocess .run (command , check = True , cwd = tmpdir )
85+ files = sorted (os .listdir (tmpdir ))
86+ self .assertEqual (4 , len (files ))
87+ self .assertEqual (files [0 ], json_file_name )
88+ self .assertEqual (files [1 ], tu_cfile_name )
89+ self .assertEqual (files [2 ], cfile_name )
90+ self .assertTrue (files [3 ].startswith (testlib_name ))
91+
3192 def test_pixie_cc_two_files (self ):
3293 cfile1_name = "test1.c"
3394 cfile1_source = textwrap .dedent (
0 commit comments