1/*
2 * Copyright (C) 2019 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27
28#include "HeapCellInlines.h"
29#include "JSCJSValueInlines.h"
30// The above are needed before DFGAbstractValue.h
31#include "DFGAbstractValue.h"
32#include "InitializeThreading.h"
33#include <wtf/DataLog.h>
34#include <wtf/text/StringCommon.h>
35
36// We don't have a NO_RETURN_DUE_TO_EXIT, nor should we. That's ridiculous.
37static bool hiddenTruthBecauseNoReturnIsStupid() { return true; }
38
39static void usage()
40{
41 dataLog("Usage: testdfg [<filter>]\n");
42 if (hiddenTruthBecauseNoReturnIsStupid())
43 exit(1);
44}
45
46#if ENABLE(DFG_JIT)
47
48using namespace JSC;
49using namespace JSC::DFG;
50
51namespace {
52
53// Nothing fancy for now; we just use the existing WTF assertion machinery.
54#define CHECK(x) do { \
55 if (!!(x)) \
56 break; \
57 WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #x); \
58 CRASH(); \
59 } while (false)
60
61
62#define RUN_NOW(test) do { \
63 if (!shouldRun(#test)) \
64 break; \
65 dataLog(#test "...\n"); \
66 test; \
67 dataLog(#test ": OK!\n"); \
68 } while (false)
69
70static void testEmptyValueDoesNotValidateWithHeapTop()
71{
72 AbstractValue value;
73
74 value.makeHeapTop();
75 CHECK(!value.validateOSREntryValue(JSValue(), FlushedJSValue));
76
77 value.makeBytecodeTop();
78 CHECK(value.validateOSREntryValue(JSValue(), FlushedJSValue));
79}
80
81void run(const char* filter)
82{
83 auto shouldRun = [&] (const char* testName) -> bool {
84 return !filter || WTF::findIgnoringASCIICaseWithoutLength(testName, filter) != WTF::notFound;
85 };
86
87 RUN_NOW(testEmptyValueDoesNotValidateWithHeapTop());
88}
89
90} // anonymous namespace
91
92#else // ENABLE(DFG_JIT)
93
94static void run(const char*)
95{
96 dataLog("DFG JIT is not enabled.\n");
97}
98
99#endif // ENABLE(DFG_JIT)
100
101int main(int argc, char** argv)
102{
103 const char* filter = nullptr;
104 switch (argc) {
105 case 1:
106 break;
107 case 2:
108 filter = argv[1];
109 break;
110 default:
111 usage();
112 break;
113 }
114
115 JSC::initializeThreading();
116
117 run(filter);
118
119 return 0;
120}
121
122#if OS(WINDOWS)
123extern "C" __declspec(dllexport) int WINAPI dllLauncherEntryPoint(int argc, const char* argv[])
124{
125 return main(argc, const_cast<char**>(argv));
126}
127#endif
128