[llvm] r236106 - Relax assert to avoid spurious failures with /dev/null.

Reid Kleckner rnk at google.com
Wed Apr 29 09:57:33 PDT 2015


TestDevNull fails on Windows, so I disabled it in r236126. Changing it to
open "NUL" instead of "/dev/null" doesn't fix it either.

On Wed, Apr 29, 2015 at 7:53 AM, Rafael Espindola <
rafael.espindola at gmail.com> wrote:

> Author: rafael
> Date: Wed Apr 29 09:53:25 2015
> New Revision: 236106
>
> URL: http://llvm.org/viewvc/llvm-project?rev=236106&view=rev
> Log:
> Relax assert to avoid spurious failures with /dev/null.
>
> Modified:
>     llvm/trunk/include/llvm/Support/raw_ostream.h
>     llvm/trunk/unittests/Support/raw_pwrite_stream_test.cpp
>
> Modified: llvm/trunk/include/llvm/Support/raw_ostream.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/raw_ostream.h?rev=236106&r1=236105&r2=236106&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/raw_ostream.h (original)
> +++ llvm/trunk/include/llvm/Support/raw_ostream.h Wed Apr 29 09:53:25 2015
> @@ -323,7 +323,13 @@ public:
>    explicit raw_pwrite_stream(bool Unbuffered = false)
>        : raw_ostream(Unbuffered) {}
>    void pwrite(const char *Ptr, size_t Size, uint64_t Offset) {
> -    assert(Size + Offset <= tell() && "We don't support extending the
> stream");
> +#ifndef NDBEBUG
> +    uint64_t Pos = tell();
> +    // /dev/null always reports a pos of 0, so we cannot perform this
> check
> +    // in that case.
> +    if (Pos)
> +      assert(Size + Offset <= Pos && "We don't support extending the
> stream");
> +#endif
>      pwrite_impl(Ptr, Size, Offset);
>    }
>  };
>
> Modified: llvm/trunk/unittests/Support/raw_pwrite_stream_test.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/raw_pwrite_stream_test.cpp?rev=236106&r1=236105&r2=236106&view=diff
>
> ==============================================================================
> --- llvm/trunk/unittests/Support/raw_pwrite_stream_test.cpp (original)
> +++ llvm/trunk/unittests/Support/raw_pwrite_stream_test.cpp Wed Apr 29
> 09:53:25 2015
> @@ -9,6 +9,7 @@
>
>  #include "gtest/gtest.h"
>  #include "llvm/ADT/SmallString.h"
> +#include "llvm/Support/FileSystem.h"
>  #include "llvm/Support/raw_ostream.h"
>
>  using namespace llvm;
> @@ -30,4 +31,32 @@ TEST(raw_pwrite_ostreamTest, TestSVector
>  #endif
>  #endif
>  }
> +
> +TEST(raw_pwrite_ostreamTest, TestFD) {
> +  SmallString<64> Path;
> +  int FD;
> +  sys::fs::createTemporaryFile("foo", "bar", FD, Path);
> +  raw_fd_ostream OS(FD, true);
> +  OS << "abcd";
> +  StringRef Test = "test";
> +  OS.pwrite(Test.data(), Test.size(), 0);
> +  OS.pwrite(Test.data(), Test.size(), 0);
> +
> +#ifdef GTEST_HAS_DEATH_TEST
> +#ifndef NDEBUG
> +  EXPECT_DEATH(OS.pwrite("12345", 5, 0),
> +               "We don't support extending the stream");
> +#endif
> +#endif
> +}
> +
> +TEST(raw_pwrite_ostreamTest, TestDevNull) {
> +  int FD;
> +  sys::fs::openFileForWrite("/dev/null", FD, sys::fs::F_None);
> +  raw_fd_ostream OS(FD, true);
> +  OS << "abcd";
> +  StringRef Test = "test";
> +  OS.pwrite(Test.data(), Test.size(), 0);
> +  OS.pwrite(Test.data(), Test.size(), 0);
> +}
>  }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150429/9a09f530/attachment.html>


More information about the llvm-commits mailing list