|
8 | 8 |
|
9 | 9 | #include <kunit/test.h>
|
10 | 10 |
|
| 11 | +// Configuration ROM for AV/C Devices 1.0 (Dec. 12, 2000, 1394 Trading Association) |
| 12 | +// Annex C:Configuration ROM example(informative) |
| 13 | +// C.1 Simple AV/C device |
| 14 | +// |
| 15 | +// Copied from the documentation. |
| 16 | +static const u32 simple_avc_config_rom[] = { |
| 17 | + 0x0404eabf, |
| 18 | + 0x31333934, |
| 19 | + 0xe0646102, |
| 20 | + 0xffffffff, |
| 21 | + 0xffffffff, |
| 22 | + 0x00063287, // root directory. |
| 23 | + 0x03ffffff, |
| 24 | + 0x8100000a, |
| 25 | + 0x17ffffff, |
| 26 | + 0x8100000e, |
| 27 | + 0x0c0083c0, |
| 28 | + 0xd1000001, |
| 29 | + 0x0004442d, // unit 0 directory. |
| 30 | + 0x1200a02d, |
| 31 | + 0x13010001, |
| 32 | + 0x17ffffff, |
| 33 | + 0x81000007, |
| 34 | + 0x0005c915, // leaf for textual descriptor. |
| 35 | + 0x00000000, |
| 36 | + 0x00000000, |
| 37 | + 0x56656e64, |
| 38 | + 0x6f72204e, |
| 39 | + 0x616d6500, |
| 40 | + 0x00057f16, // leaf for textual descriptor. |
| 41 | + 0x00000000, |
| 42 | + 0x00000000, |
| 43 | + 0x4d6f6465, |
| 44 | + 0x6c204e61, |
| 45 | + 0x6d650000, |
| 46 | +}; |
| 47 | + |
| 48 | +static void device_attr_simple_avc(struct kunit *test) |
| 49 | +{ |
| 50 | + static const struct fw_device node = { |
| 51 | + .device = { |
| 52 | + .type = &fw_device_type, |
| 53 | + }, |
| 54 | + .config_rom = simple_avc_config_rom, |
| 55 | + .config_rom_length = sizeof(simple_avc_config_rom), |
| 56 | + }; |
| 57 | + static const struct fw_unit unit0 = { |
| 58 | + .device = { |
| 59 | + .type = &fw_unit_type, |
| 60 | + .parent = (struct device *)&node.device, |
| 61 | + }, |
| 62 | + .directory = &simple_avc_config_rom[12], |
| 63 | + }; |
| 64 | + struct device *node_dev = (struct device *)&node.device; |
| 65 | + struct device *unit0_dev = (struct device *)&unit0.device; |
| 66 | + static const int unit0_expected_ids[] = {0x00ffffff, 0x00ffffff, 0x0000a02d, 0x00010001}; |
| 67 | + char *buf = kunit_kzalloc(test, PAGE_SIZE, GFP_KERNEL); |
| 68 | + int ids[4] = {0, 0, 0, 0}; |
| 69 | + |
| 70 | + // Ensure associations for node and unit devices. |
| 71 | + |
| 72 | + KUNIT_ASSERT_TRUE(test, is_fw_device(node_dev)); |
| 73 | + KUNIT_ASSERT_FALSE(test, is_fw_unit(node_dev)); |
| 74 | + KUNIT_ASSERT_PTR_EQ(test, fw_device(node_dev), &node); |
| 75 | + |
| 76 | + KUNIT_ASSERT_FALSE(test, is_fw_device(unit0_dev)); |
| 77 | + KUNIT_ASSERT_TRUE(test, is_fw_unit(unit0_dev)); |
| 78 | + KUNIT_ASSERT_PTR_EQ(test, fw_parent_device((&unit0)), &node); |
| 79 | + KUNIT_ASSERT_PTR_EQ(test, fw_unit(unit0_dev), &unit0); |
| 80 | + |
| 81 | + // For entries in root directory. |
| 82 | + |
| 83 | + // Vendor immediate entry is found. |
| 84 | + KUNIT_EXPECT_GT(test, show_immediate(node_dev, &config_rom_attributes[0].attr, buf), 0); |
| 85 | + KUNIT_EXPECT_STREQ(test, buf, "0xffffff\n"); |
| 86 | + |
| 87 | + // Model immediate entry is found. |
| 88 | + KUNIT_EXPECT_GT(test, show_immediate(node_dev, &config_rom_attributes[4].attr, buf), 0); |
| 89 | + KUNIT_EXPECT_STREQ(test, buf, "0xffffff\n"); |
| 90 | + |
| 91 | + // Descriptor leaf entry for vendor is found. |
| 92 | + KUNIT_EXPECT_GT(test, show_text_leaf(node_dev, &config_rom_attributes[5].attr, buf), 0); |
| 93 | + KUNIT_EXPECT_STREQ(test, buf, "Vendor Name\n"); |
| 94 | + |
| 95 | + // Descriptor leaf entry for model is found. |
| 96 | + KUNIT_EXPECT_GT(test, show_text_leaf(node_dev, &config_rom_attributes[6].attr, buf), 0); |
| 97 | + KUNIT_EXPECT_STREQ(test, buf, "Model Name\n"); |
| 98 | + |
| 99 | + // For entries in unit 0 directory. |
| 100 | + |
| 101 | + // Vendor immediate entry is not found. |
| 102 | + KUNIT_EXPECT_LT(test, show_immediate(unit0_dev, &config_rom_attributes[0].attr, buf), 0); |
| 103 | + |
| 104 | + // Model immediate entry is found. |
| 105 | + KUNIT_EXPECT_GT(test, show_immediate(unit0_dev, &config_rom_attributes[4].attr, buf), 0); |
| 106 | + KUNIT_EXPECT_STREQ(test, buf, "0xffffff\n"); |
| 107 | + |
| 108 | + // Descriptor leaf entry for vendor is not found. |
| 109 | + KUNIT_EXPECT_LT(test, show_text_leaf(unit0_dev, &config_rom_attributes[5].attr, buf), 0); |
| 110 | + |
| 111 | + // Descriptor leaf entry for model is found. |
| 112 | + KUNIT_EXPECT_GT(test, show_text_leaf(unit0_dev, &config_rom_attributes[6].attr, buf), 0); |
| 113 | + KUNIT_EXPECT_STREQ(test, buf, "Model Name\n"); |
| 114 | + |
| 115 | + // Specifier_ID immediate entry is found. |
| 116 | + KUNIT_EXPECT_GT(test, show_immediate(unit0_dev, &config_rom_attributes[2].attr, buf), 0); |
| 117 | + KUNIT_EXPECT_STREQ(test, buf, "0x00a02d\n"); |
| 118 | + |
| 119 | + // Version immediate entry is found. |
| 120 | + KUNIT_EXPECT_GT(test, show_immediate(unit0_dev, &config_rom_attributes[3].attr, buf), 0); |
| 121 | + KUNIT_EXPECT_STREQ(test, buf, "0x010001\n"); |
| 122 | + |
| 123 | + kunit_kfree(test, buf); |
| 124 | + |
| 125 | + get_modalias_ids(&unit0, ids); |
| 126 | + KUNIT_EXPECT_MEMEQ(test, ids, unit0_expected_ids, sizeof(ids)); |
| 127 | +} |
| 128 | + |
11 | 129 | static struct kunit_case device_attr_test_cases[] = {
|
| 130 | + KUNIT_CASE(device_attr_simple_avc), |
12 | 131 | {}
|
13 | 132 | };
|
14 | 133 |
|
|
0 commit comments