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/common/condition_test.cc b/aos/common/condition_test.cc
index 65a1028..6914a8b 100644
--- a/aos/common/condition_test.cc
+++ b/aos/common/condition_test.cc
@@ -75,7 +75,7 @@
     new (shared_) Shared();
   }
   ~ConditionTestProcess() {
-    assert(child_ == -1);
+    CHECK_EQ(child_, -1);
   }
 
   void Start() {
@@ -87,7 +87,7 @@
       Run();
       exit(EXIT_SUCCESS);
     } else {  // in parent
-      assert(child_ != -1);
+      CHECK_NE(child_, -1);
 
       shared_->ready.Lock();
 
@@ -170,16 +170,16 @@
   }
 
   void Join() {
-    assert(child_ != -1);
+    CHECK_NE(child_, -1);
     int status;
     do {
-      assert(waitpid(child_, &status, 0) == child_);
+      CHECK_EQ(waitpid(child_, &status, 0), child_);
     } while (!(WIFEXITED(status) || WIFSIGNALED(status)));
     child_ = -1;
   }
   void Kill() {
-    assert(child_ != -1);
-    assert(kill(child_, SIGTERM) == 0);
+    CHECK_NE(child_, -1);
+    PCHECK(kill(child_, SIGTERM));
     Join();
   }
 
diff --git a/aos/common/input/driver_station_data.h b/aos/common/input/driver_station_data.h
index dca33f9..4bef0b6 100644
--- a/aos/common/input/driver_station_data.h
+++ b/aos/common/input/driver_station_data.h
@@ -4,8 +4,6 @@
 // This file defines several types to support nicely looking at the data
 // received from the driver's station.
 
-#include <assert.h>
-
 #include <memory>
 
 #include "aos/externals/WPILib/WPILib/NetworkRobot/NetworkRobotValues.h"
diff --git a/aos/common/libc/aos_strerror.cc b/aos/common/libc/aos_strerror.cc
index d5fc2b4..4bca500 100644
--- a/aos/common/libc/aos_strerror.cc
+++ b/aos/common/libc/aos_strerror.cc
@@ -26,7 +26,8 @@
 __attribute__((unused))
 char *aos_strerror_handle_result(int error, int ret, char *buffer) {
   if (ret != 0) {
-    assert(snprintf(buffer, kBufferSize, "Unknown error %d", error) > 0);
+    const int r = snprintf(buffer, kBufferSize, "Unknown error %d", error);
+    assert(r > 0);
   }
   return buffer;
 }
diff --git a/aos/common/logging/logging.h b/aos/common/logging/logging.h
index e6e14f9..c54e434 100644
--- a/aos/common/logging/logging.h
+++ b/aos/common/logging/logging.h
@@ -131,7 +131,6 @@
 // don't support streaming in extra text. Some of the implementation is borrowed
 // from there too.
 // They all LOG(FATAL) with a helpful message when the check fails.
-// TODO(brians): Replace assert with CHECK
 // Portions copyright (c) 1999, Google Inc.
 // All rights reserved.
 //
@@ -221,6 +220,18 @@
 // initializer lists.
 #define CHECK_NOTNULL(val) ::aos::CheckNotNull(STRINGIFY(val), val)
 
+inline int CheckSyscall(const char *syscall_string, int value) {
+  if (__builtin_expect(value == -1, false)) {
+    PLOG(FATAL, "%s failed", syscall_string);
+  }
+  return value;
+}
+
+// Check that syscall does not return -1. If it does, PLOG(FATAL)s. This is
+// useful for quickly checking syscalls where it's not very useful to print out
+// the values of any of the arguments.
+#define PCHECK(syscall) ::aos::CheckSyscall(STRINGIFY(syscall), syscall)
+
 }  // namespace aos
 
 #endif  // __cplusplus
diff --git a/aos/common/logging/logging_impl.cc b/aos/common/logging/logging_impl.cc
index 969c0ee..8aa66f5 100644
--- a/aos/common/logging/logging_impl.cc
+++ b/aos/common/logging/logging_impl.cc
@@ -1,6 +1,5 @@
 #include "aos/common/logging/logging_impl.h"
 
-#include <assert.h>
 #include <stdarg.h>
 
 #include "aos/common/time.h"
diff --git a/aos/common/logging/logging_impl.h b/aos/common/logging/logging_impl.h
index f24ce6a..35e24a0 100644
--- a/aos/common/logging/logging_impl.h
+++ b/aos/common/logging/logging_impl.h
@@ -351,6 +351,7 @@
 
 // Runs the given function with the current LogImplementation (handles switching
 // it out while running function etc).
+// levels is how many LogImplementations to not use off the stack.
 void RunWithCurrentImplementation(
     int levels, ::std::function<void(LogImplementation *)> function);
 
diff --git a/aos/common/logging/logging_impl_test.cc b/aos/common/logging/logging_impl_test.cc
index 34bcdd1..8331c37 100644
--- a/aos/common/logging/logging_impl_test.cc
+++ b/aos/common/logging/logging_impl_test.cc
@@ -1,10 +1,11 @@
 #include <string>
 
+#include <inttypes.h>
+
 #include "gtest/gtest.h"
 
 #include "aos/common/logging/logging_impl.h"
 #include "aos/common/time.h"
-#include <inttypes.h>
 
 using ::testing::AssertionResult;
 using ::testing::AssertionSuccess;
@@ -19,6 +20,11 @@
   virtual void DoLog(log_level level, const char *format, va_list ap) {
     internal::FillInMessage(level, format, ap, &message_);
 
+    if (level == FATAL) {
+      internal::PrintMessage(stderr, message_);
+      abort();
+    }
+
     used_ = true;
   }
 
@@ -82,8 +88,6 @@
       first = false;
 
       Init();
-      // We'll end up with several of them stacked up, but it really doesn't
-      // matter.
       AddImplementation(log_implementation = new TestLogImplementation());
     }
 
@@ -133,13 +137,20 @@
   EXPECT_TRUE(WasLogged(WARNING, expected.str()));
 }
 
-#ifndef __VXWORKS__
 TEST_F(LoggingDeathTest, Fatal) {
   ASSERT_EXIT(LOG(FATAL, "this should crash it\n"),
               ::testing::KilledBySignal(SIGABRT),
               "this should crash it");
 }
-#endif
+
+TEST_F(LoggingDeathTest, PCHECK) {
+  EXPECT_DEATH(PCHECK(fprintf(stdin, "nope")),
+               ".*fprintf\\(stdin, \"nope\"\\).*failed.*");
+}
+
+TEST_F(LoggingTest, PCHECK) {
+  EXPECT_EQ(7, PCHECK(printf("abc123\n")));
+}
 
 TEST_F(LoggingTest, PrintfDirectives) {
   LOG(INFO, "test log %%1 %%d\n");
diff --git a/aos/common/logging/logging_interface.cc b/aos/common/logging/logging_interface.cc
index e4c6fcd..0bec52c 100644
--- a/aos/common/logging/logging_interface.cc
+++ b/aos/common/logging/logging_interface.cc
@@ -1,6 +1,5 @@
 #include "aos/common/logging/logging_impl.h"
 
-#include <assert.h>
 #include <stdarg.h>
 #include <string.h>
 
@@ -47,7 +46,6 @@
   LogImplementation *const top_implementation = context->implementation;
   LogImplementation *new_implementation = top_implementation;
   LogImplementation *implementation = NULL;
-  assert(levels >= 1);
   for (int i = 0; i < levels; ++i) {
     implementation = new_implementation;
     if (new_implementation == NULL) {
diff --git a/aos/common/queue_testutils.cc b/aos/common/queue_testutils.cc
index ed89d4f..824cb89 100644
--- a/aos/common/queue_testutils.cc
+++ b/aos/common/queue_testutils.cc
@@ -4,7 +4,6 @@
 #include <sys/mman.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <assert.h>
 
 #include "gtest/gtest.h"
 
@@ -126,7 +125,7 @@
   // "shared" memory.
   void *memory = mmap(NULL, kCoreSize, PROT_READ | PROT_WRITE,
                       MAP_SHARED | MAP_ANONYMOUS, -1, 0);
-  assert(memory != MAP_FAILED);
+  CHECK_NE(memory, MAP_FAILED);
 
   aos_core_use_address_as_shared_mem(memory, kCoreSize);
 
@@ -134,7 +133,7 @@
 }
 
 GlobalCoreInstance::~GlobalCoreInstance() {
-  assert(munmap(global_core->mem_struct, kCoreSize) == 0);
+  PCHECK(munmap(global_core->mem_struct, kCoreSize));
   global_core = NULL;
 }
 
@@ -143,7 +142,7 @@
 }
 
 void PreventExit() {
-  assert(atexit(TerminateExitHandler) == 0);
+  CHECK_EQ(atexit(TerminateExitHandler), 0);
 }
 
 }  // namespace testing
diff --git a/aos/common/queue_types_test.cc b/aos/common/queue_types_test.cc
index 96b7dfb..514499b 100644
--- a/aos/common/queue_types_test.cc
+++ b/aos/common/queue_types_test.cc
@@ -9,6 +9,7 @@
 #include "aos/common/test_queue.q.h"
 #include "aos/common/byteorder.h"
 #include "aos/queue_primitives.h"
+#include "aos/common/logging/logging.h"
 
 using ::aos::common::testing::Structure;
 using ::aos::common::testing::MessageWithStructure;
@@ -160,7 +161,7 @@
   input_bytes = sizeof(kData) + kExtraInputBytes;
   to_network(&kData, input);
   output_bytes = kString.size() + 1;
-  assert(output_bytes <= sizeof(output));
+  CHECK_LE(output_bytes, sizeof(output));
   ASSERT_TRUE(PrintField(output, &output_bytes, input, &input_bytes,
                          Structure::GetType()->fields[2]->type));
   EXPECT_EQ(kExtraInputBytes, input_bytes);
@@ -195,7 +196,7 @@
     ", struct_float:8.560000}";
 
 TEST_F(PrintMessageTest, Basic) {
-  assert(sizeof(input) >= kTestMessage1.Size());
+  CHECK_GE(sizeof(input), kTestMessage1.Size());
   input_bytes = kTestMessage1.Serialize(input);
   output_bytes = sizeof(output);
   ASSERT_TRUE(PrintMessage(output, &output_bytes, input, &input_bytes,
@@ -205,7 +206,7 @@
 }
 
 TEST_F(PrintMessageTest, OutputTooSmall) {
-  assert(sizeof(input) >= kTestMessage1.Size());
+  CHECK_GE(sizeof(input), kTestMessage1.Size());
   input_bytes = kTestMessage1.Serialize(input);
   output_bytes = kTestMessage1String.size();
   EXPECT_FALSE(PrintMessage(output, &output_bytes, input, &input_bytes,
@@ -220,7 +221,7 @@
 }
 
 TEST_F(PrintMessageTest, Structure) {
-  assert(sizeof(input) >= kTestStructure1.Size());
+  CHECK_GE(sizeof(input), kTestStructure1.Size());
   input_bytes = kTestStructure1.Serialize(input);
   output_bytes = sizeof(output);
   ASSERT_TRUE(PrintMessage(output, &output_bytes, input, &input_bytes,
diff --git a/aos/common/util/trapezoid_profile.cc b/aos/common/util/trapezoid_profile.cc
index 4c5f07d..4aa5285 100644
--- a/aos/common/util/trapezoid_profile.cc
+++ b/aos/common/util/trapezoid_profile.cc
@@ -1,7 +1,5 @@
 #include "aos/common/util/trapezoid_profile.h"
 
-#include <assert.h>
-
 #include "aos/common/logging/logging.h"
 
 using ::Eigen::Matrix;
@@ -117,7 +115,7 @@
         acceleration_;
   }
 
-  assert(top_velocity > -maximum_velocity_);
+  CHECK_GT(top_velocity, -maximum_velocity_);
 
   deceleration_time_ = (goal_velocity - top_velocity) /
       deceleration_;