Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b04e6a92 authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi
Browse files

floss: Recover via reset after multiple starts

If we attempt to start multiple times and are unsuccessful, try using
the reset mechanism to recover instead of trying to start.

This also changes the condition for attempting a restart/reset from
depending on device presence. On Linux, when we bind the socket as
userchannel, the device presence is false (index is removed). It makes
more sense to attempt retry if we want the device enabled.

Bug: 236709385
Tag: #floss
Test: Enable/disable cycles to bad state and trigger reset.
Change-Id: I8a9003385f8fcb6d1ac237670087d34ed9590048
parent 1edf39ec
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -437,7 +437,8 @@ class HostBuild():
    def _target_rootcanal(self):
        """ Build rust artifacts for RootCanal in an already prepared environment.
        """
        self.run_command('rust', ['cargo', 'build'], cwd=os.path.join(self.platform_dir, 'bt/tools/rootcanal'), env=self.env)
        self.run_command(
            'rust', ['cargo', 'build'], cwd=os.path.join(self.platform_dir, 'bt/tools/rootcanal'), env=self.env)

    def _target_main(self):
        """ Build the main GN artifacts in an already prepared environment.
@@ -450,7 +451,7 @@ class HostBuild():
        # Rust tests first
        rust_test_cmd = ['cargo', 'test']
        if self.args.test_name:
            rust_test_cmd = rust_test_cmd + [self.args.test_name]
            rust_test_cmd = rust_test_cmd + [self.args.test_name, "--", "--test-threads=1", "--nocapture"]

        self.run_command('test', rust_test_cmd, cwd=os.path.join(self.platform_dir, 'bt'), env=self.env)
        self.run_command('test', rust_test_cmd, cwd=os.path.join(self.platform_dir, 'bt/tools/rootcanal'), env=self.env)
+6 −0
Original line number Diff line number Diff line
@@ -139,6 +139,12 @@ pub fn list_pid_files(pid_dir: &str) -> Vec<String> {
    }
}

/// Calls the reset sysfs entry for an hci device. Returns True if the write succeeds.
pub fn reset_hci_device(hci: i32) -> bool {
    let path = format!("/sys/class/bluetooth/hci{}/reset", hci);
    std::fs::write(path, "1").is_ok()
}

#[cfg(test)]
mod tests {
    use super::*;
+164 −61

File changed.

Preview size limit exceeded, changes collapsed.