test_ids 0.7.1 → 0.8.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7349366c381561bec8b1fc71f12f322ab443b50e
4
- data.tar.gz: be512c9947423b3f8f5466ad0ea769e390789a31
3
+ metadata.gz: 3187c134f83d0e5a9c3513027fb2c1bad26a1b12
4
+ data.tar.gz: 8d265c7f97de0eb22d62efff091a0974fc5e0482
5
5
  SHA512:
6
- metadata.gz: b6eca8998668fda629296815c729d9a3b519b8b00b1a834223894862437ec665d6db005d93d853193c11101a0c07675dfab89f2e390c06b6228e3a3a21373316
7
- data.tar.gz: a392383d2fff3e4ea061c72710e04e7667a5b36894e89cd987ce9c524e6a8ffa8ec64ef9c7bc47550049f3d1536e5c2998ff1eb80b09cb1f172134e6181b4bc0
6
+ metadata.gz: f30d12207607a2eac1335af1f9e4e4e37854dbd36aea7647c79e74cb68e3c1810d7cdbe5d4174f2c52ac8e7081ad3b96119cb8f3386d314d4966672fac29b9ce
7
+ data.tar.gz: 2d0347b9c85d6edec9f36be9994639916f1a6eb0447a9ab5bbc5f98b48b0f9d54d565e7aca366fa1edbea7f13f3a1ea41a530d717586b1e8bc1d911e143cf659
@@ -3,14 +3,21 @@ case @command
3
3
 
4
4
  when "test_ids:rollback"
5
5
  if ARGV[0]
6
- TestIds::Git.rollback(ARGV[0])
6
+ local = TestIds::Git.path_to_local
7
+ TestIds::Git.new(local: local).rollback(ARGV[0])
7
8
  else
8
9
  puts "You must supply a commit ID to rollback to, e.g. origen test_ids:rollback 456ac3f53"
9
10
  end
10
11
  exit 0
12
+
13
+ when "test_ids:clear"
14
+ require "test_ids/commands/#{@command.split(':').last}"
15
+ exit 0
16
+
11
17
  else
12
18
  @plugin_commands << <<-EOT
13
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
14
21
  EOT
15
22
 
16
23
  end
@@ -1,7 +1,7 @@
1
1
  module TestIds
2
2
  MAJOR = 0
3
- MINOR = 7
4
- BUGFIX = 1
3
+ MINOR = 8
4
+ BUGFIX = 0
5
5
  DEV = nil
6
6
 
7
7
  VERSION = [MAJOR, MINOR, BUGFIX].join(".") + (DEV ? ".pre#{DEV}" : '')
@@ -6,17 +6,13 @@ module TestIds
6
6
  # THIS FILE SHOULD ONLY BE USED TO LOAD RUNTIME DEPENDENCIES
7
7
  # If this plugin has any development dependencies (e.g. dummy DUT or other models that are only used
8
8
  # for testing), then these should be loaded from config/boot.rb
9
-
10
- # Example of how to explicitly require a file
11
- # require "test_ids/my_file"
12
-
13
- # Load all files in the lib/test_ids directory.
14
- # Note that there is no problem from requiring a file twice (Ruby will ignore
15
- # the second require), so if you have a file that must be required first, then
16
- # explicitly require it up above and then let this take care of the rest.
17
- Dir.glob("#{File.dirname(__FILE__)}/test_ids/**/*.rb").sort.each do |file|
18
- require file
19
- end
9
+ require 'test_ids/allocator'
10
+ require 'test_ids/bin_array'
11
+ require 'test_ids/configuration'
12
+ require 'test_ids/git'
13
+ require 'test_ids/shutdown_handler'
14
+ require 'test_ids/origen/origen'
15
+ require 'test_ids/origen_testers/flow'
20
16
 
21
17
  class <<self
22
18
  # Allocates a number to the given test and returns a new hash containing
@@ -34,6 +30,12 @@ module TestIds
34
30
  }
35
31
  end
36
32
 
33
+ # Load an existing allocator, which will be loaded with an empty configuration
34
+ # @api internal
35
+ def load_allocator(id = nil)
36
+ Configuration.new(id).allocator
37
+ end
38
+
37
39
  def current_configuration
38
40
  configuration(@configuration_id)
39
41
  end
@@ -64,6 +66,27 @@ module TestIds
64
66
  initialize_git
65
67
  end
66
68
 
69
+ ## Can be called in place of TestIDs.configure to change the configuration from
70
+ ## the one that was originally supplied.
71
+ ## It is expected that this is mainly useful for testing purposes only.
72
+ # def reconfigure(id = nil, options = {}, &block)
73
+ # id, options = nil, id if id.is_a?(Hash)
74
+
75
+ # @configuration_id = id || options[:id] || :not_specified
76
+
77
+ # @configuration ||= {}
78
+
79
+ # old = @configuration[@configuration_id]
80
+ # new = Configuration.new(@configuration_id)
81
+ # new.instance_variable_set('@allocator', old.allocator)
82
+ # new.allocator.instance_variable_set('@config', new)
83
+ # @configuration[@configuration_id] = new
84
+
85
+ # yield new
86
+
87
+ # new.validate!
88
+ # end
89
+
67
90
  def configured?
68
91
  !!@configuration_id
69
92
  end
@@ -82,7 +105,7 @@ module TestIds
82
105
  # git storage has not been enabled
83
106
  def database_file(id)
84
107
  if repo
85
- if id == :not_specified
108
+ if id == :not_specified || !id || id == ''
86
109
  f = 'store.json'
87
110
  else
88
111
  f = "store_#{id.to_s.downcase}.json"
@@ -136,6 +159,20 @@ module TestIds
136
159
  @publish = val ? :save : :dont_save
137
160
  end
138
161
 
162
+ ## When set to true, all numbers generated will be checked to see if they comply
163
+ ## with the current configuration, and if not they will be re-assigned based on the
164
+ ## current configuration
165
+ # def reallocate_non_compliant
166
+ # @reallocate_non_compliant
167
+ # end
168
+
169
+ ## When set to true, all numbers generated will be checked to see if they comply
170
+ ## with the current configuration, and if not they will be re-assigned based on the
171
+ ## current configuration
172
+ # def reallocate_non_compliant=(val)
173
+ # @reallocate_non_compliant = val
174
+ # end
175
+
139
176
  private
140
177
 
141
178
  def on_origen_shutdown
@@ -16,6 +16,7 @@ module TestIds
16
16
  # Main method to inject generated bin and test numbers, the given
17
17
  # options instance is modified accordingly
18
18
  def allocate(instance, options)
19
+ orig_options = options.dup
19
20
  clean(options)
20
21
  @callbacks = []
21
22
  name = extract_test_name(instance, options)
@@ -93,10 +94,19 @@ module TestIds
93
94
  # Otherwise generate the missing ones
94
95
  bin['number'] ||= allocate_bin(size: bin_size)
95
96
  bin['size'] ||= bin_size
96
- softbin['number'] ||= allocate_softbin(bin: bin['number'], size: softbin_size)
97
- softbin['size'] ||= softbin_size
98
- number['number'] ||= allocate_number(bin: bin['number'], softbin: softbin['number'], size: number_size)
99
- number['size'] ||= number_size
97
+ # If the softbin is based on the test number, then need to calculate the
98
+ # test number first
99
+ if config.softbins.algorithm && config.softbins.algorithm.to_s =~ /n/
100
+ number['number'] ||= allocate_number(bin: bin['number'], size: number_size)
101
+ number['size'] ||= number_size
102
+ softbin['number'] ||= allocate_softbin(bin: bin['number'], number: number['number'], size: softbin_size)
103
+ softbin['size'] ||= softbin_size
104
+ else
105
+ softbin['number'] ||= allocate_softbin(bin: bin['number'], size: softbin_size)
106
+ softbin['size'] ||= softbin_size
107
+ number['number'] ||= allocate_number(bin: bin['number'], softbin: softbin['number'], size: number_size)
108
+ number['size'] ||= number_size
109
+ end
100
110
 
101
111
  # Record that there has been a reference to the final numbers
102
112
  time = Time.now.to_f
@@ -123,6 +133,18 @@ module TestIds
123
133
  options[:number] = number['number']
124
134
  options[:number_size] = number['size']
125
135
  end
136
+
137
+ ## If reallocation is on, then check if the generated numbers are compliant, if not
138
+ ## clear them and go back around again to generate a new set
139
+ # if TestIds.reallocate_non_compliant
140
+ # if !config.bins.function?
141
+ # if !config.bins.compliant?(options[:bin])
142
+ # store["assigned"]["bin"].delete(bin_id)
143
+ # return allocate(instance, orig_options)
144
+ # end
145
+ # end
146
+ # end
147
+
126
148
  options
127
149
  end
128
150
 
@@ -162,6 +184,28 @@ module TestIds
162
184
  end
163
185
  end
164
186
 
187
+ # Clear the :bins, :softbins and/or :numbers by setting the options for each item to true
188
+ def clear(options)
189
+ if options[:softbin] || options[:softbins]
190
+ store['assigned']['softbin'] = {}
191
+ store['manually_assigned']['softbin'] = {}
192
+ store['pointers']['softbin'] = nil
193
+ store['references']['softbin'] = {}
194
+ end
195
+ if options[:bin] || options[:bins]
196
+ store['assigned']['bin'] = {}
197
+ store['manually_assigned']['bin'] = {}
198
+ store['pointers']['bin'] = nil
199
+ store['references']['bin'] = {}
200
+ end
201
+ if options[:number] || options[:numbers]
202
+ store['assigned']['number'] = {}
203
+ store['manually_assigned']['number'] = {}
204
+ store['pointers']['number'] = nil
205
+ store['references']['number'] = {}
206
+ end
207
+ end
208
+
165
209
  # Saves the current allocator state to the repository
166
210
  def save
167
211
  if file
@@ -220,19 +264,28 @@ module TestIds
220
264
 
221
265
  def allocate_softbin(options)
222
266
  bin = options[:bin]
267
+ num = options[:number]
223
268
  return nil if config.softbins.empty?
224
269
  if config.softbins.algorithm
225
270
  algo = config.softbins.algorithm.to_s.downcase
226
- if algo.to_s =~ /^[b\dx]+$/
271
+ if algo.to_s =~ /^[b\dxn]+$/
227
272
  number = algo.to_s
228
273
  bin = bin.to_s
229
274
  if number =~ /(b+)/
230
275
  max_bin_size = Regexp.last_match(1).size
231
276
  if bin.size > max_bin_size
232
- fail "Bin number (#{bin}) overflows the test number algorithm (#{algo})"
277
+ fail "Bin number (#{bin}) overflows the softbin number algorithm (#{algo})"
233
278
  end
234
279
  number = number.sub(/b+/, bin.rjust(max_bin_size, '0'))
235
280
  end
281
+ if number =~ /(n+)/
282
+ num = num.to_s
283
+ max_num_size = Regexp.last_match(1).size
284
+ if num.size > max_num_size
285
+ fail "Test number (#{num}) overflows the softbin number algorithm (#{algo})"
286
+ end
287
+ number = number.sub(/n+/, num.rjust(max_num_size, '0'))
288
+ end
236
289
  if number =~ /(x+)/
237
290
  max_counter_size = Regexp.last_match(1).size
238
291
  refs = store['references']['softbin']
@@ -0,0 +1,52 @@
1
+ require 'optparse'
2
+
3
+ options = {}
4
+
5
+ # App options are options that the application can supply to extend this command
6
+ app_options = @application_options || []
7
+ opt_parser = OptionParser.new do |opts|
8
+ opts.banner = <<-EOT
9
+ Clear all existing bin, softbin or test number allocations in the given TestId database.
10
+
11
+ Usage: origen test_ids:clear [ID] [options]
12
+
13
+ Examples: origen test_ids:clear --bins # Clear the bins in the default database
14
+ origen test_ids:clear wafer_test --numbers # Clear the test numbers in the wafer_test database
15
+ origen test_ids:clear --bins --softbin --numbers # Clear everything in the default database
16
+
17
+ EOT
18
+ opts.on('--bins', 'Clear the bin database') { options[:bins] = true }
19
+ opts.on('--softbins', 'Clear the softbin database') { options[:softbins] = true }
20
+ opts.on('--numbers', 'Clear the test number database') { options[:numbers] = true }
21
+ # opts.on('-pl', '--plugin PLUGIN_NAME', String, 'Set current plugin') { |pl_n| options[:current_plugin] = pl_n }
22
+ opts.on('-d', '--debugger', 'Enable the debugger') { options[:debugger] = true }
23
+ app_options.each do |app_option|
24
+ opts.on(*app_option) {}
25
+ end
26
+ opts.separator ''
27
+ opts.on('-h', '--help', 'Show this message') { puts opts; exit 0 }
28
+ end
29
+
30
+ opt_parser.parse! ARGV
31
+
32
+ local = TestIds::Git.path_to_local
33
+ git = TestIds::Git.new(local: local)
34
+ TestIds.repo = git.repo.remote.url
35
+ git.get_lock
36
+ rollback_id = nil
37
+ begin
38
+ # Get the commit before the lock to give the user later
39
+ rollback_id = git.repo.object('HEAD^').sha[0, 11]
40
+ a = TestIds.load_allocator(ARGV.first)
41
+ a.clear(options)
42
+ a.save
43
+ ensure
44
+ git.publish
45
+ end
46
+ if rollback_id
47
+ puts
48
+ puts 'TestIDs database cleared as requested, you can rollback this change by running:'
49
+ puts
50
+ puts " origen test_ids:rollback #{rollback_id}"
51
+ puts
52
+ end
@@ -25,6 +25,9 @@ module TestIds
25
25
  !!algorithm || !!callback
26
26
  end
27
27
 
28
+ # def compliant?(number)
29
+ # end
30
+
28
31
  def freeze
29
32
  @include.freeze
30
33
  @exclude.freeze
@@ -14,10 +14,11 @@ module TestIds
14
14
 
15
15
  attr_reader :repo, :local
16
16
 
17
- class Rollback
17
+ # @api private
18
+ class PathToLocal
18
19
  include Origen::Utility::InputCapture
19
20
 
20
- def initialize(id)
21
+ def find
21
22
  repos = Dir.glob("#{Origen.app.imports_dir}/test_ids/*.git")
22
23
  if repos.size == 0
23
24
  puts 'No TestIds repositories were found in this application'
@@ -37,37 +38,15 @@ module TestIds
37
38
  else
38
39
  selection = 0
39
40
  end
40
- name = Pathname.new(repos[selection]).basename.to_s
41
- repo = ::Git.open(repos[selection])
42
- begin
43
- commit = repo.object(id)
44
- rescue ::Git::GitExecuteError
45
- puts 'The given commit ID cannot be found in that repository'
46
- exit
47
- end
48
- day = 24 * 60 * 60
49
- if commit.date < Time.now - (7 * day)
50
- puts "Sorry, that commit is more than a week old and I'm too scared to rollback that far."
51
- puts 'You will need to do that manually if you must.'
52
- exit
53
- end
54
- puts
55
- puts "About to rollback the TestIds repository #{name} to commit #{id}."
56
- puts
57
- puts 'This will permanently delete any IDs assigned by anyone, anywhere, since that commit.'
58
- puts
59
- puts 'ARE YOU SURE YOU KNOW WHAT YOU ARE DOING?'
60
- puts
61
- get_text(confirm: true, default: 'no')
62
- repo.reset_hard(id)
63
- repo.push('origin', 'master', force: true)
64
- puts 'As you wish, rolled back successfully!'
41
+ repos[selection]
65
42
  end
66
43
  end
67
44
 
68
- def self.rollback(id)
45
+ # Returns a path to the local test IDs repo, if multiple are found the user will be
46
+ # prompted to choose one
47
+ def self.path_to_local
69
48
  # Implemented as a class as a hack to get access to InputCapture
70
- Rollback.new(id)
49
+ PathToLocal.new.find
71
50
  end
72
51
 
73
52
  def initialize(options)
@@ -93,6 +72,34 @@ module TestIds
93
72
  @repo.reset_hard
94
73
  end
95
74
 
75
+ # Roll the repo back to the given commit ID
76
+ def rollback(id)
77
+ name = Pathname.new(local).basename.to_s
78
+ begin
79
+ commit = repo.object(id)
80
+ rescue ::Git::GitExecuteError
81
+ puts 'The given commit ID cannot be found in that repository'
82
+ exit
83
+ end
84
+ # day = 24 * 60 * 60
85
+ # if commit.date < Time.now - (7 * day)
86
+ # puts "Sorry, that commit is more than a week old and I'm too scared to rollback that far."
87
+ # puts 'You will need to do that manually if you must.'
88
+ # exit
89
+ # end
90
+ puts
91
+ puts "About to rollback the TestIds repository #{name} to commit #{id}."
92
+ puts
93
+ puts 'This will permanently delete any IDs assigned by anyone, anywhere, since that commit.'
94
+ puts
95
+ puts 'ARE YOU SURE YOU KNOW WHAT YOU ARE DOING?'
96
+ puts
97
+ get_text(confirm: true, default: 'no')
98
+ repo.reset_hard(id)
99
+ repo.push('origin', 'master', force: true)
100
+ puts 'As you wish, rolled back successfully!'
101
+ end
102
+
96
103
  def exec(cmd)
97
104
  r = system(cmd)
98
105
  unless r
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: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen McGinty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-10 00:00:00.000000000 Z
11
+ date: 2017-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: origen
@@ -68,6 +68,7 @@ files:
68
68
  - lib/test_ids.rb
69
69
  - lib/test_ids/allocator.rb
70
70
  - lib/test_ids/bin_array.rb
71
+ - lib/test_ids/commands/clear.rb
71
72
  - lib/test_ids/configuration.rb
72
73
  - lib/test_ids/git.rb
73
74
  - lib/test_ids/origen/origen.rb