summaryrefslogtreecommitdiffstats
path: root/libcxx/test/support/rapid-cxx-test.hpp
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2018-07-20 01:22:32 +0000
committerEric Fiselier <eric@efcs.ca>2018-07-20 01:22:32 +0000
commitc16998649e1f55c61158004f461fd629d9b8b7f9 (patch)
treec1434a61a1da354f770f4ac06994211375a84253 /libcxx/test/support/rapid-cxx-test.hpp
parent40fa4a1a559765ada93268c4d45c54b62779166b (diff)
downloadbcm5719-llvm-c16998649e1f55c61158004f461fd629d9b8b7f9.tar.gz
bcm5719-llvm-c16998649e1f55c61158004f461fd629d9b8b7f9.zip
[libc++] Implement Directory Entry Caching -- Sort of.
Summary: This patch implements directory_entry caching *almost* as specified in P0317r1. However, I explicitly chose to deviate from the standard as I'll explain below. The approach I decided to take is a fully caching one. When `refresh()` is called, the cache is populated by calls to `stat` and `lstat` as needed. During directory iteration the cache is only populated with the `file_type` as reported by `readdir`. The cache can be in the following states: * `_Empty`: There is nothing in the cache (likely due to an error) * `_IterSymlink`: Created by directory iteration when we walk onto a symlink only the symlink file type is known. * `_IterNonSymlink`: Created by directory iteration when we walk onto a non-symlink. Both the regular file type and symlink file type are known. * `_RefreshSymlink` and `_RefreshNonSymlink`: A full cache created by `refresh()`. This case includes dead symlinks. * `_RefreshSymlinkUnresolved`: A partial cache created by refresh when we fail to resolve the file pointed to by a symlink (likely due to permissions). Symlink attributes are cached, but attributes about the linked entity are not. As mentioned, this implementation purposefully deviates from the standard. According to some readings of the specification, and the Windows filesystem implementation, the constructors and modifiers which don't pass an `error_code` must throw when the `directory_entry` points to a entity which doesn't exist. or when attribute resolution fails for another reason. @BillyONeal has proposed a more reasonable set of requirements, where modifiers other than refresh ignore errors. This is the behavior libc++ currently implements, with the expectation some form of the new language will be accepted into the standard. Some additional semantics which differ from the Windows implementation: 1. `refresh` will not throw when the entry doesn't exist. In this case we can still meet the functions specification, so we don't treat it as an error. 2. We don't clear the path name when a constructor fails via refresh (this will hopefully be changed in the standard as well). It should be noted that libstdc++'s current implementation has the same behavior as libc++, except for point (2). If the changes to the specification don't get accepted, we'll be able to make the changes later. [1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0317r1.html Reviewers: mclow.lists, gromer, ldionne, aaron.ballman Subscribers: BillyONeal, christof, cfe-commits Differential Revision: https://reviews.llvm.org/D49530 llvm-svn: 337516
Diffstat (limited to 'libcxx/test/support/rapid-cxx-test.hpp')
-rw-r--r--libcxx/test/support/rapid-cxx-test.hpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/libcxx/test/support/rapid-cxx-test.hpp b/libcxx/test/support/rapid-cxx-test.hpp
index a25bda53109..eb24ac25976 100644
--- a/libcxx/test/support/rapid-cxx-test.hpp
+++ b/libcxx/test/support/rapid-cxx-test.hpp
@@ -221,6 +221,24 @@ namespace Name \
} while (false)
#
+#define TEST_CHECK_THROW_RESULT(Except, Checker, ...) \
+ do { \
+ TEST_SET_CHECKPOINT(); \
+ ::rapid_cxx_test::test_outcome m_f(::rapid_cxx_test::failure_type::none, \
+ __FILE__, TEST_FUNC_NAME(), __LINE__, \
+ "TEST_CHECK_THROW_RESULT(" #Except \
+ "," #Checker "," #__VA_ARGS__ ")", \
+ ""); \
+ try { \
+ (static_cast<void>(__VA_ARGS__)); \
+ m_f.type = ::rapid_cxx_test::failure_type::check; \
+ } catch (Except const& Caught) { \
+ Checker(Caught); \
+ } \
+ ::rapid_cxx_test::get_reporter().report(m_f); \
+ } while (false)
+#
+
#else // TEST_HAS_NO_EXCEPTIONS
# define TEST_CHECK_NO_THROW(...) \
@@ -236,6 +254,7 @@ namespace Name \
#
#define TEST_CHECK_THROW(Except, ...) ((void)0)
+#define TEST_CHECK_THROW_RESULT(Except, Checker, ...) ((void)0)
#endif // TEST_HAS_NO_EXCEPTIONS
OpenPOWER on IntegriCloud