31 virtual void SetUp() {
40 TEST_F(DepsLogTest, WriteRead) {
49 deps.push_back(state1.
GetNode(
"foo.h", 0));
50 deps.push_back(state1.
GetNode(
"bar.h", 0));
54 deps.push_back(state1.
GetNode(
"foo.h", 0));
55 deps.push_back(state1.
GetNode(
"bar2.h", 0));
74 for (
int i = 0; i < (int)log1.
nodes().size(); ++i) {
90 TEST_F(DepsLogTest, LotsOfDeps) {
91 const int kNumDeps = 100000;
101 for (
int i = 0; i < kNumDeps; ++i) {
103 sprintf(buf,
"file%d.h", i);
104 deps.push_back(state1.
GetNode(buf, 0));
124 TEST_F(DepsLogTest, DoubleEntry) {
135 deps.push_back(state.
GetNode(
"foo.h", 0));
136 deps.push_back(state.
GetNode(
"bar.h", 0));
142 file_size = (int)st.st_size;
157 deps.push_back(state.
GetNode(
"foo.h", 0));
158 deps.push_back(state.
GetNode(
"bar.h", 0));
164 int file_size_2 = (int)st.st_size;
170 TEST_F(DepsLogTest, Recompact) {
171 const char kManifest[] =
176 "build other_out.o: cc\n";
189 deps.push_back(state.
GetNode(
"foo.h", 0));
190 deps.push_back(state.
GetNode(
"bar.h", 0));
194 deps.push_back(state.
GetNode(
"foo.h", 0));
195 deps.push_back(state.
GetNode(
"baz.h", 0));
202 file_size = (int)st.st_size;
219 deps.push_back(state.
GetNode(
"foo.h", 0));
225 file_size_2 = (int)st.st_size;
262 ASSERT_EQ(
"foo.h", deps->nodes[0]->path());
269 ASSERT_EQ(
"foo.h", deps->nodes[0]->path());
270 ASSERT_EQ(
"baz.h", deps->nodes[1]->path());
276 file_size_3 = (int)st.st_size;
320 int file_size_4 = (int)st.st_size;
326 TEST_F(DepsLogTest, InvalidHeader) {
327 const char *kInvalidHeaders[] = {
331 "# ninjadeps\n\001\002",
332 "# ninjadeps\n\001\002\003\004" 334 for (
size_t i = 0; i <
sizeof(kInvalidHeaders) /
sizeof(kInvalidHeaders[0]);
339 strlen(kInvalidHeaders[i]),
340 fwrite(kInvalidHeaders[i], 1, strlen(kInvalidHeaders[i]), deps_log));
347 EXPECT_EQ(
"bad deps log signature or version; starting over", err);
352 TEST_F(DepsLogTest, Truncated) {
362 deps.push_back(state.
GetNode(
"foo.h", 0));
363 deps.push_back(state.
GetNode(
"bar.h", 0));
367 deps.push_back(state.
GetNode(
"foo.h", 0));
368 deps.push_back(state.
GetNode(
"bar2.h", 0));
383 for (
int size = (
int)st.st_size; size > 0; --size) {
396 node_count = log.
nodes().size();
399 int new_deps_count = 0;
400 for (vector<DepsLog::Deps*>::const_iterator i = log.
deps().begin();
401 i != log.
deps().end(); ++i) {
406 deps_count = new_deps_count;
411 TEST_F(DepsLogTest, TruncatedRecovery) {
421 deps.push_back(state.
GetNode(
"foo.h", 0));
422 deps.push_back(state.
GetNode(
"bar.h", 0));
426 deps.push_back(state.
GetNode(
"foo.h", 0));
427 deps.push_back(state.
GetNode(
"bar2.h", 0));
447 ASSERT_EQ(
"premature end of file; recovering", err);
458 deps.push_back(state.
GetNode(
"foo.h", 0));
459 deps.push_back(state.
GetNode(
"bar2.h", 0));
const vector< Node * > & nodes() const
Used for tests.
void AssertParse(State *state, const char *input, ManifestParserOptions opts)
const string & path() const
Node * GetNode(StringPiece path, uint64_t slash_bits)
Information about a node in the dependency graph: the file, whether it's dirty, mtime, etc.
Node * LookupNode(StringPiece path) const
As build commands run they can output extra dependency information (e.g.
bool OpenForWrite(const string &path, string *err)
const vector< Deps * > & deps() const
Deps * GetDeps(Node *node)
const char kTestFilename[]
bool Load(const string &path, State *state, string *err)
bool Recompact(const string &path, string *err)
Rewrite the known log entries, throwing away old data.
bool Truncate(const string &path, size_t size, string *err)
Truncates a file to the given size.
#define ASSERT_NO_FATAL_FAILURE(a)
Global state (file status) for a single run.
bool RecordDeps(Node *node, TimeStamp mtime, const vector< Node *> &nodes)