Commit e1448b97 authored by dterei's avatar dterei
Browse files

Add test for new ghc mem* prim ops

parent 58160c6c
......@@ -513,7 +513,7 @@ def test_common_work (name, opts, func, args):
# All the ways we might run this test
if func == compile or func == multimod_compile:
all_ways = config.compile_ways
elif func == compile_and_run or func == multimod_compile_and_run:
elif func == compile_and_run or func == multimod_compile_and_run or func == multisrc_compile_and_run:
all_ways = config.run_ways
elif func == ghci_script:
if 'ghci' in config.run_ways:
......@@ -738,7 +738,7 @@ def multimod_compile_fail( name, way, top_mod, extra_hc_opts ):
def do_compile( name, way, should_fail, top_mod, extra_hc_opts ):
# print 'Compile only, extra args = ', extra_hc_opts
pretest_cleanup(name)
result = simple_build( name, way, extra_hc_opts, should_fail, top_mod, 0 )
result = simple_build( name, way, extra_hc_opts, should_fail, top_mod, 0, 1)
if result == 'fail':
return result
......@@ -765,16 +765,20 @@ def do_compile( name, way, should_fail, top_mod, extra_hc_opts ):
# -----------------------------------------------------------------------------
# Compile-and-run tests
def compile_and_run__( name, way, extra_hc_opts, top_mod ):
def compile_and_run__( name, way, extra_hc_opts, top_mod, extra_mods ):
# print 'Compile and run, extra args = ', extra_hc_opts
pretest_cleanup(name)
for mod in extra_mods:
simple_build( mod, way, extra_hc_opts, 0, '', 0, 0 )
extra_hc_opts += " " + replace_suffix(mod, 'o')
if way == 'ghci': # interpreted...
return interpreter_run( name, way, extra_hc_opts, 0, top_mod )
elif way == 'extcore' or way == 'optextcore' :
return extcore_run( name, way, extra_hc_opts, 0, top_mod )
else: # compiled...
result = simple_build( name, way, extra_hc_opts, 0, top_mod, 1 )
result = simple_build( name, way, extra_hc_opts, 0, top_mod, 1, 1 )
if result == 'fail':
return result
......@@ -786,10 +790,13 @@ def compile_and_run__( name, way, extra_hc_opts, top_mod ):
return simple_run( name, way, cmd, getTestOpts().extra_run_opts )
def compile_and_run( name, way, extra_hc_opts ):
return compile_and_run__( name, way, extra_hc_opts, '')
return compile_and_run__( name, way, extra_hc_opts, '', [])
def multimod_compile_and_run( name, way, top_mod, extra_hc_opts ):
return compile_and_run__( name, way, extra_hc_opts, top_mod)
return compile_and_run__( name, way, extra_hc_opts, top_mod, [])
def multisrc_compile_and_run( name, way, top_mod, extra_mods, extra_hc_opts ):
return compile_and_run__( name, way, extra_hc_opts, '', extra_mods)
# -----------------------------------------------------------------------------
# Check -t stats info
......@@ -823,16 +830,20 @@ def checkStats(stats_file, num_fields):
# -----------------------------------------------------------------------------
# Build a single-module program
def simple_build( name, way, extra_hc_opts, should_fail, top_mod, link ):
def simple_build( name, way, extra_hc_opts, should_fail, top_mod, link, addsuf ):
opts = getTestOpts()
errname = add_suffix(name, 'comp.stderr')
rm_no_fail( errname )
rm_no_fail( name )
if top_mod != '':
srcname = top_mod
else:
rm_no_fail( name )
elif addsuf:
srcname = add_hs_lhs_suffix(name)
rm_no_fail( name )
else:
srcname = name
rm_no_fail( name + '.o' )
to_do = ''
if top_mod != '':
......@@ -1461,6 +1472,10 @@ def add_hs_lhs_suffix(name):
else:
return add_suffix(name, 'hs')
def replace_suffix( name, suffix ):
base, suf = os.path.splitext(name)
return base + '.' + suffix
def in_testdir( name ):
return (getTestOpts().testdir + '/' + name)
......
......@@ -2,9 +2,3 @@ TOP=../../../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
.PHONY: 5149
5149:
$(RM) 5149_cmm.o 5149.o 5149.hi 5149$(exeext)
"$(TEST_HC)" -v0 -O -c 5149_cmm.cmm
"$(TEST_HC)" -v0 --make -O 5149.hs 5149_cmm.o -o 5149$(exeext)
./5149
......@@ -24,10 +24,8 @@ test('cgrun020', normal, compile_and_run, [''])
test('cgrun021', normal, compile_and_run, [''])
test('cgrun022', normal, compile_and_run, [''])
test('cgrun024', normal, compile_and_run, [''])
test('cgrun025', compose(reqlib('regex-compat'), compose(extra_run_opts('cg025.hs'),exit_code(1))),
compile_and_run, ['-package regex-compat'])
test('cgrun026', only_compiler_types(['ghc']), compile_and_run, [''])
test('cgrun027', normal, compile_and_run, [''])
test('cgrun028', normal, compile_and_run, [''])
......@@ -56,18 +54,12 @@ test('cgrun053', normal, compile_and_run, [''])
test('cgrun054', normal, compile_and_run, [''])
test('cgrun055', normal, compile_and_run, [''])
test('cgrun056', normal, compile_and_run, [''])
test('cgrun057', composes([expect_broken(948),
only_ways(['prof','profasm']),
extra_run_opts('+RTS -xc')]),
compile_and_run, [''])
test('cgrun058', normal, compile_and_run, [''])
test('cgrun059', exit_code(1), compile_and_run, [''])
test('1852', normal, compile_and_run, [''])
test('2080', normal, compile_and_run, [''])
test('cgrun060',
extra_run_opts('+RTS -K64k -RTS'),
compile_and_run, [''])
......@@ -80,15 +72,16 @@ test('cgrun066', normal, compile_and_run, [''])
test('cgrun067', extra_clean(['Cgrun067A.hi', 'Cgrun067A.o']),
compile_and_run, [''])
test('cgrun068', normal, compile_and_run, [''])
test('cgrun069', omit_ways(['ghci']), multisrc_compile_and_run,
['cgrun069', ['cgrun069_cmm.cmm'], ''])
test('1852', normal, compile_and_run, [''])
test('1861', extra_run_opts('0'), compile_and_run, [''])
test('2080', normal, compile_and_run, [''])
test('2838', normal, compile_and_run, [''])
test('3207', normal, compile_and_run, [''])
test('3561', normal, compile_and_run, [''])
test('3677', extra_run_opts('+RTS -K8k -RTS'), compile_and_run, [''])
test('4441', normal, compile_and_run, [''])
test('5149', [ extra_clean(['5149.o', '5149.hi', '5149_cmm.o', '5149']) ],
run_command,
['$MAKE -s --no-print-directory 5149'])
test('5149', omit_ways(['ghci']), multisrc_compile_and_run,
['5149', ['5149_cmm.cmm'], ''])
{-# LANGUAGE MagicHash,GHCForeignImportPrim,UnliftedFFITypes #-}
module Main where
import GHC.Exts
import Control.Exception
import System.IO
foreign import prim "memintrinTest" memcpyTest :: Int# -> Int#
main = do
putStrLn "Mem{cpy,set,move} Intrinsics Test..."
_ <- evaluate (I# (memcpyTest 1#))
putStrLn "Test Passed!"
return ()
Mem{cpy,set,move} Intrinsics Test...
Test Passed!
#include "Cmm.h"
// Test that the Memcpy, Memmove, Memset GHC intrinsic functions
// are working correctly.
section "rodata" { memsetErr : bits8[] "Memset Error Occured\n"; }
section "rodata" { memcpyErr : bits8[] "Memcpy Error Occured\n"; }
section "rodata" { memmoveErr : bits8[] "Memmove Error Occured\n"; }
memintrinTest
{
W_ size, src, dst, off, alignV, set;
bits8 set8;
// Need two versions as memset takes a word for historical reasons
// but really its a bits8. We check that setting has ben done correctly
// at the bits8 level, so need bits8 version for checking.
set = 4;
set8 = 4::bits8;
size = 1024;
alignV = 4;
("ptr" src) = foreign "C" malloc(size);
("ptr" dst) = foreign "C" malloc(size);
// Test memset
prim %memset(src "ptr", set, size, alignV) [];
// Check memset worked
off = 0;
while1:
if (off == size) {
goto while1_end;
}
if (bits8[src + off] != set8) {
foreign "C" printf(memsetErr "ptr") [];
goto while1_end;
}
off = off + 1;
goto while1;
while1_end:
// Test memcpy
prim %memcpy(dst "ptr", src "ptr", size, alignV) [];
// Check memcpy worked
off = 0;
while2:
if (off == size) {
goto while2_end;
}
if (bits8[dst + off] != set8) {
foreign "C" printf(memcpyErr "ptr") [];
goto while2_end;
}
off = off + 1;
goto while2;
while2_end:
// Test memove
set = 8;
set8 = 8::bits8;
size = 100;
W_ src2;
src2 = src + 50;
prim %memset(src "ptr", set, size, alignV) [];
prim %memmove(src2 "ptr", src "ptr", size, alignV) [];
// Check memmove worked
off = 0;
while3:
if (off == size) {
goto while3_end;
}
if (bits8[src2 + off] != set8) {
foreign "C" printf(memmoveErr "ptr") [];
goto while3_end;
}
off = off + 1;
goto while3;
while3_end:
foreign "C" free(src);
foreign "C" free(dst);
jump %ENTRY_CODE(Sp(0));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment