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

Commit d2d1a3eb authored by Myles Watson's avatar Myles Watson Committed by Gerrit Code Review
Browse files

Merge "Remove unused osi_rand" into main

parents 0b4ec6dd 112b6996
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ cc_library_static {
        "src/hash_map_utils.cc",
        "src/list.cc",
        "src/mutex.cc",
        "src/osi.cc",
        "src/properties.cc",
        "src/reactor.cc",
        "src/ringbuffer.cc",
@@ -117,7 +116,6 @@ cc_test {
        "test/hash_map_utils_test.cc",
        "test/list_test.cc",
        "test/properties_test.cc",
        "test/rand_test.cc",
        "test/reactor_test.cc",
        "test/ringbuffer_test.cc",
        "test/stack_power_telemetry_test.cc",
+0 −2
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ static_library("osi") {
    "src/hash_map_utils.cc",
    "src/list.cc",
    "src/mutex.cc",
    "src/osi.cc",
    "src/properties.cc",
    "src/reactor.cc",
    "src/ringbuffer.cc",
@@ -76,7 +75,6 @@ if (use.test) {
      "test/hash_map_utils_test.cc",
      "test/list_test.cc",
      "test/properties_test.cc",
      "test/rand_test.cc",
      "test/reactor_test.cc",
      "test/ringbuffer_test.cc",
      "test/thread_test.cc",
+0 −6
Original line number Diff line number Diff line
@@ -46,12 +46,6 @@
#define PTR_TO_INT(p) ((int)((intptr_t)(p)))
#define INT_TO_PTR(i) ((void*)((intptr_t)(i)))

// Obtain a random number between 0 and INT_MAX inclusive.
// Taken from a system random source such as /dev/random.
// No guarantees of distribution are made.
// Effort is made for this to come from a real random source.
int osi_rand(void);

// Re-run |fn| system call until the system call doesn't cause EINTR.
#define OSI_NO_INTR(fn) \
  do {                  \

system/osi/src/osi.cc

deleted100644 → 0
+0 −54
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright 2016 Google, Inc.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

#define LOG_TAG "bt_osi_rand"

#include "osi/include/osi.h"

#include <bluetooth/log.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include "os/log.h"

#define RANDOM_PATH "/dev/urandom"

int osi_rand(void) {
  int rand;
  int rand_fd = open(RANDOM_PATH, O_RDONLY);

  if (rand_fd == INVALID_FD) {
    bluetooth::log::error("can't open rand fd {}: {}", RANDOM_PATH,
                          strerror(errno));
    bluetooth::log::assert_that(rand_fd != INVALID_FD,
                                "assert failed: rand_fd != INVALID_FD");
  }

  ssize_t read_bytes = read(rand_fd, &rand, sizeof(rand));
  close(rand_fd);

  bluetooth::log::assert_that(read_bytes == sizeof(rand),
                              "assert failed: read_bytes == sizeof(rand)");

  if (rand < 0) rand = -rand;

  return rand;
}

system/osi/test/rand_test.cc

deleted100644 → 0
+0 −15
Original line number Diff line number Diff line
#include <gtest/gtest.h>

#include "osi/include/osi.h"

class RandTest : public ::testing::Test {};

TEST_F(RandTest, test_rand) {
  // We can't guarantee any distribution
  // We'd like it to not crash though.
  for (int i = 0; i < 10; i++) {
    int x;
    x = osi_rand();
    EXPECT_TRUE(x >= 0);
  }
}
Loading