This is an archive of the discontinued LLVM Phabricator instance.

Give libcxx tests temporary filenames that are actually unique.
ClosedPublic

Authored by jroelofs on Aug 18 2014, 3:51 PM.

Details

Reviewers
danalbert
EricWF
Summary

With newlib as the libc, the following program would print out the same filename twice:

#include "support/platform_support.h"
#include <iostream>
int main() {
std::string temp1 = get_temp_file_name();
std::string temp2 = get_temp_file_name();
std::cout << temp1 << " " << temp2 << std::endl;
}

This breaks a few of the tests similar to input.output/file.streams/fstreams/filebuf.assign/member_swap.pass.cpp which expect the returned filenames to be different.

This patch fixes that bug by creating a TempFileName class which, on construction, is guaranteed to have a unique name.

Please double check the Windows side of the TempFileName class with extra scrutiny. I have neither tested, nor built this on Windows (and I don't have a machine to try it out on either).

Diff Detail

Event Timeline

jroelofs updated this revision to Diff 12632.Aug 18 2014, 3:51 PM
jroelofs retitled this revision from to Give libcxx tests temporary filenames that are actually unique..
jroelofs updated this object.
jroelofs edited the test plan for this revision. (Show Details)
jroelofs added a reviewer: danalbert.
jroelofs added a subscriber: Unknown Object (MLST).
danalbert added inline comments.Aug 18 2014, 4:54 PM
test/support/platform_support.h
55

It's actually a TempFile, not a TempFileName, since you leave the fd open. I think what you actually wanted was to mkstemp(), stash the name and then close the fd (before leaving the constructor).

76

I must be missing something here... std::remove() takes three arguments.

jroelofs added inline comments.Aug 18 2014, 5:57 PM
test/support/platform_support.h
44

s/algorithm/cstdio/

yikes. I guess it builds with out this include...

55

Oh good point. For some reason, I thought I needed to keep the fd open in order to keep the file name unique between concurrent processes running these tests.... but after reading the doc again, I guess not.

76

There's another std::remove... bad naming, as it does something completely different than the version you're thinking of.

http://en.cppreference.com/w/cpp/io/c/remove

jroelofs updated this revision to Diff 12640.Aug 18 2014, 6:51 PM

Update the patch to reflect @danalbert's comments.

danalbert accepted this revision.Aug 18 2014, 7:22 PM
danalbert edited edge metadata.
This revision is now accepted and ready to land.Aug 18 2014, 7:22 PM
jroelofs closed this revision.Aug 19 2014, 7:06 AM

r215977