Revise loopback device handling to be parallelization safe.
Update engine tests were allocating loopback devices in a non-atomic fashion.
When they were run in parallel with other tests that were using loopback
devices, this could lead to two tests using the same device and failing.
This change follows jrbarnette's advice and allocates loopback devices
atomically using "losetup --show -f <file to bind>".
NOTE: integration_unittest.cc is not currently being built or run, and
so the change here has not been verified. I only discovered it wasn't being
built while making this change, and fixing/deleting it seemed out of scope
for the change.
BUG=chromium-os:24975
TEST=Ran unittests
Change-Id: Ica060c8add009cac134e22b46b4e87588d0246e0
Reviewed-on: https://gerrit.chromium.org/gerrit/15128
Reviewed-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Darin Petkov <petkov@chromium.org>
Tested-by: Don Garrett <dgarrett@chromium.org>
Commit-Ready: Don Garrett <dgarrett@chromium.org>
diff --git a/postinstall_runner_action_unittest.cc b/postinstall_runner_action_unittest.cc
index 69a5eb0..a5649e0 100644
--- a/postinstall_runner_action_unittest.cc
+++ b/postinstall_runner_action_unittest.cc
@@ -123,24 +123,12 @@
ASSERT_EQ(0, System(string("rm -f ") + cwd + "/postinst_called"));
// get a loop device we can use for the install device
- FILE* find_dev_cmd = popen("losetup -f", "r");
- ASSERT_TRUE(find_dev_cmd);
+ string dev = "/dev/null";
- char dev[100] = {0};
- size_t r = fread(dev, 1, sizeof(dev), find_dev_cmd);
- ASSERT_GT(r, 0);
- ASSERT_LT(r, sizeof(dev));
- ASSERT_TRUE(feof(find_dev_cmd));
- fclose(find_dev_cmd);
-
- // strip trailing newline on dev
- if (dev[strlen(dev) - 1] == '\n')
- dev[strlen(dev) - 1] = '\0';
-
- scoped_ptr<ScopedLoopbackDeviceReleaser> loop_releaser;
+ scoped_ptr<ScopedLoopbackDeviceBinder> loop_releaser;
if (do_losetup) {
- ASSERT_EQ(0, System(string("losetup ") + dev + " " + cwd + "/image.dat"));
- loop_releaser.reset(new ScopedLoopbackDeviceReleaser(dev));
+ loop_releaser.reset(new ScopedLoopbackDeviceBinder(cwd + "/image.dat",
+ &dev));
}
ActionProcessor processor;