aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/cpp
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2018-06-25 01:10:26 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-25 01:12:27 -0700
commitda91730760ac9078183c236cb9ab95f38a5fd3b8 (patch)
treebc83357596371d3d3b284d5775492f806e38ffb3 /src/test/cpp
parent88d1caeef07533429468515f63b3d4e2cb9a7a80 (diff)
Windows,Bazel client: check embedded tools faster
The Bazel client on Windows is now 50% faster to check the embedded tools than it was before. Results: - Linux: 20 ms -> 6 ms - Windows: 294 ms -> 133 ms Measurements were done with n=10 runs and a hot server, using blaze::GetMillisecondsMonotonic(). Previously the client performed the same tasks multiple times while trying to determine if a path was a good extracted binary. (E.g. converted the path to Windows format multiple times, checked if it was a directory twice, opened the path twice.) Now the client performes these tasks only once, e.g. it converts path once and stats only once. See https://github.com/bazelbuild/bazel/issues/5444 Closes #5445. PiperOrigin-RevId: 201913758
Diffstat (limited to 'src/test/cpp')
-rw-r--r--src/test/cpp/util/file_test.cc28
-rw-r--r--src/test/cpp/util/file_windows_test.cc28
2 files changed, 39 insertions, 17 deletions
diff --git a/src/test/cpp/util/file_test.cc b/src/test/cpp/util/file_test.cc
index 9683d9dcbe..a7eb9c7614 100644
--- a/src/test/cpp/util/file_test.cc
+++ b/src/test/cpp/util/file_test.cc
@@ -148,37 +148,31 @@ TEST(FileTest, TestMtimeHandling) {
string tempdir(tempdir_cstr);
std::unique_ptr<IFileMtime> mtime(CreateFileMtime());
- bool actual = false;
- ASSERT_TRUE(mtime->GetIfInDistantFuture(tempdir, &actual));
- ASSERT_FALSE(actual);
-
+ // Assert that a directory is always untampered with. (We do
+ // not care about directories' mtimes.)
+ ASSERT_TRUE(mtime->IsUntampered(tempdir));
// Create a new file, assert its mtime is not in the future.
string file(JoinPath(tempdir, "foo.txt"));
ASSERT_TRUE(WriteFile("hello", 5, file));
- ASSERT_TRUE(mtime->GetIfInDistantFuture(file, &actual));
- ASSERT_FALSE(actual);
+ ASSERT_FALSE(mtime->IsUntampered(file));
// Set the file's mtime to the future, assert that it's so.
ASSERT_TRUE(mtime->SetToDistantFuture(file));
- ASSERT_TRUE(mtime->GetIfInDistantFuture(file, &actual));
- ASSERT_TRUE(actual);
- // Overwrite the file, resetting its mtime, assert that GetIfInDistantFuture
- // notices.
+ ASSERT_TRUE(mtime->IsUntampered(file));
+ // Overwrite the file, resetting its mtime, assert that
+ // IsUntampered notices.
ASSERT_TRUE(WriteFile("world", 5, file));
- ASSERT_TRUE(mtime->GetIfInDistantFuture(file, &actual));
- ASSERT_FALSE(actual);
+ ASSERT_FALSE(mtime->IsUntampered(file));
// Set it to the future again so we can reset it using SetToNow.
ASSERT_TRUE(mtime->SetToDistantFuture(file));
- ASSERT_TRUE(mtime->GetIfInDistantFuture(file, &actual));
- ASSERT_TRUE(actual);
+ ASSERT_TRUE(mtime->IsUntampered(file));
// Assert that SetToNow resets the timestamp.
ASSERT_TRUE(mtime->SetToNow(file));
- ASSERT_TRUE(mtime->GetIfInDistantFuture(file, &actual));
- ASSERT_FALSE(actual);
+ ASSERT_FALSE(mtime->IsUntampered(file));
// Delete the file and assert that we can no longer set or query its mtime.
ASSERT_TRUE(UnlinkPath(file));
ASSERT_FALSE(mtime->SetToNow(file));
ASSERT_FALSE(mtime->SetToDistantFuture(file));
- ASSERT_FALSE(mtime->GetIfInDistantFuture(file, &actual));
+ ASSERT_FALSE(mtime->IsUntampered(file));
}
TEST(FileTest, TestRenameDirectory) {
diff --git a/src/test/cpp/util/file_windows_test.cc b/src/test/cpp/util/file_windows_test.cc
index 7bef9cf593..c048e07950 100644
--- a/src/test/cpp/util/file_windows_test.cc
+++ b/src/test/cpp/util/file_windows_test.cc
@@ -34,6 +34,8 @@
#error("This test should only be run on Windows")
#endif // !defined(_WIN32) && !defined(__CYGWIN__)
+#define TOSTRING(x) #x
+
namespace blaze_util {
using bazel::windows::CreateJunction;
@@ -297,4 +299,30 @@ TEST_F(FileWindowsTest, TestMakeCanonical) {
ASSERT_EQ(dircanon, symcanon);
}
+TEST_F(FileWindowsTest, TestMtimeHandling) {
+ const char* tempdir_cstr = getenv("TEST_TMPDIR");
+ ASSERT_NE(tempdir_cstr, nullptr);
+ ASSERT_NE(tempdir_cstr[0], 0);
+ string tempdir(tempdir_cstr);
+
+ string target(JoinPath(tempdir, "target" TOSTRING(__LINE__)));
+ wstring wtarget;
+ EXPECT_TRUE(AsWindowsPath(target, &wtarget, nullptr));
+ EXPECT_TRUE(CreateDirectoryW(wtarget.c_str(), NULL));
+
+ std::unique_ptr<IFileMtime> mtime(CreateFileMtime());
+ // Assert that a directory is always a good embedded binary. (We do not care
+ // about directories' mtimes.)
+ ASSERT_TRUE(mtime.get()->IsUntampered(target));
+ // Assert that junctions whose target exists are "good" embedded binaries.
+ string sym(JoinPath(tempdir, "junc" TOSTRING(__LINE__)));
+ CREATE_JUNCTION(sym, target);
+ ASSERT_TRUE(mtime.get()->IsUntampered(sym));
+ // Assert that checking fails for non-existent directories and dangling
+ // junctions.
+ EXPECT_TRUE(RemoveDirectoryW(wtarget.c_str()));
+ ASSERT_FALSE(mtime.get()->IsUntampered(target));
+ ASSERT_FALSE(mtime.get()->IsUntampered(sym));
+}
+
} // namespace blaze_util