removed lots of asserts
Some of them relied on the side effects of evaluating their argument but
for most of them it just makes more sense to use CHECK.
diff --git a/aos/linux_code/ipc_lib/ipc_lib.gyp b/aos/linux_code/ipc_lib/ipc_lib.gyp
index 35091e5..9f0de33 100644
--- a/aos/linux_code/ipc_lib/ipc_lib.gyp
+++ b/aos/linux_code/ipc_lib/ipc_lib.gyp
@@ -87,6 +87,7 @@
'<(AOS)/common/common.gyp:die',
'<(AOS)/common/libc/libc.gyp:dirname',
'<(AOS)/common/libc/libc.gyp:aos_strsignal',
+ '<(AOS)/build/aos.gyp:logging',
],
'variables': {
'is_special_test': 1,
diff --git a/aos/linux_code/ipc_lib/ipc_stress_test.cc b/aos/linux_code/ipc_lib/ipc_stress_test.cc
index 58d88b3..880d226 100644
--- a/aos/linux_code/ipc_lib/ipc_stress_test.cc
+++ b/aos/linux_code/ipc_lib/ipc_stress_test.cc
@@ -5,7 +5,6 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <libgen.h>
-#include <assert.h>
#include <string>
@@ -17,6 +16,7 @@
#include "aos/common/die.h"
#include "aos/common/libc/dirname.h"
#include "aos/common/libc/aos_strsignal.h"
+#include "aos/common/logging/logging.h"
// This runs all of the IPC-related tests in a bunch of parallel processes for a
// while and makes sure that they don't fail. It also captures the stdout and
@@ -180,7 +180,7 @@
WTERMSIG(status), aos_strsignal(WTERMSIG(status)));
fputs(output.c_str(), stderr);
} else {
- assert(WIFSTOPPED(status));
+ CHECK(WIFSTOPPED(status));
Die("Test %s was stopped.\n", (*test)[0]);
}
@@ -205,7 +205,10 @@
}
int Main(int argc, char **argv) {
- assert(argc >= 1);
+ if (argc < 1) {
+ fputs("need an argument\n", stderr);
+ return EXIT_FAILURE;
+ }
::aos::common::testing::GlobalCoreInstance global_core;
diff --git a/aos/linux_code/ipc_lib/queue.h b/aos/linux_code/ipc_lib/queue.h
index 31e8075..d27c6bf 100644
--- a/aos/linux_code/ipc_lib/queue.h
+++ b/aos/linux_code/ipc_lib/queue.h
@@ -1,8 +1,6 @@
#ifndef AOS_LINUX_CODE_IPC_LIB_QUEUE_H_
#define AOS_LINUX_CODE_IPC_LIB_QUEUE_H_
-#include <assert.h>
-
#include "aos/linux_code/ipc_lib/shared_mem.h"
#include "aos/common/mutex.h"
#include "aos/common/condition.h"
diff --git a/aos/linux_code/ipc_lib/raw_queue_test.cc b/aos/linux_code/ipc_lib/raw_queue_test.cc
index c85d36a..2267c92 100644
--- a/aos/linux_code/ipc_lib/raw_queue_test.cc
+++ b/aos/linux_code/ipc_lib/raw_queue_test.cc
@@ -161,7 +161,7 @@
std::unique_ptr<ForkedProcess> ForkExecute(void (*function)(T*), T *arg) {
mutex *lock = static_cast<mutex *>(shm_malloc_aligned(
sizeof(*lock), sizeof(int)));
- assert(mutex_lock(lock) == 0);
+ CHECK_EQ(mutex_lock(lock), 0);
const pid_t pid = fork();
switch (pid) {
case 0: // child
diff --git a/aos/linux_code/starter/netconsole.cc b/aos/linux_code/starter/netconsole.cc
index 4d32afe..c4ca5b9 100644
--- a/aos/linux_code/starter/netconsole.cc
+++ b/aos/linux_code/starter/netconsole.cc
@@ -7,7 +7,6 @@
#include <fcntl.h>
#include <pthread.h>
#include <sys/stat.h>
-#include <assert.h>
#include "aos/common/logging/logging_impl.h"
#include "aos/common/util/inet_addr.h"
@@ -33,8 +32,8 @@
char buffer[32768];
ssize_t position = 0;
while (true) {
- assert(position >= 0);
- assert(position <= static_cast<ssize_t>(sizeof(buffer)));
+ CHECK_GE(position, 0);
+ CHECK_LE(position, static_cast<ssize_t>(sizeof(buffer)));
if (position != sizeof(buffer)) {
ssize_t read_bytes;
bool good_data = true;
@@ -73,7 +72,7 @@
}
}
if (to_copy->source_address != nullptr) {
- assert(header.msg_namelen >= sizeof(struct sockaddr_in));
+ CHECK_GE(header.msg_namelen, sizeof(struct sockaddr_in));
if (to_copy->source_address->sin_port != hton<uint16_t>(0)) {
if (sender_address.sin_port !=
to_copy->source_address->sin_port) {
@@ -104,8 +103,8 @@
}
}
- assert(position >= 0);
- assert(position <= static_cast<ssize_t>(sizeof(buffer)));
+ CHECK_GE(position, 0);
+ CHECK_LE(position, static_cast<ssize_t>(sizeof(buffer)));
if (position > 0) {
ssize_t sent_bytes = write(to_copy->output, buffer, position);
if (sent_bytes == -1) {
diff --git a/aos/linux_code/starter/starter.cc b/aos/linux_code/starter/starter.cc
index 59aa88d..0fbb7ed 100644
--- a/aos/linux_code/starter/starter.cc
+++ b/aos/linux_code/starter/starter.cc
@@ -10,7 +10,6 @@
#include <sys/inotify.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
-#include <assert.h>
#include <signal.h>
#include <stdint.h>
#include <errno.h>
@@ -114,8 +113,8 @@
// After calling this method, this object won't really be doing much of
// anything besides possibly running its callback or something.
void RemoveWatch() {
- assert(watch_ != -1);
- assert(watch_to_remove_ == -1);
+ CHECK_NE(watch_, -1);
+ CHECK_EQ(watch_to_remove_, -1);
if (inotify_rm_watch(notify_fd, watch_) == -1) {
PLOG(WARNING, "inotify_rm_watch(%d, %d) failed", notify_fd, watch_);
@@ -139,7 +138,7 @@
void RemoveWatchFromMap() {
int watch = watch_to_remove_;
if (watch == -1) {
- assert(watch_ != -1);
+ CHECK_NE(watch, -1);
watch = watch_;
}
if (watchers[watch] != this) {
@@ -157,7 +156,7 @@
}
void CreateWatch() {
- assert(watch_ == -1);
+ CHECK_EQ(watch_, -1);
watch_ = inotify_add_watch(notify_fd, filename_.c_str(),
create_ ? IN_CREATE : (IN_ATTRIB |
IN_MODIFY |
@@ -227,7 +226,7 @@
// INotifyReadable calls this method whenever the watch for our file triggers.
void FileNotified(const char *filename) {
- assert(watch_ != -1);
+ CHECK_NE(watch_, -1);
LOG(DEBUG, "got a notification for %s\n", filename_.c_str());
if (!check_filename_.empty()) {