Class: OrigenTesters::PatternCompilers::IGXLBasedPatternCompiler

Inherits:
BasePatternCompiler show all
Defined in:
lib/origen_testers/pattern_compilers/igxl_based.rb

Instance Attribute Summary

Attributes inherited from BasePatternCompiler

#id, #jobs

Instance Method Summary collapse

Methods inherited from BasePatternCompiler

#clear, #count, #empty?, #inspect_options, #is_j750?, #is_ultraflex?, #is_v93k?, #name, #platform

Constructor Details

#initialize(id, options = {}) ⇒ IGXLBasedPatternCompiler

Returns a new instance of IGXLBasedPatternCompiler.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/origen_testers/pattern_compilers/igxl_based.rb', line 4

def initialize(id, options = {})
  super

  # The following are pattern compiler options that are common between all IGXL platforms, these
  #   are added onto the base options.  Specifc IGXL platforms can add on additional options
  #   in their respective initialize methods.
  @user_options = {}.merge(@user_options)

  @job_options = {
    pinmap_workbook:  dut.pinmap,    # required: will default to $dut.pinmap
  }.merge(@job_options)

  # These are compiler options that are common to both the UltraFLEX and J750 compilers
  # Set all of these compiler options that don't have args to true/flase.  if true then send compiler '-opt'
  @compiler_options = {
    comments:              false,     # preserves comments in pattern binary
    cpp:                   false,     # runs C++ preprocessor on pattern file
    debug:                 false,     # generate intermediate file(s) to simplify debug ( application dependent )
    import_all_undefineds: false,     # automatically import all undefined symbols.  the key is mis-spelled but correct!
    suppress_log:          false,     # disables output to main log file
    template:              false,     # generate setup template
    timestamp:             false,     # enable log timestamp
  }.merge(@compiler_options)

  # These are compiler options that are common to both the UltraFLEX and J750 compilers
  @compiler_options_with_args = {
    define:       nil,       # Define macro values to be passed to C-preprocessor
    digital_inst: nil,       # Name of digital instrument
    logfile:      nil,       # Messages go to <filename> instead of <infile> log
    opcode_mode:  nil,       # Patgen opcode mode, specific to digital instrument
    output:       nil,       # Name of output file
    pinmap_sheet: nil,       # Name of workbook containing pinmap
    # pinmap_workbook:     nil,       # Name of sheet in workbook which contains pinmap (moved to @job_options)
    setup:        nil,       # path to setup file
  }.merge(@compiler_options_with_args)
end

Instance Method Details

#bad_optionsObject Also known as: bad_opts



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/origen_testers/pattern_compilers/igxl_based.rb', line 315

def bad_options
  bad = []
  options = {
    output_directory:    @job_options[:output_directory],
    reference_directory: @user_options[:reference_directory],
    path:                @path,
    pinmap_workbook:     @job_options[:pinmap_workbook],
    clean:               @job_options[:clean],
    location:            @job_options[:location],
    compiler:            @job_options[:compiler]
  }
  options.each do |k, v|
    bad << k if v.nil?
    if v.is_a? String # compiler
      v = Pathname.new(v)
      bad << k unless v.file?
    elsif v.is_a? Symbol # clean
      bad << k unless [:local, :lsf].include? v
    elsif v.is_a? Pathname
      if k.match(/directory/)
        bad << k unless v.directory?
      elsif k == :path
        bad << k unless v.exist?
      else # pinmap
        bad << k unless v.file?
      end
    end
  end
  bad
end

#find_jobs(path = @path) ⇒ Object

Finds the patterns and creates a compiler job for each one found. Handles singles files (.atp, .atp.gz, or .list) and directories (recursively or flat)



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/origen_testers/pattern_compilers/igxl_based.rb', line 133

def find_jobs(path = @path)
  fail 'Pattern path is set to nil, pass in a valid file (.atp or .atp.gz) or a valid directory' if path.nil?
  @path = Pathname.new(path)
  fail 'Pattern path does not exist, pass in a valid file (.atp or .atp.gz) or a valid directory' unless @path.exist?
  @path = @path.expand_path
  # Set the reference directory for pattern sub-dir mirroring
  set_reference_directory
  Origen.profile 'Linux pattern compiler finds patterns' do
    # Check if the path is a file or a directory
    if @path.directory?
      # Get all of the patterns inside this dir or inside this directory recursively
      process_directory(@path, @files, @user_options[:recursive])
    elsif @path.file? # Found a file so no searching is necessary
      process_file(@path, @files)
    else # Didn't find a directory or a file so user must want a search for this arg string * NOT SUPPORTED YET
      fail 'Error: Did not find a file or directory to compile, exiting...'
    end
  end

  Origen.profile 'Linux pattern compiler creates jobs' do
    @files.each do |f|
      rel_dir = Pathname.new("#{f.dirname.to_s[@user_options[:reference_directory].to_s.size..-1]}")
      if @job_options[:output_directory].nil?
        # job output dir not specified, create a unique (hash) based on path/compiler_name
        s = Digest::MD5.new
        s << @user_options[:reference_directory].to_s
        s << @id.to_s
        out = "#{@user_options[:reference_directory]}/job_#{@id}_#{s.to_s[0..6].upcase}#{rel_dir}"
        output_dir = Pathname.new(out)
      else
        output_dir = Pathname.new("#{@job_options[:output_directory]}#{rel_dir}")
      end
      unless output_dir.directory?
        puts "Output directory #{output_dir} for pattern #{f.basename} does not exist, creating it..."
        FileUtils.mkdir_p(output_dir)
      end
      current_job_options = @job_options.merge(@compiler_options_with_args)
      current_job_options[:output_directory] = output_dir
      @jobs << Job.new(f, current_job_options, @compiler_options)
      current_job_options = {}
    end
  end
  @files = []
  if empty?
    empty_msg
  else
    inspect_jobs
  end
end

#inspect_jobs(index = nil) ⇒ Object

alias_method :find, :find_jobs

Output the compiler jobs in the queue to the console



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/origen_testers/pattern_compilers/igxl_based.rb', line 229

def inspect_jobs(index = nil)
  return empty_msg if empty?
  desc = []
  puts "\n"
  @jobs.each_with_index do |j, i|
    unless index.nil?
      next unless i == index
    end
    desc << '| Job: ' + "#{i + 1} ".rjust(8) + '|' + 'Pattern:'.rjust(18) + " #{j.pattern.basename}".ljust(120) + '|'
    desc << '|              |' + 'Compiler ID:'.rjust(18) + " #{j.id} ".ljust(120) + '|'
    desc << '|              |' + 'Pinmap:'.rjust(18) + " #{j.pinmap_workbook} ".ljust(120) + '|'
    desc << '|              |' + '.atp directory:'.rjust(18) + " #{j.pattern.dirname} ".ljust(120) + '|'
    desc << '|              |' + '.pat directory:'.rjust(18) + " #{j.output_directory} ".ljust(120) + '|'
    desc << '|              |' + 'LSF:'.rjust(18) + " #{j.location == :lsf ? true : false} ".ljust(120) + '|'
    desc << '|              |' + 'Delete log files:'.rjust(18) + " #{j.clean} ".ljust(120) + '|'
    desc << '|              |' + 'Verbose:'.rjust(18) + " #{j.verbose} ".ljust(120) + '|'
    fragment = '|              |' + 'Compiler args:'.rjust(18)
    overflow_fragment = '|              |' + ' '.rjust(18)
    compiler_args = []
    compiler_fragment = ''
    j.compiler_options.each_key do |k|
      if compiler_fragment.size + " -#{k}".size >= 120
        compiler_args << compiler_fragment
        compiler_fragment = nil
      end
      compiler_fragment += " -#{k}"
    end
    compiler_args << compiler_fragment unless compiler_fragment.nil?
    compiler_fragment = ''
    j.compiler_options_with_args.each_pair do |k, v|
      if compiler_fragment.size + " -#{k}:#{v}".size >= 120
        compiler_args << compiler_fragment
        compiler_fragment = nil
      end
      compiler_fragment += " -#{k}:#{v}"
    end
    compiler_args << compiler_fragment unless compiler_fragment.nil?
    if compiler_args.join.length <= 120
      desc << fragment + "#{compiler_args.join}".ljust(120) + '|'
    else
      # Need to cycle through compiler args and build a fragment <= 100 characters
      # and print it.  Keep going until the remaining args is <= 100 and print again
      char_cnt = 0
      line_cnt = 0
      args = []
      compiler_args = compiler_args.join.strip.split(/\s+/)
      until compiler_args.empty?
        args = compiler_args.select { |e| (char_cnt += e.length + 1) < 120 }
        # remove the args that fit on the first line
        compiler_args -= args
        if line_cnt == 0
          desc << fragment + " #{args.join(' ')}".ljust(120) + '|'
        else
          desc << overflow_fragment + " #{args.join(' ')}".ljust(120) + '|'
        end
        args = []
        line_cnt += 1
        char_cnt = 0
      end
    end
    desc << '-' * desc.first.size
  end
  puts desc.flatten.join("\n")
end

#options_ok?Boolean

For future checks on incorrect or incompatible arguments to compiler options

Returns:

  • (Boolean)


294
295
# File 'lib/origen_testers/pattern_compilers/igxl_based.rb', line 294

def options_ok?
end

#pinmapObject

Return the compiler instance pinmap



55
56
57
# File 'lib/origen_testers/pattern_compilers/igxl_based.rb', line 55

def pinmap
  @job_options[:pinmap_workbook]
end

#ready?Boolean

Returns:

  • (Boolean)


297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/origen_testers/pattern_compilers/igxl_based.rb', line 297

def ready?
  ready = true
  paths_contain_data = true
  ready &= paths_contain_data
  ready &= !@job_options[:output_directory].nil?
  ready &= !@user_options[:reference_directory].nil?
  ready &= !@path.nil?
  ready &= !@job_options[:pinmap_workbook].nil?
  ready &= @job_options[:output_directory].directory?
  ready &= @user_options[:reference_directory].directory?
  ready &= @path.exist?
  ready &= @job_options[:pinmap_workbook].file?
  ready &= [true, false].include?(@job_options[:clean])
  ready &= [:local, :lsf].include?(@job_options[:location])
  ready &= File.exist?(@job_options[:compiler])
  ready
end

#run(list = nil, options = {}) ⇒ Object

Executes the compiler for each job in the queue



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/origen_testers/pattern_compilers/igxl_based.rb', line 60

def run(list = nil, options = {})
  # Check if there was a pattern list passed as an argument
  # If so, then compile the patterns inside it.
  # Otherwise compile the jobs in the queue
  if list.nil?
    if empty?
      empty_msg
      return
    end
    @jobs.each do |job|
      fail "Error: compiler #{job.id} not ready for pattern #{job.name}" unless job.ready?
      if job.location == :lsf
        Origen.app.lsf.submit(ATPC_SETUP + '; ' + job.cmd)
      else
        Origen.profile "Linux pattern compiler compiles pattern #{job.pattern}" do
          system job.cmd
        end
      end
    end
    if @job_options[:location] == :local
      if @job_options[:clean] == true
        puts 'Log file :clean option set to true, deleting log files'
        clean_output
      end
    end
    # Clear @jobs
    clear
  else
    list = convert_to_pathname(list)
    fail "Error: pattern list #{list} does not exist, exiting..." unless list.file?
    File.open(list, 'r') do |file|
      while (line = file.gets)
        current_job_options = @job_options.merge(@compiler_options_with_args)
        current_job_options.update_common(options)
        # puts "current job options is #{current_job_options}"
        compiler_opts = {}
        line.strip!
        pattern = line.match(/^(\S+)\s+(.*)/).captures[0]
        unless File.file? pattern
          puts "Warning: Pattern #{pattern} does not exist, skipping..."
          next
        end
        pattern = convert_to_pathname(pattern)
        line.match(/^\S+\s+(.*)/).captures[0].split(/\s+/).each do |e|
          opt, arg = e.split(':')
          opt.gsub!('-', '')
          if arg.nil?
            compiler_opts[opt.to_sym] = true
          else
            # Check for some specific options
            case opt
              when 'pinmap_workbook'
                current_job_options[opt.to_sym] = Pathname.new(arg)
              when 'output'
                dot_pat = Pathname.new(arg)
                current_job_options[:output_directory] = dot_pat.dirname
              else
                current_job_options[opt.to_sym] = arg
            end
          end
        end
        @jobs << Job.new(pattern, current_job_options, compiler_opts)
        inspect_jobs
      end
    end
    run
    # Clear @jobs
    clear
  end
end

#to_list(options = {}) ⇒ Object

Output all of the jobs into a pattern list so it can be compiled later Must be executed after the ‘find_jobs’ method and before the ‘run’ method or @jobs will be empty



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/origen_testers/pattern_compilers/igxl_based.rb', line 186

def to_list(options = {})
  options = {
    name:             @id,
    output_directory: Dir.pwd,
    expand:           true,
    force:            false
  }.update_common(options)
  list = "#{options[:output_directory]}/#{options[:name]}.list"
  list = convert_to_pathname(list)
  if empty?
    empty_msg
    return
  end
  if list.file?
    if options[:force] == true
      puts "Pattern list file #{list} already exists, deleting it..."
      list.delete
    else
      fail "Pattern list file #{list} already exists, exiting..."
    end
  end
  File.open(list, 'w') do |patlist|
    @jobs.each do |job|
      if options[:expand] == true
        pinmap = job.pinmap_workbook
        dot_pat_name = "#{job.output_directory}/#{job.pattern.basename.to_s.split('.').first}.PAT"
        dot_atp_name = job.pattern
      else
        pinmap = job.pinmap_workbook.basename
        dot_pat_name = "#{job.pattern.basename.to_s.split('.').first}.PAT"
        dot_atp_name = job.pattern.basename
      end
      patlist.print("#{dot_atp_name} -pinmap_workbook:#{pinmap} -output:#{dot_pat_name}")
      job.compiler_options.each_key { |k| patlist.print(" -#{k}") }
      job.compiler_options_with_args.each_pair { |k, v| patlist.print(" -#{k}:#{v}") }
      patlist.puts('')
    end
  end
end

#verify_pinmap_is_specifiedObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/origen_testers/pattern_compilers/igxl_based.rb', line 41

def verify_pinmap_is_specified
  if @job_options[:pinmap_workbook].nil?
    # Check if the app has dut.pinmap defined
    if dut.pinmap && File.exist?(dut.pinmap)
      @job_options[:pinmap_workbook] = dut.pinmap
    else
      fail 'Pinmap is not defined!  Pass as an option or set $dut.pinmap.'
    end
  end
  @job_options[:pinmap_workbook] = convert_to_pathname(@job_options[:pinmap_workbook])
  fail 'Pinmap is not a file!' unless @job_options[:pinmap_workbook].file?
end