|
| 1 | +definitions = ''' |
| 2 | + struct Single { |
| 3 | + int bitfield : 3; |
| 4 | + }; |
| 5 | +
|
| 6 | + struct WithinBytes { |
| 7 | + char a : 3; |
| 8 | + char b : 5; |
| 9 | + char c : 7; |
| 10 | + }; |
| 11 | +
|
| 12 | + struct StraddleBytes { |
| 13 | + char a : 7; |
| 14 | + char b : 7; |
| 15 | + char c : 2; |
| 16 | + }; |
| 17 | +
|
| 18 | + struct Mixed { |
| 19 | + int a; |
| 20 | + char b : 4; |
| 21 | + short c : 12; |
| 22 | + char d; |
| 23 | + int e : 22; |
| 24 | + }; |
| 25 | +
|
| 26 | + #pragma clang diagnostic push |
| 27 | + #pragma clang diagnostic ignored "-Wbitfield-width" |
| 28 | + // The bitfield will max out at the size of its type. Extra bits act as padding. |
| 29 | + struct MoreBitsThanType { |
| 30 | + char a : 29; |
| 31 | + }; |
| 32 | + #pragma clang diagnostic pop |
| 33 | +
|
| 34 | + // A zero-sized bitfield adds default padding between neighbouring bitfields |
| 35 | + struct ZeroBits { |
| 36 | + char b1 : 3; |
| 37 | + char : 0; |
| 38 | + char b2 : 2; |
| 39 | + }; |
| 40 | +
|
| 41 | + enum class MyEnum { |
| 42 | + One, |
| 43 | + Two, |
| 44 | + Three, |
| 45 | + }; |
| 46 | +
|
| 47 | + struct Enum { |
| 48 | + MyEnum e : 2; |
| 49 | + MyEnum f : 4; |
| 50 | + }; |
| 51 | +''' |
| 52 | +# TODO The sizes do not take bitfields into account. They count each field as |
| 53 | +# if they were regular primitives. |
| 54 | +[cases] |
| 55 | + [cases.single] |
| 56 | + cli_options = ["-ftype-graph"] |
| 57 | + oil_skip = "not implemented" |
| 58 | + param_types = ["Single&"] |
| 59 | + setup = "return {};" |
| 60 | + expect_json = '''[ |
| 61 | + {"staticSize":4, "dynamicSize":0, "exclusiveSize":0, "members":[ |
| 62 | + {"staticSize":4, "dynamicSize":0, "exclusiveSize":4} |
| 63 | + ]}]''' |
| 64 | + [cases.within_bytes] |
| 65 | + cli_options = ["-ftype-graph"] |
| 66 | + oil_skip = "not implemented" |
| 67 | + param_types = ["WithinBytes&"] |
| 68 | + setup = "return {};" |
| 69 | + expect_json = '''[ |
| 70 | + {"staticSize":2, "dynamicSize":0, "exclusiveSize":0, "members":[ |
| 71 | + {"staticSize":1, "dynamicSize":0, "exclusiveSize":1}, |
| 72 | + {"staticSize":1, "dynamicSize":0, "exclusiveSize":1}, |
| 73 | + {"staticSize":1, "dynamicSize":0, "exclusiveSize":1} |
| 74 | + ]}]''' |
| 75 | + [cases.straddle_bytes] |
| 76 | + cli_options = ["-ftype-graph"] |
| 77 | + oil_skip = "not implemented" |
| 78 | + param_types = ["StraddleBytes&"] |
| 79 | + setup = "return {};" |
| 80 | + expect_json = '''[ |
| 81 | + {"staticSize":3, "dynamicSize":0, "exclusiveSize":0, "members":[ |
| 82 | + {"staticSize":1, "dynamicSize":0, "exclusiveSize":1}, |
| 83 | + {"staticSize":1, "dynamicSize":0, "exclusiveSize":1}, |
| 84 | + {"staticSize":1, "dynamicSize":0, "exclusiveSize":1} |
| 85 | + ]}]''' |
| 86 | + [cases.mixed] |
| 87 | + cli_options = ["-ftype-graph"] |
| 88 | + oil_skip = "not implemented" |
| 89 | + param_types = ["Mixed&"] |
| 90 | + setup = "return {};" |
| 91 | + expect_json = '''[ |
| 92 | + {"staticSize":12, "dynamicSize":0, "exclusiveSize":0, "members":[ |
| 93 | + {"staticSize":4, "dynamicSize":0, "exclusiveSize":4}, |
| 94 | + {"staticSize":1, "dynamicSize":0, "exclusiveSize":1}, |
| 95 | + {"staticSize":2, "dynamicSize":0, "exclusiveSize":2}, |
| 96 | + {"staticSize":1, "dynamicSize":0, "exclusiveSize":1}, |
| 97 | + {"staticSize":4, "dynamicSize":0, "exclusiveSize":4} |
| 98 | + ]}]''' |
| 99 | + [cases.more_bits_than_type] # TODO member sizes are wrong |
| 100 | + skip = "drgn errors out" |
| 101 | + cli_options = ["-ftype-graph"] |
| 102 | + oil_skip = "not implemented" |
| 103 | + param_types = ["MoreBitsThanType&"] |
| 104 | + setup = "return {};" |
| 105 | + expect_json = '"TODO"' |
| 106 | + [cases.zero_bits] |
| 107 | + cli_options = ["-ftype-graph"] |
| 108 | + oil_skip = "not implemented" |
| 109 | + param_types = ["ZeroBits&"] |
| 110 | + setup = "return {};" |
| 111 | + expect_json = '''[ |
| 112 | + {"staticSize":2, "dynamicSize":0, "exclusiveSize":0, "members":[ |
| 113 | + {"staticSize":1, "dynamicSize":0, "exclusiveSize":1}, |
| 114 | + {"staticSize":1, "dynamicSize":0, "exclusiveSize":1} |
| 115 | + ]}]''' |
| 116 | + [cases.enum] |
| 117 | + cli_options = ["-ftype-graph"] |
| 118 | + oil_skip = "not implemented" |
| 119 | + param_types = ["Enum&"] |
| 120 | + setup = "return {};" |
| 121 | + expect_json = '''[ |
| 122 | + {"staticSize":4, "dynamicSize":0, "exclusiveSize":0, "members":[ |
| 123 | + {"staticSize":4, "dynamicSize":0, "exclusiveSize":4}, |
| 124 | + {"staticSize":4, "dynamicSize":0, "exclusiveSize":4} |
| 125 | + ]}]''' |
0 commit comments