1
- # Copyright (C) 2019 Intel Corporation
1
+ # Copyright (C) 2019-2024 Intel Corporation
2
2
# SPDX-License-Identifier: BSD-3-Clause
3
3
4
- import unittest
5
4
import logging
6
- from codebasin import config , finder , preprocessor
5
+ import os
6
+ import unittest
7
+
8
+ from codebasin import finder , preprocessor
7
9
from codebasin .walkers .platform_mapper import PlatformMapper
8
10
9
- class TestExampleFile (unittest .TestCase ):
11
+
12
+ class TestLiterals (unittest .TestCase ):
10
13
"""
11
14
Simple test of C-style literal handling.
12
15
e.g. 0x0ULL, 0b11
@@ -16,21 +19,57 @@ def setUp(self):
16
19
self .rootdir = "./tests/literals/"
17
20
logging .getLogger ("codebasin" ).disabled = True
18
21
19
- self .expected_setmap = {frozenset ([' CPU' , ' GPU' ]): 9 }
22
+ self .expected_setmap = {frozenset ([" CPU" , " GPU" ]): 9 }
20
23
21
- def test_yaml (self ):
24
+ def test_literals (self ):
22
25
"""literals/literals.yaml"""
23
- codebase , configuration = config .load ("./tests/literals/literals.yaml" , self .rootdir )
26
+ codebase = {
27
+ "files" : [
28
+ os .path .realpath (os .path .join (self .rootdir , "main.cpp" )),
29
+ ],
30
+ "platforms" : ["CPU" , "GPU" ],
31
+ "exclude_files" : set (),
32
+ "exclude_patterns" : [],
33
+ "rootdir" : self .rootdir ,
34
+ }
35
+ configuration = {
36
+ "CPU" : [
37
+ {
38
+ "file" : codebase ["files" ][0 ],
39
+ "defines" : ["USE_CPU" ],
40
+ "include_paths" : [],
41
+ "include_files" : [],
42
+ },
43
+ ],
44
+ "GPU" : [
45
+ {
46
+ "file" : codebase ["files" ][0 ],
47
+ "defines" : ["USE_GPU" ],
48
+ "include_paths" : [],
49
+ "include_files" : [],
50
+ },
51
+ ],
52
+ }
24
53
state = finder .find (self .rootdir , codebase , configuration )
25
54
mapper = PlatformMapper (codebase )
26
55
setmap = mapper .walk (state )
27
- self .assertDictEqual (setmap , self .expected_setmap , "Mismatch in setmap" )
56
+ self .assertDictEqual (
57
+ setmap ,
58
+ self .expected_setmap ,
59
+ "Mismatch in setmap" ,
60
+ )
28
61
29
62
def test_strings (self ):
30
63
expected_str = r'"L + 2-2 \"\\\" \\n\""'
31
64
tokens = preprocessor .Lexer (expected_str ).tokenize ()
32
- expected = preprocessor .StringConstant ('Unknown' , 'Unknown' , False , r'L + 2-2 \"\\\" \\n\"' )
65
+ expected = preprocessor .StringConstant (
66
+ "Unknown" ,
67
+ "Unknown" ,
68
+ False ,
69
+ r"L + 2-2 \"\\\" \\n\"" ,
70
+ )
33
71
self .assertEqual (tokens [0 ].token , expected .token )
34
72
35
- if __name__ == '__main__' :
73
+
74
+ if __name__ == "__main__" :
36
75
unittest .main ()
0 commit comments