From 4f063c40536884a2378b02f436c24081596f051c Mon Sep 17 00:00:00 2001 From: nillerusr Date: Fri, 7 Apr 2023 13:25:58 +0300 Subject: [PATCH] unittests: fix library loading --- gameui/BasePanel.cpp | 20 +++- public/dispcoll_common.cpp | 10 +- public/tier0/platform.h | 6 + public/tier0/tslist.h | 15 +-- scripts/tests-ubuntu-amd64.sh | 2 +- scripts/tests-ubuntu-i386.sh | 2 +- tier1/interface.cpp | 12 ++ unittests/tier1test/wscript | 2 +- wscript | 214 +++++++++++++++++----------------- 9 files changed, 156 insertions(+), 127 deletions(-) diff --git a/gameui/BasePanel.cpp b/gameui/BasePanel.cpp index 89ce02ba..a5336366 100644 --- a/gameui/BasePanel.cpp +++ b/gameui/BasePanel.cpp @@ -915,7 +915,7 @@ CBasePanel::CBasePanel() : Panel(NULL, "BaseGameUIPanel") } } - if( IsAndroid() ) +// if( IsAndroid() ) { AddUrlButton( this, "vgui/\x64\x69\x73\x63\x6f\x72\x64\x5f\x6c\x6f\x67\x6f", "\x68\x74\x74\x70\x73\x3a\x2f\x2f\x64\x69\x73\x63\x6f\x72\x64\x2e\x67\x67\x2f\x68\x5a\x52\x42\x37\x57\x4d\x67\x47\x77" ); AddUrlButton( this, "vgui/\x74\x77\x69\x74\x74\x65\x72\x5f\x6c\x6f\x67\x6f", "\x68\x74\x74\x70\x73\x3a\x2f\x2f\x74\x77\x69\x74\x74\x65\x72\x2e\x63\x6f\x6d\x2f\x6e\x69\x6c\x6c\x65\x72\x75\x73\x72" ); @@ -1607,6 +1607,21 @@ CGameMenu *CBasePanel::RecursiveLoadGameMenu(KeyValues *datafile) else menu->AddMenuItem("Console", "CONSOLE", "OpenConsole", this); + bool bFoundServerBrowser = false; + + for (KeyValues *dat = datafile->GetFirstSubKey(); dat != NULL; dat = dat->GetNextKey()) + { + const char *label = dat->GetString("label", ""); + const char *cmd = dat->GetString("command", NULL); + const char *name = dat->GetString("name", label); + + if( cmd && Q_strcmp(cmd, "OpenServerBrowser") == 0 ) + bFoundServerBrowser = true; + } + + if( !bFoundServerBrowser && !ModInfo().IsSinglePlayerOnly() ) + menu->AddMenuItem("AntiM*dG*yButton", "#GameUI_GameMenu_FindServers", "OpenServerBrowser", this); + // loop through all the data adding items to the menu for (KeyValues *dat = datafile->GetFirstSubKey(); dat != NULL; dat = dat->GetNextKey()) { @@ -1614,7 +1629,8 @@ CGameMenu *CBasePanel::RecursiveLoadGameMenu(KeyValues *datafile) const char *cmd = dat->GetString("command", NULL); const char *name = dat->GetString("name", label); - if ( cmd && !Q_stricmp( cmd, "OpenFriendsDialog" ) && bSteamCommunityFriendsVersion ) + if ( cmd && (!Q_stricmp( cmd, "OpenFriendsDialog" ) + || !Q_stricmp( cmd, "engine bug" )) ) continue; menu->AddMenuItem(name, label, cmd, this, dat); diff --git a/public/dispcoll_common.cpp b/public/dispcoll_common.cpp index 307e1408..cfaaba80 100644 --- a/public/dispcoll_common.cpp +++ b/public/dispcoll_common.cpp @@ -429,13 +429,7 @@ void CDispCollTree::AABBTree_CreateLeafs( void ) } } -#if COMPILER_CLANG -#define NOASAN __attribute__((no_sanitize("address"))) -#else -#define NOASAN -#endif - -void NOASAN CDispCollTree::AABBTree_GenerateBoxes_r( int nodeIndex, Vector *pMins, Vector *pMaxs ) +void NO_ASAN CDispCollTree::AABBTree_GenerateBoxes_r( int nodeIndex, Vector *pMins, Vector *pMaxs ) { // leaf ClearBounds( *pMins, *pMaxs ); @@ -467,8 +461,6 @@ void NOASAN CDispCollTree::AABBTree_GenerateBoxes_r( int nodeIndex, Vector *pMin } } -#undef NOASAN - //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- diff --git a/public/tier0/platform.h b/public/tier0/platform.h index 2c912e04..4a4c4883 100644 --- a/public/tier0/platform.h +++ b/public/tier0/platform.h @@ -606,6 +606,12 @@ typedef void * HINSTANCE; #define FMTFUNCTION( a, b ) #endif +#if COMPILER_CLANG || COMPILER_GCC +#define NO_ASAN __attribute__((no_sanitize("address"))) +#else +#define NO_ASAN +#endif + #if defined( _WIN32 ) // Used for dll exporting and importing diff --git a/public/tier0/tslist.h b/public/tier0/tslist.h index a1b2be7f..f5661258 100644 --- a/public/tier0/tslist.h +++ b/public/tier0/tslist.h @@ -123,21 +123,21 @@ union TSLIST_HEAD_ALIGN TSLHead_t // but it could perhaps (?) lead to problems with store forwarding. I don't know 'cause I didn't // performance-test or design original code, I'm just making it work on PowerPC. #ifdef VALVE_BIG_ENDIAN - int16 Sequence; - int16 Depth; + uint16 Sequence; + uint16 Depth; #else - int16 Depth; - int16 Sequence; + uint16 Depth; + uint16 Sequence; #endif #ifdef PLATFORM_64BITS - int32 Padding; + uint32 Padding; #endif } value; struct Value32_t { TSLNodeBase_t *Next_do_not_use_me; - int32 DepthAndSequence; + uint32 DepthAndSequence; } value32; #ifdef PLATFORM_64BITS @@ -254,7 +254,8 @@ public: #endif } - TSLNodeBase_t *Pop() + // TODO(nillerusr): fix asan issue later + NO_ASAN TSLNodeBase_t *Pop() { #ifdef USE_NATIVE_SLIST #ifdef _X360 diff --git a/scripts/tests-ubuntu-amd64.sh b/scripts/tests-ubuntu-amd64.sh index af0c589e..080ef65a 100755 --- a/scripts/tests-ubuntu-amd64.sh +++ b/scripts/tests-ubuntu-amd64.sh @@ -4,7 +4,7 @@ git submodule init && git submodule update sudo apt-get update sudo apt-get install -f -y gdb libopenal-dev g++-multilib gcc-multilib libpng-dev libjpeg-dev libfreetype6-dev libfontconfig1-dev libcurl4-gnutls-dev libsdl2-dev zlib1g-dev libbz2-dev libedit-dev -./waf configure -T release --disable-warns --tests --prefix=out/ --64bits $* && +./waf configure -T release --sanitize=address,undefined --disable-warns --tests --prefix=out/ --64bits $* && ./waf install && cd out && LD_LIBRARY_PATH=bin/ ./unittest diff --git a/scripts/tests-ubuntu-i386.sh b/scripts/tests-ubuntu-i386.sh index ee451ee4..b3d71837 100755 --- a/scripts/tests-ubuntu-i386.sh +++ b/scripts/tests-ubuntu-i386.sh @@ -6,7 +6,7 @@ sudo apt-get update sudo apt-get install -y aptitude sudo aptitude install -y libopenal-dev:i386 g++-multilib gcc-multilib libpng-dev:i386 libjpeg-dev:i386 libfreetype6-dev:i386 libfontconfig1-dev:i386 libcurl4-gnutls-dev:i386 libsdl2-dev:i386 zlib1g-dev:i386 libbz2-dev:i386 libedit-dev:i386 -PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig ./waf configure -T release --disable-warns --tests --prefix=out/ $* && +PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig ./waf configure -T release --sanitize=address,undefined --disable-warns --tests --prefix=out/ $* && ./waf install && cd out && LD_LIBRARY_PATH=bin/ ./unittest diff --git a/tier1/interface.cpp b/tier1/interface.cpp index 78dacc82..47fda8f9 100644 --- a/tier1/interface.cpp +++ b/tier1/interface.cpp @@ -292,6 +292,18 @@ bool foundLibraryWithPrefix( char *pModuleAbsolutePath, size_t AbsolutePathSize, bFound |= stat(pModuleAbsolutePath, &statBuf) == 0; } + if( !bFound ) + { + Q_snprintf(pModuleAbsolutePath, AbsolutePathSize, "%s/lib%s", pPath, str); + bFound |= stat(pModuleAbsolutePath, &statBuf) == 0; + } + + if( !bFound ) + { + Q_snprintf(pModuleAbsolutePath, AbsolutePathSize, "%s/%s", pPath, str); + bFound |= stat(pModuleAbsolutePath, &statBuf) == 0; + } + return bFound; } diff --git a/unittests/tier1test/wscript b/unittests/tier1test/wscript index ba69010a..774398ba 100755 --- a/unittests/tier1test/wscript +++ b/unittests/tier1test/wscript @@ -14,7 +14,7 @@ def configure(conf): conf.define('TIER1TEST_EXPORTS', 1) def build(bld): - source = ['commandbuffertest.cpp', 'utlstringtest.cpp', 'tier1test.cpp'] + source = ['commandbuffertest.cpp', 'utlstringtest.cpp', 'tier1test.cpp'] #, 'lzsstest.cpp'] includes = ['../../public', '../../public/tier0'] defines = [] libs = ['tier0', 'tier1', 'mathlib', 'unitlib'] diff --git a/wscript b/wscript index d5487927..ef760ccc 100644 --- a/wscript +++ b/wscript @@ -165,7 +165,7 @@ def define_platform(conf): # conf.options.GL = False conf.define('DEDICATED', 1) - if conf.options.GL: + if conf.options.GL and not conf.options.TESTS: conf.env.append_unique('DEFINES', [ 'DX_TO_GL_ABSTRACTION', 'GL_GLEXT_PROTOTYPES', @@ -175,7 +175,7 @@ def define_platform(conf): if conf.options.TOGLES: conf.env.append_unique('DEFINES', ['TOGLES']) - if conf.options.SDL: + if conf.options.SDL and not conf.options.TESTS: conf.env.SDL = 1 conf.define('USE_SDL', 1) @@ -285,6 +285,111 @@ def options(opt): opt.load('msvc msdev msvs') opt.load('reconfigure') +def check_deps(conf): + if conf.env.DEST_OS != 'win32': + conf.check_cc(lib='dl', mandatory=False) + conf.check_cc(lib='bz2', mandatory=False) + conf.check_cc(lib='rt', mandatory=False) + + if not conf.env.LIB_M: # HACK: already added in xcompile! + conf.check_cc(lib='m') + else: + # Common Win32 libraries + # Don't check them more than once, to save time + # Usually, they are always available + # but we need them in uselib + a = [ + 'user32', + 'shell32', + 'gdi32', + 'advapi32', + 'dbghelp', + 'psapi', + 'ws2_32', + 'rpcrt4', + 'winmm', + 'wininet', + 'ole32', + 'shlwapi', + 'imm32' + ] + + if conf.env.COMPILER_CC == 'msvc': + for i in a: + conf.check_lib_msvc(i) + else: + for i in a: + conf.check_cc(lib = i) + + + if conf.options.TESTS: + return + + if conf.env.DEST_OS != 'android': + if conf.env.DEST_OS != 'win32': + if conf.options.SDL: + conf.check_cfg(package='sdl2', uselib_store='SDL2', args=['--cflags', '--libs']) + if conf.options.DEDICATED: + conf.check_cfg(package='libedit', uselib_store='EDIT', args=['--cflags', '--libs']) + else: + conf.check_pkg('freetype2', 'FT2', FT2_CHECK) + conf.check_pkg('fontconfig', 'FC', FC_CHECK) + if conf.env.DEST_OS == "darwin": + conf.env.FRAMEWORK_OPENAL = "OpenAL" + else: + conf.check_cfg(package='openal', uselib_store='OPENAL', args=['--cflags', '--libs']) + conf.check_cfg(package='libjpeg', uselib_store='JPEG', args=['--cflags', '--libs']) + conf.check_cfg(package='libpng', uselib_store='PNG', args=['--cflags', '--libs']) + conf.check_cfg(package='libcurl', uselib_store='CURL', args=['--cflags', '--libs']) + conf.check_cfg(package='zlib', uselib_store='ZLIB', args=['--cflags', '--libs']) + + if conf.options.OPUS: + conf.check_cfg(package='opus', uselib_store='OPUS', args=['--cflags', '--libs']) + else: + conf.check(lib='SDL2', uselib_store='SDL2') + conf.check(lib='freetype2', uselib_store='FT2') + conf.check(lib='jpeg', uselib_store='JPEG', define_name='HAVE_JPEG') + conf.check(lib='png', uselib_store='PNG', define_name='HAVE_PNG') + conf.check(lib='curl', uselib_store='CURL', define_name='HAVE_CURL') + conf.check(lib='z', uselib_store='ZLIB', define_name='HAVE_ZLIB') + if conf.env.DEST_CPU != 'aarch64': + conf.check(lib='unwind', uselib_store='UNWIND') + conf.check(lib='crypto', uselib_store='CRYPTO') + conf.check(lib='ssl', uselib_store='SSL') + conf.check(lib='android_support', uselib_store='ANDROID_SUPPORT') + conf.check(lib='opus', uselib_store='OPUS') + + if conf.env.DEST_OS == "darwin": + conf.check(lib='iconv', uselib_store='ICONV') + conf.env.FRAMEWORK_APPKIT = "AppKit" + conf.env.FRAMEWORK_IOKIT = "IOKit" + conf.env.FRAMEWORK_FOUNDATION = "Foundation" + conf.env.FRAMEWORK_COREFOUNDATION = "CoreFoundation" + conf.env.FRAMEWORK_COREGRAPHICS = "CoreGraphics" + conf.env.FRAMEWORK_OPENGL = "OpenGL" + conf.env.FRAMEWORK_CARBON = "Carbon" + conf.env.FRAMEWORK_APPLICATIONSERVICES = "ApplicationServices" + conf.env.FRAMEWORK_CORESERVICES = "CoreServices" + conf.env.FRAMEWORK_COREAUDIO = "CoreAudio" + conf.env.FRAMEWORK_AUDIOTOOLBOX = "AudioToolbox" + conf.env.FRAMEWORK_SYSTEMCONFIGURATION = "SystemConfiguration" + + if conf.env.DEST_OS == 'win32': + conf.check(lib='libz', uselib_store='ZLIB', define_name='USE_ZLIB') + # conf.check(lib='nvtc', uselib_store='NVTC') + # conf.check(lib='ati_compress_mt_vc10', uselib_store='ATI_COMPRESS_MT_VC10') + conf.check(lib='SDL2', uselib_store='SDL2') + conf.check(lib='libjpeg', uselib_store='JPEG', define_name='HAVE_JPEG') + conf.check(lib='libpng', uselib_store='PNG', define_name='HAVE_PNG') + conf.check(lib='d3dx9', uselib_store='D3DX9') + conf.check(lib='d3d9', uselib_store='D3D9') + conf.check(lib='dsound', uselib_store='DSOUND') + conf.check(lib='dxguid', uselib_store='DXGUID') + if conf.options.OPUS: + conf.check(lib='opus', uselib_store='OPUS') + + # conf.multicheck(*a, run_all_tests = True, mandatory = True) + def configure(conf): conf.load('fwgslib reconfigure compiler_optimizations') @@ -428,12 +533,6 @@ def configure(conf): cxxflags += ['-std=c++11','-fpermissive'] if conf.env.COMPILER_CC == 'gcc': -# wrapfunctions = ['freopen','creat','access','__xstat','stat','lstat','fopen64','open64', -# 'opendir','__lxstat','chmod','chown','lchown','symlink','link','__lxstat64','mknod', -# 'utimes','unlink','rename','utime','__xstat64','mount','mkdir','rmdir','scandir','realpath','mkfifo'] - -# for func in wrapfunctions: -# linkflags += ['-Wl,--wrap='+func] conf.define('COMPILER_GCC', 1) elif conf.env.COMPILER_CC == 'msvc': conf.define('COMPILER_MSVC', 1) @@ -459,104 +558,7 @@ def configure(conf): conf.env.append_unique('LINKFLAGS', linkflags) conf.env.append_unique('INCLUDES', [os.path.abspath('common/')]) - if conf.env.DEST_OS != 'android': - if conf.env.DEST_OS != 'win32': - if conf.options.SDL: - conf.check_cfg(package='sdl2', uselib_store='SDL2', args=['--cflags', '--libs']) - if conf.options.DEDICATED: - conf.check_cfg(package='libedit', uselib_store='EDIT', args=['--cflags', '--libs']) - else: - conf.check_pkg('freetype2', 'FT2', FT2_CHECK) - conf.check_pkg('fontconfig', 'FC', FC_CHECK) - if conf.env.DEST_OS == "darwin": - conf.env.FRAMEWORK_OPENAL = "OpenAL" - else: - conf.check_cfg(package='openal', uselib_store='OPENAL', args=['--cflags', '--libs']) - conf.check_cfg(package='libjpeg', uselib_store='JPEG', args=['--cflags', '--libs']) - conf.check_cfg(package='libpng', uselib_store='PNG', args=['--cflags', '--libs']) - conf.check_cfg(package='libcurl', uselib_store='CURL', args=['--cflags', '--libs']) - conf.check_cfg(package='zlib', uselib_store='ZLIB', args=['--cflags', '--libs']) - - if conf.options.OPUS: - conf.check_cfg(package='opus', uselib_store='OPUS', args=['--cflags', '--libs']) - else: - conf.check(lib='SDL2', uselib_store='SDL2') - conf.check(lib='freetype2', uselib_store='FT2') - conf.check(lib='jpeg', uselib_store='JPEG', define_name='HAVE_JPEG') - conf.check(lib='png', uselib_store='PNG', define_name='HAVE_PNG') - conf.check(lib='curl', uselib_store='CURL', define_name='HAVE_CURL') - conf.check(lib='z', uselib_store='ZLIB', define_name='HAVE_ZLIB') - if conf.env.DEST_CPU != 'aarch64': - conf.check(lib='unwind', uselib_store='UNWIND') - conf.check(lib='crypto', uselib_store='CRYPTO') - conf.check(lib='ssl', uselib_store='SSL') - conf.check(lib='android_support', uselib_store='ANDROID_SUPPORT') - conf.check(lib='opus', uselib_store='OPUS') - - if conf.env.DEST_OS == "darwin": - conf.check(lib='iconv', uselib_store='ICONV') - conf.env.FRAMEWORK_APPKIT = "AppKit" - conf.env.FRAMEWORK_IOKIT = "IOKit" - conf.env.FRAMEWORK_FOUNDATION = "Foundation" - conf.env.FRAMEWORK_COREFOUNDATION = "CoreFoundation" - conf.env.FRAMEWORK_COREGRAPHICS = "CoreGraphics" - conf.env.FRAMEWORK_OPENGL = "OpenGL" - conf.env.FRAMEWORK_CARBON = "Carbon" - conf.env.FRAMEWORK_APPLICATIONSERVICES = "ApplicationServices" - conf.env.FRAMEWORK_CORESERVICES = "CoreServices" - conf.env.FRAMEWORK_COREAUDIO = "CoreAudio" - conf.env.FRAMEWORK_AUDIOTOOLBOX = "AudioToolbox" - conf.env.FRAMEWORK_SYSTEMCONFIGURATION = "SystemConfiguration" - - if conf.env.DEST_OS != 'win32': - conf.check_cc(lib='dl', mandatory=False) - conf.check_cc(lib='bz2', mandatory=False) - conf.check_cc(lib='rt', mandatory=False) - - if not conf.env.LIB_M: # HACK: already added in xcompile! - conf.check_cc(lib='m') - else: - # Common Win32 libraries - # Don't check them more than once, to save time - # Usually, they are always available - # but we need them in uselib - a = [ - 'user32', - 'shell32', - 'gdi32', - 'advapi32', - 'dbghelp', - 'psapi', - 'ws2_32', - 'rpcrt4', - 'winmm', - 'wininet', - 'ole32', - 'shlwapi', - 'imm32' - ] - - if conf.env.COMPILER_CC == 'msvc': - for i in a: - conf.check_lib_msvc(i) - else: - for i in a: - conf.check_cc(lib = i) - - conf.check(lib='libz', uselib_store='ZLIB', define_name='USE_ZLIB') - # conf.check(lib='nvtc', uselib_store='NVTC') - # conf.check(lib='ati_compress_mt_vc10', uselib_store='ATI_COMPRESS_MT_VC10') - conf.check(lib='SDL2', uselib_store='SDL2') - conf.check(lib='libjpeg', uselib_store='JPEG', define_name='HAVE_JPEG') - conf.check(lib='libpng', uselib_store='PNG', define_name='HAVE_PNG') - conf.check(lib='d3dx9', uselib_store='D3DX9') - conf.check(lib='d3d9', uselib_store='D3D9') - conf.check(lib='dsound', uselib_store='DSOUND') - conf.check(lib='dxguid', uselib_store='DXGUID') - if conf.options.OPUS: - conf.check(lib='opus', uselib_store='OPUS') - - # conf.multicheck(*a, run_all_tests = True, mandatory = True) + check_deps( conf ) # indicate if we are packaging for Linux/BSD if conf.env.DEST_OS != 'android':