25 #include <sys/types.h> 37 virtual void SetUp() {
41 virtual void TearDown() {
44 virtual bool IsPathDead(
StringPiece s)
const {
return false; }
47 TEST_F(BuildLogTest, WriteRead) {
49 "build out: cat mid\n" 50 "build mid: cat in\n");
75 TEST_F(BuildLogTest, FirstWriteAddsSignature) {
76 const char kExpectedVersion[] =
"# ninja log vX\n";
77 const size_t kVersionPos = strlen(kExpectedVersion) - 2;
88 if (contents.size() >= kVersionPos)
89 contents[kVersionPos] =
'X';
100 if (contents.size() >= kVersionPos)
101 contents[kVersionPos] =
'X';
105 TEST_F(BuildLogTest, DoubleEntry) {
107 fprintf(f,
"# ninja log v4\n");
108 fprintf(f,
"0\t1\t2\tout\tcommand abc\n");
109 fprintf(f,
"3\t4\t5\tout\tcommand def\n");
124 "build out: cat mid\n" 125 "build mid: cat in\n");
143 for (off_t size = statbuf.st_size; size > 0; --size) {
160 TEST_F(BuildLogTest, ObsoleteOldVersion) {
162 fprintf(f,
"# ninja log v3\n");
163 fprintf(f,
"123 456 0 out command\n");
169 ASSERT_NE(err.find(
"version"), string::npos);
172 TEST_F(BuildLogTest, SpacesInOutputV4) {
174 fprintf(f,
"# ninja log v4\n");
175 fprintf(f,
"123\t456\t456\tout with space\tcommand\n");
191 TEST_F(BuildLogTest, DuplicateVersionHeader) {
196 fprintf(f,
"# ninja log v4\n");
197 fprintf(f,
"123\t456\t456\tout\tcommand\n");
198 fprintf(f,
"# ninja log v4\n");
199 fprintf(f,
"456\t789\t789\tout2\tcommand2\n");
223 virtual TimeStamp Stat(
const string& path,
string* err)
const {
226 virtual bool WriteFile(
const string& path,
const string& contents) {
230 virtual bool MakeDir(
const string& path) {
234 virtual Status
ReadFile(
const string& path,
string* contents,
string* err) {
238 virtual int RemoveFile(
const string& path) {
244 TEST_F(BuildLogTest, Restat) {
246 fprintf(f,
"# ninja log v4\n" 247 "1\t2\t3\tout\tcommand\n");
256 TestDiskInterface testDiskInterface;
257 char out2[] = {
'o',
'u',
't',
'2', 0 };
258 char* filter2[] = { out2 };
270 TEST_F(BuildLogTest, VeryLongInputLine) {
274 fprintf(f,
"# ninja log v4\n");
275 fprintf(f,
"123\t456\t456\tout\tcommand start");
276 for (
size_t i = 0; i < (512 << 10) / strlen(
" more_command"); ++i)
277 fputs(
" more_command", f);
279 fprintf(f,
"456\t789\t789\tout2\tcommand2\n");
298 TEST_F(BuildLogTest, MultiTargetEdge) {
300 "build out out.d: cat\n");
318 struct BuildLogRecompactTest :
public BuildLogTest {
319 virtual bool IsPathDead(
StringPiece s)
const {
return s ==
"out2"; }
322 TEST_F(BuildLogRecompactTest, Recompact) {
324 "build out: cat in\n" 325 "build out2: cat in\n");
333 for (
int i = 0; i < 200; ++i)
bool OpenForWrite(const std::string &path, const BuildLogUser &user, std::string *err)
Prepares writing to the log file without actually opening it - that will happen when/if it's needed...
const Entries & entries() const
LoadStatus Load(const std::string &path, std::string *err)
Load the on-disk log.
void AssertParse(State *state, const char *input, ManifestParserOptions opts)
bool RecordCommand(Edge *edge, int start_time, int end_time, TimeStamp mtime=0)
bool Restat(StringPiece path, const DiskInterface &disk_interface, int output_count, char **outputs, std::string *err)
Restat all outputs in the log.
StringPiece represents a slice of a string whose memory is managed externally.
Interface for accessing the disk.
Store a log of every command ran for every build.
A base test fixture that includes a State object with a builtin "cat" rule.
const char kTestFilename[]
int ReadFile(const string &path, string *contents, string *err)
bool Truncate(const string &path, size_t size, string *err)
#define ASSERT_NO_FATAL_FAILURE(a)
LogEntry * LookupByOutput(const std::string &path)
Lookup a previously-run command by its output path.
void AssertHash(const char *expected, uint64_t actual)
Can answer questions about the manifest for the BuildLog.