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 , platform
5
+ import os
6
+ import unittest
7
+
8
+ from codebasin import finder , platform , preprocessor
7
9
from codebasin .walkers .platform_mapper import PlatformMapper
8
10
9
- class TestExampleFile (unittest .TestCase ):
11
+
12
+ class TestOperators (unittest .TestCase ):
10
13
"""
11
14
Simple test of ability to recognize different operators when used
12
15
within directives
@@ -16,23 +19,54 @@ def setUp(self):
16
19
self .rootdir = "./tests/operators/"
17
20
logging .getLogger ("codebasin" ).disabled = True
18
21
19
- self .expected_setmap = {frozenset ([' CPU' , ' GPU' ]): 32 }
22
+ self .expected_setmap = {frozenset ([" CPU" , " GPU" ]): 32 }
20
23
21
- def test_yaml (self ):
24
+ def test_operators (self ):
22
25
"""operators/operators.yaml"""
23
- codebase , configuration = config .load ("./tests/operators/operators.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" : ["CPU" ],
40
+ "include_paths" : [],
41
+ "include_files" : [],
42
+ },
43
+ ],
44
+ "GPU" : [
45
+ {
46
+ "file" : codebase ["files" ][0 ],
47
+ "defines" : ["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_paths (self ):
30
- input_str = r' FUNCTION(looks/2like/a/path/with_/bad%%identifiers)'
63
+ input_str = r" FUNCTION(looks/2like/a/path/with_/bad%%identifiers)"
31
64
tokens = preprocessor .Lexer (input_str ).tokenize ()
32
65
p = platform .Platform ("Test" , self .rootdir )
33
66
macro = preprocessor .macro_from_definition_string ("FUNCTION(x)=#x" )
34
- p ._definitions = {macro .name : macro }
35
- exp = preprocessor .MacroExpander (p ).expand (tokens )
67
+ p ._definitions = {macro .name : macro }
68
+ _ = preprocessor .MacroExpander (p ).expand (tokens )
69
+
36
70
37
- if __name__ == ' __main__' :
71
+ if __name__ == " __main__" :
38
72
unittest .main ()
0 commit comments