Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / lib / sanitizer_common / tests / sanitizer_range_test.cpp
blobd8162152011b6532f902a4a7a5311f18af1b1219
1 //===-- sanitizer_region_test.cpp -----------------------------------------===//
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 #include "sanitizer_common/sanitizer_range.h"
10 #include <algorithm>
12 #include "gtest/gtest.h"
13 #include "sanitizer_common/sanitizer_common.h"
15 namespace __sanitizer {
17 class SanitizerCommon
18 : public testing::TestWithParam<std::tuple<
19 std::vector<Range>, std::vector<Range>, std::vector<Range>>> {};
21 TEST_P(SanitizerCommon, Intersect) {
23 InternalMmapVector<Range> output;
24 Intersect(std::get<0>(GetParam()), std::get<1>(GetParam()), output);
25 EXPECT_EQ(std::get<2>(GetParam()),
26 std::vector<Range>(output.begin(), output.end()));
29 InternalMmapVector<Range> output;
30 Intersect(std::get<1>(GetParam()), std::get<0>(GetParam()), output);
31 EXPECT_EQ(std::get<2>(GetParam()),
32 std::vector<Range>(output.begin(), output.end()));
36 static void PrintTo(const Range &r, std::ostream *os) {
37 *os << "[" << r.begin << ", " << r.end << ")";
40 static const std::tuple<std::vector<Range>, std::vector<Range>,
41 std::vector<Range>>
42 kTests[] = {
43 {{}, {}, {}},
44 {{{100, 1000}}, {{5000, 10000}}, {}},
45 {{{100, 1000}, {200, 2000}}, {{5000, 10000}, {6000, 11000}}, {}},
46 {{{100, 1000}}, {{100, 1000}}, {{100, 1000}}},
47 {{{100, 1000}}, {{50, 150}}, {{100, 150}}},
48 {{{100, 1000}}, {{150, 250}}, {{150, 250}}},
49 {{{100, 1000}, {100, 1000}}, {{100, 1000}}, {{100, 1000}}},
50 {{{100, 1000}}, {{500, 1500}}, {{500, 1000}}},
51 {{{100, 200}}, {{200, 300}, {1, 1000}}, {{100, 200}}},
52 {{{100, 200}, {200, 300}}, {{100, 300}}, {{100, 300}}},
53 {{{100, 200}, {200, 300}, {300, 400}}, {{150, 350}}, {{150, 350}}},
54 {{{100, 200}, {300, 400}, {500, 600}},
55 {{0, 1000}},
56 {{100, 200}, {300, 400}, {500, 600}}},
59 INSTANTIATE_TEST_SUITE_P(SanitizerCommonEmpty, SanitizerCommon,
60 testing::ValuesIn(kTests));
62 } // namespace __sanitizer