OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [testsuite/] [gdb.gdbtk/] [cpp_variable.test] - Blame information for rev 1767

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#   Copyright (C) 1998 Cygnus Solutions
2
#
3
# This Program Is Free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
 
17
# Please email any bugs, comments, and/or additions to this file to:
18
# bug-gdb@prep.ai.mit.edu
19
 
20
# This file was written by Keith Seitz (keiths@cygnus.com)
21
 
22
# Read in the standard defs file
23
if {![gdbtk_read_defs]} {
24
  break
25
}
26
 
27
global objdir test_ran
28
 
29
# Load in a file
30
set program [file join $objdir cpp_variable]
31
if {[catch {gdbtk_test_file $program} t]} {
32
  # This isn't a test case, since if this fails, we're hosed.
33
  gdbtk_test_error "loading \"$program\": $t"
34
}
35
 
36
# The variables that are created are stored in an array called "var".
37
 
38
# proc to tell us which of the variables are changed/out of scope
39
proc check_update {} {
40
  global var
41
 
42
  set changed {}
43
  set unchanged {}
44
  set out {}
45
  #FIXME: Should get a list of root variables instead of using the array
46
  foreach ind [array names var] {
47
    set changed [concat $changed [$var($ind) update]]
48
  }
49
 
50
  foreach ind [array names var] {
51
    set ix [lsearch -exact $changed $var($ind)]
52
    if {$ix < 0} {
53
      lappend unchanged $var($ind)
54
    }
55
  }
56
 
57
  return [list $changed $unchanged $out]
58
}
59
 
60
# proc to create a variable
61
proc create_variable {expr} {
62
  global var
63
 
64
  set err [catch {gdb_variable create "$expr" -expr $expr} v]
65
  if {!$err} {
66
    set var($expr) $v
67
  }
68
 
69
  return $err
70
}
71
 
72
# proc to get the children
73
# Children are stored in the global "var" as
74
# PARENT.child. So for struct _foo {int a; int b} bar;,
75
# the children returned are {a b} and var(bar.a) and var(bar.b)
76
# map the actual objects to their names.
77
proc get_children {parent} {
78
  global var
79
 
80
  set kiddies [$var($parent) children]
81
  set children {}
82
  foreach child $kiddies {
83
    set name [lindex [split $child .] end]
84
    lappend children $name
85
    set var($parent.$name) $child
86
  }
87
 
88
  return $children
89
}
90
 
91
proc delete_variable {varname} {
92
  global var
93
 
94
  if {[info exists var($varname)]} {
95
    # This has to be caught, since deleting a parent
96
    # will erase all children.
97
    $var($varname) delete
98
    set vars [array names var $varname*]
99
    foreach v $vars {
100
      if {[info exists var($v)]} {
101
        unset var($v)
102
      }
103
    }
104
  }
105
}
106
 
107
# Compare the values of variable V in format FMT with value of OBJ
108
# with gdb's value.
109
proc cppvalue {obj v fmt} {
110
  global var
111
  global _test
112
 
113
  puts $_test(logfile) "obj=$obj v=$v fmt=$fmt"
114
  puts $_test(logfile) "var(\$obj)=$var($obj)"
115
 
116
  set value [$var($obj) value]
117
  set gdb [gdb_cmd "output/$fmt $v"]
118
  puts $_test(logfile) "output/$fmt $v"
119
  if {$value == $gdb} {
120
    puts $_test(logfile) "gdbtk: $value == gdb: $gdb"
121
    set result ok
122
  } else {
123
    set result $v
124
    puts $_test(logfile) "gdbtk: $value <> gdb: $gdb"
125
  }
126
 
127
  return $result
128
}
129
 
130
proc delete_all_variables {} {
131
  global var
132
 
133
  foreach variable [array names var] {
134
    delete_variable $variable
135
  }
136
}
137
 
138
#####            #####
139
#                    #
140
# Simple Class Tests #
141
#                    #
142
#####            #####
143
 
144
# run to "do_simple_class_tests"
145
gdb_cmd "break do_simple_class_tests"
146
gdb_cmd "run"
147
 
148
# Test:  cpp_variable-1.1
149
# Desc:  stopped in do_simple_class_tests
150
gdbtk_test cpp_variable-1.1 {stopped in do_simple_class_tests} {
151
  lindex [gdb_loc] 1
152
} {do_simple_class_tests(void)}
153
 
154
# Test: cpp_variable-1.2
155
# Desc: create variable v
156
gdbtk_test cpp_variable-1.2 {create variable v} {
157
  create_variable v
158
} {0}
159
 
160
# Test: cpp_variable-1.3
161
# Desc: number of children of v
162
gdbtk_test cpp_variable-1.3 {number of children of v} {
163
  $var(v) numChildren
164
} {5}
165
 
166
# Test: cpp_variable-1.4a
167
# Desc: children of v
168
gdbtk_test cpp_variable-1.4a {children of v} {
169
  get_children v
170
} {VA VB VC public private}
171
 
172
# Test: cpp_variable-1.4b
173
# Desc: public children of v
174
gdbtk_test cpp_variable-1.4b {public children of v} {
175
  get_children v.public
176
} {v_pub_int v_pub_charp}
177
 
178
# Test: cpp_variable-1.4c
179
# Desc: private children of v
180
gdbtk_test cpp_variable-1.4c {private children of v} {
181
  get_children v.private
182
} {v_priv_int v_priv_charp}
183
 
184
# Test: cpp_variable-1.5
185
# Desc: type of v
186
gdbtk_test cpp_variable-1.5 {type of v} {
187
  $var(v) type
188
} {V *}
189
 
190
# Test: cpp_variable-1.6
191
# Desc: format of v
192
gdbtk_test cpp_variable-1.6 {format of v} {
193
  $var(v) format
194
} {natural}
195
 
196
set value [$var(v) value]
197
 
198
# Step over "V *v = new V;"
199
gdb_cmd "next"
200
 
201
# Test: cpp_variable-1.7
202
# Desc: check value of v changed
203
gdbtk_test cpp_variable-1.7 {check value of v changed} {
204
  check_update
205
} {{v v.public.v_pub_int v.public.v_pub_charp v.private.v_priv_int v.private.v_priv_charp} {v.VB v.VC v.private v.public v.VA} {}}
206
 
207
# Test: cpp_variable-1.8
208
# Desc: check values of v
209
gdbtk_test cpp_variable-1.8 {check values of v} {
210
  set new [$var(v) value]
211
  expr {$new != $value}
212
} {1}
213
 
214
# Test: cpp_variable-1.9
215
# Desc: v editable
216
gdbtk_test cpp_variable-1.9 {v editable} {
217
  $var(v) editable
218
} {1}
219
 
220
#####             #####
221
#                     #
222
# Children of v tests #
223
#                     #
224
#####             #####
225
 
226
# Test: cpp_variable-2.1
227
# Desc: type of v.v_pub_int
228
gdbtk_test cpp_variable-2.1 {type of v.v_pub_int} {
229
  $var(v.public.v_pub_int) type
230
} {int}
231
 
232
# Test: cpp_variable-2.2
233
# Desc: format of v.v_pub_int
234
gdbtk_test cpp_variable-2.2 {format of v.v_pub_int} {
235
  $var(v.public.v_pub_int) format
236
} {natural}
237
 
238
gdb_cmd "set variable v.v_pub_int=2112"
239
 
240
# Test: cpp_variable-2.3
241
# Desc: value of v.v_pub_int changed
242
gdbtk_test cpp_variable-2.3 {value of v.v_pub_int changed} {
243
  check_update
244
} {v.public.v_pub_int {v.private.v_priv_charp v.VB v.private.v_priv_int v.VC v.public.v_pub_charp v v.private v.public v.VA} {}}
245
 
246
# Test: cpp_variable-2.4
247
# Desc: value of v.v_pub_int
248
gdbtk_test cpp_variable-2.4 {value of v.v_pub_int} {
249
  $var(v.public.v_pub_int) value
250
} {2112}
251
 
252
# Test: cpp_variable-2.5
253
# Desc: changed format of v.v_pub_int
254
gdbtk_test cpp_variable-2.5 {changed format of v.v_pub_int} {
255
  $var(v.public.v_pub_int) format octal
256
  $var(v.public.v_pub_int) format
257
} {octal}
258
 
259
# Test: cpp_variable-2.6
260
# Desc: value of v.v_pub_int with new format
261
gdbtk_test cpp_variable-2.6 {value of v.v_pub_int with new format} {
262
  $var(v.public.v_pub_int) value
263
} {04100}
264
 
265
# Test: cpp_variable-2.7
266
# Desc: change value of v.v_pub_int (decimal)
267
gdbtk_test cpp_variable-2.7 {change value of v.v_pub_int (decimal)} {
268
  $var(v.public.v_pub_int) value 3
269
  cppvalue v.public.v_pub_int v.v_pub_int o
270
} {ok}
271
 
272
# Test: cpp_variable-2.8
273
# Desc: change value of v.v_pub_int (hexadecimal)
274
gdbtk_test cpp_variable-2.8 {change value of v.v_pub_int (hexadecimal)} {
275
  $var(v.public.v_pub_int) value 0x21
276
  cppvalue v.public.v_pub_int v.v_pub_int o
277
} {ok}
278
 
279
# Test: cpp_variable-2.9
280
# Desc: number of children of v_pub_int
281
gdbtk_test cpp_variable-2.9 {number of children of v_pub_int} {
282
  $var(v.public.v_pub_int) numChildren
283
} {0}
284
 
285
# Test: cpp_variable-2.10
286
# Desc: children of v.v_pub_int
287
gdbtk_test cpp_variable-2.10 {children of v.v_pub_int} {
288
  get_children v.public.v_pub_int
289
} {}
290
 
291
# Test: cpp_variable-2.11
292
# Desc: v.v_pub_int editable
293
gdbtk_test cpp_variable-2.11 {v.v_pub_int editable} {
294
  $var(v.public.v_pub_int) editable
295
} {1}
296
 
297
# Test: cpp_variable-2.21
298
# Desc: type of v.v_priv_charp
299
gdbtk_test cpp_variable-2.21 {type of v.v_priv_charp} {
300
  $var(v.private.v_priv_charp) type
301
} {char *}
302
 
303
# Test: cpp_variable-2.22
304
# Desc: format of v.v_priv_charp
305
gdbtk_test cpp_variable-2.22 {format of v.v_priv_charp} {
306
  $var(v.private.v_priv_charp) format
307
} {natural}
308
 
309
gdb_cmd "set variable v.v_priv_charp=2112"
310
 
311
# Test: cpp_variable-2.23
312
# Desc: value of v.v_priv_charp changed
313
gdbtk_test cpp_variable-2.23 {value of v.v_priv_charp changed} {
314
  check_update
315
} {v.private.v_priv_charp {v.VB v.private.v_priv_int v.VC v.public.v_pub_charp v v.public.v_pub_int v.private v.public v.VA} {}}
316
 
317
# Test: cpp_variable-2.24
318
# Desc: value of v.v_priv_charp
319
gdbtk_test cpp_variable-2.24 {value of v.v_priv_charp} {
320
  $var(v.private.v_priv_charp) format hexadecimal
321
  $var(v.private.v_priv_charp) value
322
} {0x840}
323
 
324
# Test: cpp_variable-2.25
325
# Desc: changed format of v.v_priv_charp
326
gdbtk_test cpp_variable-2.25 {changed format of v.v_priv_charp} {
327
  $var(v.private.v_priv_charp) format octal
328
  $var(v.private.v_priv_charp) format
329
} {octal}
330
 
331
# Test: cpp_variable-2.26
332
# Desc: value of v.v_priv_charp with new format
333
gdbtk_test cpp_variable-2.26 {value of v.v_priv_charp with new format} {
334
  $var(v.private.v_priv_charp) value
335
} {04100}
336
 
337
# Test: cpp_variable-2.27
338
# Desc: change value of v.v_priv_charp (decimal)
339
gdbtk_test cpp_variable-2.27 {change value of v.v_priv_charp (decimal)} {
340
  $var(v.private.v_priv_charp) value 3
341
  cppvalue v.private.v_priv_charp v.v_priv_charp o
342
} {ok}
343
 
344
# Test: cpp_variable-2.28
345
# Desc: change value of v.v_priv_charp (hexadecimal)
346
gdbtk_test cpp_variable-2.28 {change value of v.v_priv_charp (hexadecimal)} {
347
  $var(v.private.v_priv_charp) value 0x21
348
  cppvalue v.private.v_priv_charp v.v_priv_charp o
349
} {ok}
350
 
351
# Test: cpp_variable-2.29
352
# Desc: number of children of v_priv_charp
353
gdbtk_test cpp_variable-2.29 {number of children of v_priv_charp} {
354
  $var(v.private.v_priv_charp) numChildren
355
} {0}
356
 
357
# Test: cpp_variable-2.30
358
# Desc: children of v.v_priv_charp
359
gdbtk_test cpp_variable-2.30 {children of v.v_priv_charp} {
360
  get_children v.private.v_priv_charp
361
} {}
362
 
363
# Test: cpp_variable-2.31
364
# Desc: v.v_priv_int editable
365
gdbtk_test cpp_variable-2.31 {v.v_priv_int editable} {
366
  $var(v.private.v_priv_int) editable
367
} {1}
368
 
369
# Test: cpp_variable-2.41
370
# Desc: type of v.VA
371
gdbtk_test cpp_variable-2.41 {type of v.VA} {
372
  $var(v.VA) type
373
} {VA}
374
 
375
# Test: cpp_variable-2.42
376
# Desc: format of v.VA
377
gdbtk_test cpp_variable-2.42 {format of v.VA} {
378
  $var(v.VA) format
379
} {natural}
380
 
381
# Test: cpp_variable-2.43
382
# Desc: value of v.VA changed
383
gdbtk_test cpp_variable-2.43 {value of v.VA changed} {
384
  check_update
385
} {{} {v.private.v_priv_charp v.VB v.private.v_priv_int v.VC v.public.v_pub_charp v v.public.v_pub_int v.private v.public v.VA} {}}
386
 
387
# Test: cpp_variable-2.44
388
# Desc: value of v.VA
389
gdbtk_test cpp_variable-2.44 {value of v.VA} {
390
  $var(v.VA) value
391
} {{...}}
392
 
393
# Test: cpp_variable-2.45
394
# Desc: changed format of v.VA
395
gdbtk_test cpp_variable-2.45 {changed format of v.VA} {
396
  $var(v.VA) format octal
397
  $var(v.VA) format
398
} {octal}
399
 
400
# Test: cpp_variable-2.46
401
# Desc: value of v.VA with new format
402
gdbtk_test cpp_variable-2.46 {value of v.VA with new format} {
403
  $var(v.VA) value
404
} {{...}}
405
 
406
# Test: cpp_variable-2.47
407
# Desc: number of children of VA
408
gdbtk_test cpp_variable-2.47 {number of children of VA} {
409
  $var(v.VA) numChildren
410
} {3}
411
 
412
# Test: cpp_variable-2.48a
413
# Desc: children of v.VA
414
gdbtk_test cpp_variable-2.48a {children of v.VA} {
415
  get_children v.VA
416
} {public private protected}
417
 
418
# Test: cpp_variable-2.48b
419
# Desc: public children of v.VA
420
gdbtk_test cpp_variable-2.48b {children of v.VA} {
421
  get_children v.VA.public
422
} {va_pub_int va_pub_charp}
423
 
424
# Test: cpp_variable-2.48c
425
# Desc: private children of v.VA
426
gdbtk_test cpp_variable-2.48c {children of v.VA} {
427
  get_children v.VA.private
428
} {va_priv_int va_priv_charp}
429
 
430
# Test: cpp_variable-2.48d
431
# Desc: protected children of v.VA
432
gdbtk_test cpp_variable-2.48d {children of v.VA} {
433
  get_children v.VA.protected
434
} {bar}
435
 
436
# Test: cpp_variable-2.49
437
# Desc: v.VA editable
438
gdbtk_test cpp_variable-2.49 {v.VA editable} {
439
  $var(v.VA) editable
440
} {0}
441
 
442
# Test: cpp_variable-2.61
443
# Desc: type of v.VB
444
gdbtk_test cpp_variable-2.61 {type of v.VB} {
445
  $var(v.VB) type
446
} {VB}
447
 
448
# Test: cpp_variable-2.62
449
# Desc: format of v.VB
450
gdbtk_test cpp_variable-2.62 {format of v.VB} {
451
  $var(v.VB) format
452
} {natural}
453
 
454
# Test: cpp_variable-2.63
455
# Desc: value of v.VB changed
456
gdbtk_test cpp_variable-2.63 {value of v.VB changed} {
457
  check_update
458
} {{} {v.VA.protected v.VA.private v.VA.public.va_pub_int v.private.v_priv_int v v.public.v_pub_int v.VA.public.va_pub_charp v.private.v_priv_charp v.VA.public v.public.v_pub_charp v.VA.private.va_priv_int v.VA v.public v.VB v.VC v.VA.protected.bar v.VA.private.va_priv_charp v.private} {}}
459
 
460
# Test: cpp_variable-2.64
461
 # Desc: value of v.VB
462
gdbtk_test cpp_variable-2.64 {value of v.VB} {
463
  $var(v.VB) value
464
} {{...}}
465
 
466
# Test: cpp_variable-2.65
467
# Desc: changed format of v.VB
468
gdbtk_test cpp_variable-2.65 {changed format of v.VB} {
469
  $var(v.VB) format octal
470
  $var(v.VB) format
471
} {octal}
472
 
473
# Test: cpp_variable-2.66
474
# Desc: value of v.VB with new format
475
gdbtk_test cpp_variable-2.66 {value of v.VB with new format} {
476
  $var(v.VB) value
477
} {{...}}
478
 
479
# Note: The next two tests show whether or not the logic
480
# concerning vptr tables is working.
481
# Test: cpp_variable-2.67
482
# Desc: number of children of VB
483
gdbtk_test cpp_variable-2.67 {number of children of VB} {
484
  $var(v.VB) numChildren
485
} {2}
486
 
487
# Test: cpp_variable-2.68a
488
# Desc: children of v.VB
489
gdbtk_test cpp_variable-2.68a {children of v.VB} {
490
  get_children v.VB
491
} {public private}
492
 
493
# Test: cpp_variable-2.68b
494
# Desc: public children of v.VB
495
gdbtk_test cpp_variable-2.68b {children of v.VB} {
496
  get_children v.VB.public
497
} {vb_pub_int}
498
 
499
# Test: cpp_variable-2.68c
500
# Desc: private children of v.VB
501
gdbtk_test cpp_variable-2.68c {children of v.VB} {
502
  get_children v.VB.private
503
} {vb_priv_int vb_priv_charp}
504
 
505
# Test: cpp_variable-2.69
506
# Desc: v.VB editable
507
gdbtk_test cpp_variable-2.69 {v.VB editable} {
508
  $var(v.VB) editable
509
} {0}
510
 
511
# Test: cpp_variable-2.70
512
# Desc: v.VB.public editable
513
gdbtk_test cpp_variable-2.70 {v.VB.public editable} {
514
  $var(v.VB.public) editable
515
} {0}
516
 
517
# Test: cpp_variable-2.71
518
# Desc: v.VB.vb_pub_int editable
519
gdbtk_test cpp_variable-2.71 {v.VB.vb_pub_int editable} {
520
  $var(v.VB.public.vb_pub_int) editable
521
} {1}
522
 
523
gdb_cmd "set variable v.vb_pub_int=2112"
524
 
525
# Test: cpp_variable-2.72
526
# Desc: value of v.vb_pub_int changed
527
gdbtk_test cpp_variable-2.72 {value of v.vb_pub_int changed} {
528
  check_update
529
} {v.VB.public.vb_pub_int {v.VB.public v.VA.protected v.VA.private v.VB.private.vb_priv_int v.VB.private v.VA.public.va_pub_int v.private.v_priv_int v v.public.v_pub_int v.VB.private.vb_priv_charp v.VA.public.va_pub_charp v.private.v_priv_charp v.VA.public v.public.v_pub_charp v.VA.private.va_priv_int v.VA v.public v.VB v.VC v.VA.protected.bar v.VA.private.va_priv_charp v.private} {}}
530
 
531
# Test: cpp_variable-2.73
532
# Desc: value of v.VB.vb_pub_int
533
gdbtk_test cpp_variable-2.73 {changed value of v.vb_pub_int} {
534
  $var(v.VB.public.vb_pub_int) value
535
} {2112}
536
 
537
# Test: cpp_variable-2.74
538
# Desc: change value of v.VB.vb_pub_int
539
gdbtk_test cpp_variable-2.74 {change value of v.VB.public.vb_pub_int} {
540
  $var(v.VB.public.vb_pub_int) value 3
541
  cppvalue v.VB.public.vb_pub_int v.vb_pub_int d
542
} {ok}
543
 
544
# Test: cpp_variable-2.75
545
# Desc: value of v.VB.vb_pub_int
546
gdbtk_test cpp_variable-2.75 {changed value of v.VB.public.vb_pub_int} {
547
  $var(v.VB.public.vb_pub_int) value
548
} {3}
549
 
550
 
551
#  Exit
552
#
553
gdbtk_test_done
554
 
555
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.