[TESTS] Add a test for spec2def

This commit is contained in:
Mark Jansen 2019-08-20 19:09:10 +02:00
parent 767d424b0a
commit 6d2381631f
No known key found for this signature in database
GPG key ID: B39240EE84BEAE8B
22 changed files with 504 additions and 0 deletions

View file

@ -3,3 +3,4 @@ if(NOT MSVC)
add_subdirectory(pseh2)
endif()
add_subdirectory(dllexport)
add_subdirectory(spec2def)

View file

@ -0,0 +1,3 @@
add_custom_target(spec2def_test
py -3 ${CMAKE_CURRENT_SOURCE_DIR}/test.py $<TARGET_FILE:native-spec2def>)

View file

@ -0,0 +1,113 @@
import subprocess
import os
import tempfile
import sys
import difflib
# ${_spec_file} = ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
# spec2def -n=${_dllname} -a=${ARCH} ${ARGN} --implib -d=${BIN_PATH}/${_libname}_implib.def ${_spec_file}
# spec2def -n=${_dllname} -a=${ARCH} -d=${BIN_PATH}/${_file}.def -s=${BIN_PATH}/${_file}_stubs.c ${__with_relay_arg} ${__version_arg} ${_spec_file}
# spec2def --ms -a=${_ARCH} --implib -n=${_dllname} -d=${_def_file} -l=${_asm_stubs_file} ${_spec_file}
# spec2def --ms -a=${ARCH} -n=${_dllname} -d=${BIN_PATH}/${_file}.def -s=${BIN_PATH}/${_file}_stubs.c ${__with_relay_arg} ${__version_arg} ${_spec_file}
SCRIPT_DIR = os.path.dirname(__file__)
SPEC_FILE = os.path.join(SCRIPT_DIR, 'test.spec')
DATA_DIR = os.path.join(SCRIPT_DIR, 'testdata')
class ResultFile:
def __init__(self, datadir, filename):
self.filename = filename
with open(os.path.join(datadir, filename), 'r') as content:
self.data = content.read()
def normalize(self):
data = self.data.splitlines()
data = [line for line in data if line]
return '\n'.join(data)
class TestCase:
def __init__(self, spec_args, prefix):
self.spec_args = spec_args
self.prefix = prefix
self.expect_files = []
self.result_files = []
self.stdout = self.stderr = None
self.returncode = None
def run(self, cmd, tmpdir, all_datafiles):
datafiles = [filename for filename in all_datafiles if filename.startswith(self.prefix)]
self.expect_files = [ResultFile(DATA_DIR, datafile) for datafile in datafiles]
tmppath = os.path.join(tmpdir, self.prefix)
args = [elem.replace('$tmp$', tmppath) for elem in self.spec_args]
args = [cmd] + args + [SPEC_FILE]
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
self.stdout, self.stderr = proc.communicate()
self.returncode = proc.returncode
self.result_files = [ResultFile(tmpdir, tmpfile) for tmpfile in os.listdir(tmpdir)]
def verify(self):
if False:
for result in self.result_files:
with open(os.path.join(DATA_DIR, result.filename), 'w') as content:
content.write(result.data)
return
if self.returncode != 0:
print('Failed return code', self.returncode, 'for', self.prefix)
return
self.expect_files.sort(key= lambda elem: elem.filename)
self.result_files.sort(key= lambda elem: elem.filename)
exp_len = len(self.expect_files)
res_len = len(self.result_files)
if exp_len != res_len:
print('Not enough files for', self.prefix, 'got:', res_len, 'wanted:', exp_len)
return
for n in range(len(self.expect_files)):
exp = self.expect_files[n]
res = self.result_files[n]
if exp.normalize() == res.normalize():
# Content 100% the same, ignoring empty newlines
continue
exp_name = 'expected/' + exp.filename
res_name = 'output/' + res.filename
exp = exp.data.splitlines()
res = res.data.splitlines()
diff = difflib.unified_diff(exp, res, fromfile=exp_name, tofile=res_name, lineterm='')
for line in diff:
print(line)
TEST_CASES = [
# GCC implib
TestCase([ '-n=testdll.xyz', '-a=i386', '--implib', '-d=$tmp$test.def', '--no-private-warnings' ], '01-'),
TestCase([ '-n=testdll.xyz', '-a=x86_64', '--implib', '-d=$tmp$test.def', '--no-private-warnings' ], '02-'),
# GCC normal
TestCase([ '-n=testdll.xyz', '-a=i386', '-d=$tmp$test.def', '-s=$tmp$stubs.c' ], '03-'),
TestCase([ '-n=testdll.xyz', '-a=x86_64', '-d=$tmp$test.def', '-s=$tmp$stubs.c' ], '04-'),
TestCase([ '-n=testdll.xyz', '-a=i386', '-d=$tmp$test.def', '-s=$tmp$stubs.c', '--with-tracing' ], '05-'),
# MSVC implib
TestCase([ '--ms', '-n=testdll.xyz', '-a=i386', '--implib', '-d=$tmp$test.def', '-l=$tmp$stubs.asm' ], '06-'),
TestCase([ '--ms', '-n=testdll.xyz', '-a=x86_64', '--implib', '-d=$tmp$test.def', '-l=$tmp$stubs.asm' ], '07-'),
# MSVC normal
TestCase([ '--ms', '-n=testdll.xyz', '-a=i386', '-d=$tmp$test.def', '-s=$tmp$stubs.c' ], '08-'),
TestCase([ '--ms', '-n=testdll.xyz', '-a=x86_64', '-d=$tmp$test.def', '-s=$tmp$stubs.c' ], '09-'),
TestCase([ '--ms', '-n=testdll.xyz', '-a=i386', '-d=$tmp$test.def', '-s=$tmp$stubs.c', '--with-tracing' ], '10-'),
]
def run_test(testcase, cmd, all_files):
with tempfile.TemporaryDirectory() as tmpdirname:
testcase.run(cmd, tmpdirname, all_files)
testcase.verify()
def main(args):
cmd = args[0] if args else 'spec2def'
all_files = os.listdir(DATA_DIR)
for testcase in TEST_CASES:
run_test(testcase, cmd, all_files)
if __name__ == '__main__':
main(sys.argv[1:])

View file

@ -0,0 +1,19 @@
; Comments be here()
# 2 stdcall CommentedOutFunction(ptr long ptr ptr) # comment 2
6 fastcall FastcallFunction(ptr ptr ptr long)
@ stdcall StdcallFunction(long)
8 fastcall -ret64 Ret64Function(double)
7 fastcall -arch=i386 Fastcalli386(long)
10 stdcall -arch=i386,x86_64 Stdcalli386x64()
@ stdcall -version=0x351-0x502 StdcallVersionRange(long long wstr wstr)
@ stdcall -stub -version=0x600+ StdcallStubVersion600(ptr)
@ stdcall StdcallForwarderToSameDll() StdcallTargetInSameDll
@ stdcall -version=0x600+ StdcallForwarder(ptr ptr ptr) ntdll.RtlStdcallForwarder
@ stub StubFunction
@ stdcall -stub StdcallSuccessStub(ptr)

View file

@ -0,0 +1,14 @@
; File generated automatically, do not edit!
NAME testdll.xyz
EXPORTS
@FastcallFunction@16
StdcallFunction@4
@Ret64Function@8
@Fastcalli386@4
Stdcalli386x64@0
StdcallVersionRange@16
StdcallForwarderToSameDll@0=StdcallTargetInSameDll@0
StubFunction
StdcallSuccessStub@4

View file

@ -0,0 +1,13 @@
; File generated automatically, do not edit!
NAME testdll.xyz
EXPORTS
FastcallFunction
StdcallFunction
Ret64Function
Stdcalli386x64
StdcallVersionRange
StdcallForwarderToSameDll=StdcallTargetInSameDll
StubFunction
StdcallSuccessStub

View file

@ -0,0 +1,17 @@
/* This file is autogenerated, do not edit. */
#include <stubs.h>
int StubFunction()
{
DbgPrint("WARNING: calling stub StubFunction()\n");
__wine_spec_unimplemented_stub("testdll.xyz", __FUNCTION__);
return 0;
}
int __stdcall StdcallSuccessStub(void* a0)
{
DbgPrint("WARNING: calling stub StdcallSuccessStub(0x%p)\n", (void*)a0);
return 0;
}

View file

@ -0,0 +1,14 @@
; File generated automatically, do not edit!
NAME testdll.xyz
EXPORTS
FastcallFunction=@FastcallFunction@16 @6
StdcallFunction=StdcallFunction@4
Ret64Function=@Ret64Function@8 @8
Fastcalli386=@Fastcalli386@4 @7
Stdcalli386x64=Stdcalli386x64@0 @10
StdcallVersionRange=StdcallVersionRange@16
StdcallForwarderToSameDll=StdcallTargetInSameDll@0
StubFunction
StdcallSuccessStub=StdcallSuccessStub@4

View file

@ -0,0 +1,17 @@
/* This file is autogenerated, do not edit. */
#include <stubs.h>
int StubFunction()
{
DbgPrint("WARNING: calling stub StubFunction()\n");
__wine_spec_unimplemented_stub("testdll.xyz", __FUNCTION__);
return 0;
}
int StdcallSuccessStub(void* a0)
{
DbgPrint("WARNING: calling stub StdcallSuccessStub(0x%p)\n", (void*)a0);
return 0;
}

View file

@ -0,0 +1,13 @@
; File generated automatically, do not edit!
NAME testdll.xyz
EXPORTS
FastcallFunction @6
StdcallFunction
Ret64Function @8
Stdcalli386x64 @10
StdcallVersionRange
StdcallForwarderToSameDll=StdcallTargetInSameDll
StubFunction
StdcallSuccessStub

View file

@ -0,0 +1,59 @@
/* This file is autogenerated, do not edit. */
#include <stubs.h>
#include <wine/debug.h>
#include <inttypes.h>
WINE_DECLARE_DEBUG_CHANNEL(relay);
extern int __stdcall StdcallFunction(long a0);
int __stdcall $relaytrace$StdcallFunction(long a0)
{
int retval;
if (TRACE_ON(relay))
DPRINTF("testdll.xyz: StdcallFunction(0x%lx)\n", (long)a0);
retval = StdcallFunction(a0);
if (TRACE_ON(relay))
DPRINTF("testdll.xyz: StdcallFunction: retval = 0x%lx\n", retval);
return retval;
}
extern int __stdcall Stdcalli386x64();
int __stdcall $relaytrace$Stdcalli386x64()
{
int retval;
if (TRACE_ON(relay))
DPRINTF("testdll.xyz: Stdcalli386x64()\n");
retval = Stdcalli386x64();
if (TRACE_ON(relay))
DPRINTF("testdll.xyz: Stdcalli386x64: retval = 0x%lx\n", retval);
return retval;
}
extern int __stdcall StdcallVersionRange(long a0, long a1, wchar_t* a2, wchar_t* a3);
int __stdcall $relaytrace$StdcallVersionRange(long a0, long a1, wchar_t* a2, wchar_t* a3)
{
int retval;
if (TRACE_ON(relay))
DPRINTF("testdll.xyz: StdcallVersionRange(0x%lx,0x%lx,'%ws','%ws')\n", (long)a0, (long)a1, (wchar_t*)a2, (wchar_t*)a3);
retval = StdcallVersionRange(a0, a1, a2, a3);
if (TRACE_ON(relay))
DPRINTF("testdll.xyz: StdcallVersionRange: retval = 0x%lx\n", retval);
return retval;
}
int StubFunction()
{
DbgPrint("WARNING: calling stub StubFunction()\n");
__wine_spec_unimplemented_stub("testdll.xyz", __FUNCTION__);
return 0;
}
int __stdcall StdcallSuccessStub(void* a0)
{
DbgPrint("WARNING: calling stub StdcallSuccessStub(0x%p)\n", (void*)a0);
return 0;
}

View file

@ -0,0 +1,14 @@
; File generated automatically, do not edit!
NAME testdll.xyz
EXPORTS
FastcallFunction=@FastcallFunction@16 @6
StdcallFunction=$relaytrace$StdcallFunction@4
Ret64Function=@Ret64Function@8 @8
Fastcalli386=@Fastcalli386@4 @7
Stdcalli386x64=$relaytrace$Stdcalli386x64@0 @10
StdcallVersionRange=$relaytrace$StdcallVersionRange@16
StdcallForwarderToSameDll=StdcallTargetInSameDll@0
StubFunction
StdcallSuccessStub=$relaytrace$StdcallSuccessStub@4

View file

@ -0,0 +1,25 @@
; File generated automatically, do not edit!
.586
.model flat
.code
PUBLIC @_stub_FastcallFunction@16
@_stub_FastcallFunction@16: nop
PUBLIC __stub_StdcallFunction@4
__stub_StdcallFunction@4: nop
PUBLIC @_stub_Ret64Function@8
@_stub_Ret64Function@8: nop
PUBLIC @_stub_Fastcalli386@4
@_stub_Fastcalli386@4: nop
PUBLIC __stub_Stdcalli386x64@0
__stub_Stdcalli386x64@0: nop
PUBLIC __stub_StdcallVersionRange@16
__stub_StdcallVersionRange@16: nop
PUBLIC __stub_StdcallForwarderToSameDll@0
__stub_StdcallForwarderToSameDll@0: nop
PUBLIC __stub_StubFunction
__stub_StubFunction: nop
PUBLIC __stub_StdcallSuccessStub@4
__stub_StdcallSuccessStub@4: nop
END

View file

@ -0,0 +1,14 @@
; File generated automatically, do not edit!
NAME testdll.xyz
EXPORTS
FastcallFunction=_stub_FastcallFunction
StdcallFunction=_stub_StdcallFunction
Ret64Function=_stub_Ret64Function
Fastcalli386=_stub_Fastcalli386
Stdcalli386x64=_stub_Stdcalli386x64
StdcallVersionRange=_stub_StdcallVersionRange
StdcallForwarderToSameDll=_stub_StdcallForwarderToSameDll
StubFunction=_stub_StubFunction
StdcallSuccessStub=_stub_StdcallSuccessStub

View file

@ -0,0 +1,21 @@
; File generated automatically, do not edit!
.code
PUBLIC _stub_FastcallFunction
_stub_FastcallFunction: nop
PUBLIC _stub_StdcallFunction
_stub_StdcallFunction: nop
PUBLIC _stub_Ret64Function
_stub_Ret64Function: nop
PUBLIC _stub_Stdcalli386x64
_stub_Stdcalli386x64: nop
PUBLIC _stub_StdcallVersionRange
_stub_StdcallVersionRange: nop
PUBLIC _stub_StdcallForwarderToSameDll
_stub_StdcallForwarderToSameDll: nop
PUBLIC _stub_StubFunction
_stub_StubFunction: nop
PUBLIC _stub_StdcallSuccessStub
_stub_StdcallSuccessStub: nop
END

View file

@ -0,0 +1,13 @@
; File generated automatically, do not edit!
NAME testdll.xyz
EXPORTS
FastcallFunction=_stub_FastcallFunction
StdcallFunction=_stub_StdcallFunction
Ret64Function=_stub_Ret64Function
Stdcalli386x64=_stub_Stdcalli386x64
StdcallVersionRange=_stub_StdcallVersionRange
StdcallForwarderToSameDll=_stub_StdcallForwarderToSameDll
StubFunction=_stub_StubFunction
StdcallSuccessStub=_stub_StdcallSuccessStub

View file

@ -0,0 +1,17 @@
/* This file is autogenerated, do not edit. */
#include <stubs.h>
int StubFunction()
{
DbgPrint("WARNING: calling stub StubFunction()\n");
__wine_spec_unimplemented_stub("testdll.xyz", __FUNCTION__);
return 0;
}
int __stdcall StdcallSuccessStub(void* a0)
{
DbgPrint("WARNING: calling stub StdcallSuccessStub(0x%p)\n", (void*)a0);
return 0;
}

View file

@ -0,0 +1,14 @@
; File generated automatically, do not edit!
NAME testdll.xyz
EXPORTS
FastcallFunction @6
StdcallFunction
Ret64Function @8
Fastcalli386 @7
Stdcalli386x64 @10
StdcallVersionRange
StdcallForwarderToSameDll=StdcallTargetInSameDll
StubFunction
StdcallSuccessStub

View file

@ -0,0 +1,17 @@
/* This file is autogenerated, do not edit. */
#include <stubs.h>
int StubFunction()
{
DbgPrint("WARNING: calling stub StubFunction()\n");
__wine_spec_unimplemented_stub("testdll.xyz", __FUNCTION__);
return 0;
}
int StdcallSuccessStub(void* a0)
{
DbgPrint("WARNING: calling stub StdcallSuccessStub(0x%p)\n", (void*)a0);
return 0;
}

View file

@ -0,0 +1,13 @@
; File generated automatically, do not edit!
NAME testdll.xyz
EXPORTS
FastcallFunction @6
StdcallFunction
Ret64Function @8
Stdcalli386x64 @10
StdcallVersionRange
StdcallForwarderToSameDll=StdcallTargetInSameDll
StubFunction
StdcallSuccessStub

View file

@ -0,0 +1,59 @@
/* This file is autogenerated, do not edit. */
#include <stubs.h>
#include <wine/debug.h>
#include <inttypes.h>
WINE_DECLARE_DEBUG_CHANNEL(relay);
extern int __stdcall StdcallFunction(long a0);
int __stdcall $relaytrace$StdcallFunction(long a0)
{
int retval;
if (TRACE_ON(relay))
DPRINTF("testdll.xyz: StdcallFunction(0x%lx)\n", (long)a0);
retval = StdcallFunction(a0);
if (TRACE_ON(relay))
DPRINTF("testdll.xyz: StdcallFunction: retval = 0x%lx\n", retval);
return retval;
}
extern int __stdcall Stdcalli386x64();
int __stdcall $relaytrace$Stdcalli386x64()
{
int retval;
if (TRACE_ON(relay))
DPRINTF("testdll.xyz: Stdcalli386x64()\n");
retval = Stdcalli386x64();
if (TRACE_ON(relay))
DPRINTF("testdll.xyz: Stdcalli386x64: retval = 0x%lx\n", retval);
return retval;
}
extern int __stdcall StdcallVersionRange(long a0, long a1, wchar_t* a2, wchar_t* a3);
int __stdcall $relaytrace$StdcallVersionRange(long a0, long a1, wchar_t* a2, wchar_t* a3)
{
int retval;
if (TRACE_ON(relay))
DPRINTF("testdll.xyz: StdcallVersionRange(0x%lx,0x%lx,'%ws','%ws')\n", (long)a0, (long)a1, (wchar_t*)a2, (wchar_t*)a3);
retval = StdcallVersionRange(a0, a1, a2, a3);
if (TRACE_ON(relay))
DPRINTF("testdll.xyz: StdcallVersionRange: retval = 0x%lx\n", retval);
return retval;
}
int StubFunction()
{
DbgPrint("WARNING: calling stub StubFunction()\n");
__wine_spec_unimplemented_stub("testdll.xyz", __FUNCTION__);
return 0;
}
int __stdcall StdcallSuccessStub(void* a0)
{
DbgPrint("WARNING: calling stub StdcallSuccessStub(0x%p)\n", (void*)a0);
return 0;
}

View file

@ -0,0 +1,14 @@
; File generated automatically, do not edit!
NAME testdll.xyz
EXPORTS
FastcallFunction @6
StdcallFunction=$relaytrace$StdcallFunction
Ret64Function @8
Fastcalli386 @7
Stdcalli386x64=$relaytrace$Stdcalli386x64 @10
StdcallVersionRange=$relaytrace$StdcallVersionRange
StdcallForwarderToSameDll=StdcallTargetInSameDll
StubFunction
StdcallSuccessStub=$relaytrace$StdcallSuccessStub