Repository navigation
Expand file tree
/
Copy pathtestLibJSCTools.cpp
More file actions
162 lines (142 loc) · 5.81 KB
/
Copy pathtestLibJSCTools.cpp
File metadata and controls
162 lines (142 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* Copyright (C) 2026 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include <wtf/DataLog.h>
#if (OS(MACOS) || USE(APPLE_INTERNAL_SDK)) && !PLATFORM(MACCATALYST) && !PLATFORM(IOS_FAMILY_SIMULATOR)
#include "CorpseAddressTest.h"
#include "CorpseByteParserTest.h"
#include "CorpseExportsTrieTest.h"
#include "CorpseMemoryTest.h"
#include "CorpseProcessTest.h"
#include "CorpseRegionTest.h"
#include "CorpseSnapshotTest.h"
#include "CorpseSymbolTest.h"
#include "CorpseThreadTest.h"
#include "LibJSCToolsTestUtilities.h"
#include <stdlib.h>
#include <string.h>
#include <string_view>
#include <wtf/StdLibExtras.h>
#include <wtf/text/StringToIntegerConversion.h>
#include <wtf/text/StringView.h>
namespace {
// A default that runs in well under a second, so that every run exercises the
// decoder on inputs nobody wrote. A longer hunt is a matter of passing a bigger
// count and a different seed.
constexpr uint64_t defaultFuzzSeed = 0x5eed1234;
constexpr unsigned defaultFuzzIterations = 20000;
void printUsage()
{
dataLogLn("Usage: testLibJSCTools [--verbose] [<suite filter>]");
dataLogLn(" testLibJSCTools --fuzz-trie [<seed> [<iterations>]]");
dataLogLn("");
dataLogLn(" Runs the tests for libJavaScriptCoreTools. With a filter, only the");
dataLogLn(" suites whose name contains it run.");
}
bool parseUint64(std::string_view text, uint64_t& out)
{
uint8_t base = text.starts_with("0x") || text.starts_with("0X") ? 16 : 10;
if (base == 16)
text = text.substr(2);
auto parsed = WTF::parseInteger<uint64_t>(StringView::fromLatin1(std::string(text).c_str()), base);
if (!parsed)
return false;
out = *parsed;
return true;
}
} // anonymous namespace
int main(int argc, char** argv)
{
uint64_t fuzzSeed = defaultFuzzSeed;
uint64_t fuzzIterations = defaultFuzzIterations;
bool fuzzOnly = false;
// argv is wrapped in a span so that nothing here walks off the end of it.
auto arguments = unsafeMakeSpan(argv, static_cast<size_t>(argc));
for (size_t index = 1; index < arguments.size(); ++index) {
std::string_view argument = arguments[index];
if (argument == "--help" || argument == "-h") {
printUsage();
return 0;
}
if (argument == "--verbose") {
JSCToolsTest::verbose = true;
continue;
}
if (argument == "--fuzz-trie") {
fuzzOnly = true;
if (index + 1 < arguments.size() && parseUint64(arguments[index + 1], fuzzSeed)) {
++index;
if (index + 1 < arguments.size() && parseUint64(arguments[index + 1], fuzzIterations))
++index;
}
continue;
}
if (argument.starts_with("-")) {
dataLogLn("Unknown option '", arguments[index], "'");
printUsage();
return 1;
}
JSCToolsTest::suiteFilter = arguments[index];
}
dataLogLn("Starting libJavaScriptCoreTools tests");
if (fuzzOnly)
JSCToolsTest::fuzzExportsTrie(fuzzSeed, static_cast<unsigned>(fuzzIterations));
else {
JSCToolsTest::testByteParser();
JSCToolsTest::testExportsTrie();
JSCToolsTest::fuzzExportsTrie(fuzzSeed, static_cast<unsigned>(fuzzIterations));
JSCToolsTest::testAddress();
JSCToolsTest::testProcess();
JSCToolsTest::testSnapshot();
JSCToolsTest::testRegion();
JSCToolsTest::testMemory();
JSCToolsTest::testThreads();
JSCToolsTest::testSymbol();
}
dataLogLn("Ran ", JSCToolsTest::assertionsRun, " assertions, ",
JSCToolsTest::assertionsFailed, " failed, ",
JSCToolsTest::suitesSkipped, " suites skipped, in ",
static_cast<uint64_t>(JSCToolsTest::totalSuiteTime().milliseconds()), " ms");
if (JSCToolsTest::assertionsFailed) {
dataLogLn("Some libJavaScriptCoreTools tests FAILED!");
return 1;
}
if (!JSCToolsTest::assertionsRun) {
dataLogLn("No tests ran!");
return 1;
}
dataLogLn("All libJavaScriptCoreTools tests PASSED!");
return 0;
}
#else // libJavaScriptCoreTools support unavailable
int main(int, char**)
{
// The corpse support is built on Mach task APIs, so there is nothing to test
// on other platforms. Simulators and MacCatalyst are also not supported.
// Report success so that a run here is not a failure.
printf("Not supported platform for testLibJSCTools\n");
return 0;
}
#endif // (OS(MACOS) || USE(APPLE_INTERNAL_SDK)) && !PLATFORM(MACCATALYST) && !PLATFORM(IOS_FAMILY_SIMULATOR)