2014-07-09 19:40:08 +00:00
|
|
|
//===- SpecialCaseListTest.cpp - Unit tests for SpecialCaseList -----------===//
|
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-07-09 19:40:08 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 11:06:56 +00:00
|
|
|
#include "llvm/Support/SpecialCaseList.h"
|
2015-02-04 17:39:48 +00:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2014-07-09 19:40:08 +00:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2019-11-21 11:32:17 +01:00
|
|
|
#include "llvm/Support/VirtualFileSystem.h"
|
2023-09-01 08:48:07 -07:00
|
|
|
#include "gmock/gmock.h"
|
2014-07-09 19:40:08 +00:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2023-09-01 08:48:07 -07:00
|
|
|
using testing::HasSubstr;
|
|
|
|
using testing::StartsWith;
|
2014-07-09 19:40:08 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class SpecialCaseListTest : public ::testing::Test {
|
|
|
|
protected:
|
2014-09-02 18:13:54 +00:00
|
|
|
std::unique_ptr<SpecialCaseList> makeSpecialCaseList(StringRef List,
|
2023-09-01 08:48:07 -07:00
|
|
|
std::string &Error,
|
|
|
|
bool UseGlobs = true) {
|
|
|
|
auto S = List.str();
|
2023-12-11 15:30:28 -08:00
|
|
|
if (!UseGlobs)
|
|
|
|
S = (Twine("#!special-case-list-v1\n") + S).str();
|
2023-09-01 08:48:07 -07:00
|
|
|
std::unique_ptr<MemoryBuffer> MB = MemoryBuffer::getMemBuffer(S);
|
2014-07-09 19:40:08 +00:00
|
|
|
return SpecialCaseList::create(MB.get(), Error);
|
|
|
|
}
|
|
|
|
|
2023-09-01 08:48:07 -07:00
|
|
|
std::unique_ptr<SpecialCaseList> makeSpecialCaseList(StringRef List,
|
|
|
|
bool UseGlobs = true) {
|
2014-07-09 19:40:08 +00:00
|
|
|
std::string Error;
|
2023-09-01 08:48:07 -07:00
|
|
|
auto SCL = makeSpecialCaseList(List, Error, UseGlobs);
|
2014-07-09 19:40:08 +00:00
|
|
|
assert(SCL);
|
|
|
|
assert(Error == "");
|
|
|
|
return SCL;
|
|
|
|
}
|
2015-02-04 17:39:48 +00:00
|
|
|
|
2023-09-01 08:48:07 -07:00
|
|
|
std::string makeSpecialCaseListFile(StringRef Contents,
|
|
|
|
bool UseGlobs = true) {
|
2015-02-04 17:39:48 +00:00
|
|
|
int FD;
|
|
|
|
SmallString<64> Path;
|
|
|
|
sys::fs::createTemporaryFile("SpecialCaseListTest", "temp", FD, Path);
|
|
|
|
raw_fd_ostream OF(FD, true, true);
|
2023-12-11 15:30:28 -08:00
|
|
|
if (!UseGlobs)
|
|
|
|
OF << "#!special-case-list-v1\n";
|
2015-02-04 17:39:48 +00:00
|
|
|
OF << Contents;
|
|
|
|
OF.close();
|
2020-01-28 20:23:46 +01:00
|
|
|
return std::string(Path.str());
|
2015-02-04 17:39:48 +00:00
|
|
|
}
|
2014-07-09 19:40:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(SpecialCaseListTest, Basic) {
|
2014-09-02 18:13:54 +00:00
|
|
|
std::unique_ptr<SpecialCaseList> SCL =
|
2014-07-09 19:40:08 +00:00
|
|
|
makeSpecialCaseList("# This is a comment.\n"
|
|
|
|
"\n"
|
|
|
|
"src:hello\n"
|
|
|
|
"src:bye\n"
|
|
|
|
"src:hi=category\n"
|
2014-09-02 18:13:54 +00:00
|
|
|
"src:z*=category\n");
|
2017-09-25 22:11:11 +00:00
|
|
|
EXPECT_TRUE(SCL->inSection("", "src", "hello"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "src", "bye"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "src", "hi", "category"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "src", "zzzz", "category"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "src", "hi"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "fun", "hello"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "src", "hello", "category"));
|
2017-11-07 21:16:46 +00:00
|
|
|
|
2023-12-11 15:30:28 -08:00
|
|
|
EXPECT_EQ(3u, SCL->inSectionBlame("", "src", "hello"));
|
|
|
|
EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "bye"));
|
|
|
|
EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "hi", "category"));
|
|
|
|
EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "zzzz", "category"));
|
2017-11-07 21:16:46 +00:00
|
|
|
EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hi"));
|
|
|
|
EXPECT_EQ(0u, SCL->inSectionBlame("", "fun", "hello"));
|
|
|
|
EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hello", "category"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpecialCaseListTest, CorrectErrorLineNumberWithBlankLine) {
|
|
|
|
std::string Error;
|
|
|
|
EXPECT_EQ(nullptr, makeSpecialCaseList("# This is a comment.\n"
|
|
|
|
"\n"
|
|
|
|
"[not valid\n",
|
|
|
|
Error));
|
2023-12-11 15:30:28 -08:00
|
|
|
EXPECT_THAT(Error, StartsWith("malformed section header on line 3:"));
|
2017-11-07 21:16:46 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(nullptr, makeSpecialCaseList("\n\n\n"
|
|
|
|
"[not valid\n",
|
|
|
|
Error));
|
2023-12-11 15:30:28 -08:00
|
|
|
EXPECT_THAT(Error, StartsWith("malformed section header on line 4:"));
|
2017-09-25 22:11:11 +00:00
|
|
|
}
|
|
|
|
|
2023-09-01 08:48:07 -07:00
|
|
|
TEST_F(SpecialCaseListTest, SectionGlobErrorHandling) {
|
2017-09-25 22:11:11 +00:00
|
|
|
std::string Error;
|
|
|
|
EXPECT_EQ(makeSpecialCaseList("[address", Error), nullptr);
|
2023-09-01 08:48:07 -07:00
|
|
|
EXPECT_THAT(Error, StartsWith("malformed section header "));
|
2017-09-25 22:11:11 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(makeSpecialCaseList("[[]", Error), nullptr);
|
2023-09-01 08:48:07 -07:00
|
|
|
EXPECT_EQ(
|
|
|
|
Error,
|
2023-12-11 15:30:28 -08:00
|
|
|
"malformed section at line 1: '[': invalid glob pattern, unmatched '['");
|
2017-10-24 23:56:12 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(makeSpecialCaseList("src:=", Error), nullptr);
|
2023-09-01 08:48:07 -07:00
|
|
|
EXPECT_THAT(Error, HasSubstr("Supplied glob was blank"));
|
2017-09-25 22:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpecialCaseListTest, Section) {
|
|
|
|
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("src:global\n"
|
2023-09-01 08:48:07 -07:00
|
|
|
"[{sect1,sect2}]\n"
|
2017-09-25 22:11:11 +00:00
|
|
|
"src:test1\n"
|
|
|
|
"[sect3*]\n"
|
|
|
|
"src:test2\n");
|
|
|
|
EXPECT_TRUE(SCL->inSection("arbitrary", "src", "global"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "src", "global"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect1", "src", "test1"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("sect1-arbitrary", "src", "test1"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("sect", "src", "test1"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("sect1", "src", "test2"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect2", "src", "test1"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect3", "src", "test2"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect3-arbitrary", "src", "test2"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "src", "test1"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "src", "test2"));
|
2014-07-09 19:40:08 +00:00
|
|
|
}
|
|
|
|
|
2014-11-20 01:27:19 +00:00
|
|
|
TEST_F(SpecialCaseListTest, GlobalInit) {
|
2014-09-02 18:13:54 +00:00
|
|
|
std::unique_ptr<SpecialCaseList> SCL =
|
|
|
|
makeSpecialCaseList("global:foo=init\n");
|
2017-09-25 22:11:11 +00:00
|
|
|
EXPECT_FALSE(SCL->inSection("", "global", "foo"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "global", "bar"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "global", "foo", "init"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "global", "bar", "init"));
|
2014-07-09 19:40:08 +00:00
|
|
|
|
2014-09-02 18:13:54 +00:00
|
|
|
SCL = makeSpecialCaseList("type:t2=init\n");
|
2017-09-25 22:11:11 +00:00
|
|
|
EXPECT_FALSE(SCL->inSection("", "type", "t1"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "type", "t2"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "type", "t1", "init"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "type", "t2", "init"));
|
2014-07-09 19:40:08 +00:00
|
|
|
|
2014-09-02 18:13:54 +00:00
|
|
|
SCL = makeSpecialCaseList("src:hello=init\n");
|
2017-09-25 22:11:11 +00:00
|
|
|
EXPECT_FALSE(SCL->inSection("", "src", "hello"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "src", "bye"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "src", "hello", "init"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "src", "bye", "init"));
|
2014-07-09 19:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpecialCaseListTest, Substring) {
|
2014-09-02 18:13:54 +00:00
|
|
|
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("src:hello\n"
|
|
|
|
"fun:foo\n"
|
|
|
|
"global:bar\n");
|
2017-09-25 22:11:11 +00:00
|
|
|
EXPECT_FALSE(SCL->inSection("", "src", "othello"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "fun", "tomfoolery"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "global", "bartender"));
|
2014-07-09 19:40:08 +00:00
|
|
|
|
2014-09-02 18:13:54 +00:00
|
|
|
SCL = makeSpecialCaseList("fun:*foo*\n");
|
2017-09-25 22:11:11 +00:00
|
|
|
EXPECT_TRUE(SCL->inSection("", "fun", "tomfoolery"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "fun", "foobar"));
|
2014-07-09 19:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpecialCaseListTest, InvalidSpecialCaseList) {
|
|
|
|
std::string Error;
|
|
|
|
EXPECT_EQ(nullptr, makeSpecialCaseList("badline", Error));
|
2023-12-11 15:30:28 -08:00
|
|
|
EXPECT_EQ("malformed line 1: 'badline'", Error);
|
2014-07-09 19:40:08 +00:00
|
|
|
EXPECT_EQ(nullptr, makeSpecialCaseList("src:bad[a-", Error));
|
2023-09-01 08:48:07 -07:00
|
|
|
EXPECT_EQ(
|
2023-12-11 15:30:28 -08:00
|
|
|
"malformed glob in line 1: 'bad[a-': invalid glob pattern, unmatched '['",
|
2023-09-01 08:48:07 -07:00
|
|
|
Error);
|
2015-02-04 17:39:48 +00:00
|
|
|
std::vector<std::string> Files(1, "unexisting");
|
2019-11-21 11:32:17 +01:00
|
|
|
EXPECT_EQ(nullptr,
|
|
|
|
SpecialCaseList::create(Files, *vfs::getRealFileSystem(), Error));
|
2023-09-01 08:48:07 -07:00
|
|
|
EXPECT_THAT(Error, StartsWith("can't open file 'unexisting':"));
|
2014-07-09 19:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpecialCaseListTest, EmptySpecialCaseList) {
|
2014-09-02 18:13:54 +00:00
|
|
|
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("");
|
2017-09-25 22:11:11 +00:00
|
|
|
EXPECT_FALSE(SCL->inSection("", "foo", "bar"));
|
2014-07-09 19:40:08 +00:00
|
|
|
}
|
|
|
|
|
2020-06-20 16:02:27 -07:00
|
|
|
TEST_F(SpecialCaseListTest, MultipleExclusions) {
|
2015-02-04 17:39:48 +00:00
|
|
|
std::vector<std::string> Files;
|
|
|
|
Files.push_back(makeSpecialCaseListFile("src:bar\n"
|
|
|
|
"src:*foo*\n"
|
|
|
|
"src:ban=init\n"));
|
|
|
|
Files.push_back(makeSpecialCaseListFile("src:baz\n"
|
|
|
|
"src:*fog*\n"));
|
2019-11-21 11:32:17 +01:00
|
|
|
auto SCL = SpecialCaseList::createOrDie(Files, *vfs::getRealFileSystem());
|
2017-09-25 22:11:11 +00:00
|
|
|
EXPECT_TRUE(SCL->inSection("", "src", "bar"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "src", "baz"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "src", "ban"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "src", "ban", "init"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "src", "tomfoolery"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "src", "tomfoglery"));
|
2016-09-02 00:51:34 +00:00
|
|
|
for (auto &Path : Files)
|
|
|
|
sys::fs::remove(Path);
|
2014-07-09 19:40:08 +00:00
|
|
|
}
|
|
|
|
|
Use trigrams to speed up SpecialCaseList.
Summary:
it's often the case when the rules in the SpecialCaseList
are of the form hel.o*bar. That gives us a chance to build
trigram index to quickly discard 99% of inputs without
running a full regex. A similar idea was used in Google Code Search
as described in the blog post:
https://swtch.com/~rsc/regexp/regexp4.html
The check is defeated, if there's at least one regex
more complicated than that. In this case, all inputs
will go through the regex. That said, the real-world
rules are often simple or can be simplied. That considerably
speeds up compiling Chromium with CFI and UBSan.
As measured on Chromium's content_message_generator.cc:
before, CFI: 44 s
after, CFI: 23 s
after, CFI, no blacklist: 23 s (~1% slower, but 3 runs were unable to show the difference)
after, regular compilation to bitcode: 23 s
Reviewers: pcc
Subscribers: mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D27188
llvm-svn: 288303
2016-12-01 02:54:54 +00:00
|
|
|
TEST_F(SpecialCaseListTest, NoTrigramsInRules) {
|
2023-09-01 08:48:07 -07:00
|
|
|
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("fun:b?r\n"
|
Use trigrams to speed up SpecialCaseList.
Summary:
it's often the case when the rules in the SpecialCaseList
are of the form hel.o*bar. That gives us a chance to build
trigram index to quickly discard 99% of inputs without
running a full regex. A similar idea was used in Google Code Search
as described in the blog post:
https://swtch.com/~rsc/regexp/regexp4.html
The check is defeated, if there's at least one regex
more complicated than that. In this case, all inputs
will go through the regex. That said, the real-world
rules are often simple or can be simplied. That considerably
speeds up compiling Chromium with CFI and UBSan.
As measured on Chromium's content_message_generator.cc:
before, CFI: 44 s
after, CFI: 23 s
after, CFI, no blacklist: 23 s (~1% slower, but 3 runs were unable to show the difference)
after, regular compilation to bitcode: 23 s
Reviewers: pcc
Subscribers: mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D27188
llvm-svn: 288303
2016-12-01 02:54:54 +00:00
|
|
|
"fun:za*az\n");
|
2017-09-25 22:11:11 +00:00
|
|
|
EXPECT_TRUE(SCL->inSection("", "fun", "bar"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "fun", "baz"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "fun", "zakaz"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "fun", "zaraza"));
|
Use trigrams to speed up SpecialCaseList.
Summary:
it's often the case when the rules in the SpecialCaseList
are of the form hel.o*bar. That gives us a chance to build
trigram index to quickly discard 99% of inputs without
running a full regex. A similar idea was used in Google Code Search
as described in the blog post:
https://swtch.com/~rsc/regexp/regexp4.html
The check is defeated, if there's at least one regex
more complicated than that. In this case, all inputs
will go through the regex. That said, the real-world
rules are often simple or can be simplied. That considerably
speeds up compiling Chromium with CFI and UBSan.
As measured on Chromium's content_message_generator.cc:
before, CFI: 44 s
after, CFI: 23 s
after, CFI, no blacklist: 23 s (~1% slower, but 3 runs were unable to show the difference)
after, regular compilation to bitcode: 23 s
Reviewers: pcc
Subscribers: mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D27188
llvm-svn: 288303
2016-12-01 02:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpecialCaseListTest, NoTrigramsInARule) {
|
|
|
|
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("fun:*bar*\n"
|
|
|
|
"fun:za*az\n");
|
2017-09-25 22:11:11 +00:00
|
|
|
EXPECT_TRUE(SCL->inSection("", "fun", "abara"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "fun", "bor"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "fun", "zakaz"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "fun", "zaraza"));
|
Use trigrams to speed up SpecialCaseList.
Summary:
it's often the case when the rules in the SpecialCaseList
are of the form hel.o*bar. That gives us a chance to build
trigram index to quickly discard 99% of inputs without
running a full regex. A similar idea was used in Google Code Search
as described in the blog post:
https://swtch.com/~rsc/regexp/regexp4.html
The check is defeated, if there's at least one regex
more complicated than that. In this case, all inputs
will go through the regex. That said, the real-world
rules are often simple or can be simplied. That considerably
speeds up compiling Chromium with CFI and UBSan.
As measured on Chromium's content_message_generator.cc:
before, CFI: 44 s
after, CFI: 23 s
after, CFI, no blacklist: 23 s (~1% slower, but 3 runs were unable to show the difference)
after, regular compilation to bitcode: 23 s
Reviewers: pcc
Subscribers: mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D27188
llvm-svn: 288303
2016-12-01 02:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpecialCaseListTest, RepetitiveRule) {
|
|
|
|
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("fun:*bar*bar*bar*bar*\n"
|
|
|
|
"fun:bar*\n");
|
2017-09-25 22:11:11 +00:00
|
|
|
EXPECT_TRUE(SCL->inSection("", "fun", "bara"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "fun", "abara"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "fun", "barbarbarbar"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "fun", "abarbarbarbar"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "fun", "abarbarbar"));
|
Use trigrams to speed up SpecialCaseList.
Summary:
it's often the case when the rules in the SpecialCaseList
are of the form hel.o*bar. That gives us a chance to build
trigram index to quickly discard 99% of inputs without
running a full regex. A similar idea was used in Google Code Search
as described in the blog post:
https://swtch.com/~rsc/regexp/regexp4.html
The check is defeated, if there's at least one regex
more complicated than that. In this case, all inputs
will go through the regex. That said, the real-world
rules are often simple or can be simplied. That considerably
speeds up compiling Chromium with CFI and UBSan.
As measured on Chromium's content_message_generator.cc:
before, CFI: 44 s
after, CFI: 23 s
after, CFI, no blacklist: 23 s (~1% slower, but 3 runs were unable to show the difference)
after, regular compilation to bitcode: 23 s
Reviewers: pcc
Subscribers: mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D27188
llvm-svn: 288303
2016-12-01 02:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpecialCaseListTest, SpecialSymbolRule) {
|
|
|
|
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("src:*c\\+\\+abi*\n");
|
2017-09-25 22:11:11 +00:00
|
|
|
EXPECT_TRUE(SCL->inSection("", "src", "c++abi"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "src", "c\\+\\+abi"));
|
Use trigrams to speed up SpecialCaseList.
Summary:
it's often the case when the rules in the SpecialCaseList
are of the form hel.o*bar. That gives us a chance to build
trigram index to quickly discard 99% of inputs without
running a full regex. A similar idea was used in Google Code Search
as described in the blog post:
https://swtch.com/~rsc/regexp/regexp4.html
The check is defeated, if there's at least one regex
more complicated than that. In this case, all inputs
will go through the regex. That said, the real-world
rules are often simple or can be simplied. That considerably
speeds up compiling Chromium with CFI and UBSan.
As measured on Chromium's content_message_generator.cc:
before, CFI: 44 s
after, CFI: 23 s
after, CFI, no blacklist: 23 s (~1% slower, but 3 runs were unable to show the difference)
after, regular compilation to bitcode: 23 s
Reviewers: pcc
Subscribers: mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D27188
llvm-svn: 288303
2016-12-01 02:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpecialCaseListTest, PopularTrigram) {
|
|
|
|
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("fun:*aaaaaa*\n"
|
|
|
|
"fun:*aaaaa*\n"
|
|
|
|
"fun:*aaaa*\n"
|
|
|
|
"fun:*aaa*\n");
|
2017-09-25 22:11:11 +00:00
|
|
|
EXPECT_TRUE(SCL->inSection("", "fun", "aaa"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "fun", "aaaa"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "fun", "aaaabbbaaa"));
|
Use trigrams to speed up SpecialCaseList.
Summary:
it's often the case when the rules in the SpecialCaseList
are of the form hel.o*bar. That gives us a chance to build
trigram index to quickly discard 99% of inputs without
running a full regex. A similar idea was used in Google Code Search
as described in the blog post:
https://swtch.com/~rsc/regexp/regexp4.html
The check is defeated, if there's at least one regex
more complicated than that. In this case, all inputs
will go through the regex. That said, the real-world
rules are often simple or can be simplied. That considerably
speeds up compiling Chromium with CFI and UBSan.
As measured on Chromium's content_message_generator.cc:
before, CFI: 44 s
after, CFI: 23 s
after, CFI, no blacklist: 23 s (~1% slower, but 3 runs were unable to show the difference)
after, regular compilation to bitcode: 23 s
Reviewers: pcc
Subscribers: mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D27188
llvm-svn: 288303
2016-12-01 02:54:54 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 23:30:16 +00:00
|
|
|
TEST_F(SpecialCaseListTest, EscapedSymbols) {
|
|
|
|
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("src:*c\\+\\+abi*\n"
|
|
|
|
"src:*hello\\\\world*\n");
|
2017-09-25 22:11:11 +00:00
|
|
|
EXPECT_TRUE(SCL->inSection("", "src", "dir/c++abi"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "src", "dir/c\\+\\+abi"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "src", "c\\+\\+abi"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "src", "C:\\hello\\world"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("", "src", "hello\\world"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("", "src", "hello\\\\world"));
|
2016-12-02 23:30:16 +00:00
|
|
|
}
|
|
|
|
|
2023-09-01 08:48:07 -07:00
|
|
|
TEST_F(SpecialCaseListTest, Version1) {
|
|
|
|
std::unique_ptr<SpecialCaseList> SCL =
|
|
|
|
makeSpecialCaseList("[sect1|sect2]\n"
|
|
|
|
// Does not match foo!
|
|
|
|
"fun:foo.*\n"
|
|
|
|
"fun:abc|def\n"
|
|
|
|
"fun:b.r\n",
|
|
|
|
/*UseGlobs=*/false);
|
|
|
|
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect1", "fun", "fooz"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect2", "fun", "fooz"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("sect3", "fun", "fooz"));
|
|
|
|
|
|
|
|
// `foo.*` does not match `foo` because the pattern is translated to `foo..*`
|
|
|
|
EXPECT_FALSE(SCL->inSection("sect1", "fun", "foo"));
|
|
|
|
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect1", "fun", "abc"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect2", "fun", "abc"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("sect3", "fun", "abc"));
|
|
|
|
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect1", "fun", "def"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect2", "fun", "def"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("sect3", "fun", "def"));
|
|
|
|
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect1", "fun", "bar"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect2", "fun", "bar"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("sect3", "fun", "bar"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpecialCaseListTest, Version2) {
|
|
|
|
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("[{sect1,sect2}]\n"
|
|
|
|
"fun:foo*\n"
|
|
|
|
"fun:{abc,def}\n"
|
|
|
|
"fun:b?r\n");
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect1", "fun", "fooz"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect2", "fun", "fooz"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("sect3", "fun", "fooz"));
|
|
|
|
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect1", "fun", "foo"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect2", "fun", "foo"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("sect3", "fun", "foo"));
|
|
|
|
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect1", "fun", "abc"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect2", "fun", "abc"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("sect3", "fun", "abc"));
|
|
|
|
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect1", "fun", "def"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect2", "fun", "def"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("sect3", "fun", "def"));
|
|
|
|
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect1", "fun", "bar"));
|
|
|
|
EXPECT_TRUE(SCL->inSection("sect2", "fun", "bar"));
|
|
|
|
EXPECT_FALSE(SCL->inSection("sect3", "fun", "bar"));
|
|
|
|
}
|
2015-02-04 17:39:48 +00:00
|
|
|
}
|