aboutsummaryrefslogtreecommitdiff
path: root/lldb/test/API/lang/cpp/fpnan/TestFPNaN.py
blob: 6093ef91ac1f03efb752dc59f5cf532d2825b8e5 (plain)
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
"""
Test floating point expressions with zero, NaN, dernormalized and infinite
numbers.
"""

import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class FPNaNTestCase(TestBase):
    def setUp(self):
        # Call super's setUp().
        TestBase.setUp(self)
        # Find the line number to break inside main().
        self.line = line_number("main.cpp", "// Set break point at this line.")

    def test(self):
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break inside the main.
        lldbutil.run_break_set_by_file_and_line(
            self, "main.cpp", self.line, num_expected_locations=1
        )

        self.runCmd("run", RUN_SUCCEEDED)
        # Zero and denorm
        self.expect(
            "expr +0.0",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["double", "0"],
        )
        self.expect(
            "expr -0.0",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["double", "0"],
        )
        self.expect(
            "expr 0.0 / 0",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["double", "NaN"],
        )
        self.expect(
            "expr 0 / 0.0",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["double", "NaN"],
        )
        self.expect(
            "expr 1 / +0.0",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["double", "+Inf"],
        )
        self.expect(
            "expr 1 / -0.0",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["double", "-Inf"],
        )
        self.expect(
            "expr +0.0 / +0.0 != +0.0 / +0.0",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["bool", "true"],
        )
        self.expect(
            "expr -1.f * 0",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["float", "-0"],
        )
        self.expect(
            "expr 0x0.123p-1",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["double", "0.0355224609375"],
        )
        # NaN
        self.expect(
            "expr fnan < fnan",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["bool", "false"],
        )
        self.expect(
            "expr fnan <= fnan",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["bool", "false"],
        )
        self.expect(
            "expr fnan > fnan",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["bool", "false"],
        )
        self.expect(
            "expr fnan >= fnan",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["bool", "false"],
        )
        self.expect(
            "expr fnan == fnan",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["bool", "false"],
        )
        self.expect(
            "expr fnan != fnan",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["bool", "true"],
        )
        self.expect(
            "expr 1.0 <= fnan",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["bool", "false"],
        )
        self.expect(
            "expr 1.0f < fnan",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["bool", "false"],
        )
        self.expect(
            "expr 1.0f != fnan",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["bool", "true"],
        )
        self.expect(
            "expr (unsigned int) fdenorm",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["int", "0"],
        )
        self.expect(
            "expr (unsigned int) (1.0f + fdenorm)",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=["int", "1"],
        )