1a03700fdSPhilippe Mathieu-Daudé#!/usr/bin/env bash 2d1f3a23bSKevin Wolf 3d1f3a23bSKevin Wolf# Copyright (c) 2013 Kevin Wolf <kwolf@redhat.com> 4d1f3a23bSKevin Wolf# 5d1f3a23bSKevin Wolf# Permission is hereby granted, free of charge, to any person obtaining a copy 6d1f3a23bSKevin Wolf# of this software and associated documentation files (the "Software"), to deal 7d1f3a23bSKevin Wolf# in the Software without restriction, including without limitation the rights 8d1f3a23bSKevin Wolf# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9d1f3a23bSKevin Wolf# copies of the Software, and to permit persons to whom the Software is 10d1f3a23bSKevin Wolf# furnished to do so, subject to the following conditions: 11d1f3a23bSKevin Wolf# 12d1f3a23bSKevin Wolf# The above copyright notice and this permission notice shall be included in 13d1f3a23bSKevin Wolf# all copies or substantial portions of the Software. 14d1f3a23bSKevin Wolf# 15d1f3a23bSKevin Wolf# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16d1f3a23bSKevin Wolf# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17d1f3a23bSKevin Wolf# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18d1f3a23bSKevin Wolf# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19d1f3a23bSKevin Wolf# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20d1f3a23bSKevin Wolf# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21d1f3a23bSKevin Wolf# THE SOFTWARE. 22d1f3a23bSKevin Wolf 23*64ed6f92SPaolo BonziniQEMU=${QEMU:-"../../qemu-system-x86_64"} 24d1f3a23bSKevin Wolf 25d1f3a23bSKevin Wolfrun_qemu() { 26d1f3a23bSKevin Wolf local kernel=$1 27d1f3a23bSKevin Wolf shift 28d1f3a23bSKevin Wolf 2901a02ec4SEric Blake printf %b "\n\n=== Running test case: $kernel $* ===\n\n" >> test.log 30d1f3a23bSKevin Wolf 31d1f3a23bSKevin Wolf $QEMU \ 32d1f3a23bSKevin Wolf -kernel $kernel \ 33d1f3a23bSKevin Wolf -display none \ 34d1f3a23bSKevin Wolf -device isa-debugcon,chardev=stdio \ 35d1f3a23bSKevin Wolf -chardev file,path=test.out,id=stdio \ 36d1f3a23bSKevin Wolf -device isa-debug-exit,iobase=0xf4,iosize=0x4 \ 371c8c426fSKevin Wolf "$@" >> test.log 2>&1 38d1f3a23bSKevin Wolf ret=$? 39d1f3a23bSKevin Wolf 40d1f3a23bSKevin Wolf cat test.out >> test.log 4149713c41SKevin Wolf 4249713c41SKevin Wolf debugexit=$((ret & 0x1)) 4349713c41SKevin Wolf ret=$((ret >> 1)) 4449713c41SKevin Wolf 4549713c41SKevin Wolf if [ $debugexit != 1 ]; then 4649713c41SKevin Wolf printf %b "\e[31m ?? \e[0m $kernel $* (no debugexit used, exit code $ret)\n" 4749713c41SKevin Wolf pass=0 4849713c41SKevin Wolf elif [ $ret != 0 ]; then 4949713c41SKevin Wolf printf %b "\e[31mFAIL\e[0m $kernel $* (exit code $ret)\n" 5049713c41SKevin Wolf pass=0 5149713c41SKevin Wolf fi 52d1f3a23bSKevin Wolf} 53d1f3a23bSKevin Wolf 54d1f3a23bSKevin Wolfmmap() { 55d1f3a23bSKevin Wolf run_qemu mmap.elf 56d1f3a23bSKevin Wolf run_qemu mmap.elf -m 1.1M 57d1f3a23bSKevin Wolf run_qemu mmap.elf -m 2G 58d1f3a23bSKevin Wolf run_qemu mmap.elf -m 4G 59d1f3a23bSKevin Wolf run_qemu mmap.elf -m 8G 60d1f3a23bSKevin Wolf} 61d1f3a23bSKevin Wolf 62a9c837d8SKevin Wolfmodules() { 63a9c837d8SKevin Wolf run_qemu modules.elf 64a9c837d8SKevin Wolf run_qemu modules.elf -initrd module.txt 65a9c837d8SKevin Wolf run_qemu modules.elf -initrd "module.txt argument" 66a9c837d8SKevin Wolf run_qemu modules.elf -initrd "module.txt argument,,with,,commas" 67a9c837d8SKevin Wolf run_qemu modules.elf -initrd "module.txt,module.txt argument,module.txt" 68a9c837d8SKevin Wolf} 69d1f3a23bSKevin Wolf 701c8c426fSKevin Wolfaout_kludge() { 711c8c426fSKevin Wolf for i in $(seq 1 9); do 721c8c426fSKevin Wolf run_qemu aout_kludge_$i.bin 731c8c426fSKevin Wolf done 741c8c426fSKevin Wolf} 751c8c426fSKevin Wolf 76d1f3a23bSKevin Wolfmake all 77d1f3a23bSKevin Wolf 781c8c426fSKevin Wolffor t in mmap modules aout_kludge; do 79d1f3a23bSKevin Wolf 80d1f3a23bSKevin Wolf echo > test.log 81d1f3a23bSKevin Wolf pass=1 8249713c41SKevin Wolf $t 83d1f3a23bSKevin Wolf 84d1f3a23bSKevin Wolf if ! diff $t.out test.log > /dev/null 2>&1; then 85b43671f8SEric Blake printf %b "\e[31mFAIL\e[0m $t (output difference)\n" 86d1f3a23bSKevin Wolf diff -u $t.out test.log 87d1f3a23bSKevin Wolf pass=0 88d1f3a23bSKevin Wolf fi 89d1f3a23bSKevin Wolf 90d1f3a23bSKevin Wolf if [ $pass == 1 ]; then 91b43671f8SEric Blake printf %b "\e[32mPASS\e[0m $t\n" 92d1f3a23bSKevin Wolf fi 93d1f3a23bSKevin Wolf 94d1f3a23bSKevin Wolfdone 95