Convert aos over to flatbuffers
Everything builds, and all the tests pass. I suspect that some entries
are missing from the config files, but those will be found pretty
quickly on startup.
There is no logging or live introspection of queue messages.
Change-Id: I496ee01ed68f202c7851bed7e8786cee30df29f5
diff --git a/aos/util/BUILD b/aos/util/BUILD
index f18fd82..4d7a3d1 100644
--- a/aos/util/BUILD
+++ b/aos/util/BUILD
@@ -65,7 +65,7 @@
name = "math",
hdrs = ["math.h"],
deps = [
- "//third_party/eigen",
+ "@org_tuxfamily_eigen//:eigen",
],
)
@@ -111,7 +111,6 @@
"phased_loop.h",
],
deps = [
- "//aos/logging",
"//aos/time",
"@com_github_google_glog//:glog",
],
@@ -156,7 +155,7 @@
],
deps = [
"//aos:macros",
- "//aos/logging",
+ "@com_github_google_glog//:glog",
],
)
@@ -174,7 +173,7 @@
deps = [
"//aos/logging",
"//aos/time",
- "//third_party/eigen",
+ "@org_tuxfamily_eigen//:eigen",
],
)
@@ -296,8 +295,8 @@
"file.h",
],
deps = [
- "//aos/logging",
"//aos/scoped:scoped_fd",
+ "@com_github_google_glog//:glog",
"@com_google_absl//absl/strings",
],
)
@@ -311,7 +310,6 @@
deps = [
":file",
"//aos/testing:googletest",
- "//aos/testing:test_logging",
],
)
diff --git a/aos/util/file.cc b/aos/util/file.cc
index 5418aab..f78239a 100644
--- a/aos/util/file.cc
+++ b/aos/util/file.cc
@@ -4,8 +4,8 @@
#include <unistd.h>
#include "absl/strings/string_view.h"
-#include "aos/logging/logging.h"
#include "aos/scoped/scoped_fd.h"
+#include "glog/logging.h"
namespace aos {
namespace util {
@@ -13,17 +13,12 @@
::std::string ReadFileToStringOrDie(const absl::string_view filename) {
::std::string r;
ScopedFD fd(open(::std::string(filename).c_str(), O_RDONLY));
- if (fd.get() == -1) {
- AOS_PLOG(FATAL, "opening %*s", static_cast<int>(filename.size()),
- filename.data());
- }
+ PCHECK(fd.get() != -1) << ": opening " << filename;
while (true) {
char buffer[1024];
const ssize_t result = read(fd.get(), buffer, sizeof(buffer));
- if (result < 0) {
- AOS_PLOG(FATAL, "reading from %*s", static_cast<int>(filename.size()),
- filename.data());
- } else if (result == 0) {
+ PCHECK(result >= 0) << ": reading from " << filename;
+ if (result == 0) {
break;
}
r.append(buffer, result);
@@ -31,5 +26,24 @@
return r;
}
+void WriteStringToFileOrDie(const absl::string_view filename,
+ const absl::string_view contents) {
+ ::std::string r;
+ ScopedFD fd(open(::std::string(filename).c_str(),
+ O_CREAT | O_WRONLY | O_TRUNC, S_IRWXU));
+ PCHECK(fd.get() != -1) << ": opening " << filename;
+ size_t size_written = 0;
+ while (size_written != contents.size()) {
+ const ssize_t result = write(fd.get(), contents.data() + size_written,
+ contents.size() - size_written);
+ PCHECK(result >= 0) << ": reading from " << filename;
+ if (result == 0) {
+ break;
+ }
+
+ size_written += result;
+ }
+}
+
} // namespace util
} // namespace aos
diff --git a/aos/util/file.h b/aos/util/file.h
index 385aba7..5d354a7 100644
--- a/aos/util/file.h
+++ b/aos/util/file.h
@@ -12,6 +12,10 @@
// encountered.
::std::string ReadFileToStringOrDie(const absl::string_view filename);
+// Creates filename if it doesn't exist and sets the contents to contents.
+void WriteStringToFileOrDie(const absl::string_view filename,
+ const absl::string_view contents);
+
} // namespace util
} // namespace aos
diff --git a/aos/util/file_test.cc b/aos/util/file_test.cc
index f904259..fa259e8 100644
--- a/aos/util/file_test.cc
+++ b/aos/util/file_test.cc
@@ -6,21 +6,12 @@
#include "gtest/gtest.h"
-#include "aos/testing/test_logging.h"
-
namespace aos {
namespace util {
namespace testing {
-class FileTest : public ::testing::Test {
- protected:
- FileTest() {
- ::aos::testing::EnableTestLogging();
- }
-};
-
// Basic test of reading a normal file.
-TEST_F(FileTest, ReadNormalFile) {
+TEST(FileTest, ReadNormalFile) {
const ::std::string tmpdir(getenv("TEST_TMPDIR"));
const ::std::string test_file = tmpdir + "/test_file";
ASSERT_EQ(0, system(("echo contents > " + test_file).c_str()));
@@ -28,7 +19,7 @@
}
// Tests reading a file with 0 size, among other weird things.
-TEST_F(FileTest, ReadSpecialFile) {
+TEST(FileTest, ReadSpecialFile) {
const ::std::string stat = ReadFileToStringOrDie("/proc/self/stat");
EXPECT_EQ('\n', stat[stat.size() - 1]);
const ::std::string my_pid = ::std::to_string(getpid());
diff --git a/aos/util/phased_loop_test.cc b/aos/util/phased_loop_test.cc
index 0a0d5db..4a80522 100644
--- a/aos/util/phased_loop_test.cc
+++ b/aos/util/phased_loop_test.cc
@@ -10,11 +10,7 @@
using ::std::chrono::milliseconds;
-class PhasedLoopTest : public ::testing::Test {
- protected:
- PhasedLoopTest() { ::aos::testing::EnableTestLogging(); }
-};
-
+typedef ::testing::Test PhasedLoopTest;
typedef PhasedLoopTest PhasedLoopDeathTest;
monotonic_clock::time_point InMs(int ms) {
diff --git a/aos/util/thread.cc b/aos/util/thread.cc
index ae18fe9..bb5999f 100644
--- a/aos/util/thread.cc
+++ b/aos/util/thread.cc
@@ -3,7 +3,7 @@
#include <pthread.h>
#include <signal.h>
-#include "aos/logging/logging.h"
+#include "glog/logging.h"
namespace aos {
namespace util {
@@ -11,24 +11,24 @@
Thread::Thread() : started_(false), joined_(false), should_terminate_(false) {}
Thread::~Thread() {
- AOS_CHECK(!(started_ && !joined_));
+ CHECK(!(started_ && !joined_));
}
void Thread::Start() {
- AOS_CHECK(!started_);
+ CHECK(!started_);
started_ = true;
- AOS_CHECK(pthread_create(&thread_, NULL, &Thread::StaticRun, this) == 0);
+ CHECK(pthread_create(&thread_, NULL, &Thread::StaticRun, this) == 0);
}
void Thread::Join() {
- AOS_CHECK(!joined_ && started_);
+ CHECK(!joined_ && started_);
joined_ = true;
should_terminate_.store(true);
- AOS_CHECK(pthread_join(thread_, NULL) == 0);
+ CHECK(pthread_join(thread_, NULL) == 0);
}
bool Thread::TryJoin() {
- AOS_CHECK(!joined_ && started_);
+ CHECK(!joined_ && started_);
#ifdef AOS_SANITIZER_thread
// ThreadSanitizer misses the tryjoin and then complains about leaking the
// thread. Instead, we'll just check if the thread is still around and then
@@ -39,7 +39,8 @@
if (kill_ret == 0) return false;
// If it died, we'll get ESRCH. Otherwise, something went wrong.
if (kill_ret != ESRCH) {
- AOS_PELOG(FATAL, kill_ret, "pthread_kill(thread_, 0) failed");
+ errno = kill_ret;
+ PLOG(FATAL) << "pthread_kill(thread_, 0) failed";
}
Join();
return true;
@@ -51,20 +52,22 @@
} else if (ret == EBUSY) {
return false;
} else {
- AOS_PELOG(FATAL, ret, "pthread_tryjoin_np(thread_, nullptr) failed");
+ errno = ret;
+ PLOG(FATAL) << "pthread_tryjoin_np(thread_, nullptr) failed";
+ return false;
}
#endif
}
void Thread::RequestStop() {
- AOS_CHECK(!joined_ && started_);
+ CHECK(!joined_ && started_);
should_terminate_.store(true);
}
void Thread::WaitUntilDone() {
- AOS_CHECK(!joined_ && started_);
+ CHECK(!joined_ && started_);
joined_ = true;
- AOS_CHECK(pthread_join(thread_, NULL) == 0);
+ CHECK(pthread_join(thread_, NULL) == 0);
}
void *Thread::StaticRun(void *self) {
diff --git a/aos/util/thread.h b/aos/util/thread.h
index 5992810..337ea48 100644
--- a/aos/util/thread.h
+++ b/aos/util/thread.h
@@ -13,7 +13,7 @@
// A nice wrapper around a pthreads thread.
//
-// TODO(aschuh): Test this.
+// TODO(aschuh): replace this with std::thread
class Thread {
public:
Thread();