Skip to content

Commit 1ccbe2b

Browse files
committed
unitests: add mathlib test
1 parent 7d00b04 commit 1ccbe2b

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//========= Copyright Valve Corporation, All rights reserved. ============//
2+
//
3+
// Purpose: Unit test program for CommandBuffer
4+
//
5+
// $NoKeywords: $
6+
//=============================================================================//
7+
8+
#include "unitlib/unitlib.h"
9+
#include "tier1/CommandBuffer.h"
10+
#include "tier1/strtools.h"
11+
#include "tier0/platform.h"
12+
#include "tier0/fasttimer.h"
13+
14+
15+
DEFINE_TESTSUITE( MathlibTestSuite )
16+
17+
DEFINE_TESTCASE( MathlibTestSSE, MathlibTestSuite )
18+
{
19+
CFastTimer timer;
20+
timer.Start();
21+
22+
float sum = 0.f;
23+
24+
for( float a = 0.f; a <= M_PI; a += 0.000001f )
25+
sum += sinf(a);
26+
27+
timer.End();
28+
29+
Msg("cos Cycles: %llu\n", timer.GetDuration().GetLongCycles());
30+
Msg("cos sum - %f\n", sum);
31+
32+
timer.Start();
33+
34+
for( float a = 0.f; a <= M_PI; a += 0.000001f )
35+
sum += FastCos(a);
36+
37+
timer.End();
38+
39+
Msg("ssecos Cycles: %llu\n", timer.GetDuration().GetLongCycles());
40+
Msg("ssecos sum - %f\n", sum);
41+
}
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//========= Copyright Valve Corporation, All rights reserved. ============//
2+
//
3+
// Purpose: Unit test program for testing of mathlib
4+
//
5+
// $NoKeywords: $
6+
//=============================================================================//
7+
8+
#include "unitlib/unitlib.h"
9+
#include "filesystem.h"
10+
#include "tier2/tier2.h"
11+
#include "mathlib/mathlib.h"
12+
13+
//-----------------------------------------------------------------------------
14+
// Used to connect/disconnect the DLL
15+
//-----------------------------------------------------------------------------
16+
class CTier2TestAppSystem : public CTier2AppSystem< IAppSystem >
17+
{
18+
typedef CTier2AppSystem< IAppSystem > BaseClass;
19+
20+
public:
21+
virtual bool Connect( CreateInterfaceFn factory )
22+
{
23+
if ( !BaseClass::Connect( factory ) )
24+
return false;
25+
26+
if ( !g_pFullFileSystem )
27+
return false;
28+
return true;
29+
}
30+
31+
virtual InitReturnVal_t Init()
32+
{
33+
MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f );
34+
35+
InitReturnVal_t nRetVal = BaseClass::Init();
36+
if ( nRetVal != INIT_OK )
37+
return nRetVal;
38+
39+
return INIT_OK;
40+
}
41+
};
42+
43+
USE_UNITTEST_APPSYSTEM( CTier2TestAppSystem )

unittests/mathlibtest/wscript

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#! /usr/bin/env python
2+
# encoding: utf-8
3+
4+
from waflib import Utils
5+
import os
6+
7+
top = '.'
8+
PROJECT_NAME = 'mathlibtest'
9+
10+
def options(opt):
11+
return
12+
13+
def configure(conf):
14+
conf.define('TIER2TEST_EXPORTS', 1)
15+
16+
def build(bld):
17+
source = ['mathlib_performance_test.cpp', 'mathlib_test.cpp']
18+
includes = ['../../public', '../../public/tier0']
19+
defines = []
20+
libs = ['tier0', 'tier1','tier2', 'mathlib', 'unitlib']
21+
22+
if bld.env.DEST_OS != 'win32':
23+
libs += [ 'DL', 'LOG' ]
24+
else:
25+
libs += ['USER32', 'SHELL32']
26+
27+
install_path = bld.env.TESTDIR
28+
bld.shlib(
29+
source = source,
30+
target = PROJECT_NAME,
31+
name = PROJECT_NAME,
32+
features = 'c cxx',
33+
includes = includes,
34+
defines = defines,
35+
use = libs,
36+
install_path = install_path,
37+
subsystem = bld.env.MSVC_SUBSYSTEM,
38+
idx = bld.get_taskgen_count()
39+
)

wscript

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ projects={
5151
'launcher',
5252
'launcher_main',
5353
'materialsystem',
54+
# 'materialsystem/shaderapiempty',
5455
'materialsystem/shaderapidx9',
5556
'materialsystem/shaderlib',
5657
'materialsystem/stdshaders',
@@ -94,6 +95,7 @@ projects={
9495
'unittests/tier1test',
9596
'unittests/tier2test',
9697
'unittests/tier3test',
98+
'unittests/mathlibtest',
9799
'utils/unittest'
98100
],
99101
'dedicated': [

0 commit comments

Comments
 (0)