unaligned.t revision 139595
1139823Simp#!/usr/bin/env perl -w
21541Srgrimes#
31541Srgrimes# Copyright (c) 2005 Marcel Moolenaar
41541Srgrimes# All rights reserved.
51541Srgrimes#
61541Srgrimes# Redistribution and use in source and binary forms, with or without
71541Srgrimes# modification, are permitted provided that the following conditions
81541Srgrimes# are met:
91541Srgrimes#
101541Srgrimes# 1. Redistributions of source code must retain the above copyright
111541Srgrimes#    notice, this list of conditions and the following disclaimer.
121541Srgrimes# 2. Redistributions in binary form must reproduce the above copyright
131541Srgrimes#    notice, this list of conditions and the following disclaimer in the
141541Srgrimes#    documentation and/or other materials provided with the distribution.
151541Srgrimes#
161541Srgrimes# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
171541Srgrimes# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
181541Srgrimes# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
191541Srgrimes# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
201541Srgrimes# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
211541Srgrimes# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
221541Srgrimes# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
231541Srgrimes# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
241541Srgrimes# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
251541Srgrimes# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
261541Srgrimes#
271541Srgrimes# $FreeBSD: head/tools/regression/ia64/unaligned/unaligned.t 139595 2005-01-02 21:33:40Z marcel $
281541Srgrimes
291541Srgrimesmy $srcdir = `dirname $0`;
3050477Speterchomp $srcdir;
311541Srgrimes
321541Srgrimesmy $tmpfile = "/tmp/unaligned." . $$;
332168Spaul
344507Sbdemy @types = ("short", "int", "long", "float", "double", "long double");
352168Spaulmy %values = (	"short" => "0x1234",
361541Srgrimes		"int" => "0x12345678",
371541Srgrimes		"long" => "0x123456789abcdef0",
381541Srgrimes		"float" => "1.04716",
391541Srgrimes		"double" => "3.1415",
401541Srgrimes		"long double" => "0.33312112048384"
411541Srgrimes	     );
421541Srgrimesmy @tests = ("TEST_LOAD", "TEST_STORE");
431541Srgrimes
441541Srgrimessub run ($$$) {
451541Srgrimes	local ($nr, $type, $test) = @_;
461541Srgrimes	local $value = $values{$type};
471541Srgrimes	local $st;
481541Srgrimes	$st = system("cc -o $tmpfile -DDATA_TYPE='$type' -DDATA_VALUE=$value -D$test -Wall $srcdir/test.c"); 
4944165Sjulian	if ($st != 0) {
5084931Sfjoe		print "not ok $nr ($type,$test) # compiling $tmpfile\n";
511541Srgrimes		return;
52130407Sdfr	}
531541Srgrimes	$st = system($tmpfile);
541541Srgrimes	if ($st == 0) {
551541Srgrimes		print "ok $nr ($type,$test)\n";
561541Srgrimes	}
571541Srgrimes	elsif ($st == 1) {
581541Srgrimes		print "not ok $nr ($type,$test) # value mismatch\n";
591541Srgrimes	}
601541Srgrimes	else {
611541Srgrimes		print "not ok $nr ($type,$test) # signalled\n";
621541Srgrimes	}
631541Srgrimes	unlink $tmpfile;
641541Srgrimes}
651541Srgrimes
661541Srgrimessystem("sysctl debug.unaligned_test=1");
671541Srgrimesif (`sysctl -n debug.unaligned_test` != "1") {
681541Srgrimes    print "1..0 # SKIP The debug.unaligned_test sysctl could not be set\n";
691541Srgrimes    exit 0;
701541Srgrimes}
711541Srgrimes
721541Srgrimesmy $count = @types * @tests;
731541Srgrimesprint "1..$count\n";
741541Srgrimes
7584931Sfjoemy $nr=0;
7684931Sfjoeforeach $type (@types) {
7784931Sfjoe	foreach $test (@tests) {
7884931Sfjoe		run ++$nr, $type, $test;
7984931Sfjoe	}
8084931Sfjoe}
8184931Sfjoe
8284931Sfjoesystem("sysctl debug.unaligned_test=0");
8384931Sfjoe
841541Srgrimesexit 0;
851541Srgrimes