Enforce channel message limits when building configs

We only support 2^16-1 messages/channel.  Enforce this when building the
configuration, rather than at runtime in the simulation.  This will
make the errors cleaner and more direct.

Change-Id: I368f6c6596a7b0eaa562a70cd385ca1b94e10b93
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/aos/configuration_test.cc b/aos/configuration_test.cc
index 242ee17..fa74e20 100644
--- a/aos/configuration_test.cc
+++ b/aos/configuration_test.cc
@@ -16,6 +16,7 @@
 namespace testing {
 
 using aos::testing::ArtifactPath;
+namespace chrono = std::chrono;
 
 class ConfigurationTest : public ::testing::Test {
  public:
@@ -988,6 +989,28 @@
       "Found duplicate logger_nodes in");
 }
 
+// Tests that we properly compute the queue size for the provided duration.
+TEST_F(ConfigurationTest, QueueSize) {
+  EXPECT_EQ(QueueSize(100, chrono::seconds(2)), 200);
+  EXPECT_EQ(QueueSize(200, chrono::seconds(2)), 400);
+  EXPECT_EQ(QueueSize(100, chrono::seconds(6)), 600);
+  EXPECT_EQ(QueueSize(100, chrono::milliseconds(10)), 1);
+  EXPECT_EQ(QueueSize(100, chrono::milliseconds(10) - chrono::nanoseconds(1)),
+            1);
+  EXPECT_EQ(QueueSize(100, chrono::milliseconds(10) - chrono::nanoseconds(2)),
+            1);
+}
+
+// Tests that we compute scratch buffer size correctly too.
+TEST_F(ConfigurationTest, QueueScratchBufferSize) {
+  const aos::FlatbufferDetachedBuffer<Channel> channel =
+      JsonToFlatbuffer<Channel>(
+          "{ \"name\": \"/foo\", \"type\": \".aos.bar\", \"num_readers\": 5, "
+          "\"num_senders\": 10 }");
+
+  EXPECT_EQ(QueueScratchBufferSize(&channel.message()), 15);
+}
+
 }  // namespace testing
 }  // namespace configuration
 }  // namespace aos