Remove usage of CHECK_NOTNULL
We want to switch to absl logging instead of glog. gtest and ceres are
going there, and we already have absl as a dependency. ABSL doesn't
have CHECK_NOTNULL, and we can move things over in an easier to review
fashion.
Change-Id: Ifd9a11ec34a2357cec43f88dba015db9c28ed2cf
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/aos/events/epoll.cc b/aos/events/epoll.cc
index 61c346e..d5f5162 100644
--- a/aos/events/epoll.cc
+++ b/aos/events/epoll.cc
@@ -193,7 +193,9 @@
}
void EPoll::SetEvents(int fd, uint32_t events) {
- DoEpollCtl(CHECK_NOTNULL(GetEventData(fd)), events);
+ EventData *event_data;
+ CHECK((event_data = GetEventData(fd)) != nullptr);
+ DoEpollCtl(event_data, events);
}
// Removes fd from the event loop.
@@ -257,12 +259,14 @@
}
void EPoll::EnableEvents(int fd, uint32_t events) {
- EventData *const event_data = CHECK_NOTNULL(GetEventData(fd));
+ EventData *const event_data = GetEventData(fd);
+ CHECK(event_data != nullptr);
DoEpollCtl(event_data, event_data->events | events);
}
void EPoll::DisableEvents(int fd, uint32_t events) {
- EventData *const event_data = CHECK_NOTNULL(GetEventData(fd));
+ EventData *const event_data = GetEventData(fd);
+ CHECK(event_data != nullptr);
DoEpollCtl(event_data, event_data->events & ~events);
}
diff --git a/aos/events/event_loop.h b/aos/events/event_loop.h
index 389ea08..c8cf487 100644
--- a/aos/events/event_loop.h
+++ b/aos/events/event_loop.h
@@ -265,7 +265,8 @@
// Fetches the next message. Returns true if it fetched a new message. This
// method will only return messages sent after the Fetcher was created.
bool FetchNext() {
- const bool result = CHECK_NOTNULL(fetcher_)->FetchNext();
+ CHECK(fetcher_ != nullptr);
+ const bool result = fetcher_->FetchNext();
if (result) {
CheckChannelDataAlignment(fetcher_->context().data,
fetcher_->context().size);
@@ -277,7 +278,8 @@
// true. The data and buffer_index are the only pieces of the Context which
// are zeroed out. The function must be valid.
bool FetchNextIf(std::function<bool(const Context &)> fn) {
- const bool result = CHECK_NOTNULL(fetcher_)->FetchNextIf(std::move(fn));
+ CHECK(fetcher_ != nullptr);
+ const bool result = fetcher_->FetchNextIf(std::move(fn));
if (result) {
CheckChannelDataAlignment(fetcher_->context().data,
fetcher_->context().size);
@@ -289,7 +291,8 @@
// This will return the latest message regardless of if it was sent before or
// after the fetcher was created.
bool Fetch() {
- const bool result = CHECK_NOTNULL(fetcher_)->Fetch();
+ CHECK(fetcher_ != nullptr);
+ const bool result = fetcher_->Fetch();
if (result) {
CheckChannelDataAlignment(fetcher_->context().data,
fetcher_->context().size);
@@ -301,7 +304,8 @@
// new message. This will return the latest message regardless of if it was
// sent before or after the fetcher was created. The function must be valid.
bool FetchIf(std::function<bool(const Context &)> fn) {
- const bool result = CHECK_NOTNULL(fetcher_)->FetchIf(std::move(fn));
+ CHECK(fetcher_ != nullptr);
+ const bool result = fetcher_->FetchIf(std::move(fn));
if (result) {
CheckChannelDataAlignment(fetcher_->context().data,
fetcher_->context().size);
@@ -312,18 +316,25 @@
// Returns a pointer to the contained flatbuffer, or nullptr if there is no
// available message.
const T *get() const {
- return CHECK_NOTNULL(fetcher_)->context().data != nullptr
+ CHECK(fetcher_ != nullptr);
+ return fetcher_->context().data != nullptr
? flatbuffers::GetRoot<T>(
reinterpret_cast<const char *>(fetcher_->context().data))
: nullptr;
}
// Returns the channel this fetcher uses
- const Channel *channel() const { return CHECK_NOTNULL(fetcher_)->channel(); }
+ const Channel *channel() const {
+ CHECK(fetcher_ != nullptr);
+ return fetcher_->channel();
+ }
// Returns the context holding timestamps and other metadata about the
// message.
- const Context &context() const { return CHECK_NOTNULL(fetcher_)->context(); }
+ const Context &context() const {
+ CHECK(fetcher_ != nullptr);
+ return fetcher_->context();
+ }
const T &operator*() const { return *get(); }
const T *operator->() const { return get(); }
@@ -366,7 +377,9 @@
class StaticBuilder {
public:
StaticBuilder(RawSender *sender, fbs::SpanAllocator *allocator)
- : builder_(allocator), sender_(CHECK_NOTNULL(sender)) {}
+ : builder_(allocator), sender_(sender) {
+ CHECK(sender != nullptr);
+ }
StaticBuilder(const StaticBuilder &) = delete;
StaticBuilder(StaticBuilder &&) = default;
@@ -408,7 +421,8 @@
Builder(RawSender *sender, ChannelPreallocatedAllocator *allocator)
: fbb_(allocator->size(), allocator),
allocator_(allocator),
- sender_(CHECK_NOTNULL(sender)) {
+ sender_(sender) {
+ CHECK(sender != nullptr);
CheckChannelDataAlignment(allocator->data(), allocator->size());
fbb_.ForceDefaults(true);
}
@@ -480,12 +494,16 @@
// Equivalent to RawSender::CheckOk
void CheckOk(const RawSender::Error err) {
- CHECK_NOTNULL(sender_)->CheckOk(err);
+ CHECK(sender_ != nullptr);
+ sender_->CheckOk(err);
};
// Returns the name of the underlying queue, if valid. You must check valid()
// first.
- const Channel *channel() const { return CHECK_NOTNULL(sender_)->channel(); }
+ const Channel *channel() const {
+ CHECK(sender_ != nullptr);
+ return sender_->channel();
+ }
// Returns true if the Sender is a valid Sender. If you, e.g., are using
// TryMakeSender, then you must check valid() before attempting to use the
@@ -496,19 +514,25 @@
// Returns the time_points that the last message was sent at.
aos::monotonic_clock::time_point monotonic_sent_time() const {
- return CHECK_NOTNULL(sender_)->monotonic_sent_time();
+ CHECK(sender_ != nullptr);
+ return sender_->monotonic_sent_time();
}
aos::realtime_clock::time_point realtime_sent_time() const {
- return CHECK_NOTNULL(sender_)->realtime_sent_time();
+ CHECK(sender_ != nullptr);
+ return sender_->realtime_sent_time();
}
// Returns the queue index that this was sent with.
uint32_t sent_queue_index() const {
- return CHECK_NOTNULL(sender_)->sent_queue_index();
+ CHECK(sender_ != nullptr);
+ return sender_->sent_queue_index();
}
// Returns the buffer index which MakeBuilder() will expose access to. This is
// the buffer the caller can fill out.
- int buffer_index() const { return CHECK_NOTNULL(sender_)->buffer_index(); }
+ int buffer_index() const {
+ CHECK(sender_ != nullptr);
+ return sender_->buffer_index();
+ }
// Convenience function to build and send a message created from JSON
// representation.
diff --git a/aos/events/logging/buffer_encoder_param_test.cc b/aos/events/logging/buffer_encoder_param_test.cc
index 7c9bb4b..f6bc3b6 100644
--- a/aos/events/logging/buffer_encoder_param_test.cc
+++ b/aos/events/logging/buffer_encoder_param_test.cc
@@ -2,6 +2,8 @@
#include "gmock/gmock.h"
+#include "aos/testing/tmpdir.h"
+
namespace aos::logger::testing {
// Verifies that Clear affects the sizes as expected.
@@ -39,8 +41,8 @@
// it comes back out the same.
TEST_P(BufferEncoderTest, RoundTrip) {
std::uniform_int_distribution<int> quantity_distribution(20, 60);
- const char *const test_dir = CHECK_NOTNULL(getenv("TEST_TMPDIR"));
- const std::string file_path = std::string(test_dir) + "/foo";
+ const std::string test_dir = aos::testing::TestTmpDir();
+ const std::string file_path = test_dir + "/foo";
std::vector<std::vector<uint8_t>> encoded_buffers;
{
diff --git a/aos/events/logging/buffer_encoder_test.cc b/aos/events/logging/buffer_encoder_test.cc
index 7dda300..127fb4f 100644
--- a/aos/events/logging/buffer_encoder_test.cc
+++ b/aos/events/logging/buffer_encoder_test.cc
@@ -9,6 +9,7 @@
#include "gtest/gtest.h"
#include "aos/events/logging/buffer_encoder_param_test.h"
+#include "aos/testing/tmpdir.h"
namespace aos::logger::testing {
@@ -44,8 +45,7 @@
TEST(DummyDecoderTest, ReadsIntoExactBuffer) {
static const std::string kTestString{"Just some random words."};
- const char *const test_dir = CHECK_NOTNULL(getenv("TEST_TMPDIR"));
- const std::string file_path = std::string(test_dir) + "/foo";
+ const std::string file_path = aos::testing::TestTmpDir() + "/foo";
std::ofstream(file_path, std::ios::binary) << kTestString;
// Read the contents of the file into the buffer.
@@ -65,8 +65,7 @@
TEST(DummyDecoderTest, ReadsIntoLargerBuffer) {
static const std::string kTestString{"Just some random words."};
- const char *const test_dir = CHECK_NOTNULL(getenv("TEST_TMPDIR"));
- const std::string file_path = std::string(test_dir) + "/foo";
+ const std::string file_path = aos::testing::TestTmpDir() + "/foo";
std::ofstream(file_path, std::ios::binary) << kTestString;
DummyDecoder dummy_decoder(file_path.c_str());
@@ -84,8 +83,7 @@
TEST(DummyDecoderTest, ReadsRepeatedlyIntoSmallerBuffer) {
static const std::string kTestString{"Just some random words."};
- const char *const test_dir = CHECK_NOTNULL(getenv("TEST_TMPDIR"));
- const std::string file_path = std::string(test_dir) + "/foo";
+ const std::string file_path = aos::testing::TestTmpDir() + "/foo";
std::ofstream(file_path, std::ios::binary) << kTestString;
DummyDecoder dummy_decoder(file_path.c_str());
diff --git a/aos/events/logging/config_remapper.cc b/aos/events/logging/config_remapper.cc
index 21f45d5..088d393 100644
--- a/aos/events/logging/config_remapper.cc
+++ b/aos/events/logging/config_remapper.cc
@@ -263,7 +263,8 @@
result.reserve(remapped_channels_.size());
for (auto &pair : remapped_channels_) {
const Channel *const original_channel =
- CHECK_NOTNULL(original_configuration()->channels()->Get(pair.first));
+ original_configuration()->channels()->Get(pair.first);
+ CHECK(original_channel != nullptr);
auto channel_iterator = std::lower_bound(
remapped_configuration_->channels()->cbegin(),
@@ -472,9 +473,10 @@
// Reconstruct the remapped channels.
for (auto &pair : remapped_channels_) {
- const Channel *const c = CHECK_NOTNULL(configuration::GetChannel(
+ const Channel *const c = configuration::GetChannel(
base_config, original_configuration()->channels()->Get(pair.first), "",
- nullptr));
+ nullptr);
+ CHECK(c != nullptr);
channel_offsets.emplace_back(
CopyChannel(c, pair.second.remapped_name, "", &fbb));
diff --git a/aos/events/logging/log_cat.cc b/aos/events/logging/log_cat.cc
index 31d12be..d7347be 100644
--- a/aos/events/logging/log_cat.cc
+++ b/aos/events/logging/log_cat.cc
@@ -245,7 +245,7 @@
}
VLOG(1) << "Listening on " << name << " " << type;
- CHECK_NOTNULL(channel->schema());
+ CHECK(channel->schema() != nullptr);
event_loop_->MakeRawWatcher(channel, [this, channel, start_time,
end_time](
const aos::Context &context,
diff --git a/aos/events/logging/log_namer.cc b/aos/events/logging/log_namer.cc
index 6c88d89..c065f68 100644
--- a/aos/events/logging/log_namer.cc
+++ b/aos/events/logging/log_namer.cc
@@ -1065,7 +1065,7 @@
void MultiNodeLogNamer::CloseWriter(
std::unique_ptr<DetachedBufferWriter> *writer_pointer) {
- CHECK_NOTNULL(writer_pointer);
+ CHECK(writer_pointer != nullptr);
if (!(*writer_pointer)) {
return;
}
diff --git a/aos/events/logging/log_namer.h b/aos/events/logging/log_namer.h
index 08601f2..2c0982a 100644
--- a/aos/events/logging/log_namer.h
+++ b/aos/events/logging/log_namer.h
@@ -422,7 +422,7 @@
bool ran_out_of_space() const {
return accumulate_data_writers<bool>(
ran_out_of_space_, [](bool x, const NewDataWriter &data_writer) {
- CHECK_NOTNULL(data_writer.writer);
+ CHECK(data_writer.writer != nullptr);
return x ||
(data_writer.writer && data_writer.writer->ran_out_of_space());
});
@@ -435,7 +435,7 @@
size_t maximum_total_bytes() const {
return accumulate_data_writers<size_t>(
0, [](size_t x, const NewDataWriter &data_writer) {
- CHECK_NOTNULL(data_writer.writer);
+ CHECK(data_writer.writer != nullptr);
return std::max(x, data_writer.writer->total_bytes());
});
}
@@ -452,7 +452,7 @@
return accumulate_data_writers(
max_write_time_,
[](std::chrono::nanoseconds x, const NewDataWriter &data_writer) {
- CHECK_NOTNULL(data_writer.writer);
+ CHECK(data_writer.writer != nullptr);
return std::max(
x, data_writer.writer->WriteStatistics()->max_write_time());
});
@@ -462,7 +462,7 @@
std::make_tuple(max_write_time_bytes_, max_write_time_),
[](std::tuple<int, std::chrono::nanoseconds> x,
const NewDataWriter &data_writer) {
- CHECK_NOTNULL(data_writer.writer);
+ CHECK(data_writer.writer != nullptr);
if (data_writer.writer->WriteStatistics()->max_write_time() >
std::get<1>(x)) {
return std::make_tuple(
@@ -477,7 +477,7 @@
std::make_tuple(max_write_time_messages_, max_write_time_),
[](std::tuple<int, std::chrono::nanoseconds> x,
const NewDataWriter &data_writer) {
- CHECK_NOTNULL(data_writer.writer);
+ CHECK(data_writer.writer != nullptr);
if (data_writer.writer->WriteStatistics()->max_write_time() >
std::get<1>(x)) {
return std::make_tuple(
@@ -492,14 +492,14 @@
return accumulate_data_writers(
total_write_time_,
[](std::chrono::nanoseconds x, const NewDataWriter &data_writer) {
- CHECK_NOTNULL(data_writer.writer);
+ CHECK(data_writer.writer != nullptr);
return x + data_writer.writer->WriteStatistics()->total_write_time();
});
}
int total_write_count() const {
return accumulate_data_writers(
total_write_count_, [](int x, const NewDataWriter &data_writer) {
- CHECK_NOTNULL(data_writer.writer);
+ CHECK(data_writer.writer != nullptr);
return x + data_writer.writer->WriteStatistics()->total_write_count();
});
}
@@ -513,7 +513,7 @@
int total_write_bytes() const {
return accumulate_data_writers(
total_write_bytes_, [](int x, const NewDataWriter &data_writer) {
- CHECK_NOTNULL(data_writer.writer);
+ CHECK(data_writer.writer != nullptr);
return x + data_writer.writer->WriteStatistics()->total_write_bytes();
});
}
@@ -522,7 +522,7 @@
return accumulate_data_writers(
total_encode_duration_,
[](std::chrono::nanoseconds x, const NewDataWriter &data_writer) {
- CHECK_NOTNULL(data_writer.writer);
+ CHECK(data_writer.writer != nullptr);
return x +
data_writer.writer->WriteStatistics()->total_encode_duration();
});
diff --git a/aos/events/logging/log_reader.cc b/aos/events/logging/log_reader.cc
index 192dade..81f8466 100644
--- a/aos/events/logging/log_reader.cc
+++ b/aos/events/logging/log_reader.cc
@@ -196,7 +196,7 @@
{
// Log files container validates that log files shared the same config.
const Configuration *config = log_files_.config().get();
- CHECK_NOTNULL(config);
+ CHECK(config != nullptr);
}
if (replay_channels_ != nullptr) {
@@ -386,7 +386,7 @@
std::vector<
std::pair<const aos::Channel *, NodeEventLoopFactory::ExclusiveSenders>>
LogReader::State::NonExclusiveChannels() {
- CHECK_NOTNULL(node_event_loop_factory_);
+ CHECK(node_event_loop_factory_ != nullptr);
const aos::Configuration *config = node_event_loop_factory_->configuration();
std::vector<
std::pair<const aos::Channel *, NodeEventLoopFactory::ExclusiveSenders>>
@@ -1423,10 +1423,11 @@
if (remote_timestamp_senders_[timestamped_message.channel_index] != nullptr) {
State *source_state =
- CHECK_NOTNULL(channel_source_state_[timestamped_message.channel_index]);
- std::vector<ContiguousSentTimestamp> *queue_index_map = CHECK_NOTNULL(
- source_state->queue_index_map_[timestamped_message.channel_index]
- .get());
+ channel_source_state_[timestamped_message.channel_index];
+ CHECK(source_state != nullptr);
+ std::vector<ContiguousSentTimestamp> *queue_index_map =
+ source_state->queue_index_map_[timestamped_message.channel_index].get();
+ CHECK(queue_index_map != nullptr);
struct SentTimestamp {
monotonic_clock::time_point monotonic_event_time;
@@ -1495,15 +1496,13 @@
// Sanity check that we are using consistent boot uuids.
State *source_state =
channel_source_state_[timestamped_message.channel_index];
+ CHECK(source_state != nullptr);
+ CHECK(source_state->event_loop_ != nullptr);
CHECK_EQ(multinode_filters_->boot_uuid(
configuration::GetNodeIndex(event_loop_->configuration(),
source_state->node()),
timestamped_message.monotonic_remote_time.boot),
- CHECK_NOTNULL(
- CHECK_NOTNULL(
- channel_source_state_[timestamped_message.channel_index])
- ->event_loop_)
- ->boot_uuid());
+ source_state->event_loop_->boot_uuid());
}
SharedSpan to_send;
@@ -1529,20 +1528,23 @@
// Send! Use the replayed queue index here instead of the logged queue index
// for the remote queue index. This makes re-logging work.
+ const UUID boot_uuid = [&]() -> UUID {
+ if (channel_source_state_[timestamped_message.channel_index] != nullptr) {
+ CHECK(multinode_filters_ != nullptr);
+ return multinode_filters_->boot_uuid(
+ configuration::GetNodeIndex(
+ event_loop_->configuration(),
+ channel_source_state_[timestamped_message.channel_index]->node()),
+ timestamped_message.monotonic_remote_time.boot);
+ } else {
+ return event_loop_->boot_uuid();
+ }
+ }();
const RawSender::Error err = sender->Send(
std::move(to_send), timestamped_message.monotonic_remote_time.time,
timestamped_message.realtime_remote_time,
timestamped_message.monotonic_remote_transmit_time.time,
- remote_queue_index,
- (channel_source_state_[timestamped_message.channel_index] != nullptr
- ? CHECK_NOTNULL(multinode_filters_)
- ->boot_uuid(configuration::GetNodeIndex(
- event_loop_->configuration(),
- channel_source_state_[timestamped_message
- .channel_index]
- ->node()),
- timestamped_message.monotonic_remote_time.boot)
- : event_loop_->boot_uuid()));
+ remote_queue_index, boot_uuid);
if (err != RawSender::Error::kOk) return false;
if (monotonic_start_time(timestamped_message.monotonic_event_time.boot) <=
timestamped_message.monotonic_event_time.time) {
@@ -1601,7 +1603,8 @@
// that the timestamps correspond to. This code, as written, also doesn't
// correctly handle a non-zero clock_offset for the *_remote_time fields.
State *source_state =
- CHECK_NOTNULL(channel_source_state_[timestamped_message.channel_index]);
+ channel_source_state_[timestamped_message.channel_index];
+ CHECK(source_state != nullptr);
flatbuffers::FlatBufferBuilder fbb;
fbb.ForceDefaults(true);
@@ -1655,14 +1658,14 @@
void LogReader::RemoteMessageSender::ScheduleTimestamp() {
if (remote_timestamps_.empty()) {
- CHECK_NOTNULL(timer_);
+ CHECK(timer_ != nullptr);
timer_->Disable();
scheduled_time_ = monotonic_clock::min_time;
return;
}
if (scheduled_time_ != remote_timestamps_.front().monotonic_timestamp_time) {
- CHECK_NOTNULL(timer_);
+ CHECK(timer_ != nullptr);
timer_->Schedule(remote_timestamps_.front().monotonic_timestamp_time);
scheduled_time_ = remote_timestamps_.front().monotonic_timestamp_time;
CHECK_GE(scheduled_time_, event_loop_->monotonic_now())
diff --git a/aos/events/logging/log_reader.h b/aos/events/logging/log_reader.h
index f25f1f6..85d4d2c 100644
--- a/aos/events/logging/log_reader.h
+++ b/aos/events/logging/log_reader.h
@@ -655,7 +655,7 @@
}
monotonic_clock::time_point monotonic_now() const {
- CHECK_NOTNULL(event_loop_);
+ CHECK(event_loop_ != nullptr);
return event_loop_->monotonic_now();
}
diff --git a/aos/events/logging/log_stats.cc b/aos/events/logging/log_stats.cc
index c0540bf..a45a167 100644
--- a/aos/events/logging/log_stats.cc
+++ b/aos/events/logging/log_stats.cc
@@ -128,7 +128,10 @@
: channel_(channel),
config_(factory->configuration()),
factory_(factory),
- schema_(CHECK_NOTNULL(schema)),
+ schema_([&]() {
+ CHECK(schema != nullptr);
+ return schema;
+ }()),
destination_node_(destination_node),
flatbuffer_type_(schema) {
// Multi-node channel
diff --git a/aos/events/logging/log_writer.cc b/aos/events/logging/log_writer.cc
index c00d216..42dbbb5 100644
--- a/aos/events/logging/log_writer.cc
+++ b/aos/events/logging/log_writer.cc
@@ -297,8 +297,9 @@
log_namer_->MakeTimestampWriter(f.event_loop_channel);
}
if (f.wants_contents_writer) {
+ CHECK(f.timestamp_node != nullptr);
f.contents_writer = log_namer_->MakeForwardedTimestampWriter(
- f.event_loop_channel, CHECK_NOTNULL(f.timestamp_node));
+ f.event_loop_channel, f.timestamp_node);
}
}
@@ -426,8 +427,9 @@
log_namer_->MakeTimestampWriter(f.event_loop_channel);
}
if (f.wants_contents_writer) {
+ CHECK(f.timestamp_node != nullptr);
f.contents_writer = log_namer_->MakeForwardedTimestampWriter(
- f.event_loop_channel, CHECK_NOTNULL(f.timestamp_node));
+ f.event_loop_channel, f.timestamp_node);
}
// Mark each channel with data as not written. That triggers each channel
diff --git a/aos/events/logging/logfile_utils.cc b/aos/events/logging/logfile_utils.cc
index 30ed3d7..0d10a99 100644
--- a/aos/events/logging/logfile_utils.cc
+++ b/aos/events/logging/logfile_utils.cc
@@ -2442,7 +2442,7 @@
Message TimestampMapper::MatchingMessageFor(const Message &message) {
// Figure out what queue index we are looking for.
- CHECK_NOTNULL(message.header);
+ CHECK(message.header != nullptr);
CHECK(message.header->remote_queue_index.has_value());
const BootQueueIndex remote_queue_index =
BootQueueIndex{.boot = message.monotonic_remote_boot,
diff --git a/aos/events/logging/lzma_encoder_test.cc b/aos/events/logging/lzma_encoder_test.cc
index 60444d3..92b4f54 100644
--- a/aos/events/logging/lzma_encoder_test.cc
+++ b/aos/events/logging/lzma_encoder_test.cc
@@ -4,6 +4,7 @@
#include "gtest/gtest.h"
#include "aos/events/logging/buffer_encoder_param_test.h"
+#include "aos/testing/tmpdir.h"
#include "aos/util/file.h"
DECLARE_int32(lzma_threads);
@@ -62,8 +63,7 @@
// corrupted.
TEST_F(BufferEncoderBaseTest, CorruptedBuffer) {
std::uniform_int_distribution<int> quantity_distribution(20, 60);
- const char *const test_dir = CHECK_NOTNULL(getenv("TEST_TMPDIR"));
- const std::string file_path = std::string(test_dir) + "/foo";
+ const std::string file_path = aos::testing::TestTmpDir() + "/foo";
std::vector<std::vector<uint8_t>> encoded_buffers;
{
diff --git a/aos/events/logging/snappy_encoder.cc b/aos/events/logging/snappy_encoder.cc
index 0160177..b1cd80e 100644
--- a/aos/events/logging/snappy_encoder.cc
+++ b/aos/events/logging/snappy_encoder.cc
@@ -127,7 +127,8 @@
}
const char *SnappyEncoder::DetachedBufferSource::Peek(size_t *length) {
- *CHECK_NOTNULL(length) = data_.size() - index_into_first_buffer_;
+ CHECK(length != nullptr);
+ *length = data_.size() - index_into_first_buffer_;
return reinterpret_cast<char *>(data_.data()) + index_into_first_buffer_;
}
diff --git a/aos/events/shm_event_loop_test.cc b/aos/events/shm_event_loop_test.cc
index 2fbe735..aae8f15 100644
--- a/aos/events/shm_event_loop_test.cc
+++ b/aos/events/shm_event_loop_test.cc
@@ -17,13 +17,6 @@
class ShmEventLoopTestFactory : public EventLoopTestFactory {
public:
ShmEventLoopTestFactory() {
- // Put all the queue files in ${TEST_TMPDIR} if it is set, otherwise
- // everything will be reusing /dev/shm when sharded.
- char *test_tmpdir = getenv("TEST_TMPDIR");
- if (test_tmpdir != nullptr) {
- FLAGS_shm_base = std::string(test_tmpdir) + "/aos";
- }
-
// Clean up anything left there before.
unlink((FLAGS_shm_base + "/test/aos.TestMessage.v7").c_str());
unlink((FLAGS_shm_base + "/test1/aos.TestMessage.v7").c_str());
@@ -58,14 +51,19 @@
}
Result<void> Run() override {
- return CHECK_NOTNULL(primary_event_loop_)->Run();
+ CHECK(primary_event_loop_ != nullptr);
+ return primary_event_loop_->Run();
}
std::unique_ptr<ExitHandle> MakeExitHandle() override {
- return CHECK_NOTNULL(primary_event_loop_)->MakeExitHandle();
+ CHECK(primary_event_loop_ != nullptr);
+ return primary_event_loop_->MakeExitHandle();
}
- void Exit() override { CHECK_NOTNULL(primary_event_loop_)->Exit(); }
+ void Exit() override {
+ CHECK(primary_event_loop_ != nullptr);
+ primary_event_loop_->Exit();
+ }
void SleepFor(::std::chrono::nanoseconds duration) override {
::std::this_thread::sleep_for(duration);
diff --git a/aos/events/simple_channel.cc b/aos/events/simple_channel.cc
index 00e30ba..51d9ef6 100644
--- a/aos/events/simple_channel.cc
+++ b/aos/events/simple_channel.cc
@@ -5,9 +5,15 @@
namespace aos {
-SimpleChannel::SimpleChannel(const Channel *channel)
- : name(CHECK_NOTNULL(CHECK_NOTNULL(channel)->name())->str()),
- type(CHECK_NOTNULL(CHECK_NOTNULL(channel)->type())->str()) {}
+SimpleChannel::SimpleChannel(const Channel *channel) {
+ CHECK(channel != nullptr);
+ const flatbuffers::String *channel_name = channel->name();
+ CHECK(channel_name != nullptr);
+ name = channel_name->str();
+ const flatbuffers::String *channel_type = channel->type();
+ CHECK(channel_type != nullptr);
+ type = channel_type->str();
+}
std::string SimpleChannel::DebugString() const {
return absl::StrCat("{ ", name, ", ", type, "}");
diff --git a/aos/events/simulated_event_loop.cc b/aos/events/simulated_event_loop.cc
index 3c84cfb..64e64ca 100644
--- a/aos/events/simulated_event_loop.cc
+++ b/aos/events/simulated_event_loop.cc
@@ -586,7 +586,7 @@
const Configuration *configuration,
std::vector<SimulatedEventLoop *> *event_loops_, const Node *node,
pid_t tid, EventLoopOptions options)
- : EventLoop(CHECK_NOTNULL(configuration)),
+ : EventLoop(configuration),
scheduler_(scheduler),
node_event_loop_factory_(node_event_loop_factory),
channels_(channels),
@@ -945,7 +945,8 @@
if (token_ != scheduler_->InvalidToken()) {
scheduler_->Deschedule(token_);
}
- CHECK_NOTNULL(simulated_channel_)->RemoveWatcher(this);
+ CHECK(simulated_channel_ != nullptr);
+ simulated_channel_->RemoveWatcher(this);
}
bool SimulatedWatcher::has_run() const {
@@ -1387,8 +1388,13 @@
SimulatedEventLoopFactory::SimulatedEventLoopFactory(
const Configuration *configuration)
- : configuration_(CHECK_NOTNULL(configuration)),
- nodes_(configuration::GetNodes(configuration_)) {
+ : configuration_(configuration),
+ nodes_(
+ // Don't crash if configuration is nullptr, handle it a bit better
+ // before doing anything.
+ configuration == nullptr ? std::vector<const Node *>{}
+ : configuration::GetNodes(configuration_)) {
+ CHECK(configuration_ != nullptr);
CHECK(IsInitialized()) << ": Need to initialize AOS first.";
for (const Node *node : nodes_) {
node_factories_.emplace_back(
diff --git a/aos/events/simulated_network_bridge.cc b/aos/events/simulated_network_bridge.cc
index 66c902f..fd2dead 100644
--- a/aos/events/simulated_network_bridge.cc
+++ b/aos/events/simulated_network_bridge.cc
@@ -863,8 +863,11 @@
}
// And the timestamps are then logged back by us again.
- if (!delivery_time_is_logged ||
- CHECK_NOTNULL(delayer)->forwarding_disabled()) {
+ if (!delivery_time_is_logged) {
+ continue;
+ }
+ CHECK(delayer != nullptr);
+ if (delayer->forwarding_disabled()) {
continue;
}
diff --git a/aos/events/timing_report_dump_lib.cc b/aos/events/timing_report_dump_lib.cc
index 15a8eb9..d83cf69 100644
--- a/aos/events/timing_report_dump_lib.cc
+++ b/aos/events/timing_report_dump_lib.cc
@@ -120,8 +120,9 @@
std::stringstream errors;
CHECK(sender->has_error_counts());
for (size_t ii = 0; ii < sender->error_counts()->size(); ++ii) {
- const size_t error_count =
- CHECK_NOTNULL(sender->error_counts()->Get(ii))->count();
+ auto *error_counts = sender->error_counts()->Get(ii);
+ CHECK(error_counts != nullptr);
+ const size_t error_count = error_counts->count();
errors << error_count;
if (error_count > 0) {
// Put send errors onto stderr so that people just interested in