OSDN Git Service

Additional changes for Linux build
authorAbhishek Pandit-Subedi <abhishekpandit@google.com>
Sat, 10 Apr 2021 00:41:07 +0000 (00:41 +0000)
committerAbhishek Pandit-Subedi <abhishekpandit@google.com>
Fri, 23 Apr 2021 18:34:02 +0000 (18:34 +0000)
While building for Linux on cloudtop, a few more problems were
identified in the build. There were a couple of missing #include and
some incomplete struct definitions in btm_int_types.h. Also put
statslog.h behind an #ifdef OS_ANDROID.

Bug: 184975659
Tag: #floss
Test: atest --host bluetooth_test_gd
Change-Id: Ic2272a3acfa66259e692db280b48b4ddadff2171

16 files changed:
BUILD.gn
btif/src/btif_bqr.cc
build.py
gd/BUILD.gn
gd/common/BUILD.gn
gd/common/circular_buffer.h
gd/common/strings.h
gd/hal/BUILD.gn
gd/os/BUILD.gn
gd/security/ecdh_keys.h
main/shim/hci_layer.cc
osi/include/compat.h
osi/src/compat.cc
service/BUILD.gn
stack/btm/btm_int_types.h
types/BUILD.gn

index 109bf71..9d2f4c7 100644 (file)
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -104,7 +104,9 @@ config("target_defaults") {
     "-Wno-final-dtor-non-final-class",
   ]
 
-  cflags_cc = [ "-std=c++17" ]
+  cflags_cc = [
+    "-std=c++17",
+  ]
 
   defines = [
     "HAS_NO_BDROID_BUILDCFG",
@@ -116,7 +118,7 @@ config("target_defaults") {
 
   # If not configured as a dynamic library, default to static library
   if (!(defined(use.bt_dynlib) && use.bt_dynlib)) {
-    defines = [
+    defines += [
       "STATIC_LIBBLUETOOTH",
     ]
   }
index 7896ea2..c437b2c 100644 (file)
@@ -17,7 +17,9 @@
 #include <base/logging.h>
 #include <errno.h>
 #include <fcntl.h>
+#ifdef OS_ANDROID
 #include <statslog.h>
+#endif
 #include <stdio.h>
 #include <sys/stat.h>
 
@@ -395,6 +397,7 @@ void AddLinkQualityEventToQueue(uint8_t length, uint8_t* p_link_quality_event) {
       p_bqr_event->bqr_link_quality_event_.no_rx_count,
       p_bqr_event->bqr_link_quality_event_.nak_count);
 
+#ifdef OS_ANDROID
   int ret = android::util::stats_write(
       android::util::BLUETOOTH_QUALITY_REPORT_REPORTED,
       p_bqr_event->bqr_link_quality_event_.quality_report_id,
@@ -420,6 +423,9 @@ void AddLinkQualityEventToQueue(uint8_t length, uint8_t* p_link_quality_event) {
     LOG(WARNING) << __func__ << ": failed to log BQR event to statsd, error "
                  << ret;
   }
+#else
+  // TODO(abps) Metrics for non-Android build
+#endif
   kpBqrEventQueue->Enqueue(p_bqr_event.release());
 }
 
index 131cbb2..3e79bff 100755 (executable)
--- a/build.py
+++ b/build.py
@@ -61,11 +61,21 @@ VALID_TARGETS = [
     'tools',  # Build the host tools (i.e. packetgen)
     'rust',  # Build only the rust components + copy artifacts to output dir
     'main',  # Build the main C++ codebase
-    'test',  # Build and run the unit tests
+    'test',  # Run the unit tests
     'clean',  # Clean up output directory
     'all',  # All targets except test and clean
 ]
 
+HOST_TESTS = [
+    'bluetooth_test_common',
+    'bluetoothtbd_test',
+    'net_test_avrcp',
+    'net_test_btcore',
+    'net_test_types',
+    'net_test_btm_iso',
+    'net_test_btpackets',
+]
+
 
 class UseFlags():
 
@@ -110,6 +120,7 @@ class HostBuild():
         self.jobs = self.args.jobs
         if not self.jobs:
             self.jobs = multiprocessing.cpu_count()
+            print("Number of jobs = {}".format(self.jobs))
 
         # Normalize all directories
         self.output_dir = os.path.abspath(self.args.output)
@@ -123,7 +134,13 @@ class HostBuild():
         if hasattr(self.args, 'target') and self.args.target:
             self.target = self.args.target
 
-        self.use = UseFlags(self.args.use if self.args.use else [])
+        target_use = self.args.use if self.args.use else []
+
+        # Unless set, always build test code
+        if not self.args.notest:
+            target_use.append('test')
+
+        self.use = UseFlags(target_use)
 
         # Validate platform directory
         assert os.path.isdir(self.platform_dir), 'Platform dir does not exist'
@@ -137,6 +154,18 @@ class HostBuild():
 
         self.configure_environ()
 
+    def _generate_rustflags(self):
+        """ Rustflags to include for the build.
+      """
+        rust_flags = [
+            '-L',
+            '{}/out/Default/'.format(self.output_dir),
+            '-C',
+            'link-arg=-Wl,--allow-multiple-definition',
+        ]
+
+        return ' '.join(rust_flags)
+
     def configure_environ(self):
         """ Configure environment variables for GN and Cargo.
         """
@@ -150,6 +179,7 @@ class HostBuild():
         # Configure Rust env variables
         self.env['CARGO_TARGET_DIR'] = self.output_dir
         self.env['CARGO_HOME'] = os.path.join(self.output_dir, 'cargo_home')
+        self.env['RUSTFLAGS'] = self._generate_rustflags()
 
         # Configure some GN variables
         if self.use_board:
@@ -364,7 +394,15 @@ class HostBuild():
     def _target_test(self):
         """ Runs the host tests.
         """
-        raise Exception('Not yet implemented')
+        # Rust tests first
+        self.run_command('test', ['cargo', 'test'], cwd=os.path.join(self.platform_dir, 'bt'), env=self.env)
+
+        # Host tests second based on host test list
+        for t in HOST_TESTS:
+            self.run_command(
+                'test', [os.path.join(self.output_dir, 'out/Default', t)],
+                cwd=os.path.join(self.output_dir),
+                env=self.env)
 
     def _target_clean(self):
         """ Delete the output directory entirely.
@@ -393,8 +431,6 @@ class HostBuild():
         elif self.target == 'main':
             self._target_main()
         elif self.target == 'test':
-            self.use.set_flag('test')
-            self._target_all()
             self._target_test()
         elif self.target == 'clean':
             self._target_clean()
@@ -406,14 +442,15 @@ if __name__ == '__main__':
     parser = argparse.ArgumentParser(description='Simple build for host.')
     parser.add_argument('--output', help='Output directory for the build.', required=True)
     parser.add_argument('--platform-dir', help='Directory where platform2 is staged.', required=True)
-    parser.add_argument('--clang', help='Use clang compiler.', default=False, action="store_true")
+    parser.add_argument('--clang', help='Use clang compiler.', default=False, action='store_true')
     parser.add_argument('--use', help='Set a specific use flag.')
+    parser.add_argument('--notest', help="Don't compile test code.", default=False, action='store_true')
     parser.add_argument('--target', help='Run specific build target')
     parser.add_argument('--sysroot', help='Set a specific sysroot path', default='/')
     parser.add_argument('--libdir', help='Libdir - default = usr/lib64', default='usr/lib64')
     parser.add_argument('--use-board', help='Use a built x86 board for dependencies. Provide path.')
     parser.add_argument('--jobs', help='Number of jobs to run', default=0, type=int)
-    parser.add_argument('--vendored-rust', help='Use vendored rust crates', default=False, action="store_true")
+    parser.add_argument('--vendored-rust', help='Use vendored rust crates', default=False, action='store_true')
     parser.add_argument('--verbose', help='Verbose logs for build.')
 
     args = parser.parse_args()
index 6abddb1..cd48264 100644 (file)
@@ -67,7 +67,7 @@ static_library("libbluetooth_gd") {
     "//bt/gd/crypto_toolbox:BluetoothCryptoToolboxSources",
     "//bt/gd/dumpsys:BluetoothDumpsysSources",
     "//bt/gd/hal:BluetoothHalSources",
-    "//bt/gd/hal:BluetoothHalSources_hci_rootcanal",
+    "//bt/gd/hal:BluetoothHalSources_hci_host",
     "//bt/gd/l2cap:BluetoothL2capSources",
     "//bt/gd/neighbor:BluetoothNeighborSources",
     "//bt/gd/rust/shim:libbluetooth_rust_interop",
index 536bfb7..fb4dad9 100644 (file)
@@ -17,7 +17,7 @@
 source_set("BluetoothCommonSources") {
   sources = [
     "init_flags.cc",
-    "metric_id_manager.cc"
+    "metric_id_manager.cc",
     "stop_watch.cc",
     "strings.cc",
   ]
@@ -25,6 +25,6 @@ source_set("BluetoothCommonSources") {
   configs += [ "//bt/gd:gd_defaults" ]
   deps = [
     "//bt/gd:gd_default_deps",
-    "//bt/third_party/proto_logging/stats:libbt-platform-protos"
+    "//bt:libbt-platform-protos-lite",
   ]
 }
index 1914fa0..46d6972 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <cstddef>
 #include <iterator>
+#include <memory>
 #include <mutex>
 #include <queue>
 
index a110cf4..c80d01e 100644 (file)
@@ -16,6 +16,7 @@
 
 #pragma once
 
+#include <limits.h>
 #include <string.h>
 #include <charconv>
 #include <iomanip>
index 1752241..9ed814a 100644 (file)
@@ -21,8 +21,8 @@ source_set("BluetoothHalSources") {
   deps = [ "//bt/gd:gd_default_deps" ]
 }
 
-source_set("BluetoothHalSources_hci_rootcanal") {
-  sources = [ "hci_hal_host_rootcanal.cc" ]
+source_set("BluetoothHalSources_hci_host") {
+  sources = [ "hci_hal_host.cc" ]
 
   configs += [ "//bt/gd:gd_defaults" ]
   deps = [ "//bt/gd:gd_default_deps" ]
index 84c9069..56ddc59 100644 (file)
@@ -20,6 +20,7 @@ source_set("BluetoothOsSources_linux") {
   ]
 
   configs += [ "//bt/gd:gd_defaults" ]
+  deps = [ "//bt:libbt-platform-protos-lite" ]
 }
 
 source_set("BluetoothOsSources_linux_generic") {
index 8ec25a8..f9c4302 100644 (file)
@@ -17,6 +17,7 @@
  ******************************************************************************/
 #pragma once
 
+#include <stdint.h>
 #include <array>
 
 namespace bluetooth {
index b273ddc..85612cb 100644 (file)
@@ -344,7 +344,7 @@ void OnTransmitPacketCommandComplete(command_complete_cb complete_callback,
                                      bluetooth::hci::CommandCompleteView view) {
   LOG_DEBUG("Received cmd complete for %s",
             bluetooth::hci::OpCodeText(view.GetCommandOpCode()).c_str());
-  std::vector<const uint8_t> data(view.begin(), view.end());
+  std::vector<uint8_t> data(view.begin(), view.end());
   BT_HDR* response = WrapPacketAndCopy(MSG_HC_TO_STACK_HCI_EVT, &view);
   complete_callback(response, context);
 }
index 95fe037..1d19a59 100644 (file)
@@ -26,7 +26,7 @@
 #include <unistd.h>
 
 /* Get thread identification. */
-pid_t gettid(void);
+pid_t gettid(void) throw();
 
 /* Copy src to string dst of size siz. */
 size_t strlcpy(char* dst, const char* src, size_t siz);
index 069964c..e5b41a5 100644 (file)
@@ -35,7 +35,7 @@
 #include "osi/include/osi.h"
 
 #if __GLIBC__
-pid_t gettid(void) { return syscall(SYS_gettid); }
+pid_t gettid(void) throw() { return syscall(SYS_gettid); }
 #endif
 
 /* These functions from bionic
index f4b4f09..64d0844 100644 (file)
@@ -63,6 +63,8 @@ source_set("service_linux_src") {
   sources = [
     "ipc/ipc_handler_linux.cc",
     "ipc/linux_ipc_host.cc",
+    "ipc/dbus/ipc_handler_dbus.cc",
+    "ipc/dbus/bluetooth_adapter.cc",
   ]
 
   deps = [
@@ -91,8 +93,6 @@ source_set("service") {
     "common/bluetooth/scan_settings.cc",
     "common/bluetooth/service.cc",
     "common/bluetooth/util/atomic_string.cc",
-    "ipc/dbus/bluetooth_adapter.cc",
-    "ipc/dbus/ipc_handler_dbus.cc",
   ]
 
   deps = [
@@ -155,6 +155,7 @@ if (use.test) {
     deps = [
       ":service_base_test_src",
       ":service_daemon_src",
+      ":service_linux_src",
       "//bt/service/common:libbluetooth_common",
     ]
 
index 6a6da3f..0622ddd 100644 (file)
@@ -126,7 +126,7 @@ typedef void(tBTM_BT_QUALITY_REPORT_RECEIVER)(uint8_t len, uint8_t* p_stream);
 
 /* Define the Device Management control structure
  */
-typedef struct {
+typedef struct tBTM_DEVCB {
   tBTM_VS_EVT_CB* p_vend_spec_cb[BTM_MAX_VSE_CALLBACKS]; /* Register for vendor
                                                             specific events  */
 
@@ -202,7 +202,7 @@ typedef struct {
   }
 } tBTM_DEVCB;
 
-typedef struct {
+typedef struct tBTM_CB {
   tBTM_CFG cfg; /* Device configuration */
 
   /*****************************************************
index 47604a9..08a47b6 100644 (file)
@@ -54,6 +54,13 @@ if (use.test) {
       "z",
     ]
 
+    # For some reason, this is required for host build. Otherwise, I get
+    # a complaint from gmock:
+    #   undefined reference to symbol 'pthread_getspecific@@GLIBC_2.2.5'
+    ldflags = [
+      "-lpthread"
+    ]
+
     deps = [
       ":types",
     ]