unaligned.t revision 139595
1139595Smarcel#!/usr/bin/env perl -w 2139595Smarcel# 3139595Smarcel# Copyright (c) 2005 Marcel Moolenaar 4139595Smarcel# All rights reserved. 5139595Smarcel# 6139595Smarcel# Redistribution and use in source and binary forms, with or without 7139595Smarcel# modification, are permitted provided that the following conditions 8139595Smarcel# are met: 9139595Smarcel# 10139595Smarcel# 1. Redistributions of source code must retain the above copyright 11139595Smarcel# notice, this list of conditions and the following disclaimer. 12139595Smarcel# 2. Redistributions in binary form must reproduce the above copyright 13139595Smarcel# notice, this list of conditions and the following disclaimer in the 14139595Smarcel# documentation and/or other materials provided with the distribution. 15139595Smarcel# 16139595Smarcel# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17139595Smarcel# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18139595Smarcel# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19139595Smarcel# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20139595Smarcel# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21139595Smarcel# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22139595Smarcel# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23139595Smarcel# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24139595Smarcel# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25139595Smarcel# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26139595Smarcel# 27139595Smarcel# $FreeBSD: head/tools/regression/ia64/unaligned/unaligned.t 139595 2005-01-02 21:33:40Z marcel $ 28139595Smarcel 29139595Smarcelmy $srcdir = `dirname $0`; 30139595Smarcelchomp $srcdir; 31139595Smarcel 32139595Smarcelmy $tmpfile = "/tmp/unaligned." . $$; 33139595Smarcel 34139595Smarcelmy @types = ("short", "int", "long", "float", "double", "long double"); 35139595Smarcelmy %values = ( "short" => "0x1234", 36139595Smarcel "int" => "0x12345678", 37139595Smarcel "long" => "0x123456789abcdef0", 38139595Smarcel "float" => "1.04716", 39139595Smarcel "double" => "3.1415", 40139595Smarcel "long double" => "0.33312112048384" 41139595Smarcel ); 42139595Smarcelmy @tests = ("TEST_LOAD", "TEST_STORE"); 43139595Smarcel 44139595Smarcelsub run ($$$) { 45139595Smarcel local ($nr, $type, $test) = @_; 46139595Smarcel local $value = $values{$type}; 47139595Smarcel local $st; 48139595Smarcel $st = system("cc -o $tmpfile -DDATA_TYPE='$type' -DDATA_VALUE=$value -D$test -Wall $srcdir/test.c"); 49139595Smarcel if ($st != 0) { 50139595Smarcel print "not ok $nr ($type,$test) # compiling $tmpfile\n"; 51139595Smarcel return; 52139595Smarcel } 53139595Smarcel $st = system($tmpfile); 54139595Smarcel if ($st == 0) { 55139595Smarcel print "ok $nr ($type,$test)\n"; 56139595Smarcel } 57139595Smarcel elsif ($st == 1) { 58139595Smarcel print "not ok $nr ($type,$test) # value mismatch\n"; 59139595Smarcel } 60139595Smarcel else { 61139595Smarcel print "not ok $nr ($type,$test) # signalled\n"; 62139595Smarcel } 63139595Smarcel unlink $tmpfile; 64139595Smarcel} 65139595Smarcel 66139595Smarcelsystem("sysctl debug.unaligned_test=1"); 67139595Smarcelif (`sysctl -n debug.unaligned_test` != "1") { 68139595Smarcel print "1..0 # SKIP The debug.unaligned_test sysctl could not be set\n"; 69139595Smarcel exit 0; 70139595Smarcel} 71139595Smarcel 72139595Smarcelmy $count = @types * @tests; 73139595Smarcelprint "1..$count\n"; 74139595Smarcel 75139595Smarcelmy $nr=0; 76139595Smarcelforeach $type (@types) { 77139595Smarcel foreach $test (@tests) { 78139595Smarcel run ++$nr, $type, $test; 79139595Smarcel } 80139595Smarcel} 81139595Smarcel 82139595Smarcelsystem("sysctl debug.unaligned_test=0"); 83139595Smarcel 84139595Smarcelexit 0; 85