Skip to content

Instantly share code, notes, and snippets.

@KevinKu
Created February 12, 2016 06:50
Show Gist options
  • Select an option

  • Save KevinKu/742dea6cef8f2b000ee9 to your computer and use it in GitHub Desktop.

Select an option

Save KevinKu/742dea6cef8f2b000ee9 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo b main >> _tmp.gdb
echo r >> _tmp.gdb
echo source create__list.gdb>> _tmp.gdb
echo source printf_list.gdb>> _tmp.gdb
echo 'set $head = (List*)0'>>_tmp.gdb
/*
_tmp.gdb為臨時產生的gdb script
因為給的測試資料可能有多組 所以測試script必須能動態的更新
這五行echo 用來準備測試前的環境佈置
*/
exec < $1
read var
echo 'create_list $head' $var>> _tmp.gdb
/*
用來讀取測資的第一行
第一行給出用作測試list的大小
例如 4
那就會create 有4個node的 list 從頭到尾為 0 1 2 3
*/
exec < $1
echo 'p "test begin------------------------------------------------------------------------------------------"'>>_tmp.gdb
while (read var)
do
echo 'p "old_list-------------------------------------------------------------------------------------------"'>>_tmp.gdb
echo 'printf_list $head'>> _tmp.gdb
read var
node_1=$var
read var
node_2=$var
echo 'p $head = swap($head,'$node_1','$node_2')'>> _tmp.gdb
echo 'p "new_list-----------------------------------------------------------------------------------------"'>>_tmp.gdb
echo 'printf_list $head'>> _tmp.gdb
done
/*
以上while依序讀出測試資料要測試的node並去執行
*/
gdb -x _tmp.gdb swap >>$2
rm _tmp.gdb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment