Class: Origen::Generator::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/origen/generator/job.rb

Overview

A job is responsible for executing a single pattern source

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, options) ⇒ Job

Returns a new instance of Job.



9
10
11
12
13
14
15
# File 'lib/origen/generator/job.rb', line 9

def initialize(pattern, options)
  @testing = options[:testing]
  @options = options
  @requested_pattern = pattern
  @no_comments = options[:no_comments]
  @output_opt = options[:output]
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/origen/generator/job.rb', line 7

def options
  @options
end

#output_file_bodyObject

:nodoc: all



5
6
7
# File 'lib/origen/generator/job.rb', line 5

def output_file_body
  @output_file_body
end

#patternObject

:nodoc: all



5
6
7
# File 'lib/origen/generator/job.rb', line 5

def pattern
  @pattern
end

#split_counterObject (readonly)

Returns the value of attribute split_counter.



6
7
8
# File 'lib/origen/generator/job.rb', line 6

def split_counter
  @split_counter
end

#split_namesObject (readonly)

Returns the value of attribute split_names.



6
7
8
# File 'lib/origen/generator/job.rb', line 6

def split_names
  @split_names
end

Instance Method Details

#inc_split_counter(name = '') ⇒ Object



26
27
28
29
30
31
# File 'lib/origen/generator/job.rb', line 26

def inc_split_counter(name = '')
  @split_counter ||= 0
  @split_names ||= ['']
  @split_counter += 1
  @split_names << name
end

#no_comments?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/origen/generator/job.rb', line 22

def no_comments?
  @no_comments
end

#output_extensionObject



103
104
105
# File 'lib/origen/generator/job.rb', line 103

def output_extension
  '.' + Origen.tester.pat_extension
end

#output_overrideObject



107
108
109
110
111
112
113
114
115
116
# File 'lib/origen/generator/job.rb', line 107

def output_override
  if @output_opt
    if @output_opt =~ /#{Origen.root}/
      return @output_opt
    else
      return "#{Origen.root}/#{@output_opt}"
    end
  end
  nil
end

#output_patternObject Also known as: output_file

Returns a full path to the output pattern, note that this is not available until the job has been run



40
41
42
# File 'lib/origen/generator/job.rb', line 40

def output_pattern
  "#{output_pattern_directory}/#{output_pattern_filename}"
end

#output_pattern_directoryObject



71
72
73
74
75
76
77
78
79
80
# File 'lib/origen/generator/job.rb', line 71

def output_pattern_directory
  @output_pattern_directory ||= begin
    dir = output_override || Origen.app.config.pattern_output_directory
    if tester.respond_to?(:subdirectory)
      dir = File.join(dir, tester.subdirectory)
    end
    FileUtils.mkdir_p(dir) unless File.exist?(dir)
    dir
  end
end

#output_pattern_filenameObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/origen/generator/job.rb', line 50

def output_pattern_filename
  return '' if @testing
  # If the pattern name has been overridden by an interator use that
  return @output_pattern_filename if @output_pattern_filename
  if !@pattern && !@output_file_body
    fail 'Sorry the output_pattern is not available until the job has been run'
  end
  body = @output_file_body ? @output_file_body : File.basename(@pattern, '.rb')
  output_prefix + body + output_postfix + split_number + output_extension
end

#output_pattern_filename=(val) ⇒ Object

This can be modified at runtime by the pattern generator in response to iterator substitutions



63
64
65
# File 'lib/origen/generator/job.rb', line 63

def output_pattern_filename=(val)
  @output_pattern_filename = val
end

#output_postfixObject



99
100
101
# File 'lib/origen/generator/job.rb', line 99

def output_postfix
  Origen.config.pattern_postfix ? '_' + Origen.config.pattern_postfix : ''
end

#output_prefixObject



93
94
95
96
97
# File 'lib/origen/generator/job.rb', line 93

def output_prefix
  p = Origen.config.pattern_prefix ? Origen.config.pattern_prefix + '_' : ''
  p = "_#{p}" if Origen.tester.doc?
  p
end

#reference_patternObject Also known as: reference_file



45
46
47
# File 'lib/origen/generator/job.rb', line 45

def reference_pattern
  "#{reference_pattern_directory}/#{output_pattern_filename}"
end

#reference_pattern_directoryObject



82
83
84
85
86
87
88
89
90
91
# File 'lib/origen/generator/job.rb', line 82

def reference_pattern_directory
  @reference_pattern_directory ||= begin
    dir = Origen.file_handler.reference_directory
    if tester.respond_to?(:subdirectory)
      dir = File.join(dir, tester.subdirectory)
    end
    FileUtils.mkdir_p(dir) unless File.exist?(dir)
    dir
  end
end

#requested_patternObject Also known as: requested_file



33
34
35
# File 'lib/origen/generator/job.rb', line 33

def requested_pattern
  @requested_pattern
end

#reset_output_pattern_filenameObject



67
68
69
# File 'lib/origen/generator/job.rb', line 67

def reset_output_pattern_filename
  @output_pattern_filename = nil
end

#runObject



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
182
183
184
185
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
# File 'lib/origen/generator/job.rb', line 134

def run
  Origen.app.current_jobs << self
  begin
    if @options[:compile]
      Origen.log.start_job(strip_dir_and_ext(@requested_pattern), :compiler)
      Origen.generator.compiler.compile(@requested_pattern, @options)
    elsif @options[:job_type] == :merge
      Origen.log.start_job(strip_dir_and_ext(@requested_pattern), :merger)
      Origen.generator.compiler.merge(@requested_pattern)
    elsif @options[:action] == :program
      if Origen.running_simulation?
        Origen.log.start_job(strip_dir_and_ext(@requested_pattern), :simulator)
      else
        Origen.log.start_job(strip_dir_and_ext(@requested_pattern), :program_generator)
      end
      Origen.flow.reset
      Origen.resources.reset
      OrigenTesters::Generator.execute_source(@pattern)
    else
      if Origen.running_simulation?
        Origen.log.start_job(strip_dir_and_ext(@requested_pattern), :simulator)
      else
        Origen.log.start_job(strip_dir_and_ext(@requested_pattern), :pattern_generator)
      end
      Origen.generator.pattern.reset      # Resets the pattern controller ready for a new pattern
      # Give the app a chance to handle pattern dispatch
      skip = false
      Origen.app.listeners_for(:before_pattern_lookup).each do |listener|
        skip ||= !listener.before_pattern_lookup(@requested_pattern)
      end
      unless skip
        if @options[:sequence]
          @pattern = @requested_pattern
          Origen.pattern.sequence do |seq|
            # This splits the pattern name by "_" then removes all values that are common to all patterns
            # and then rejoins what is left.
            # The goal is to keep the thread ID concise for the log and rather than using the whole pattern
            # name only focussing on what is different.
            # e.g. if you combined patterns flash_read_ckbd_ip1_max.rb and flash_read_ckbd_ip2_max.rb into
            # a concurrent sequence then the two threads would be called 'ip1' and 'ip2'.
            ids = @options[:patterns].map do |pat|
              Pathname.new(pat).basename('.*').to_s.split('_')
            end
            ids = ids.map { |id| id.reject { |i| ids.all? { |id| id.include?(i) } }.join('_') }

            @options[:patterns].each_with_index do |pat, i|
              id = ids[i]
              id = i.to_s if id.empty?
              seq.in_parallel id do
                seq.run pat
              end
            end
          end
        else
          @pattern = Origen.generator.pattern_finder.find(@requested_pattern, @options)
          if @pattern.is_a?(Hash)
            @output_file_body = @pattern[:output]
            @pattern = @pattern[:pattern]
          end
          load @pattern unless @pattern == :skip  # Run the pattern
        end
      end
    end
  rescue Exception => e
    # Whoever has aborted the job is responsible for cleaning it up
    unless e.is_a?(Origen::Generator::AbortError)
      if @options[:continue] || Origen.running_remotely?
        Origen.log.error "FAILED - #{@requested_pattern} (for target #{Origen.target.name})"
        Origen.log.error e.message
        e.backtrace.each do |l|
          Origen.log.error l
        end
        if @options[:compile]
          Origen.app.stats.failed_files += 1
        else
          Origen.app.stats.failed_patterns += 1
        end
      else
        raise
      end
    end
  end
  Origen.log.stop_job
  Origen.app.current_jobs.pop
end

#split_numberObject



118
119
120
121
122
123
124
125
126
127
128
# File 'lib/origen/generator/job.rb', line 118

def split_number
  if split_counter
    if split_names[split_counter] != ''
      "_#{split_names[split_counter]}"
    else
      "_part#{split_counter}"
    end
  else
    ''
  end
end

#strip_dir_and_ext(name) ⇒ Object



130
131
132
# File 'lib/origen/generator/job.rb', line 130

def strip_dir_and_ext(name)
  Pathname.new(name).basename('.*').basename('.*').to_s
end

#test?Boolean

Returns true if the job is a test job, will only be true in a test scenario

Returns:

  • (Boolean)


18
19
20
# File 'lib/origen/generator/job.rb', line 18

def test?
  @testing
end