test_ids 1.0.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/config/shared_commands.rb +1 -1
- data/config/version.rb +2 -3
- data/lib/test_ids.rb +7 -1
- data/lib/test_ids/allocator.rb +42 -26
- data/lib/test_ids/commands/clear.rb +6 -0
- data/lib/test_ids/origen_testers/flow.rb +1 -1
- metadata +5 -6
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: ba6c6bb4a004e1483a4ac17a4eb142ec56de9642a78c6abe2909d6787083a1d5
         | 
| 4 | 
            +
              data.tar.gz: 6eda1cc4e4e460e6eca95533df466bd06ac7a7e9d8dd239a4c3a7b532b3a7743
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 8764b7fe72493a7b84594f42d03240770717dde6ec6c8f2cd5c43a2c3c4fd42a3fad100fa4512894c11330c8edf9a43427b82ef15c7079c6541cf03cf6c94ae1
         | 
| 7 | 
            +
              data.tar.gz: 39c9f6b8acb3f820bd27e9e1eafe1be8b40a520517ea7bf9e2cbed60aa72cdbe1fffe572986926e8d8b00bc0b2d4bce76db76c4c63352c05e4816b79e5c4d478
         | 
    
        data/config/shared_commands.rb
    CHANGED
    
    | @@ -17,7 +17,7 @@ when "test_ids:clear", "test_ids:repair" | |
| 17 17 | 
             
            else
         | 
| 18 18 | 
             
              @plugin_commands << <<-EOT
         | 
| 19 19 | 
             
             test_ids:rollback  Rollback the TestIds store to the given commit ID
         | 
| 20 | 
            -
             test_ids:clear     Clear the assignment database for bins, softbins, numbers or all
         | 
| 20 | 
            +
             test_ids:clear     Clear the assignment database for bins, softbins, numbers, ranges or all for the given configuration database ID
         | 
| 21 21 | 
             
             test_ids:repair    Repair the given database, see -h for more
         | 
| 22 22 | 
             
              EOT
         | 
| 23 23 |  | 
    
        data/config/version.rb
    CHANGED
    
    
    
        data/lib/test_ids.rb
    CHANGED
    
    | @@ -71,7 +71,8 @@ module TestIds | |
| 71 71 | 
             
                # @api private
         | 
| 72 72 | 
             
                def inject_flow_id(options)
         | 
| 73 73 | 
             
                  if Origen.interface_loaded?
         | 
| 74 | 
            -
                     | 
| 74 | 
            +
                    flow = Origen.interface.flow
         | 
| 75 | 
            +
                    options[:test_ids_flow_id] = flow.try(:top_level).try(:id) || flow.id
         | 
| 75 76 | 
             
                  end
         | 
| 76 77 | 
             
                end
         | 
| 77 78 |  | 
| @@ -128,6 +129,11 @@ module TestIds | |
| 128 129 | 
             
                  @configuration_id = id
         | 
| 129 130 | 
             
                end
         | 
| 130 131 |  | 
| 132 | 
            +
                # Return an Array of configuration IDs
         | 
| 133 | 
            +
                def configs
         | 
| 134 | 
            +
                  @configuration.ids
         | 
| 135 | 
            +
                end
         | 
| 136 | 
            +
             | 
| 131 137 | 
             
                def bin_config=(id)
         | 
| 132 138 | 
             
                  @bin_config = id
         | 
| 133 139 | 
             
                end
         | 
    
        data/lib/test_ids/allocator.rb
    CHANGED
    
    | @@ -28,56 +28,69 @@ module TestIds | |
| 28 28 | 
             
                # If a numeric number is passed to the softbin, it uses that number.
         | 
| 29 29 | 
             
                # The configuration for the TestId plugin needs to pass in the bin number and the options from the test flow
         | 
| 30 30 | 
             
                # For this method to work as intended.
         | 
| 31 | 
            -
                 | 
| 32 | 
            -
             | 
| 31 | 
            +
                # This will handle the following range inputs:
         | 
| 32 | 
            +
                #   - Range, Ex: 0..10
         | 
| 33 | 
            +
                #   - Array, Ex: [0..10, 20..30]
         | 
| 34 | 
            +
                def next_in_range(range_definition, options)
         | 
| 35 | 
            +
                  if range_definition.is_a?(Range)
         | 
| 36 | 
            +
                    range = range_definition.to_a
         | 
| 37 | 
            +
                  elsif range_definition.is_a?(Array)
         | 
| 38 | 
            +
                    range = []
         | 
| 39 | 
            +
                    range_definition.each do |range_element|
         | 
| 40 | 
            +
                      range += range_element.is_a?(Integer) ? [range_element] : range_element.step(options[:size]).to_a
         | 
| 41 | 
            +
                    end
         | 
| 42 | 
            +
                    if range.uniq.size != range.size
         | 
| 43 | 
            +
                      Origen.log.error "Duplicate or overlapping range has been detected in configuration: \'#{TestIds.current_configuration.id}\'."
         | 
| 44 | 
            +
                      fail
         | 
| 45 | 
            +
                    end
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
                  range_item(range, range_definition, options)
         | 
| 33 48 | 
             
                end
         | 
| 34 49 |  | 
| 35 | 
            -
                def range_item(range, options)
         | 
| 36 | 
            -
                   | 
| 37 | 
            -
                  #  | 
| 38 | 
            -
                   | 
| 39 | 
            -
             | 
| 40 | 
            -
                    lines = File.readlines(file)
         | 
| 41 | 
            -
                    # Remove any header comment lines since these are not valid JSON
         | 
| 42 | 
            -
                    lines.shift while lines.first =~ /^\/\// && !lines.empty?
         | 
| 43 | 
            -
                    s = JSON.load(lines.join("\n"))
         | 
| 44 | 
            -
                    rangehash = s['pointers']['ranges']
         | 
| 45 | 
            -
                    rangehash = Hash[rangehash.map { |k, v| [k.to_sym, v] }]
         | 
| 50 | 
            +
                def range_item(range, range_definition, options)
         | 
| 51 | 
            +
                  # This is the actual fix, it should now not be dependent on the json file being read in, instead the store pointers
         | 
| 52 | 
            +
                  # will be utilized to get the correct number assigned from the range.
         | 
| 53 | 
            +
                  if store['pointers']['ranges'].nil?
         | 
| 54 | 
            +
                    rangehash = {}
         | 
| 46 55 | 
             
                  else
         | 
| 47 | 
            -
                     | 
| 48 | 
            -
                    rangehash =  | 
| 56 | 
            +
                    rangehash = store['pointers']['ranges']
         | 
| 57 | 
            +
                    rangehash = Hash[rangehash.map { |k, v| [k.to_sym, v] }]
         | 
| 49 58 | 
             
                  end
         | 
| 59 | 
            +
                  orig_options = options.dup
         | 
| 50 60 | 
             
                  # Check the database to see if the passed in range has already been included in the database hash
         | 
| 51 | 
            -
                  if rangehash.key?(:"#{ | 
| 61 | 
            +
                  if rangehash.key?(:"#{range_definition}")
         | 
| 52 62 | 
             
                    # Read out the database hash to see what the last_softbin given out was for that range.
         | 
| 53 63 | 
             
                    # This hash is updated whenever a new softbin is assigned, so it should have the updated values for each range.
         | 
| 54 | 
            -
                    previous_assigned_value = rangehash[:"#{ | 
| 64 | 
            +
                    previous_assigned_value = rangehash[:"#{range_definition}"].to_i
         | 
| 55 65 | 
             
                    # Now calculate the new pointer.
         | 
| 56 | 
            -
                    @pointer = previous_assigned_value  | 
| 66 | 
            +
                    @pointer = range.index(previous_assigned_value) + 1
         | 
| 57 67 | 
             
                    # Check if the last_softbin given out is the same as the range[@pointer],
         | 
| 58 68 | 
             
                    # if so increment pointer by softbin size, default size is 1, config.softbins.size is configurable.
         | 
| 59 69 | 
             
                    # from example above, pointer was calculated as 1,range[1] is 10101 and is same as last_softbin, so pointer is incremented
         | 
| 60 70 | 
             
                    # and new value is assigned to the softbin.
         | 
| 61 | 
            -
                    if previous_assigned_value == range | 
| 71 | 
            +
                    if previous_assigned_value == range[@pointer]
         | 
| 62 72 | 
             
                      @pointer += options[:size]
         | 
| 63 | 
            -
                      assigned_value = range | 
| 73 | 
            +
                      assigned_value = range[@pointer]
         | 
| 64 74 | 
             
                    else
         | 
| 65 75 | 
             
                      # Because of the pointer calculations above, I don't think it will ever reach here, has not in my test cases so far!
         | 
| 66 | 
            -
                      assigned_value = range | 
| 76 | 
            +
                      assigned_value = range[@pointer]
         | 
| 67 77 | 
             
                    end
         | 
| 68 78 | 
             
                    # Now update the database pointers to point to the lastest assigned softbin for a given range.
         | 
| 69 | 
            -
                    rangehash.merge!(:"#{ | 
| 79 | 
            +
                    rangehash.merge!(:"#{range_definition}" => "#{range[@pointer]}")
         | 
| 70 80 | 
             
                  else
         | 
| 71 81 | 
             
                    # This is the case for a brand new range that has not been passed before
         | 
| 72 82 | 
             
                    # We start from the first value as the assigned softbin and update the database to reflect.
         | 
| 73 83 | 
             
                    @pointer = 0
         | 
| 74 | 
            -
                    rangehash.merge!(:"#{ | 
| 75 | 
            -
                    assigned_value = range | 
| 84 | 
            +
                    rangehash.merge!(:"#{range_definition}" => "#{range[@pointer]}")
         | 
| 85 | 
            +
                    assigned_value = range[@pointer]
         | 
| 76 86 | 
             
                  end
         | 
| 77 | 
            -
                  unless !assigned_value.nil? &&  | 
| 87 | 
            +
                  unless !assigned_value.nil? && range.include?(assigned_value)
         | 
| 78 88 | 
             
                    Origen.log.error 'Assigned value not in range'
         | 
| 79 89 | 
             
                    fail
         | 
| 80 90 | 
             
                  end
         | 
| 91 | 
            +
                  # Since the assigned value for this test has now changed, update store to contain the newly assigned value
         | 
| 92 | 
            +
                  # so that when the json file is written, it contains the latest assigned value name.
         | 
| 93 | 
            +
                  store['pointers']['ranges'] = rangehash
         | 
| 81 94 | 
             
                  assigned_value
         | 
| 82 95 | 
             
                end
         | 
| 83 96 |  | 
| @@ -283,7 +296,7 @@ module TestIds | |
| 283 296 | 
             
                  end
         | 
| 284 297 | 
             
                end
         | 
| 285 298 |  | 
| 286 | 
            -
                # Clear the :bins, :softbins and/or :numbers by setting the options for each item | 
| 299 | 
            +
                # Clear the :bins, :softbins and/or :numbers and/or :ranges by setting the options for each item
         | 
| 287 300 | 
             
                def clear(options)
         | 
| 288 301 | 
             
                  if options[:softbin] || options[:softbins]
         | 
| 289 302 | 
             
                    store['assigned']['softbins'] = {}
         | 
| @@ -303,6 +316,9 @@ module TestIds | |
| 303 316 | 
             
                    store['pointers']['numbers'] = nil
         | 
| 304 317 | 
             
                    store['references']['numbers'] = {}
         | 
| 305 318 | 
             
                  end
         | 
| 319 | 
            +
                  if options[:range] || options[:ranges]
         | 
| 320 | 
            +
                    store['pointers']['ranges'] = nil
         | 
| 321 | 
            +
                  end
         | 
| 306 322 | 
             
                end
         | 
| 307 323 |  | 
| 308 324 | 
             
                # Saves the current allocator state to the repository
         | 
| @@ -18,6 +18,7 @@ Examples: origen test_ids:clear --bins                      # Clear the bins in | |
| 18 18 | 
             
              opts.on('--bins', 'Clear the bin database') {  options[:bins] = true }
         | 
| 19 19 | 
             
              opts.on('--softbins', 'Clear the softbin database') {  options[:softbins] = true }
         | 
| 20 20 | 
             
              opts.on('--numbers', 'Clear the test number database') {  options[:numbers] = true }
         | 
| 21 | 
            +
              opts.on('--ranges', 'Clear the ranges database') {  options[:ranges] = true }
         | 
| 21 22 | 
             
              # opts.on('-pl', '--plugin PLUGIN_NAME', String, 'Set current plugin') { |pl_n|  options[:current_plugin] = pl_n }
         | 
| 22 23 | 
             
              opts.on('-d', '--debugger', 'Enable the debugger') {  options[:debugger] = true }
         | 
| 23 24 | 
             
              app_options.each do |app_option|
         | 
| @@ -38,6 +39,11 @@ begin | |
| 38 39 | 
             
              # Get the commit before the lock to give the user later
         | 
| 39 40 | 
             
              rollback_id = git.repo.object('HEAD^').sha[0, 11]
         | 
| 40 41 | 
             
              a = TestIds.load_allocator(ARGV.first)
         | 
| 42 | 
            +
              if a.nil?
         | 
| 43 | 
            +
                Origen.log.error "No configuration file could be found for file ID: '#{ARGV.first}'!"
         | 
| 44 | 
            +
                Origen.log.warn 'By default, the correct ID to pass in will need to match the filename in the form: store_<file id>.json'
         | 
| 45 | 
            +
                fail
         | 
| 46 | 
            +
              end
         | 
| 41 47 | 
             
              a.clear(options)
         | 
| 42 48 | 
             
              a.save
         | 
| 43 49 | 
             
            ensure
         | 
| @@ -9,7 +9,7 @@ module OrigenTesters | |
| 9 9 | 
             
                def test(instance, options = {})
         | 
| 10 10 | 
             
                  if TestIds.configured?
         | 
| 11 11 | 
             
                    unless options[:test_ids] == :notrack
         | 
| 12 | 
            -
                      options[:test_ids_flow_id] = id
         | 
| 12 | 
            +
                      options[:test_ids_flow_id] = try(:top_level).try(:id) || id
         | 
| 13 13 |  | 
| 14 14 | 
             
                      TestIds.current_configuration.allocator.allocate(instance, options)
         | 
| 15 15 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: test_ids
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1. | 
| 4 | 
            +
              version: 1.2.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Stephen McGinty
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2021-06-14 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: origen
         | 
| @@ -16,14 +16,14 @@ dependencies: | |
| 16 16 | 
             
                requirements:
         | 
| 17 17 | 
             
                - - ">="
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version: 0. | 
| 19 | 
            +
                    version: 0.57.0
         | 
| 20 20 | 
             
              type: :runtime
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 24 | 
             
                - - ">="
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            -
                    version: 0. | 
| 26 | 
            +
                    version: 0.57.0
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: origen_testers
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -100,8 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 100 100 | 
             
                - !ruby/object:Gem::Version
         | 
| 101 101 | 
             
                  version: 1.8.11
         | 
| 102 102 | 
             
            requirements: []
         | 
| 103 | 
            -
             | 
| 104 | 
            -
            rubygems_version: 2.6.14.1
         | 
| 103 | 
            +
            rubygems_version: 3.0.1
         | 
| 105 104 | 
             
            signing_key: 
         | 
| 106 105 | 
             
            specification_version: 4
         | 
| 107 106 | 
             
            summary: Origen plugin to assign and track test program bins and test numbers
         |