Skip to content

Commit

Permalink
[libc++] Remove uses of printf in some test support headers
Browse files Browse the repository at this point in the history
In the test suite, we generally don't use printf or other reporting
utilities. It's not that it wouldn't be useful, it's just that some
platforms don't support IO.

Instead, we try to keep test cases small and self-contained so that
we can reasonably easily reproduce failures locally and debug them.
This patch removes printf in some of the last places in the test suite
that used it. The only remaining places are in a deque test and in the
filesystem tests. The filesystem tests are arguably fine to keep using
IO, since we're testing <filesystem>. The deque test will be handled
separately.

Differential Revision: https://reviews.llvm.org/D114282
  • Loading branch information
ldionne committed Nov 22, 2021
1 parent 04a6dc0 commit e7cee55
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 46 deletions.
19 changes: 12 additions & 7 deletions libcxx/test/support/controlled_allocators.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,18 @@ struct AllocController {

template <class ...Args, class Alloc, class Tp>
bool checkConstruct(Alloc const&, Tp *p) const {
auto expectAlloc = &makeTypeID<Alloc>();
auto expectTp = &makeTypeID<Tp>();
auto expectArgs = &makeArgumentID<Args...>();
return last_construct_pointer == p &&
COMPARE_TYPEID(last_construct_alloc, expectAlloc) &&
COMPARE_TYPEID(last_construct_type, expectTp) &&
COMPARE_TYPEID(last_construct_args, expectArgs);
auto expectAlloc = &makeTypeID<Alloc>();
auto expectTp = &makeTypeID<Tp>();
auto expectArgs = &makeArgumentID<Args...>();
if (last_construct_pointer != p)
return false;
if (last_construct_alloc != expectAlloc)
return false;
if (last_construct_type != expectTp)
return false;
if (last_construct_args != expectArgs)
return false;
return true;
}

template <class Alloc, class Tp>
Expand Down
18 changes: 0 additions & 18 deletions libcxx/test/support/type_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#ifndef SUPPORT_TYPE_ID_H
#define SUPPORT_TYPE_ID_H

#include <functional>
#include <string>
#include <cstdio>
#include <cassert>

#include "test_macros.h"
Expand Down Expand Up @@ -70,20 +68,4 @@ inline TypeID const& makeArgumentID() {
return makeTypeIDImp<ArgumentListID<Args...>>();
}


// COMPARE_TYPEID(...) is a utility macro for generating diagnostics when
// two typeid's are expected to be equal
#define COMPARE_TYPEID(LHS, RHS) CompareTypeIDVerbose(#LHS, LHS, #RHS, RHS)

inline bool CompareTypeIDVerbose(const char* LHSString, TypeID const* LHS,
const char* RHSString, TypeID const* RHS) {
if (*LHS == *RHS)
return true;
std::printf("TypeID's not equal:\n");
std::printf("%s: %s\n----------\n%s: %s\n",
LHSString, LHS->name().c_str(),
RHSString, RHS->name().c_str());
return false;
}

#endif // SUPPORT_TYPE_ID_H
40 changes: 19 additions & 21 deletions libcxx/test/support/uses_alloc_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define USES_ALLOC_TYPES_H

#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <memory>

Expand Down Expand Up @@ -44,17 +43,6 @@ inline const char* toString(UsesAllocatorType UA) {
}
}

#define COMPARE_ALLOC_TYPE(LHS, RHS) CompareVerbose(#LHS, LHS, #RHS, RHS)

inline bool CompareVerbose(const char* LHSString, UsesAllocatorType LHS,
const char* RHSString, UsesAllocatorType RHS) {
if (LHS == RHS)
return true;
std::printf("UsesAllocatorType's don't match:\n%s %s\n----------\n%s %s\n",
LHSString, toString(LHS), RHSString, toString(RHS));
return false;
}

template <class Alloc, std::size_t N>
class UsesAllocatorV1;
// Implements form (1) of uses-allocator construction from the specified
Expand Down Expand Up @@ -191,26 +179,36 @@ struct UsesAllocatorTestBase {
template <class ...ArgTypes>
bool checkConstruct(UsesAllocatorType expectType) const {
auto expectArgs = &makeArgumentID<ArgTypes...>();
return COMPARE_ALLOC_TYPE(expectType, constructor_called) &&
COMPARE_TYPEID(args_id, expectArgs);
if (expectType != constructor_called)
return false;
if (args_id != expectArgs)
return false;
return true;
}

template <class ...ArgTypes>
bool checkConstruct(UsesAllocatorType expectType,
CtorAlloc const& expectAlloc) const {
auto ExpectID = &makeArgumentID<ArgTypes...>() ;
return COMPARE_ALLOC_TYPE(expectType, constructor_called) &&
COMPARE_TYPEID(args_id, ExpectID) &&
has_alloc() && expectAlloc == *get_alloc();

if (expectType != constructor_called)
return false;
if (args_id != ExpectID)
return false;
if (!has_alloc() || expectAlloc != *get_alloc())
return false;
return true;
}

bool checkConstructEquiv(UsesAllocatorTestBase& O) const {
if (has_alloc() != O.has_alloc())
return false;
return COMPARE_ALLOC_TYPE(constructor_called, O.constructor_called)
&& COMPARE_TYPEID(args_id, O.args_id)
&& (!has_alloc() || *get_alloc() == *O.get_alloc());
if (constructor_called != O.constructor_called)
return false;
if (args_id != O.args_id)
return false;
if (has_alloc() && *get_alloc() != *O.get_alloc())
return false;
return true;
}

protected:
Expand Down

0 comments on commit e7cee55

Please sign in to comment.