6161 'tools' , # Build the host tools (i.e. packetgen)
6262 'rust' , # Build only the rust components + copy artifacts to output dir
6363 'main' , # Build the main C++ codebase
64- 'test' , # Build and run the unit tests
64+ 'test' , # Run the unit tests
6565 'clean' , # Clean up output directory
6666 'all' , # All targets except test and clean
6767]
6868
69+ HOST_TESTS = [
70+ 'bluetooth_test_common' ,
71+ 'bluetoothtbd_test' ,
72+ 'net_test_avrcp' ,
73+ 'net_test_btcore' ,
74+ 'net_test_types' ,
75+ 'net_test_btm_iso' ,
76+ 'net_test_btpackets' ,
77+ ]
78+
6979
7080class UseFlags ():
7181
@@ -110,6 +120,7 @@ def __init__(self, args):
110120 self .jobs = self .args .jobs
111121 if not self .jobs :
112122 self .jobs = multiprocessing .cpu_count ()
123+ print ("Number of jobs = {}" .format (self .jobs ))
113124
114125 # Normalize all directories
115126 self .output_dir = os .path .abspath (self .args .output )
@@ -123,7 +134,13 @@ def __init__(self, args):
123134 if hasattr (self .args , 'target' ) and self .args .target :
124135 self .target = self .args .target
125136
126- self .use = UseFlags (self .args .use if self .args .use else [])
137+ target_use = self .args .use if self .args .use else []
138+
139+ # Unless set, always build test code
140+ if not self .args .notest :
141+ target_use .append ('test' )
142+
143+ self .use = UseFlags (target_use )
127144
128145 # Validate platform directory
129146 assert os .path .isdir (self .platform_dir ), 'Platform dir does not exist'
@@ -137,6 +154,18 @@ def __init__(self, args):
137154
138155 self .configure_environ ()
139156
157+ def _generate_rustflags (self ):
158+ """ Rustflags to include for the build.
159+ """
160+ rust_flags = [
161+ '-L' ,
162+ '{}/out/Default/' .format (self .output_dir ),
163+ '-C' ,
164+ 'link-arg=-Wl,--allow-multiple-definition' ,
165+ ]
166+
167+ return ' ' .join (rust_flags )
168+
140169 def configure_environ (self ):
141170 """ Configure environment variables for GN and Cargo.
142171 """
@@ -150,6 +179,7 @@ def configure_environ(self):
150179 # Configure Rust env variables
151180 self .env ['CARGO_TARGET_DIR' ] = self .output_dir
152181 self .env ['CARGO_HOME' ] = os .path .join (self .output_dir , 'cargo_home' )
182+ self .env ['RUSTFLAGS' ] = self ._generate_rustflags ()
153183
154184 # Configure some GN variables
155185 if self .use_board :
@@ -364,7 +394,15 @@ def _target_main(self):
364394 def _target_test (self ):
365395 """ Runs the host tests.
366396 """
367- raise Exception ('Not yet implemented' )
397+ # Rust tests first
398+ self .run_command ('test' , ['cargo' , 'test' ], cwd = os .path .join (self .platform_dir , 'bt' ), env = self .env )
399+
400+ # Host tests second based on host test list
401+ for t in HOST_TESTS :
402+ self .run_command (
403+ 'test' , [os .path .join (self .output_dir , 'out/Default' , t )],
404+ cwd = os .path .join (self .output_dir ),
405+ env = self .env )
368406
369407 def _target_clean (self ):
370408 """ Delete the output directory entirely.
@@ -393,8 +431,6 @@ def build(self):
393431 elif self .target == 'main' :
394432 self ._target_main ()
395433 elif self .target == 'test' :
396- self .use .set_flag ('test' )
397- self ._target_all ()
398434 self ._target_test ()
399435 elif self .target == 'clean' :
400436 self ._target_clean ()
@@ -406,14 +442,15 @@ def build(self):
406442 parser = argparse .ArgumentParser (description = 'Simple build for host.' )
407443 parser .add_argument ('--output' , help = 'Output directory for the build.' , required = True )
408444 parser .add_argument ('--platform-dir' , help = 'Directory where platform2 is staged.' , required = True )
409- parser .add_argument ('--clang' , help = 'Use clang compiler.' , default = False , action = " store_true" )
445+ parser .add_argument ('--clang' , help = 'Use clang compiler.' , default = False , action = ' store_true' )
410446 parser .add_argument ('--use' , help = 'Set a specific use flag.' )
447+ parser .add_argument ('--notest' , help = "Don't compile test code." , default = False , action = 'store_true' )
411448 parser .add_argument ('--target' , help = 'Run specific build target' )
412449 parser .add_argument ('--sysroot' , help = 'Set a specific sysroot path' , default = '/' )
413450 parser .add_argument ('--libdir' , help = 'Libdir - default = usr/lib64' , default = 'usr/lib64' )
414451 parser .add_argument ('--use-board' , help = 'Use a built x86 board for dependencies. Provide path.' )
415452 parser .add_argument ('--jobs' , help = 'Number of jobs to run' , default = 0 , type = int )
416- parser .add_argument ('--vendored-rust' , help = 'Use vendored rust crates' , default = False , action = " store_true" )
453+ parser .add_argument ('--vendored-rust' , help = 'Use vendored rust crates' , default = False , action = ' store_true' )
417454 parser .add_argument ('--verbose' , help = 'Verbose logs for build.' )
418455
419456 args = parser .parse_args ()
0 commit comments