roku_builder 4.1.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 573c78252bcce4dea40430de90789acd0d4f3a05
4
- data.tar.gz: 8c96b5bfa0b1f2dcab2c8b19f47fe477f972e604
3
+ metadata.gz: 76ae977634fda5e0bf54a43c8ad3f4ed9f25ecbd
4
+ data.tar.gz: 5bc65db62d56b8a93a2abb6f1448b3972aa9f8a5
5
5
  SHA512:
6
- metadata.gz: 4e144ca75cb797bbe36846cdcfc17512ac6c13333712d7e3862e4d90e0d0d455d28f1c83c308fc2a91bdc66efaed910024199db0158e691c1a579d23a0f75597
7
- data.tar.gz: d41bb3e7113cd436cc2418e9c2f7c9a1288565bf140e373ccaf89c9da76c5a4464c1d34532d2be2de592804bcd18519e96a19df77808768da3b34a1afe45ea06
6
+ metadata.gz: 8599f80443262180266504b745ed95d3cd4751e2404b8da870b2690c9913e58ade819f7faea4bf2be45ee7ebb39081ae0991ca6b277b16fff0ddef0da4e2b016
7
+ data.tar.gz: b0e5b307b438d757dc08e636fb3e18bea910009eac62e0752ddab0bcef63006bf69f0b090dc3fcd664fa3a86641b3638141774ca7644c135f9750749c42e41f5
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ = 4.2.0 =
2
+
3
+ - Added `--sgperf` command to do performance reports
4
+ - Added `--devlog` command to turn on enhanced logging
5
+ - Added memmory profiler option to monitor image memmory usage
6
+ - Add 'roots' profiler option
7
+ - Add node id option to profiler
8
+ - images profiler option now sorts images by file size
9
+ - Improve formatting of verbose output of navigator
10
+
1
11
  = 4.1.0 =
2
12
 
3
13
  - Remove unnecessary default manifest values
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- roku_builder (4.1.0)
4
+ roku_builder (4.2.0)
5
5
  faraday (~> 0.12)
6
6
  faraday-digestauth (~> 0.2)
7
7
  git (~> 1.3)
@@ -32,6 +32,18 @@ module RokuBuilder
32
32
  output = `#{roku} --profile all`
33
33
  assert_match(/RectangleExample/, output)
34
34
  end
35
+ def test_profile_roots
36
+ `#{roku} --sideload --working`
37
+ assert_log @uuid
38
+ output = `#{roku} --profile roots`
39
+ assert_match(/Default/, output)
40
+ end
41
+ def test_profile_node
42
+ `#{roku} --sideload --working`
43
+ assert_log @uuid
44
+ output = `#{roku} --profile exampleRectangle`
45
+ assert_match(/name="exampleRectangle"/, output)
46
+ end
35
47
  def test_profile_images
36
48
  `#{roku} --sideload --working`
37
49
  assert_log @uuid
@@ -66,9 +66,10 @@ module RokuBuilder
66
66
  end
67
67
 
68
68
  commands = [
69
- "bsc", "bscs", "brkd", "bt", "classes", "cont", "cont", "down", "d",
70
- "exit", "gc", "help", "last", "list", "next", "print", "p", "?", "step",
71
- "s", "t", "over", "out", "up", "u", "var", "q"
69
+ "bsc", "bscs", "brkd", "bt", "c", "classes", "cont", "cont", "down", "d",
70
+ "exit", "gc", "help", "l", "last", "list", "n", "next", "o", "print",
71
+ "p", "?", "s", "stats", "step", "t", "th", "thread", "threads", "ths",
72
+ "over", "out", "up", "u", "q", "v", "var"
72
73
  ].sort
73
74
  commands.collect { |i| i + ' ' } if libedit
74
75
 
@@ -102,9 +102,9 @@ module RokuBuilder
102
102
  running = true
103
103
  @logger.info("Key Mappings:")
104
104
  @mappings.each_value {|key|
105
- @logger.info("#{key[1]} -> #{@commands[key[0].to_sym]}")
105
+ @logger.info(sprintf("%13s -> %s", key[1], @commands[key[0].to_sym]))
106
106
  }
107
- @logger.info("Control-C -> Exit")
107
+ @logger.info(sprintf("%13s -> %s", "Ctrl + c", "Exit"))
108
108
  while running
109
109
  char = read_char
110
110
  @logger.debug("Char: #{char.inspect}")
@@ -7,7 +7,11 @@ module RokuBuilder
7
7
  extend Plugin
8
8
 
9
9
  def self.commands
10
- {profile: {device: true}}
10
+ {
11
+ profile: {device: true},
12
+ sgperf: {device: true},
13
+ devlog: {device: true}
14
+ }
11
15
  end
12
16
 
13
17
  def self.parse_options(parser:, options:)
@@ -15,21 +19,80 @@ module RokuBuilder
15
19
  parser.on("--profile COMMAND", "Run various profiler options") do |c|
16
20
  options[:profile] = c
17
21
  end
22
+ parser.on("--sgperf", "Run scenegraph profiler") do
23
+ options[:sgperf] = true
24
+ end
25
+ parser.on("--devlog FUNCTION [TYPE]", "Run scenegraph profiler") do |f, t|
26
+ options[:devlog] = t || "rendezvous"
27
+ options[:devlog_function] = f
28
+ end
18
29
  end
19
30
 
20
31
  # Run the profiler commands
21
32
  # @param command [Symbol] The profiler command to run
22
33
  def profile(options:)
34
+ @connection = nil
23
35
  case options[:profile].to_sym
24
36
  when :stats
25
37
  print_stats
26
38
  when :all
27
39
  print_all_nodes
40
+ when :roots
41
+ print_root_nodes
28
42
  when :images
29
43
  print_image_information
44
+ when :memmory
45
+ print_memmory_usage
30
46
  when :textures
31
47
  print_texture_information
48
+ else
49
+ print_nodes_by_id(options[:profile])
32
50
  end
51
+ @connection.close if @connection
52
+ end
53
+
54
+ def sgperf(options:)
55
+ telnet_config ={
56
+ 'Host' => @roku_ip_address,
57
+ 'Port' => 8080
58
+ }
59
+ @connection = Net::Telnet.new(telnet_config)
60
+ @connection.puts("sgperf clear\n")
61
+ @connection.puts("sgperf start\n")
62
+ start_reg = /thread/
63
+ end_reg = /#{SecureRandom.uuid}/
64
+ prev_lines = 0
65
+ begin
66
+ while true
67
+ lines = get_command_response(command: "sgperf report", start_reg: start_reg,
68
+ end_reg: end_reg, ignore_warnings: true)
69
+ results = []
70
+ lines.each do |line|
71
+ match = /thread node calls: create\s*(\d*) \+ op\s*(\d*)\s*@\s*(\d*\.\d*)% rendezvous/.match(line)
72
+ results.push([match[1].to_i, match[2].to_i, match[3].to_f])
73
+ end
74
+ print "\r" + ("\e[A\e[K"*prev_lines)
75
+ prev_lines = 0
76
+ results.each_index do |i|
77
+ line = results[i]
78
+ if line[0] > 0 or line[1] > 0 or options[:verbose]
79
+ prev_lines += 1
80
+ puts "Thread #{i}: c:#{line[0]} u:#{line[1]} r:#{line[2]}%"
81
+ end
82
+ end
83
+ end
84
+ rescue SystemExit, Interrupt
85
+ @connection.close if @connection
86
+ end
87
+ end
88
+
89
+ def devlog(options:)
90
+ telnet_config ={
91
+ 'Host' => @roku_ip_address,
92
+ 'Port' => 8080
93
+ }
94
+ connection = Net::Telnet.new(telnet_config)
95
+ connection.puts("enhanced_dev_log #{options[:devlog]} #{options[:devlog_function]}\n")
33
96
  end
34
97
 
35
98
  private
@@ -67,12 +130,39 @@ module RokuBuilder
67
130
  lines = get_command_response(command: "sgnodes all", start_reg: start_reg, end_reg: end_reg)
68
131
  lines.each {|line| print line}
69
132
  end
133
+ def print_root_nodes
134
+ start_reg = /<Root_Nodes>/
135
+ end_reg = /<\/Root_Nodes>/
136
+ lines = get_command_response(command: "sgnodes roots", start_reg: start_reg, end_reg: end_reg)
137
+ lines.each {|line| print line}
138
+ end
139
+ def print_nodes_by_id(id)
140
+ start_reg = /<#{id}>/
141
+ end_reg = /<\/#{id}>/
142
+ lines = get_command_response(command: "sgnodes #{id}", start_reg: start_reg, end_reg: end_reg)
143
+ lines.each {|line| print line}
144
+ end
70
145
  def print_image_information
71
146
  start_reg = /RoGraphics instance/
72
147
  end_reg = /Available memory/
73
148
  lines = get_command_response(command: "r2d2_bitmaps", start_reg: start_reg, end_reg: end_reg)
149
+ lines = sort_image_lines(lines)
74
150
  lines.each {|line| print line}
75
151
  end
152
+ def print_memmory_usage
153
+ start_reg = /RoGraphics instance/
154
+ end_reg = /Available memory/
155
+ begin
156
+ while true
157
+ lines = get_command_response(command: "r2d2_bitmaps", start_reg: start_reg, end_reg: end_reg, ignore_warnings: true)
158
+ memmory_data = get_memmory_data(lines)
159
+ print_memmory_data(memmory_data)
160
+ sleep 1
161
+ end
162
+ rescue SystemExit, Interrupt
163
+ #Exit
164
+ end
165
+ end
76
166
  def print_texture_information
77
167
  start_reg = /\*+/
78
168
  end_reg = /#{SecureRandom.uuid}/
@@ -82,30 +172,31 @@ module RokuBuilder
82
172
 
83
173
  # Retrive list of all nodes
84
174
  # @return [Array<String>] Array of lines
85
- def get_command_response(command:, start_reg:, end_reg:, unique: false)
175
+ def get_command_response(command:, start_reg:, end_reg:, unique: false, ignore_warnings: false)
86
176
  waitfor_config = {
87
177
  'Match' => /.+/,
88
- 'Timeout' => 5
178
+ 'Timeout' => 1
89
179
  }
90
- telnet_config ={
91
- 'Host' => @roku_ip_address,
92
- 'Port' => 8080
93
- }
94
-
95
- connection = Net::Telnet.new(telnet_config)
180
+ unless @connection
181
+ telnet_config ={
182
+ 'Host' => @roku_ip_address,
183
+ 'Port' => 8080
184
+ }
185
+ @connection = Net::Telnet.new(telnet_config)
186
+ end
96
187
 
97
188
  @lines = []
98
189
  @all_txt = ""
99
190
  @begun = false
100
191
  @done = false
101
- connection.puts("#{command}\n")
192
+ @connection.puts("#{command}\n")
102
193
  while not @done
103
194
  begin
104
- connection.waitfor(waitfor_config) do |txt|
195
+ @connection.waitfor(waitfor_config) do |txt|
105
196
  handle_text(txt: txt, start_reg: start_reg, end_reg: end_reg, unique: unique)
106
197
  end
107
198
  rescue Net::ReadTimeout
108
- @logger.warn "Timed out reading profiler information"
199
+ @logger.warn "Timed out reading profiler information" unless ignore_warnings
109
200
  @done = true
110
201
  end
111
202
  end
@@ -122,6 +213,7 @@ module RokuBuilder
122
213
  while line = @all_txt.slice!(/^.*\n/) do
123
214
  if line =~ start_reg
124
215
  @begun = true
216
+ @done = false
125
217
  @lines = [] if unique
126
218
  end
127
219
  @lines.push(line) if @begun
@@ -131,6 +223,53 @@ module RokuBuilder
131
223
  end
132
224
  end
133
225
  end
226
+
227
+ def sort_image_lines(lines)
228
+ new_lines = []
229
+ line = lines.shift
230
+ while line != nil
231
+ reg = /0x[^\s]+\s+\d+\s+\d+\s+\d+\s+\d+/
232
+ line_data = []
233
+ while line =~ reg
234
+ line_data.push({line: line, size: line.split[4].to_i})
235
+ line = lines.shift
236
+ end
237
+ line_data.sort! {|a, b| b[:size] <=> a[:size]}
238
+ line_data.each {|data| new_lines.push(data[:line])}
239
+ new_lines.push(line)
240
+ line = lines.shift
241
+ end
242
+ return new_lines
243
+ end
244
+
245
+ def get_memmory_data(lines)
246
+ data = {}
247
+ line = lines.shift
248
+ while line != nil
249
+ first_match = /RoGraphics instance (0x.*)/.match(line)
250
+ if first_match
251
+ while line != nil
252
+ usage_match = /Available memory (\d*) used (\d*) max (\d*)/.match(line)
253
+ if usage_match
254
+ data[first_match[1]] = [usage_match[1].to_i, usage_match[2].to_i, usage_match[3].to_i]
255
+ break
256
+ end
257
+ line = lines.shift
258
+ end
259
+ end
260
+ line = lines.shift
261
+ end
262
+ return data
263
+ end
264
+
265
+ def print_memmory_data(data)
266
+ @prev_lines ||= 0
267
+ print "\r" + ("\e[A\e[K"*@prev_lines)
268
+ data.each_key do |key|
269
+ print "#{key}: #{(data[key][1]*100)/data[key][2]}%\n"
270
+ end
271
+ @prev_lines = data.count
272
+ end
134
273
  end
135
274
  RokuBuilder.register_plugin(Profiler)
136
275
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module RokuBuilder
4
4
  # Version of the RokuBuilder Gem
5
- VERSION = "4.1.0"
5
+ VERSION = "4.2.0"
6
6
  end
@@ -15,17 +15,16 @@ module RokuBuilder
15
15
  parser = OptionParser.new
16
16
  options = {}
17
17
  Profiler.parse_options(parser: parser, options: options)
18
- argv = ["roku", "--profile", "command"]
18
+ argv = ["roku", "--profile", "command", "--sgperf", "--devlog", "on"]
19
19
  parser.parse! argv
20
20
  assert_equal "command", options[:profile]
21
21
  end
22
22
  def test_profiler_stats
23
- Logger.set_testing
24
23
  options = {profile: "stats"}
25
24
  config, options = build_config_options_objects(ProfilerTest, options, false)
26
25
  waitfor = Proc.new do |telnet_config, &blk|
27
26
  assert_equal(/.+/, telnet_config["Match"])
28
- assert_equal(5, telnet_config["Timeout"])
27
+ assert_equal(1, telnet_config["Timeout"])
29
28
  txt = "<All_Nodes><NodeA /><NodeB /><NodeC><NodeD /></NodeC></All_Nodes>\n"
30
29
  blk.call(txt)
31
30
  true
@@ -35,6 +34,7 @@ module RokuBuilder
35
34
 
36
35
  connection.expect(:puts, nil, ["sgnodes all\n"])
37
36
  connection.expect(:waitfor, nil, &waitfor)
37
+ connection.expect(:close, nil)
38
38
 
39
39
  Net::Telnet.stub(:new, connection) do
40
40
  profiler.stub(:printf, nil) do
@@ -45,12 +45,11 @@ module RokuBuilder
45
45
  connection.verify
46
46
  end
47
47
  def test_profiler_all
48
- Logger.set_testing
49
48
  options = {profile: "all"}
50
49
  config, options = build_config_options_objects(ProfilerTest, options, false)
51
50
  waitfor = Proc.new do |telnet_config, &blk|
52
51
  assert_equal(/.+/, telnet_config["Match"])
53
- assert_equal(5, telnet_config["Timeout"])
52
+ assert_equal(1, telnet_config["Timeout"])
54
53
  txt = "<All_Nodes><NodeA /><NodeB /><NodeC><NodeD /></NodeC></All_Nodes>\n"
55
54
  blk.call(txt)
56
55
  true
@@ -60,6 +59,7 @@ module RokuBuilder
60
59
 
61
60
  connection.expect(:puts, nil, ["sgnodes all\n"])
62
61
  connection.expect(:waitfor, nil, &waitfor)
62
+ connection.expect(:close, nil)
63
63
 
64
64
  Net::Telnet.stub(:new, connection) do
65
65
  profiler.stub(:print, nil) do
@@ -69,14 +69,61 @@ module RokuBuilder
69
69
 
70
70
  connection.verify
71
71
  end
72
+ def test_profiler_roots
73
+ options = {profile: "roots"}
74
+ config, options = build_config_options_objects(ProfilerTest, options, false)
75
+ waitfor = Proc.new do |telnet_config, &blk|
76
+ assert_equal(/.+/, telnet_config["Match"])
77
+ assert_equal(1, telnet_config["Timeout"])
78
+ txt = "<Root_Nodes><NodeA /><NodeB /><NodeC><NodeD /></NodeC></Root_Nodes>\n"
79
+ blk.call(txt)
80
+ true
81
+ end
82
+ connection = Minitest::Mock.new
83
+ profiler = Profiler.new(config: config)
84
+
85
+ connection.expect(:puts, nil, ["sgnodes roots\n"])
86
+ connection.expect(:waitfor, nil, &waitfor)
87
+ connection.expect(:close, nil)
88
+
89
+ Net::Telnet.stub(:new, connection) do
90
+ profiler.stub(:print, nil) do
91
+ profiler.profile(options: options)
92
+ end
93
+ end
94
+ connection.verify
95
+ end
96
+ def test_profiler_node
97
+ options = {profile: "nodeId"}
98
+ config, options = build_config_options_objects(ProfilerTest, options, false)
99
+ waitfor = Proc.new do |telnet_config, &blk|
100
+ assert_equal(/.+/, telnet_config["Match"])
101
+ assert_equal(1, telnet_config["Timeout"])
102
+ txt = "<nodeId><NodeA /><NodeB /><NodeC><NodeD /></NodeC></nodeId>\n"
103
+ blk.call(txt)
104
+ true
105
+ end
106
+ connection = Minitest::Mock.new
107
+ profiler = Profiler.new(config: config)
108
+
109
+ connection.expect(:puts, nil, ["sgnodes nodeId\n"])
110
+ connection.expect(:waitfor, nil, &waitfor)
111
+ connection.expect(:close, nil)
112
+
113
+ Net::Telnet.stub(:new, connection) do
114
+ profiler.stub(:print, nil) do
115
+ profiler.profile(options: options)
116
+ end
117
+ end
118
+ connection.verify
119
+ end
72
120
  def test_profiler_images
73
- Logger.set_testing
74
121
  options = {profile: "images"}
75
122
  config, options = build_config_options_objects(ProfilerTest, options, false)
76
123
  waitfor = Proc.new do |telnet_config, &blk|
77
124
  assert_equal(/.+/, telnet_config["Match"])
78
- assert_equal(5, telnet_config["Timeout"])
79
- txt = " RoGraphics instance\nAvailable memory\n"
125
+ assert_equal(1, telnet_config["Timeout"])
126
+ txt = " RoGraphics instance\n0x234 1 2 3 4\nAvailable memory\n"
80
127
  blk.call(txt)
81
128
  true
82
129
  end
@@ -85,6 +132,7 @@ module RokuBuilder
85
132
 
86
133
  connection.expect(:puts, nil, ["r2d2_bitmaps\n"])
87
134
  connection.expect(:waitfor, nil, &waitfor)
135
+ connection.expect(:close, nil)
88
136
 
89
137
  Net::Telnet.stub(:new, connection) do
90
138
  profiler.stub(:print, nil) do
@@ -94,13 +142,61 @@ module RokuBuilder
94
142
 
95
143
  connection.verify
96
144
  end
145
+
146
+ def test_profiler_memmory
147
+ options = {profile: "memmory"}
148
+ config, options = build_config_options_objects(ProfilerTest, options, false)
149
+ waitfor = Proc.new do |telnet_config, &blk|
150
+ assert_equal(/.+/, telnet_config["Match"])
151
+ assert_equal(1, telnet_config["Timeout"])
152
+ txt = " RoGraphics instance 0x123\nAvailable memory 123 used 456 max 579\n"
153
+ blk.call(txt)
154
+ true
155
+ end
156
+ print_count = 0
157
+ print_stub = Proc.new do |message|
158
+ case print_count
159
+ when 0
160
+ assert_equal "\r", message
161
+ when 1
162
+ assert_equal "0x123: 78%\n", message
163
+ end
164
+ print_count +=1
165
+ true
166
+ end
167
+ first = true
168
+ puts_stub = Proc.new do |message|
169
+ if first
170
+ assert_equal "r2d2_bitmaps\n", message
171
+ first = false
172
+ else
173
+ raise SystemExit
174
+ end
175
+ true
176
+ end
177
+ connection = Minitest::Mock.new
178
+ profiler = Profiler.new(config: config)
179
+
180
+ connection.expect(:puts, nil, &puts_stub)
181
+ connection.expect(:waitfor, nil, &waitfor)
182
+ connection.expect(:puts, nil, &puts_stub)
183
+ connection.expect(:close, nil)
184
+
185
+ Net::Telnet.stub(:new, connection) do
186
+ profiler.stub(:print, print_stub) do
187
+ profiler.profile(options: options)
188
+ end
189
+ end
190
+
191
+ assert print_count > 1
192
+ connection.verify
193
+ end
97
194
  def test_profiler_textures
98
- Logger.set_testing
99
195
  options = {profile: "textures"}
100
196
  config, options = build_config_options_objects(ProfilerTest, options, false)
101
197
  waitfor = Proc.new do |telnet_config, &blk|
102
198
  assert_equal(/.+/, telnet_config["Match"])
103
- assert_equal(5, telnet_config["Timeout"])
199
+ assert_equal(1, telnet_config["Timeout"])
104
200
  txt = "*******\ntexture\n"
105
201
  blk.call(txt)
106
202
  true
@@ -114,6 +210,7 @@ module RokuBuilder
114
210
  connection.expect(:puts, nil, ["loaded_textures\n"])
115
211
  connection.expect(:waitfor, nil, &waitfor)
116
212
  connection.expect(:waitfor, nil, &timeout)
213
+ connection.expect(:close, nil)
117
214
 
118
215
  Net::Telnet.stub(:new, connection) do
119
216
  profiler.stub(:print, nil) do
@@ -123,5 +220,123 @@ module RokuBuilder
123
220
 
124
221
  connection.verify
125
222
  end
223
+ def test_profiler_devlog
224
+ options = {devlog: "rendezvous", devlog_function: "on"}
225
+ config, options = build_config_options_objects(ProfilerTest, options, false)
226
+
227
+ connection = Minitest::Mock.new
228
+ connection.expect(:puts, nil, ["enhanced_dev_log rendezvous on\n"])
229
+
230
+ profiler = Profiler.new(config: config)
231
+ Net::Telnet.stub(:new, connection) do
232
+ profiler.devlog(options: options)
233
+ end
234
+ connection.verify
235
+ end
236
+ def test_profiler_sgperf
237
+ options = {sgperf: true}
238
+ config, options = build_config_options_objects(ProfilerTest, options, false)
239
+ profiler = Profiler.new(config: config)
240
+
241
+ connection = Object.new
242
+ connection.define_singleton_method(:puts){}
243
+ connection.define_singleton_method(:waitfor){}
244
+ connection.define_singleton_method(:close){}
245
+
246
+ message_count = {}
247
+ puts_stub = Proc.new { |message|
248
+ message_count[message] ||= 0
249
+ message_count[message] += 1
250
+ case message
251
+ when "sgperf clear\n"
252
+ assert_equal 1, message_count[message]
253
+ when "sgperf start\n"
254
+ assert_equal 1, message_count[message]
255
+ when "sgperf report\n"
256
+ if message_count[message] > 1
257
+ raise SystemExit
258
+ end
259
+ end
260
+ }
261
+ waitfor = Proc.new {|telnet_config|
262
+ assert_equal(/.+/, telnet_config["Match"])
263
+ assert_equal(1, telnet_config["Timeout"])
264
+ raise Net::ReadTimeout
265
+ }
266
+
267
+ Net::Telnet.stub(:new, connection) do
268
+ connection.stub(:puts, puts_stub) do
269
+ txt = ">>thread node calls: create 0 + op 24 @ 100.0% rendezvous"
270
+ connection.stub(:waitfor, waitfor, txt) do
271
+ profiler.sgperf(options: options)
272
+ end
273
+ end
274
+ end
275
+
276
+ assert(0 < message_count["sgperf clear\n"])
277
+ assert(0 < message_count["sgperf start\n"])
278
+ assert(0 < message_count["sgperf report\n"])
279
+
280
+ end
281
+ def test_profiler_sgperf_multi_lines
282
+ options = {sgperf: true}
283
+ config, options = build_config_options_objects(ProfilerTest, options, false)
284
+ profiler = Profiler.new(config: config)
285
+
286
+ connection = Object.new
287
+ connection.define_singleton_method(:puts){}
288
+ connection.define_singleton_method(:waitfor){}
289
+ connection.define_singleton_method(:close){}
290
+
291
+ message_count = {}
292
+ connection_puts = Proc.new { |message|
293
+ message_count[message] ||= 0
294
+ message_count[message] += 1
295
+ case message
296
+ when "sgperf clear\n"
297
+ assert_equal 1, message_count[message]
298
+ when "sgperf start\n"
299
+ assert_equal 1, message_count[message]
300
+ end
301
+ }
302
+ first = true
303
+ command_response = Proc.new {
304
+ if first
305
+ first = false
306
+ [">>thread node calls: create 0 + op 24 @ 0.0% rendezvous",
307
+ "thread node calls: create 1 + op 0 @ 100.0% rendezvous",
308
+ "thread node calls: create 0 + op 1 @ 100.0% rendezvous"]
309
+ else
310
+ raise SystemExit
311
+ end
312
+ }
313
+ call_count = 0
314
+ profiler_puts = Proc.new { |message|
315
+ case call_count
316
+ when 0
317
+ assert_equal("Thread 0: c:0 u:24 r:0.0%", message)
318
+ when 1
319
+ assert_equal("Thread 1: c:1 u:0 r:100.0%", message)
320
+ when 2
321
+ assert_equal("Thread 2: c:0 u:1 r:100.0%", message)
322
+ end
323
+ call_count += 1
324
+ }
325
+
326
+ Net::Telnet.stub(:new, connection) do
327
+ connection.stub(:puts, connection_puts) do
328
+ profiler.stub(:get_command_response, command_response) do
329
+ profiler.stub(:puts, profiler_puts) do
330
+ profiler.sgperf(options: options)
331
+ end
332
+ end
333
+ end
334
+ end
335
+
336
+ assert(2 < call_count)
337
+ assert(0 < message_count["sgperf clear\n"])
338
+ assert(0 < message_count["sgperf start\n"])
339
+
340
+ end
126
341
  end
127
342
  end
@@ -119,6 +119,38 @@ module RokuBuilder
119
119
  File.delete(target_config) if File.exist?(target_config)
120
120
  end
121
121
 
122
+ def test_config_configure_edit_params_project
123
+ target_config = File.join(test_files_path(ConfigTest), "configure_test.json")
124
+ options = build_options({
125
+ config: target_config,
126
+ configure: true,
127
+ edit_params: "directory:/test/dir"
128
+ })
129
+ File.delete(target_config) if File.exist?(target_config)
130
+ refute File.exist?(target_config)
131
+ config = Config.new(options: options)
132
+ config.configure
133
+ assert File.exist?(target_config)
134
+ assert_equal "/test/dir", config.raw[:projects][config.raw[:projects][:default]][:directory]
135
+ File.delete(target_config) if File.exist?(target_config)
136
+ end
137
+
138
+ def test_config_configure_edit_params_stage
139
+ target_config = File.join(test_files_path(ConfigTest), "configure_test.json")
140
+ options = build_options({
141
+ config: target_config,
142
+ configure: true,
143
+ edit_params: "branch:test"
144
+ })
145
+ File.delete(target_config) if File.exist?(target_config)
146
+ refute File.exist?(target_config)
147
+ config = Config.new(options: options)
148
+ config.configure
149
+ assert File.exist?(target_config)
150
+ assert_equal "test", config.raw[:projects][config.raw[:projects][:default]][:stages][:production][:branch]
151
+ File.delete(target_config) if File.exist?(target_config)
152
+ end
153
+
122
154
  def test_config_configure_edit_params_default
123
155
  target_config = File.join(test_files_path(ConfigTest), "configure_test.json")
124
156
  options = build_options({
@@ -5,7 +5,8 @@ require_relative "test_helper.rb"
5
5
  module RokuBuilder
6
6
  class OptionsTest < Minitest::Test
7
7
  def setup
8
- RokuBuilder.class_variable_set(:@@plugins, [])
8
+ RokuBuilder.setup_plugins
9
+ register_plugins(Core)
9
10
  Logger.set_testing
10
11
  end
11
12
  def teardown
@@ -36,8 +37,10 @@ module RokuBuilder
36
37
  parser.expect(:banner=, nil, [String])
37
38
  parser.expect(:parse!, nil)
38
39
  OptionParser.stub(:new, parser) do
39
- options.stub(:validate_parser, nil) do
40
- options_hash = options.send(:parse)
40
+ options.stub(:add_plugin_options, nil) do
41
+ options.stub(:validate_parser, nil) do
42
+ options_hash = options.send(:parse)
43
+ end
41
44
  end
42
45
  end
43
46
  parser.verify
@@ -50,12 +53,14 @@ module RokuBuilder
50
53
  parser.expect(:banner=, nil, [String])
51
54
  parser.expect(:parse!, nil)
52
55
  OptionParser.stub(:new, parser) do
53
- options.send(:parse)
56
+ options.stub(:add_plugin_options, nil) do
57
+ options.send(:parse)
58
+ end
54
59
  end
55
60
  parser.verify
56
61
  Array.class_eval { remove_method :each_option }
57
62
  end
58
- def test_options_parse_validate_options_bad
63
+ def test_options_parse_validate_options_bad_short
59
64
  Array.class_eval { alias_method :each_option, :each }
60
65
  parser = Minitest::Mock.new()
61
66
  options = Options.allocate
@@ -64,13 +69,32 @@ module RokuBuilder
64
69
 
65
70
  OptionParser.stub(:new, parser) do
66
71
  assert_raises(ImplementationError) do
67
- options.send(:parse)
72
+ options.stub(:add_plugin_options, nil) do
73
+ options.send(:parse)
74
+ end
68
75
  end
69
76
  end
70
77
  parser.verify
71
78
  Array.class_eval { remove_method :each_option }
72
79
  end
73
- def build_stack(good = true)
80
+ def test_options_parse_validate_options_bad_long
81
+ Array.class_eval { alias_method :each_option, :each }
82
+ parser = Minitest::Mock.new()
83
+ options = Options.allocate
84
+ parser.expect(:banner=, nil, [String])
85
+ parser.expect(:instance_variable_get, build_stack(true, false), [:@stack])
86
+
87
+ OptionParser.stub(:new, parser) do
88
+ options.stub(:add_plugin_options, nil) do
89
+ assert_raises(ImplementationError) do
90
+ options.send(:parse)
91
+ end
92
+ end
93
+ end
94
+ parser.verify
95
+ Array.class_eval { remove_method :each_option }
96
+ end
97
+ def build_stack(shortgood = true, longgood = true)
74
98
  optionsA = Minitest::Mock.new()
75
99
  optionsB = Minitest::Mock.new()
76
100
  list = [optionsA, optionsB]
@@ -78,11 +102,14 @@ module RokuBuilder
78
102
  3.times do
79
103
  optionsA.expect(:short, [ "a" ])
80
104
  optionsA.expect(:long, [ "aOption" ])
81
- if good
105
+ if shortgood
82
106
  optionsB.expect(:short, [ "b" ])
83
- optionsB.expect(:long, ["bOption" ])
84
107
  else
85
108
  optionsB.expect(:short, [ "a" ])
109
+ end
110
+ if longgood
111
+ optionsB.expect(:long, ["bOption" ])
112
+ else
86
113
  optionsB.expect(:long, [ "aOption" ])
87
114
  end
88
115
  end
@@ -103,6 +130,15 @@ module RokuBuilder
103
130
  build_options(options)
104
131
  end
105
132
  end
133
+ def test_options_validate_source
134
+ options = Options.allocate
135
+ options.stub(:source_command?, true) do
136
+ assert_raises InvalidOptions do
137
+ options.send(:initialize, {options: {validate: true}})
138
+ options.validate
139
+ end
140
+ end
141
+ end
106
142
  def test_options_validate_extra_sources_sideload
107
143
  options = {
108
144
  validate: true,
@@ -123,6 +159,17 @@ module RokuBuilder
123
159
  build_options(options)
124
160
  end
125
161
  end
162
+ def test_options_validate_depricated
163
+ options = Options.allocate
164
+ logger = Minitest::Mock.new()
165
+ logger.expect(:warn, nil, ["Depricated"])
166
+ Logger.class_variable_set(:@@instance, logger)
167
+ options.stub(:depricated_options, {validate: "Depricated"}) do
168
+ options.send(:initialize, {options: {validate: true}})
169
+ options.validate
170
+ end
171
+ logger.verify
172
+ end
126
173
  def test_options_exclude_command
127
174
  options = build_options({
128
175
  validate:true,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roku_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - greeneca
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-28 00:00:00.000000000 Z
11
+ date: 2017-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip