1 2# 3# sort.exp 4# 5# This one is tricky because we have to read in a memdump.bin file 6# and verify the correctness of its contents. 7# 8 9proc verify_sorted_list_in_memdump {filename count sizeof_int} { 10 # 11 # Read in the list 12 # 13 if [catch {open $filename "r"} chan] { 14 warning "opening $filename: $chan" 15 return -1 16 } 17 fconfigure $chan -translation binary 18 set inp [read $chan [expr $count * $sizeof_int]] 19 close $chan 20 # 21 # Translate it from binary integers to an ASCII list 22 # 23 if {[vmips_target_endian] == "big"} { 24 set format "I" 25 } else { 26 set format "i" 27 } 28 binary scan "$inp" "$format$count" list 29 set list_length [llength $list] 30 verbose "Read in list ($list_length entries)" 31 # 32 # Sort the list 33 # 34 set sortedlist [lsort -integer $list] 35 set sortedlist_length [llength $sortedlist] 36 verbose "Sorted list (now $sortedlist_length entries)" 37 # 38 # See if the two are the same 39 # 40 if {$list_length != $sortedlist_length} { 41 verbose "Test fails: lists of different length after sort" 42 return -1 43 } else { 44 if {$list == $sortedlist} { 45 verbose "The list is in order" 46 return 0 47 } else { 48 verbose "The list is not in order" 49 for {set i 0} {$i < $list_length} {incr i} { 50 set list_entry [lindex $list $i] 51 set sortedlist_entry [lindex $sortedlist $i] 52 if {$list_entry != $sortedlist_entry} { 53 verbose "Diff at index $i: $list_entry != $sortedlist_entry" 54 } 55 } 56 return -1 57 } 58 } 59} 60 61# 62# Set some basic parameters. 63# 64load_lib vmips-misc.exp; misc_test_setup sort 65set memdump "memdump.bin" 66# 67# Number of integers to look for and the size of each one: 68# 69set count 128 70set sizeofint 4 71 72# 73# Run vmips on the sort ROM. 74# 75vmips_start "-o nobootmsg -o memdump -o noinstdump $romfile" 76 77# 78# Make sure we get the output we wanted. 79# 80if {$comp_output != "* BREAK instruction reached -- HALTING *\nDumping RAM to memdump.bin...succeeded.\n"} { 81 verbose "The output looked strange when we ran it:\n" 82 verbose "<$comp_output>\n" 83 fail $testcase 84} else { 85 if ![file exists $memdump] { 86 verbose "Memdump file $memdump didn't exist after run." 87 fail $testcase 88 } else { 89 # 90 # Verify the output. 91 # 92 set result [verify_sorted_list_in_memdump $memdump $count $sizeofint] 93 if {$result != 0} { 94 fail $testcase 95 } else { 96 pass $testcase 97 } 98 } 99} 100 101# 102# Clean up (remove the memdump file.) 103# 104file delete $memdump 105