From dc62be191503c932a2025b2489c2da0c55d46ec3 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Sat, 18 Jun 2016 04:10:23 +0000 Subject: Fix 3 bugs in filesystem tests and implementation. This patch fixes the following bugs, all of which were discovered while testing a 32 bit build on a 64 bit machine. * path.itr/iterator.pass.cpp has undefined behavior. 'path::iterator' stashes the value of the element inside the iterator. This violates the BiDirIterator requirements but is allowed for path::iterator. However this means that using reverse_iterator has undefined behavior because it assumes that 'Iter tmp = it; return *tmp' will not create a dangling reference. However it does, and this caused this particular test to fail. * path.native.obs/string_alloc.pass.cpp tested the SSO with a long string. On 32 bit builds std::wstring only has the SSO for strings of size 2. The test was using a string of size 4. * fs.op.space/space.pass.cpp had overflows while calculating the expected values. The fix here is to convert the statvfs data members to std::uintmax_t before multiplying them. The internal implementation already does this but the tests needed to do it as well. llvm-svn: 273078 --- .../fs.op.funcs/fs.op.space/space.pass.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'libcxx/test/std/experimental/filesystem/fs.op.funcs') diff --git a/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.space/space.pass.cpp b/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.space/space.pass.cpp index 14ea0805785..865191520be 100644 --- a/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.space/space.pass.cpp +++ b/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.space/space.pass.cpp @@ -88,13 +88,22 @@ TEST_CASE(basic_space_test) TEST_CHECK(expect.f_bfree > 0); TEST_CHECK(expect.f_bsize > 0); TEST_CHECK(expect.f_blocks > 0); - TEST_CHECK(expect.f_frsize > 0); + TEST_REQUIRE(expect.f_frsize > 0); + auto do_mult = [&](std::uintmax_t val) { + std::uintmax_t fsize = expect.f_frsize; + std::uintmax_t new_val = val * fsize; + TEST_CHECK(new_val / fsize == val); // Test for overflow + return new_val; + }; const std::uintmax_t bad_value = static_cast(-1); - const std::uintmax_t expect_cap = expect.f_blocks * expect.f_frsize; + const std::uintmax_t expect_capacity = do_mult(expect.f_blocks); + const std::uintmax_t expect_free = do_mult(expect.f_bfree); + const std::uintmax_t expect_avail = do_mult(expect.f_bavail); + // Other processes running on the operating system may have changed // the amount of space available. Check that these are within tolerances. // Currently 5% of capacity - const std::uintmax_t delta = expect_cap / 20; + const std::uintmax_t delta = expect_capacity / 20; const path cases[] = { StaticEnv::File, StaticEnv::Dir, @@ -107,11 +116,11 @@ TEST_CASE(basic_space_test) space_info info = space(p, ec); TEST_CHECK(!ec); TEST_CHECK(info.capacity != bad_value); - TEST_CHECK((expect.f_blocks * expect.f_frsize) == info.capacity); + TEST_CHECK(expect_capacity == info.capacity); TEST_CHECK(info.free != bad_value); - TEST_CHECK(EqualDelta((expect.f_bfree * expect.f_frsize), info.free, delta)); + TEST_CHECK(EqualDelta(expect_free, info.free, delta)); TEST_CHECK(info.available != bad_value); - TEST_CHECK(EqualDelta((expect.f_bavail * expect.f_frsize), info.available, delta)); + TEST_CHECK(EqualDelta(expect_avail, info.available, delta)); } } -- cgit v1.2.3