From 1ccbe2bbb62cf9ef10bb113f0ff9d24672ed5721 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Sun, 23 Apr 2023 23:45:09 +0300 Subject: [PATCH] unitests: add mathlib test --- .../mathlibtest/mathlib_performance_test.cpp | 41 ++++++++++++++++++ unittests/mathlibtest/mathlib_test.cpp | 43 +++++++++++++++++++ unittests/mathlibtest/wscript | 39 +++++++++++++++++ wscript | 2 + 4 files changed, 125 insertions(+) create mode 100644 unittests/mathlibtest/mathlib_performance_test.cpp create mode 100644 unittests/mathlibtest/mathlib_test.cpp create mode 100755 unittests/mathlibtest/wscript diff --git a/unittests/mathlibtest/mathlib_performance_test.cpp b/unittests/mathlibtest/mathlib_performance_test.cpp new file mode 100644 index 00000000..6058ed25 --- /dev/null +++ b/unittests/mathlibtest/mathlib_performance_test.cpp @@ -0,0 +1,41 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Unit test program for CommandBuffer +// +// $NoKeywords: $ +//=============================================================================// + +#include "unitlib/unitlib.h" +#include "tier1/CommandBuffer.h" +#include "tier1/strtools.h" +#include "tier0/platform.h" +#include "tier0/fasttimer.h" + + +DEFINE_TESTSUITE( MathlibTestSuite ) + +DEFINE_TESTCASE( MathlibTestSSE, MathlibTestSuite ) +{ + CFastTimer timer; + timer.Start(); + + float sum = 0.f; + + for( float a = 0.f; a <= M_PI; a += 0.000001f ) + sum += sinf(a); + + timer.End(); + + Msg("cos Cycles: %llu\n", timer.GetDuration().GetLongCycles()); + Msg("cos sum - %f\n", sum); + + timer.Start(); + + for( float a = 0.f; a <= M_PI; a += 0.000001f ) + sum += FastCos(a); + + timer.End(); + + Msg("ssecos Cycles: %llu\n", timer.GetDuration().GetLongCycles()); + Msg("ssecos sum - %f\n", sum); +} diff --git a/unittests/mathlibtest/mathlib_test.cpp b/unittests/mathlibtest/mathlib_test.cpp new file mode 100644 index 00000000..36d01847 --- /dev/null +++ b/unittests/mathlibtest/mathlib_test.cpp @@ -0,0 +1,43 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Unit test program for testing of mathlib +// +// $NoKeywords: $ +//=============================================================================// + +#include "unitlib/unitlib.h" +#include "filesystem.h" +#include "tier2/tier2.h" +#include "mathlib/mathlib.h" + +//----------------------------------------------------------------------------- +// Used to connect/disconnect the DLL +//----------------------------------------------------------------------------- +class CTier2TestAppSystem : public CTier2AppSystem< IAppSystem > +{ + typedef CTier2AppSystem< IAppSystem > BaseClass; + +public: + virtual bool Connect( CreateInterfaceFn factory ) + { + if ( !BaseClass::Connect( factory ) ) + return false; + + if ( !g_pFullFileSystem ) + return false; + return true; + } + + virtual InitReturnVal_t Init() + { + MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f ); + + InitReturnVal_t nRetVal = BaseClass::Init(); + if ( nRetVal != INIT_OK ) + return nRetVal; + + return INIT_OK; + } +}; + +USE_UNITTEST_APPSYSTEM( CTier2TestAppSystem ) diff --git a/unittests/mathlibtest/wscript b/unittests/mathlibtest/wscript new file mode 100755 index 00000000..5015ee71 --- /dev/null +++ b/unittests/mathlibtest/wscript @@ -0,0 +1,39 @@ +#! /usr/bin/env python +# encoding: utf-8 + +from waflib import Utils +import os + +top = '.' +PROJECT_NAME = 'mathlibtest' + +def options(opt): + return + +def configure(conf): + conf.define('TIER2TEST_EXPORTS', 1) + +def build(bld): + source = ['mathlib_performance_test.cpp', 'mathlib_test.cpp'] + includes = ['../../public', '../../public/tier0'] + defines = [] + libs = ['tier0', 'tier1','tier2', 'mathlib', 'unitlib'] + + if bld.env.DEST_OS != 'win32': + libs += [ 'DL', 'LOG' ] + else: + libs += ['USER32', 'SHELL32'] + + install_path = bld.env.TESTDIR + bld.shlib( + source = source, + target = PROJECT_NAME, + name = PROJECT_NAME, + features = 'c cxx', + includes = includes, + defines = defines, + use = libs, + install_path = install_path, + subsystem = bld.env.MSVC_SUBSYSTEM, + idx = bld.get_taskgen_count() + ) diff --git a/wscript b/wscript index ef760ccc..7441473c 100644 --- a/wscript +++ b/wscript @@ -51,6 +51,7 @@ projects={ 'launcher', 'launcher_main', 'materialsystem', +# 'materialsystem/shaderapiempty', 'materialsystem/shaderapidx9', 'materialsystem/shaderlib', 'materialsystem/stdshaders', @@ -94,6 +95,7 @@ projects={ 'unittests/tier1test', 'unittests/tier2test', 'unittests/tier3test', + 'unittests/mathlibtest', 'utils/unittest' ], 'dedicated': [