test_ids 1.2.2 → 1.2.4

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.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TestIds
2
4
  class Configuration
3
5
  class Item
@@ -33,9 +35,8 @@ module TestIds
33
35
  end
34
36
 
35
37
  def valid?(number)
36
- if function?
37
- fail 'valid? is not supported for algorithm or callback-based assignments'
38
- end
38
+ fail 'valid? is not supported for algorithm or callback-based assignments' if function?
39
+
39
40
  number = number.to_i
40
41
  include.include?(number) && !exclude.include?(number)
41
42
  end
@@ -85,22 +86,16 @@ module TestIds
85
86
  end
86
87
  end
87
88
 
88
- attr_reader :allocator
89
+ attr_reader :allocator, :id
89
90
 
90
91
  def initialize(id)
91
92
  @id = id
92
93
  @allocator = Allocator.new(self)
93
94
  end
94
95
 
95
- def id
96
- @id
97
- end
98
-
99
96
  def bins(options = {}, &block)
100
97
  @bins ||= Item.new
101
- if block_given?
102
- @bins.callback(options, &block)
103
- end
98
+ @bins.callback(options, &block) if block_given?
104
99
  @bins
105
100
  end
106
101
 
@@ -111,9 +106,7 @@ module TestIds
111
106
 
112
107
  def softbins(options = {}, &block)
113
108
  @softbins ||= Item.new
114
- if block_given?
115
- @softbins.callback(options, &block)
116
- end
109
+ @softbins.callback(options, &block) if block_given?
117
110
  @softbins
118
111
  end
119
112
 
@@ -124,9 +117,7 @@ module TestIds
124
117
 
125
118
  def numbers(options = {}, &block)
126
119
  @numbers ||= Item.new
127
- if block_given?
128
- @numbers.callback(options, &block)
129
- end
120
+ @numbers.callback(options, &block) if block_given?
130
121
  @numbers
131
122
  end
132
123
 
@@ -152,10 +143,10 @@ module TestIds
152
143
  end
153
144
 
154
145
  def validate!
155
- unless validated?
156
- @validated = true
157
- freeze
158
- end
146
+ return if validated?
147
+
148
+ @validated = true
149
+ freeze
159
150
  end
160
151
 
161
152
  def empty?
data/lib/test_ids/git.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
  require 'git'
3
5
  module TestIds
@@ -20,7 +22,7 @@ module TestIds
20
22
 
21
23
  def find
22
24
  repos = Dir.glob("#{Origen.app.imports_dir}/test_ids/*.git")
23
- if repos.size == 0
25
+ if repos.empty?
24
26
  puts 'No TestIds repositories were found in this application'
25
27
  elsif repos.size > 1
26
28
  puts
@@ -29,12 +31,10 @@ module TestIds
29
31
  repos.each_with_index do |repo, i|
30
32
  puts " #{i} - #{Pathname.new(repo).basename}"
31
33
  end
32
- accept = repos.map.with_index { |r, i| i }
34
+ accept = repos.map.with_index { |_r, i| i }
33
35
  puts
34
36
  selection = repos.size + 1
35
- until repos[selection]
36
- selection = get_text(single: true, accept: accept).to_i
37
- end
37
+ selection = get_text(single: true, accept: accept).to_i until repos[selection]
38
38
  else
39
39
  selection = 0
40
40
  end
@@ -50,6 +50,8 @@ module TestIds
50
50
  end
51
51
 
52
52
  def initialize(options)
53
+ return unless !TestIds.lsf_manual_init_shutdown && Origen.running_locally?
54
+
53
55
  unless File.exist?("#{options[:local]}/.git")
54
56
  FileUtils.rm_rf(options[:local]) if File.exist?(options[:local])
55
57
  FileUtils.mkdir_p(options[:local])
@@ -102,15 +104,17 @@ module TestIds
102
104
 
103
105
  def exec(cmd)
104
106
  r = system(cmd)
105
- unless r
106
- fail "Something went wrong running command: #{cmd}"
107
- end
107
+ return if r
108
+
109
+ fail "Something went wrong running command: #{cmd}"
108
110
  end
109
111
 
110
112
  def publish
113
+ return unless !TestIds.lsf_manual_init_shutdown && Origen.running_locally?
114
+
111
115
  Origen.profile 'Publishing the test IDs store' do
112
116
  release_lock
113
- repo.add # Checkin everything
117
+ repo.add # Checkin everything
114
118
  repo.commit('Publishing latest store')
115
119
  repo.push('origin', 'master', force: true)
116
120
  end
@@ -124,9 +128,11 @@ module TestIds
124
128
  end
125
129
 
126
130
  def get_lock
131
+ return unless !TestIds.lsf_manual_init_shutdown && Origen.running_locally?
127
132
  return if @lock_open
133
+
128
134
  Origen.profile 'Obtaining test IDs lock' do
129
- until available_to_lock?
135
+ until available_to_lock?(@repo)
130
136
  puts
131
137
  puts "Waiting for lock, currently locked by #{lock_user} (the lock will expire in less than #{lock_minutes_remaining} #{'minute'.pluralize(lock_minutes_remaining)} if not released before that)"
132
138
  puts
@@ -151,16 +157,16 @@ module TestIds
151
157
  write('lock.json', JSON.pretty_generate(data))
152
158
  end
153
159
 
154
- def available_to_lock?
160
+ def available_to_lock?(repo_to_use)
155
161
  result = false
156
162
  Origen.profile 'Checking for lock' do
157
- repo.fetch
158
- repo.reset_hard('origin/master')
159
- if lock_content && lock_user && lock_user != User.current.name
160
- result = Time.now.to_f > lock_expires
161
- else
162
- result = true
163
- end
163
+ repo_to_use.fetch
164
+ repo_to_use.reset_hard('origin/master')
165
+ result = if lock_content && lock_user && lock_user != User.current.name
166
+ Time.now.to_f > lock_expires
167
+ else
168
+ true
169
+ end
164
170
  end
165
171
  result
166
172
  end
@@ -179,7 +185,7 @@ module TestIds
179
185
 
180
186
  def lock_content
181
187
  f = File.join(local, 'lock.json')
182
- JSON.load(File.read(f)) if File.exist?(f)
188
+ JSON.parse(File.read(f)) if File.exist?(f)
183
189
  end
184
190
 
185
191
  def minutes(number)
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'origen'
2
4
  module Origen
3
- class <<self
5
+ class << self
4
6
  # Override the Origen.reset_interface method to clear out the TestIds
5
7
  # configuration, so that it doesn't carry over from one flow to the next
6
8
  alias_method :_orig_reset_interface, :reset_interface
@@ -1,22 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'origen_testers/flow'
2
4
  module OrigenTesters
3
5
  module Flow
4
- BIN_OPTS = [:bin, :softbin, :bin_size, :softbin_size, :number, :number_size]
6
+ BIN_OPTS = %i(bin softbin bin_size softbin_size number number_size).freeze
5
7
 
6
8
  # Override the flow.test method to inject our generated bin and
7
9
  # test numbers
8
10
  alias_method :_orig_test, :test
9
11
  def test(instance, options = {})
10
- if TestIds.configured?
11
- unless options[:test_ids] == :notrack
12
- options[:test_ids_flow_id] = try(:top_level).try(:id) || id
12
+ if TestIds.configured? && options[:test_ids] != :notrack
13
+ options[:test_ids_flow_id] = try(:top_level).try(:id) || id
13
14
 
14
- TestIds.current_configuration.allocator.allocate(instance, options)
15
+ TestIds.current_configuration.allocator.allocate(instance, options)
15
16
 
16
- unless TestIds.current_configuration.send_to_ate?
17
- BIN_OPTS.each do |opt|
18
- options.delete(opt)
19
- end
17
+ unless TestIds.current_configuration.send_to_ate?
18
+ BIN_OPTS.each do |opt|
19
+ options.delete(opt)
20
20
  end
21
21
  end
22
22
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TestIds
2
4
  class ShutdownHandler
3
5
  include Origen::PersistentCallbacks
data/lib/test_ids.rb CHANGED
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'origen'
2
- require_relative '../config/application.rb'
4
+ require_relative '../config/application'
3
5
  require 'origen_testers'
4
6
 
5
7
  module TestIds
@@ -14,7 +16,7 @@ module TestIds
14
16
  require 'test_ids/origen/origen'
15
17
  require 'test_ids/origen_testers/flow'
16
18
 
17
- class <<self
19
+ class << self
18
20
  # Allocates a number to the given test and returns a new hash containing
19
21
  # :bin, :softbin and :number keys.
20
22
  #
@@ -27,8 +29,7 @@ module TestIds
27
29
  inject_flow_id(opts)
28
30
  current_configuration.allocator.allocate(instance, opts)
29
31
  { bin: opts[:bin], bin_size: opts[:bin_size], softbin: opts[:softbin], softbin_size: opts[:softbin_size],
30
- number: opts[:number], number_size: opts[:number_size]
31
- }
32
+ number: opts[:number], number_size: opts[:number_size] }
32
33
  end
33
34
 
34
35
  # Similar to allocate, but allocates a test number only, i.e. no bin or softbin
@@ -70,10 +71,10 @@ module TestIds
70
71
 
71
72
  # @api private
72
73
  def inject_flow_id(options)
73
- if Origen.interface_loaded?
74
- flow = Origen.interface.flow
75
- options[:test_ids_flow_id] = flow.try(:top_level).try(:id) || flow.id
76
- end
74
+ return unless Origen.interface_loaded?
75
+
76
+ flow = Origen.interface.flow
77
+ options[:test_ids_flow_id] = flow.try(:top_level).try(:id) || flow.id
77
78
  end
78
79
 
79
80
  # Load an existing allocator, which will be loaded with a configuration based on what has
@@ -82,11 +83,11 @@ module TestIds
82
83
  # @api internal
83
84
  def load_allocator(id = nil)
84
85
  f = TestIds.database_file(id)
85
- if File.exist?(f)
86
- a = Configuration.new(id).allocator
87
- a.load_configuration_from_store
88
- a
89
- end
86
+ return unless File.exist?(f)
87
+
88
+ a = Configuration.new(id).allocator
89
+ a.load_configuration_from_store
90
+ a
90
91
  end
91
92
 
92
93
  def current_configuration
@@ -95,14 +96,17 @@ module TestIds
95
96
 
96
97
  def configuration(id, fail_on_missing = true)
97
98
  return @configuration[id] if @configuration && @configuration[id]
98
- if fail_on_missing
99
- fail('You have to create the configuration first before you can access it')
100
- end
99
+ return unless fail_on_missing
100
+
101
+ fail('You have to create the configuration first before you can access it')
101
102
  end
102
103
  alias_method :config, :configuration
103
104
 
104
105
  def configure(id = nil, options = {})
105
- id, options = nil, id if id.is_a?(Hash)
106
+ if id.is_a?(Hash)
107
+ options = id
108
+ id = nil
109
+ end
106
110
 
107
111
  @configuration_id = id || options[:id] || :not_specified
108
112
 
@@ -123,9 +127,8 @@ module TestIds
123
127
 
124
128
  # Switch the current configuration to the given ID
125
129
  def config=(id)
126
- unless @configuration[id]
127
- fail "The TestIds configuration '#{id}' has not been defined yet!"
128
- end
130
+ fail "The TestIds configuration '#{id}' has not been defined yet!" unless @configuration[id]
131
+
129
132
  @configuration_id = id
130
133
  end
131
134
 
@@ -134,26 +137,16 @@ module TestIds
134
137
  @configuration.ids
135
138
  end
136
139
 
137
- def bin_config=(id)
138
- @bin_config = id
139
- end
140
+ attr_writer :bin_config, :softbin_config, :number_config
140
141
 
141
142
  def bin_config
142
143
  @bin_config ? configuration(@bin_config, false) : current_configuration
143
144
  end
144
145
 
145
- def softbin_config=(id)
146
- @softbin_config = id
147
- end
148
-
149
146
  def softbin_config
150
147
  @softbin_config ? configuration(@softbin_config, false) : current_configuration
151
148
  end
152
149
 
153
- def number_config=(id)
154
- @number_config = id
155
- end
156
-
157
150
  def number_config
158
151
  @number_config ? configuration(@number_config, false) : current_configuration
159
152
  end
@@ -184,14 +177,14 @@ module TestIds
184
177
  # Returns a full path to the database file for the given id, returns nil if
185
178
  # git storage has not been enabled
186
179
  def database_file(id)
187
- if repo
188
- if id == :not_specified || !id || id == ''
189
- f = 'store.json'
190
- else
191
- f = "store_#{id.to_s.downcase}.json"
192
- end
193
- "#{git_database_dir}/#{f}"
194
- end
180
+ return unless repo
181
+
182
+ f = if id == :not_specified || !id || id == ''
183
+ 'store.json'
184
+ else
185
+ "store_#{id.to_s.downcase}.json"
186
+ end
187
+ "#{git_database_dir}/#{f}"
195
188
  end
196
189
 
197
190
  def git_database_dir
@@ -202,23 +195,16 @@ module TestIds
202
195
  end
203
196
  end
204
197
 
205
- def git
206
- @git
207
- end
198
+ attr_reader :git, :repo
208
199
 
209
200
  def repo=(val)
210
201
  return if @repo && @repo == val
211
202
  if @repo && @repo != val
212
203
  fail 'You can only use a single test ids repository per program generation run, one per application is recommended'
213
204
  end
214
- if @configuration
215
- fail 'TestIds.repo must be set before creating the first configuration'
216
- end
217
- @repo = val
218
- end
205
+ fail 'TestIds.repo must be set before creating the first configuration' if @configuration
219
206
 
220
- def repo
221
- @repo
207
+ @repo = val
222
208
  end
223
209
 
224
210
  def publish?
@@ -227,22 +213,83 @@ module TestIds
227
213
 
228
214
  def publish=(val)
229
215
  return if @publish && publish? == val
230
- if @publish && publish? != val
231
- fail 'You can only use a single setting for publish per program generation run'
232
- end
233
- if @configuration
234
- fail 'TestIds.publish must be set before creating the first configuration'
235
- end
236
- unless [true, false].include?(val)
237
- fail 'TestIds.publish must be set to either true or false'
238
- end
216
+ fail 'You can only use a single setting for publish per program generation run' if @publish && publish? != val
217
+ fail 'TestIds.publish must be set before creating the first configuration' if @configuration
218
+ fail 'TestIds.publish must be set to either true or false' unless [true, false].include?(val)
219
+
239
220
  @publish = val ? :save : :dont_save
240
221
  end
241
222
 
223
+ def lsf_manual_init_shutdown
224
+ true if @lsf_manual_init_shutdown
225
+ false
226
+ end
227
+
242
228
  def next_in_range(range, options)
243
229
  current_configuration.allocator.next_in_range(range, options)
244
230
  end
245
231
 
232
+ def lsf_init(git_repo, lsf_publish)
233
+ @lsf_manual_init_shutdown = true
234
+ local_var_git_database_dir = "#{Origen.app.imports_directory}/test_ids/#{Pathname.new(git_repo).basename}"
235
+ FileUtils.mkdir_p(local_var_git_database_dir)
236
+ unless File.exist?("#{local_var_git_database_dir}/.git")
237
+ FileUtils.rm_rf(local_var_git_database_dir) if File.exist?(local_var_git_database_dir)
238
+ FileUtils.mkdir_p(local_var_git_database_dir)
239
+ Dir.chdir local_var_git_database_dir do
240
+ `git clone #{git_repo} .`
241
+ unless File.exist?('lock.json')
242
+ # Should really try to use the Git driver for this
243
+ exec 'touch lock.json'
244
+ exec 'git add lock.json'
245
+ exec 'git commit -m "Initial commit"'
246
+ exec 'git push'
247
+ end
248
+ end
249
+ end
250
+ @local = local_var_git_database_dir
251
+ @repo = ::Git.open(local_var_git_database_dir)
252
+ # Get rid of any local edits coming in here, this is only called once at the start
253
+ # of the program generation run.
254
+ # No need to pull latest as that will be done when we obtain a lock.
255
+ @repo.reset_hard
256
+ @git = Git.new(local: local_var_git_database_dir, remote: @repo)
257
+ return unless lsf_publish
258
+ return if @lock_open
259
+
260
+ Origen.profile 'Obtaining test IDs lock' do
261
+ until @git.available_to_lock?(@repo)
262
+ puts
263
+ puts "Waiting for lock, currently locked by #{@git.lock_user} (the lock will expire in less than #{@git.lock_minutes_remaining} #{'minute'.pluralize(@git.lock_minutes_remaining)} if not released before that)"
264
+ puts
265
+ sleep 5
266
+ end
267
+ data = {
268
+ 'user' => User.current.name,
269
+ 'expires' => (Time.now + @git.minutes(5)).to_f
270
+ }
271
+ @git.write('lock.json', JSON.pretty_generate(data))
272
+ repo.commit('Obtaining lock')
273
+ repo.push('origin')
274
+ end
275
+ @lock_open = true
276
+ end
277
+
278
+ def lsf_shutdown(lsf_publish)
279
+ return unless lsf_publish
280
+
281
+ Origen.profile 'Publishing the test IDs store' do
282
+ data = {
283
+ 'user' => nil,
284
+ 'expires' => nil
285
+ }
286
+ @git.write('lock.json', JSON.pretty_generate(data))
287
+ repo.add # Checkin everything
288
+ repo.commit('Publishing latest store')
289
+ repo.push('origin', 'master', force: true)
290
+ end
291
+ end
292
+
246
293
  ## When set to true, all numbers generated will be checked to see if they comply
247
294
  ## with the current configuration, and if not they will be re-assigned based on the
248
295
  ## current configuration
@@ -261,31 +308,30 @@ module TestIds
261
308
  # only needed for cases where running several targets
262
309
  # back to back, e.g. for regression testing
263
310
  def reset_everything(are_you_sure: false)
264
- if are_you_sure
265
- @repo = nil # accessor
266
- @git = nil # accessor
267
- @git_database_dir = nil
268
- @git_initialized = nil
269
- @configuration = nil
270
- @configuration_id = nil
271
- @bin_config = nil
272
- @softbin_config = nil
273
- @number_config = nil
274
- @publish = nil
275
- end
311
+ return unless are_you_sure
312
+
313
+ @repo = nil # accessor
314
+ @git = nil # accessor
315
+ @git_database_dir = nil
316
+ @git_initialized = nil
317
+ @configuration = nil
318
+ @configuration_id = nil
319
+ @bin_config = nil
320
+ @softbin_config = nil
321
+ @number_config = nil
322
+ @publish = nil
276
323
  end
277
324
 
278
325
  private
279
326
 
280
327
  def on_origen_shutdown
281
- if !testing? && @configuration
282
- if repo
283
- @configuration.each do |id, config|
284
- config.allocator.save
285
- end
286
- git.publish if publish?
287
- end
328
+ return unless !testing? && @configuration
329
+ return unless repo
330
+
331
+ @configuration.each do |_id, config|
332
+ config.allocator.save
288
333
  end
334
+ git.publish if publish?
289
335
  end
290
336
 
291
337
  # For testing, clears all instances including the configuration
@@ -301,9 +347,7 @@ module TestIds
301
347
  @number_config = nil
302
348
  end
303
349
 
304
- def testing=(val)
305
- @testing = val
306
- end
350
+ attr_writer :testing
307
351
 
308
352
  def testing?
309
353
  !!@testing
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TestIdsDev
2
4
  class DUT
3
5
  include Origen::TopLevel
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TestIdsDev
2
4
  class Interface
3
5
  include OrigenTesters::ProgramGenerators
4
6
 
5
- def initialize(options = {})
7
+ def initialize(_options = {})
6
8
  case dut.test_ids
7
9
  when 1
8
10
  TestIds.configure id: :cfg1 do |config|
data/program/prb1.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Flow.create do
2
4
  if dut.test_ids == 2
3
5
  func :t1, bin: 11
metadata CHANGED
@@ -1,29 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_ids
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen McGinty
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-08-10 00:00:00.000000000 Z
10
+ date: 2026-08-10 00:00:00.000000000 Z
12
11
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: origen
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 0.57.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 0.57.0
27
12
  - !ruby/object:Gem::Dependency
28
13
  name: dentaku
29
14
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +38,7 @@ dependencies:
53
38
  - !ruby/object:Gem::Version
54
39
  version: 0.2.0
55
40
  - !ruby/object:Gem::Dependency
56
- name: origen_testers
41
+ name: git
57
42
  requirement: !ruby/object:Gem::Requirement
58
43
  requirements:
59
44
  - - ">="
@@ -67,7 +52,21 @@ dependencies:
67
52
  - !ruby/object:Gem::Version
68
53
  version: '0'
69
54
  - !ruby/object:Gem::Dependency
70
- name: git
55
+ name: origen
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.57.0
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 0.57.0
68
+ - !ruby/object:Gem::Dependency
69
+ name: origen_testers
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
72
  - - ">="
@@ -80,7 +79,6 @@ dependencies:
80
79
  - - ">="
81
80
  - !ruby/object:Gem::Version
82
81
  version: '0'
83
- description:
84
82
  email:
85
83
  - stephen.mcginty@nxp.com
86
84
  executables: []
@@ -110,10 +108,8 @@ files:
110
108
  - templates/web/layouts/_basic.html.erb
111
109
  - templates/web/partials/_navbar.html.erb
112
110
  - templates/web/release_notes.md.erb
113
- homepage:
114
111
  licenses: []
115
112
  metadata: {}
116
- post_install_message:
117
113
  rdoc_options: []
118
114
  require_paths:
119
115
  - lib
@@ -128,8 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
124
  - !ruby/object:Gem::Version
129
125
  version: 1.8.11
130
126
  requirements: []
131
- rubygems_version: 3.1.4
132
- signing_key:
127
+ rubygems_version: 3.6.3
133
128
  specification_version: 4
134
129
  summary: Origen plugin to assign and track test program bins and test numbers
135
130
  test_files: []