|  | 
|  | 1 | +/** | 
|  | 2 | + * @file | 
|  | 3 | + * @author  Alex Singer | 
|  | 4 | + * @date    September 2024 | 
|  | 5 | + * @brief   Unit tests for the PartialPlacement object | 
|  | 6 | + * | 
|  | 7 | + * Very quick functionality checks to make sure that the methods inside of the | 
|  | 8 | + * PartialPlacement object are working as expected. | 
|  | 9 | + */ | 
|  | 10 | + | 
|  | 11 | +#include "catch2/catch_test_macros.hpp" | 
|  | 12 | + | 
|  | 13 | +#include "ap_netlist.h" | 
|  | 14 | +#include "partial_placement.h" | 
|  | 15 | +#include "vpr_types.h" | 
|  | 16 | + | 
|  | 17 | +namespace { | 
|  | 18 | + | 
|  | 19 | +TEST_CASE("test_ap_partial_placement_verify", "[vpr_ap]") { | 
|  | 20 | +    // Create a test netlist object. | 
|  | 21 | +    APNetlist test_netlist("test_netlist"); | 
|  | 22 | +    // Create a few molecules. | 
|  | 23 | +    t_pack_molecule mol_a; | 
|  | 24 | +    t_pack_molecule mol_b; | 
|  | 25 | +    t_pack_molecule mol_c; | 
|  | 26 | +    // Create blocks for these molecules. | 
|  | 27 | +    APBlockId block_id_a = test_netlist.create_block("BlockA", &mol_a); | 
|  | 28 | +    APBlockId block_id_b = test_netlist.create_block("BlockB", &mol_b); | 
|  | 29 | +    APBlockId block_id_c = test_netlist.create_block("BlockC", &mol_c); | 
|  | 30 | +    // Fix BlockC. | 
|  | 31 | +    APFixedBlockLoc fixed_block_loc; | 
|  | 32 | +    fixed_block_loc.x = 12; | 
|  | 33 | +    fixed_block_loc.y = 42; | 
|  | 34 | +    fixed_block_loc.layer_num = 2; | 
|  | 35 | +    fixed_block_loc.sub_tile = 1; | 
|  | 36 | +    test_netlist.set_block_loc(block_id_c, fixed_block_loc); | 
|  | 37 | + | 
|  | 38 | +    // Create the PartialPlacement object. | 
|  | 39 | +    PartialPlacement test_placement(test_netlist); | 
|  | 40 | + | 
|  | 41 | +    SECTION("Test constructor places fixed blocks correctly") { | 
|  | 42 | +        REQUIRE(test_placement.block_x_locs[block_id_c] == fixed_block_loc.x); | 
|  | 43 | +        REQUIRE(test_placement.block_y_locs[block_id_c] == fixed_block_loc.y); | 
|  | 44 | +        REQUIRE(test_placement.block_layer_nums[block_id_c] == fixed_block_loc.layer_num); | 
|  | 45 | +        REQUIRE(test_placement.block_sub_tiles[block_id_c] == fixed_block_loc.sub_tile); | 
|  | 46 | +    } | 
|  | 47 | + | 
|  | 48 | +    // Place the blocks | 
|  | 49 | +    //  Place BlockA | 
|  | 50 | +    test_placement.block_x_locs[block_id_a] = 0; | 
|  | 51 | +    test_placement.block_y_locs[block_id_a] = 0; | 
|  | 52 | +    test_placement.block_layer_nums[block_id_a] = 0; | 
|  | 53 | +    test_placement.block_sub_tiles[block_id_a] = 0; | 
|  | 54 | +    //  Place BlockB | 
|  | 55 | +    test_placement.block_x_locs[block_id_b] = 0; | 
|  | 56 | +    test_placement.block_y_locs[block_id_b] = 0; | 
|  | 57 | +    test_placement.block_layer_nums[block_id_b] = 0; | 
|  | 58 | +    test_placement.block_sub_tiles[block_id_b] = 0; | 
|  | 59 | + | 
|  | 60 | +    SECTION("Test verify returns true when the placement is valid") { | 
|  | 61 | +        // NOTE: Using a very large device. | 
|  | 62 | +        REQUIRE(test_placement.verify(test_netlist, 100, 100, 100)); | 
|  | 63 | +        // Picking sizes that just fit. | 
|  | 64 | +        REQUIRE(test_placement.verify(test_netlist, 13, 100, 100)); | 
|  | 65 | +        REQUIRE(test_placement.verify(test_netlist, 100, 43, 100)); | 
|  | 66 | +        REQUIRE(test_placement.verify(test_netlist, 100, 100, 3)); | 
|  | 67 | +        REQUIRE(test_placement.verify(test_netlist, 13, 43, 3)); | 
|  | 68 | +    } | 
|  | 69 | + | 
|  | 70 | +    SECTION("Test verify methods all return true when verify returns true") { | 
|  | 71 | +        REQUIRE(test_placement.verify_locs(test_netlist, 100, 100)); | 
|  | 72 | +        REQUIRE(test_placement.verify_layer_nums(test_netlist, 100)); | 
|  | 73 | +        REQUIRE(test_placement.verify_sub_tiles(test_netlist)); | 
|  | 74 | +    } | 
|  | 75 | + | 
|  | 76 | +    SECTION("Test verify returns false when blocks are outside grid") { | 
|  | 77 | +        // NOTE: Picking device sizes that are just small enough that BlockC | 
|  | 78 | +        //       is off the device. | 
|  | 79 | +        REQUIRE(!test_placement.verify_locs(test_netlist, 100, 1)); | 
|  | 80 | +        REQUIRE(!test_placement.verify_locs(test_netlist, 1, 100)); | 
|  | 81 | +        REQUIRE(!test_placement.verify_layer_nums(test_netlist, 1)); | 
|  | 82 | +        // Make sure that the verify method also catches these cases | 
|  | 83 | +        REQUIRE(!test_placement.verify(test_netlist, 100, 1, 100)); | 
|  | 84 | +        REQUIRE(!test_placement.verify(test_netlist, 1, 100, 100)); | 
|  | 85 | +        REQUIRE(!test_placement.verify(test_netlist, 100, 100, 1)); | 
|  | 86 | +        // Move BlockA off the grid into the negative direction | 
|  | 87 | +        test_placement.block_x_locs[block_id_a] = -1; | 
|  | 88 | +        REQUIRE(!test_placement.verify_locs(test_netlist, 100, 100)); | 
|  | 89 | +        REQUIRE(!test_placement.verify(test_netlist, 100, 100, 100)); | 
|  | 90 | +        test_placement.block_x_locs[block_id_a] = 0; | 
|  | 91 | +        test_placement.block_y_locs[block_id_a] = -1; | 
|  | 92 | +        REQUIRE(!test_placement.verify_locs(test_netlist, 100, 100)); | 
|  | 93 | +        REQUIRE(!test_placement.verify(test_netlist, 100, 100, 100)); | 
|  | 94 | +        test_placement.block_y_locs[block_id_a] = 0; | 
|  | 95 | +        test_placement.block_layer_nums[block_id_a] = -1; | 
|  | 96 | +        REQUIRE(!test_placement.verify_layer_nums(test_netlist, 100)); | 
|  | 97 | +        REQUIRE(!test_placement.verify(test_netlist, 100, 100, 100)); | 
|  | 98 | +        test_placement.block_layer_nums[block_id_a] = 0; | 
|  | 99 | +        test_placement.block_sub_tiles[block_id_a] = -1; | 
|  | 100 | +        REQUIRE(!test_placement.verify_sub_tiles(test_netlist)); | 
|  | 101 | +        REQUIRE(!test_placement.verify(test_netlist, 100, 100, 100)); | 
|  | 102 | +        test_placement.block_sub_tiles[block_id_a] = 0; | 
|  | 103 | +        // Make sure everything is valid again | 
|  | 104 | +        REQUIRE(test_placement.verify(test_netlist, 100, 100, 100)); | 
|  | 105 | +    } | 
|  | 106 | + | 
|  | 107 | +    SECTION("Test verify returns false when fixed blocks are moved") { | 
|  | 108 | +        // Move BlockC's x-coordinate | 
|  | 109 | +        test_placement.block_x_locs[block_id_c] = 0; | 
|  | 110 | +        REQUIRE(!test_placement.verify_locs(test_netlist, 100, 100)); | 
|  | 111 | +        REQUIRE(!test_placement.verify(test_netlist, 100, 100, 100)); | 
|  | 112 | +        test_placement.block_x_locs[block_id_c] = fixed_block_loc.x; | 
|  | 113 | +        // Move BlockC's y-coordinate | 
|  | 114 | +        test_placement.block_y_locs[block_id_c] = 0; | 
|  | 115 | +        REQUIRE(!test_placement.verify_locs(test_netlist, 100, 100)); | 
|  | 116 | +        REQUIRE(!test_placement.verify(test_netlist, 100, 100, 100)); | 
|  | 117 | +        test_placement.block_y_locs[block_id_c] = fixed_block_loc.y; | 
|  | 118 | +        // Move BlockC's layer num | 
|  | 119 | +        test_placement.block_layer_nums[block_id_c] = 0; | 
|  | 120 | +        REQUIRE(!test_placement.verify_layer_nums(test_netlist, 100)); | 
|  | 121 | +        REQUIRE(!test_placement.verify(test_netlist, 100, 100, 100)); | 
|  | 122 | +        test_placement.block_layer_nums[block_id_c] = fixed_block_loc.layer_num; | 
|  | 123 | +        // Move BlockC's sub tile | 
|  | 124 | +        test_placement.block_sub_tiles[block_id_c] = 0; | 
|  | 125 | +        REQUIRE(!test_placement.verify_sub_tiles(test_netlist)); | 
|  | 126 | +        REQUIRE(!test_placement.verify(test_netlist, 100, 100, 100)); | 
|  | 127 | +        test_placement.block_sub_tiles[block_id_c] = fixed_block_loc.sub_tile; | 
|  | 128 | +        // Make sure everything was put back correctly. | 
|  | 129 | +        REQUIRE(test_placement.verify(test_netlist, 100, 100, 100)); | 
|  | 130 | +    } | 
|  | 131 | +} | 
|  | 132 | + | 
|  | 133 | +} // namespace | 
|  | 134 | + | 
0 commit comments