Skip to content

Commit 8553550

Browse files
Break up tests
1 parent 27baa7b commit 8553550

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1270
-708
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: std-at-least-c++23
10+
11+
/*
12+
(19.6.4.4) Comparisons [stacktrace.basic.cmp]
13+
14+
template<class Allocator2>
15+
friend bool operator==(const basic_stacktrace& x,
16+
const basic_stacktrace<Allocator2>& y) noexcept;
17+
*/
18+
19+
#include <cassert>
20+
#include <stacktrace>
21+
22+
_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE std::stacktrace test1() { return std::stacktrace::current(); }
23+
24+
_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE std::stacktrace test2a() { return test1(); }
25+
26+
_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE std::stacktrace test2b() { return test1(); }
27+
28+
_LIBCPP_NO_TAIL_CALLS
29+
int main(int, char**) {
30+
auto st1a = test1(); // [test1, main, ...]
31+
assert(st1a == st1a);
32+
33+
auto st1b = st1a;
34+
assert(st1a == st1b);
35+
36+
auto st2a = test2a(); // [test1, test2a, main, ...]
37+
assert(st1a != st2a);
38+
39+
std::stacktrace empty; // []
40+
assert(st1a != empty);
41+
assert(st2a != empty);
42+
43+
assert(st2a.size() > st1a.size());
44+
assert(st1a.size() > empty.size());
45+
46+
auto st2b = test2b(); // [test1, test2b, main, ...]
47+
assert(st2a.size() == st2b.size());
48+
assert(st2a != st2b);
49+
50+
return 0;
51+
}

libcxx/test/std/diagnostics/stacktrace/basic.cmp.pass.cpp renamed to libcxx/test/std/diagnostics/stacktrace/basic.cmp/strong_ordering.cpp

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,17 @@
88

99
// REQUIRES: std-at-least-c++23
1010

11-
#include <stacktrace>
12-
13-
#include <cassert>
14-
1511
/*
1612
(19.6.4.4) Comparisons [stacktrace.basic.cmp]
1713
18-
template<class Allocator2>
19-
friend bool operator==(const basic_stacktrace& x,
20-
const basic_stacktrace<Allocator2>& y) noexcept;
21-
2214
template<class Allocator2>
2315
friend strong_ordering operator<=>(const basic_stacktrace& x,
2416
const basic_stacktrace<Allocator2>& y) noexcept;
2517
*/
2618

19+
#include <cassert>
20+
#include <stacktrace>
21+
2722
_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE std::stacktrace test1() { return std::stacktrace::current(); }
2823

2924
_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE std::stacktrace test2a() { return test1(); }
@@ -33,39 +28,19 @@ _LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE std::stacktrace test2b() { return test1()
3328
_LIBCPP_NO_TAIL_CALLS
3429
int main(int, char**) {
3530
/*
36-
template<class Allocator2>
37-
friend bool operator==(const basic_stacktrace& x, const basic_stacktrace<Allocator2>& y) noexcept;
38-
Returns: equal(x.begin(), x.end(), y.begin(), y.end()).
31+
Returns: x.size() <=> y.size() if x.size() != y.size();
32+
lexicographical_compare_three_way(x.begin(), x.end(), y.begin(), y.end()) otherwise.
3933
*/
40-
auto st1a = test1(); // [test1, main, ...]
41-
assert(st1a == st1a);
4234

35+
auto st1a = test1(); // [test1, main, ...]
4336
auto st1b = st1a;
4437
assert(st1a == st1b);
45-
4638
auto st2a = test2a(); // [test1, test2a, main, ...]
4739
assert(st1a != st2a);
48-
4940
std::stacktrace empty; // []
50-
assert(st1a != empty);
51-
assert(st2a != empty);
52-
53-
assert(st2a.size() > st1a.size());
54-
assert(st1a.size() > empty.size());
55-
56-
auto st2b = test2b(); // [test1, test2b, main, ...]
57-
assert(st2a.size() == st2b.size());
41+
auto st2b = test2b(); // [test1, test2b, main, ...]
5842
assert(st2a != st2b);
5943

60-
/*
61-
template<class Allocator2>
62-
friend strong_ordering
63-
operator<=>(const basic_stacktrace& x, const basic_stacktrace<Allocator2>& y) noexcept;
64-
65-
Returns: x.size() <=> y.size() if x.size() != y.size();
66-
lexicographical_compare_three_way(x.begin(), x.end(), y.begin(), y.end()) otherwise.
67-
*/
68-
6944
// empty: []
7045
// st1a: [test1, main, ...]
7146
// st1b: [test1, main, ...] (copy of st1a)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: std-at-least-c++23
10+
// ADDITIONAL_COMPILE_FLAGS: -g
11+
12+
/*
13+
(19.6.4.2)
14+
15+
// [stacktrace.basic.cons], creation and assignment
16+
basic_stacktrace(const basic_stacktrace& other);
17+
basic_stacktrace(basic_stacktrace&& other) noexcept;
18+
basic_stacktrace(const basic_stacktrace& other, const allocator_type& alloc);
19+
basic_stacktrace(basic_stacktrace&& other, const allocator_type& alloc);
20+
basic_stacktrace& operator=(const basic_stacktrace& other);
21+
basic_stacktrace& operator=(basic_stacktrace&& other)
22+
noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
23+
allocator_traits<Allocator>::is_always_equal::value);
24+
*/
25+
26+
#include <cassert>
27+
#include <stacktrace>
28+
29+
// clang-format off
30+
uint32_t test1_line;
31+
uint32_t test2_line;
32+
33+
template <class A>
34+
_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE
35+
std::basic_stacktrace<A> test1(A& alloc) {
36+
test1_line = __LINE__ + 1; // add 1 to get the next line (where the call to `current` occurs)
37+
auto ret = std::basic_stacktrace<A>::current(alloc);
38+
return ret;
39+
}
40+
41+
template <class A>
42+
_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE
43+
std::basic_stacktrace<A> test2(A& alloc) {
44+
test2_line = __LINE__ + 1; // add 1 to get the next line (where the call to `current` occurs)
45+
auto ret = test1(alloc);
46+
return ret;
47+
}
48+
49+
_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE void test_copy_move_ctors() {
50+
using A = std::allocator<std::stacktrace_entry>;
51+
A alloc;
52+
auto st = std::basic_stacktrace<A>::current(alloc);
53+
54+
auto copy_constr = std::basic_stacktrace<A>(st);
55+
assert(st == copy_constr);
56+
57+
std::basic_stacktrace<A> copy_assign;
58+
copy_assign = std::basic_stacktrace<A>(st);
59+
assert(st == copy_assign);
60+
61+
auto st2 = test2(alloc);
62+
assert(st2.size());
63+
std::basic_stacktrace<A> move_constr(std::move(st2));
64+
assert(move_constr.size());
65+
assert(!st2.size());
66+
67+
auto st3 = test2(alloc);
68+
assert(st3.size());
69+
std::basic_stacktrace<A> move_assign;
70+
move_assign = std::move(st3);
71+
assert(move_assign.size());
72+
assert(!st3.size());
73+
74+
// TODO(stacktrace23): should we add test cases with `select_on_container_copy_construction`?
75+
}
76+
77+
_LIBCPP_NO_TAIL_CALLS
78+
int main(int, char**) {
79+
test_copy_move_ctors();
80+
return 0;
81+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: std-at-least-c++23
10+
// ADDITIONAL_COMPILE_FLAGS: -g
11+
12+
/*
13+
(19.6.4.2)
14+
15+
// [stacktrace.basic.cons], creation and assignment
16+
basic_stacktrace() noexcept(is_nothrow_default_constructible_v<allocator_type>);
17+
*/
18+
19+
#include <cassert>
20+
#include <stacktrace>
21+
22+
uint32_t test1_line;
23+
uint32_t test2_line;
24+
25+
template <class A>
26+
_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE std::basic_stacktrace<A> test1(A& alloc) {
27+
test1_line = __LINE__ + 1; // add 1 to get the next line (where the call to `current` occurs)
28+
auto ret = std::basic_stacktrace<A>::current(alloc);
29+
return ret;
30+
}
31+
32+
template <class A>
33+
_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE std::basic_stacktrace<A> test2(A& alloc) {
34+
test2_line = __LINE__ + 1; // add 1 to get the next line (where the call to `current` occurs)
35+
auto ret = test1(alloc);
36+
return ret;
37+
}
38+
39+
_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE void test_default_construct() {
40+
std::stacktrace st;
41+
assert(st.empty());
42+
}
43+
44+
_LIBCPP_NO_TAIL_CALLS
45+
int main(int, char**) {
46+
test_default_construct();
47+
return 0;
48+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: std-at-least-c++23
10+
// ADDITIONAL_COMPILE_FLAGS: -g
11+
12+
/*
13+
(19.6.4.2)
14+
15+
// [stacktrace.basic.cons], creation and assignment
16+
explicit basic_stacktrace(const allocator_type& alloc) noexcept;
17+
*/
18+
19+
#include <cassert>
20+
#include <stacktrace>
21+
22+
uint32_t test1_line;
23+
uint32_t test2_line;
24+
25+
template <class A>
26+
_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE std::basic_stacktrace<A> test1(A& alloc) {
27+
test1_line = __LINE__ + 1; // add 1 to get the next line (where the call to `current` occurs)
28+
auto ret = std::basic_stacktrace<A>::current(alloc);
29+
return ret;
30+
}
31+
32+
template <class A>
33+
_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE std::basic_stacktrace<A> test2(A& alloc) {
34+
test2_line = __LINE__ + 1; // add 1 to get the next line (where the call to `current` occurs)
35+
auto ret = test1(alloc);
36+
return ret;
37+
}
38+
39+
template <typename T>
40+
struct test_alloc {
41+
using size_type = size_t;
42+
using value_type = T;
43+
using pointer = T*;
44+
using const_pointer = T const*;
45+
46+
template <typename U>
47+
struct rebind {
48+
using other = test_alloc<U>;
49+
};
50+
51+
std::allocator<T> wrapped_{};
52+
53+
test_alloc() = default;
54+
55+
template <typename U>
56+
test_alloc(test_alloc<U> const& rhs) : wrapped_(rhs.wrapped_) {}
57+
58+
bool operator==(auto const& rhs) const { return &rhs == this; }
59+
bool operator==(test_alloc const&) const { return true; }
60+
61+
T* allocate(size_t n) { return wrapped_.allocate(n); }
62+
auto allocate_at_least(size_t n) { return wrapped_.allocate_at_least(n); }
63+
void deallocate(T* ptr, size_t n) { return wrapped_.deallocate(ptr, n); }
64+
};
65+
66+
_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE void test_construct_with_allocator() {
67+
test_alloc<std::stacktrace_entry> alloc;
68+
std::basic_stacktrace<decltype(alloc)> st(alloc);
69+
assert(st.empty());
70+
71+
st = std::basic_stacktrace<decltype(alloc)>::current(alloc);
72+
assert(!st.empty());
73+
}
74+
75+
_LIBCPP_NO_TAIL_CALLS
76+
int main(int, char**) {
77+
test_construct_with_allocator();
78+
return 0;
79+
}

0 commit comments

Comments
 (0)