| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 |
|
| 9 | #include <kunit/test.h>
|
| 10 |
|
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | static const u32 simple_avc_config_rom[] = {
|
| 17 | 0x0404eabf,
|
| 18 | 0x31333934,
|
| 19 | 0xe0646102,
|
| 20 | 0xffffffff,
|
| 21 | 0xffffffff,
|
| 22 | 0x00063287, |
| 23 | 0x03ffffff,
|
| 24 | 0x8100000a,
|
| 25 | 0x17ffffff,
|
| 26 | 0x8100000e,
|
| 27 | 0x0c0083c0,
|
| 28 | 0xd1000001,
|
| 29 | 0x0004442d, |
| 30 | 0x1200a02d,
|
| 31 | 0x13010001,
|
| 32 | 0x17ffffff,
|
| 33 | 0x81000007,
|
| 34 | 0x0005c915, |
| 35 | 0x00000000,
|
| 36 | 0x00000000,
|
| 37 | 0x56656e64,
|
| 38 | 0x6f72204e,
|
| 39 | 0x616d6500,
|
| 40 | 0x00057f16, |
| 41 | 0x00000000,
|
| 42 | 0x00000000,
|
| 43 | 0x4d6f6465,
|
| 44 | 0x6c204e61,
|
| 45 | 0x6d650000,
|
| 46 | };
|
| 47 |
|
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | static const u32 legacy_avc_config_rom[] = {
|
| 54 | 0x04199fe7,
|
| 55 | 0x31333934,
|
| 56 | 0xe0644000,
|
| 57 | 0x00112233,
|
| 58 | 0x44556677,
|
| 59 | 0x0005dace, |
| 60 | 0x03012345,
|
| 61 | 0x0c0083c0,
|
| 62 | 0x8d000009,
|
| 63 | 0xd1000002,
|
| 64 | 0xc3000004,
|
| 65 | 0x0002e107, |
| 66 | 0x12abcdef,
|
| 67 | 0x13543210,
|
| 68 | 0x0002cb73, |
| 69 | 0x17fedcba,
|
| 70 | 0x81000004,
|
| 71 | 0x00026dc1, |
| 72 | 0x00112233,
|
| 73 | 0x44556677,
|
| 74 | 0x00050e84, |
| 75 | 0x00000000,
|
| 76 | 0x00000000,
|
| 77 | 0x41424344,
|
| 78 | 0x45464748,
|
| 79 | 0x494a0000,
|
| 80 | };
|
| 81 |
|
| 82 | static void device_attr_simple_avc(struct kunit *test)
|
| 83 | {
|
| 84 | static const struct fw_device node = {
|
| 85 | .device = {
|
| 86 | .type = &fw_device_type,
|
| 87 | },
|
| 88 | .config_rom = simple_avc_config_rom,
|
| 89 | .config_rom_length = sizeof(simple_avc_config_rom),
|
| 90 | };
|
| 91 | static const struct fw_unit unit0 = {
|
| 92 | .device = {
|
| 93 | .type = &fw_unit_type,
|
| 94 | .parent = (struct device *)&node.device,
|
| 95 | },
|
| 96 | .directory = &simple_avc_config_rom[12],
|
| 97 | };
|
| 98 | struct device *node_dev = (struct device *)&node.device;
|
| 99 | struct device *unit0_dev = (struct device *)&unit0.device;
|
| 100 | static const int unit0_expected_ids[] = {0x00ffffff, 0x00ffffff, 0x0000a02d, 0x00010001};
|
| 101 | char *buf = kunit_kzalloc(test, PAGE_SIZE, GFP_KERNEL);
|
| 102 | KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
|
| 103 | int ids[4] = {0, 0, 0, 0};
|
| 104 |
|
| 105 | |
| 106 |
|
| 107 | KUNIT_ASSERT_TRUE(test, is_fw_device(node_dev));
|
| 108 | KUNIT_ASSERT_FALSE(test, is_fw_unit(node_dev));
|
| 109 | KUNIT_ASSERT_PTR_EQ(test, fw_device(node_dev), &node);
|
| 110 |
|
| 111 | KUNIT_ASSERT_FALSE(test, is_fw_device(unit0_dev));
|
| 112 | KUNIT_ASSERT_TRUE(test, is_fw_unit(unit0_dev));
|
| 113 | KUNIT_ASSERT_PTR_EQ(test, fw_parent_device((&unit0)), &node);
|
| 114 | KUNIT_ASSERT_PTR_EQ(test, fw_unit(unit0_dev), &unit0);
|
| 115 |
|
| 116 | |
| 117 |
|
| 118 | |
| 119 | KUNIT_EXPECT_GT(test, show_immediate(node_dev, &config_rom_attributes[0].attr, buf), 0);
|
| 120 | KUNIT_EXPECT_STREQ(test, buf, "0xffffff\n");
|
| 121 |
|
| 122 | |
| 123 | KUNIT_EXPECT_GT(test, show_immediate(node_dev, &config_rom_attributes[4].attr, buf), 0);
|
| 124 | KUNIT_EXPECT_STREQ(test, buf, "0xffffff\n");
|
| 125 |
|
| 126 | |
| 127 | KUNIT_EXPECT_GT(test, show_text_leaf(node_dev, &config_rom_attributes[5].attr, buf), 0);
|
| 128 | KUNIT_EXPECT_STREQ(test, buf, "Vendor Name\n");
|
| 129 |
|
| 130 | |
| 131 | KUNIT_EXPECT_GT(test, show_text_leaf(node_dev, &config_rom_attributes[6].attr, buf), 0);
|
| 132 | KUNIT_EXPECT_STREQ(test, buf, "Model Name\n");
|
| 133 |
|
| 134 | |
| 135 |
|
| 136 | |
| 137 | KUNIT_EXPECT_LT(test, show_immediate(unit0_dev, &config_rom_attributes[0].attr, buf), 0);
|
| 138 |
|
| 139 | |
| 140 | KUNIT_EXPECT_GT(test, show_immediate(unit0_dev, &config_rom_attributes[4].attr, buf), 0);
|
| 141 | KUNIT_EXPECT_STREQ(test, buf, "0xffffff\n");
|
| 142 |
|
| 143 | |
| 144 | KUNIT_EXPECT_LT(test, show_text_leaf(unit0_dev, &config_rom_attributes[5].attr, buf), 0);
|
| 145 |
|
| 146 | |
| 147 | KUNIT_EXPECT_GT(test, show_text_leaf(unit0_dev, &config_rom_attributes[6].attr, buf), 0);
|
| 148 | KUNIT_EXPECT_STREQ(test, buf, "Model Name\n");
|
| 149 |
|
| 150 | |
| 151 | KUNIT_EXPECT_GT(test, show_immediate(unit0_dev, &config_rom_attributes[2].attr, buf), 0);
|
| 152 | KUNIT_EXPECT_STREQ(test, buf, "0x00a02d\n");
|
| 153 |
|
| 154 | |
| 155 | KUNIT_EXPECT_GT(test, show_immediate(unit0_dev, &config_rom_attributes[3].attr, buf), 0);
|
| 156 | KUNIT_EXPECT_STREQ(test, buf, "0x010001\n");
|
| 157 |
|
| 158 | kunit_kfree(test, buf);
|
| 159 |
|
| 160 | get_modalias_ids(&unit0, ids);
|
| 161 | KUNIT_EXPECT_MEMEQ(test, ids, unit0_expected_ids, sizeof(ids));
|
| 162 | }
|
| 163 |
|
| 164 | static void device_attr_legacy_avc(struct kunit *test)
|
| 165 | {
|
| 166 | static const struct fw_device node = {
|
| 167 | .device = {
|
| 168 | .type = &fw_device_type,
|
| 169 | },
|
| 170 | .config_rom = legacy_avc_config_rom,
|
| 171 | .config_rom_length = sizeof(legacy_avc_config_rom),
|
| 172 | };
|
| 173 | static const struct fw_unit unit0 = {
|
| 174 | .device = {
|
| 175 | .type = &fw_unit_type,
|
| 176 | .parent = (struct device *)&node.device,
|
| 177 | },
|
| 178 | .directory = &legacy_avc_config_rom[11],
|
| 179 | };
|
| 180 | struct device *node_dev = (struct device *)&node.device;
|
| 181 | struct device *unit0_dev = (struct device *)&unit0.device;
|
| 182 | static const int unit0_expected_ids[] = {0x00012345, 0x00fedcba, 0x00abcdef, 0x00543210};
|
| 183 | char *buf = kunit_kzalloc(test, PAGE_SIZE, GFP_KERNEL);
|
| 184 | KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
|
| 185 | int ids[4] = {0, 0, 0, 0};
|
| 186 |
|
| 187 | |
| 188 |
|
| 189 | KUNIT_ASSERT_TRUE(test, is_fw_device(node_dev));
|
| 190 | KUNIT_ASSERT_FALSE(test, is_fw_unit(node_dev));
|
| 191 | KUNIT_ASSERT_PTR_EQ(test, fw_device((node_dev)), &node);
|
| 192 |
|
| 193 | KUNIT_ASSERT_FALSE(test, is_fw_device(unit0_dev));
|
| 194 | KUNIT_ASSERT_TRUE(test, is_fw_unit(unit0_dev));
|
| 195 | KUNIT_ASSERT_PTR_EQ(test, fw_parent_device((&unit0)), &node);
|
| 196 | KUNIT_ASSERT_PTR_EQ(test, fw_unit(unit0_dev), &unit0);
|
| 197 |
|
| 198 | |
| 199 |
|
| 200 | |
| 201 | KUNIT_EXPECT_GT(test, show_immediate(node_dev, &config_rom_attributes[0].attr, buf), 0);
|
| 202 | KUNIT_EXPECT_STREQ(test, buf, "0x012345\n");
|
| 203 |
|
| 204 | |
| 205 | KUNIT_EXPECT_GT(test, show_immediate(node_dev, &config_rom_attributes[4].attr, buf), 0);
|
| 206 | KUNIT_EXPECT_STREQ(test, buf, "0xfedcba\n");
|
| 207 |
|
| 208 | |
| 209 | KUNIT_EXPECT_LT(test, show_text_leaf(node_dev, &config_rom_attributes[5].attr, buf), 0);
|
| 210 |
|
| 211 | |
| 212 | KUNIT_EXPECT_GT(test, show_text_leaf(node_dev, &config_rom_attributes[6].attr, buf), 0);
|
| 213 | KUNIT_EXPECT_STREQ(test, buf, "ABCDEFGHIJ\n");
|
| 214 |
|
| 215 | |
| 216 |
|
| 217 | |
| 218 | KUNIT_EXPECT_LT(test, show_immediate(unit0_dev, &config_rom_attributes[0].attr, buf), 0);
|
| 219 |
|
| 220 | |
| 221 | KUNIT_EXPECT_LT(test, show_immediate(unit0_dev, &config_rom_attributes[4].attr, buf), 0);
|
| 222 |
|
| 223 | |
| 224 | KUNIT_EXPECT_LT(test, show_text_leaf(unit0_dev, &config_rom_attributes[5].attr, buf), 0);
|
| 225 |
|
| 226 | |
| 227 | KUNIT_EXPECT_LT(test, show_text_leaf(unit0_dev, &config_rom_attributes[6].attr, buf), 0);
|
| 228 |
|
| 229 | |
| 230 | KUNIT_EXPECT_GT(test, show_immediate(unit0_dev, &config_rom_attributes[2].attr, buf), 0);
|
| 231 | KUNIT_EXPECT_STREQ(test, buf, "0xabcdef\n");
|
| 232 |
|
| 233 | |
| 234 | KUNIT_EXPECT_GT(test, show_immediate(unit0_dev, &config_rom_attributes[3].attr, buf), 0);
|
| 235 | KUNIT_EXPECT_STREQ(test, buf, "0x543210\n");
|
| 236 |
|
| 237 | kunit_kfree(test, buf);
|
| 238 |
|
| 239 | get_modalias_ids(&unit0, ids);
|
| 240 | KUNIT_EXPECT_MEMEQ(test, ids, unit0_expected_ids, sizeof(ids));
|
| 241 | }
|
| 242 |
|
| 243 | static struct kunit_case device_attr_test_cases[] = {
|
| 244 | KUNIT_CASE(device_attr_simple_avc),
|
| 245 | KUNIT_CASE(device_attr_legacy_avc),
|
| 246 | {}
|
| 247 | };
|
| 248 |
|
| 249 | static struct kunit_suite device_attr_test_suite = {
|
| 250 | .name = "firewire-device-attribute",
|
| 251 | .test_cases = device_attr_test_cases,
|
| 252 | };
|
| 253 | kunit_test_suite(device_attr_test_suite);
|