Decouple <cstdint>

This commit is contained in:
Martin Natano
2023-04-21 22:13:41 +02:00
parent bcea05dd67
commit aa87f85eef
167 changed files with 1533 additions and 1307 deletions
+14 -13
View File
@@ -9,6 +9,7 @@
#include "test_misc.h"
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -45,7 +46,7 @@ void dump_bin( const char *fn, const char *buf, int size )
close( fd );
}
void dump( const char *fn, const int16_t *buf, int samples )
void dump( const char *fn, const std::int16_t *buf, int samples )
{
FILE *f = fopen( fn, "w+");
ASSERT( f );
@@ -71,7 +72,7 @@ void dump( const char *buf, int size )
printf("\n\n");
}
void dump( const int16_t *buf, int samples )
void dump( const std::int16_t *buf, int samples )
{
for( int i = 0; i < samples; ++i )
printf( "0x%04hx,", buf[i] );
@@ -85,11 +86,11 @@ void dump( const float *buf, int samples )
printf( "\n" );
}
bool compare( const float *m1, const int16_t *m2, int iSamples )
bool compare( const float *m1, const std::int16_t *m2, int iSamples )
{
for( int i = 0; i < iSamples; ++i )
{
int16_t iSample1 = std::lrint(m1[i]*32768);
std::int16_t iSample1 = std::lrint(m1[i]*32768);
if( iSample1 != m2[i] )
return false;
}
@@ -98,7 +99,7 @@ bool compare( const float *m1, const int16_t *m2, int iSamples )
}
void compare_buffers( const int16_t *expect, const int16_t *got, int frames,
void compare_buffers( const std::int16_t *expect, const std::int16_t *got, int frames,
int &NumInaccurateSamplesAtStart,
int &NumInaccurateSamples )
{
@@ -124,7 +125,7 @@ void compare_buffers( const int16_t *expect, const int16_t *got, int frames,
}
bool compare_buffers( const int16_t *expect, const int16_t *got, int frames, int channels )
bool compare_buffers( const std::int16_t *expect, const std::int16_t *got, int frames, int channels )
{
/*
* Compare each channel separately. Try to figure out if
@@ -164,8 +165,8 @@ bool test_read( RageSoundReader *snd, float *expected_data, int frames )
int got = snd->Read( buf, frames );
ASSERT( got == frames );
//compare_buffers( (const int16_t *) expected_data,
// (const int16_t *) buf,
//compare_buffers( (const std::int16_t *) expected_data,
// (const std::int16_t *) buf,
// bytes/2,
// 2 );
@@ -257,7 +258,7 @@ const int TestDataSize = 2;
/* Find "haystack" in "needle". Start looking at "expect" and move outward; find
* the closest. */
void *xmemsearch( const float *haystack, std::size_t iHaystackSamples,
const int16_t *needle, std::size_t iNeedleSamples,
const std::int16_t *needle, std::size_t iNeedleSamples,
int expect )
{
if( !iNeedleSamples )
@@ -300,10 +301,10 @@ struct TestFile
int SilentFrames;
/* The first two frames (four samples): */
int16_t initial[TestDataSize*2];
std::int16_t initial[TestDataSize*2];
/* Frames of data half a second in: */
int16_t later[TestDataSize*2];
std::int16_t later[TestDataSize*2];
};
const int channels = 2;
@@ -377,7 +378,7 @@ bool RunTests( RageSoundReader *snd, const TestFile &tf )
dump( LaterData, 16 );
/* See if we can find the half second data. */
float *p = (float *) xmemsearch( sdata, one_second_bytes, tf.later, sizeof(tf.later), LaterOffsetSamples*sizeof(int16_t) );
float *p = (float *) xmemsearch( sdata, one_second_bytes, tf.later, sizeof(tf.later), LaterOffsetSamples*sizeof(std::int16_t) );
if( p )
{
int SamplesOff = p-sdata;
@@ -386,7 +387,7 @@ bool RunTests( RageSoundReader *snd, const TestFile &tf )
FramesOff, LaterOffsetFrames, FramesOff-LaterOffsetFrames );
}
// else
// dump( "foo", sdata, one_second/sizeof(int16_t) );
// dump( "foo", sdata, one_second/sizeof(std::int16_t) );
}
}
+23 -22
View File
@@ -6,11 +6,12 @@
#include "archutils/Unix/BacktraceNames.h"
#include "test_misc.h"
#include <cstdint>
#include <unistd.h>
#include "archutils/Common/PthreadHelpers.h"
/* These are volatile, so writes to them aren't optimized. */
volatile uint64_t g_ThreadId = (uint64_t) -1;
volatile std::uint64_t g_ThreadId = (std::uint64_t) -1;
volatile int g_Counter = 0;
volatile bool g_Finish = false;
@@ -30,11 +31,11 @@ int TestSuspendThread( void *p )
return 0;
}
void test_suspend_threadid( uint64_t ThreadId )
void test_suspend_threadid( std::uint64_t ThreadId )
{
/* Wait for g_Counter to increment a bit. */
usleep( 100000 );
/* Stop the thread. */
SuspendThread( ThreadId );
@@ -73,21 +74,21 @@ void test_suspend_threadid( uint64_t ThreadId )
void test_suspend_secondary_thread()
{
ASSERT( !g_Finish );
ASSERT( g_ThreadId == (uint64_t) -1 );
ASSERT( g_ThreadId == (std::uint64_t) -1 );
RageThread testing;
testing.SetName( "TestSuspend" );
testing.Create( TestSuspendThread, NULL );
while( g_ThreadId == (uint64_t) -1 )
while( g_ThreadId == (std::uint64_t) -1 )
;
test_suspend_threadid( g_ThreadId );
g_Finish = true;
testing.Wait();
g_Finish = false;
g_ThreadId = (uint64_t) -1;
g_ThreadId = (std::uint64_t) -1;
}
int TestSuspendMainThread( void *p )
@@ -96,7 +97,7 @@ int TestSuspendMainThread( void *p )
printf("Test thread started\n");
ASSERT( g_ThreadId != (uint64_t) -1 );
ASSERT( g_ThreadId != (std::uint64_t) -1 );
test_suspend_threadid( g_ThreadId );
g_Finish = true;
@@ -107,7 +108,7 @@ int TestSuspendMainThread( void *p )
void test_suspend_main_thread()
{
ASSERT( !g_Finish );
ASSERT( g_ThreadId == (uint64_t) -1 );
ASSERT( g_ThreadId == (std::uint64_t) -1 );
g_ThreadId = GetCurrentThreadId();
@@ -119,7 +120,7 @@ void test_suspend_main_thread()
testing.Wait();
g_Finish = false;
g_ThreadId = (uint64_t) -1;
g_ThreadId = (std::uint64_t) -1;
}
/* Run a second function, so we have two symbols to search for. */
@@ -143,7 +144,7 @@ bool test_thread_backtrace( int ThreadId, const void *expect1, const void *expec
BacktraceContext ctx;
int ret = GetThreadBacktraceContext( ThreadId, &ctx );
ASSERT( ret );
const void *BacktracePointers[1024];
GetBacktrace( BacktracePointers, 1024, &ctx );
@@ -177,9 +178,9 @@ void test_backtracing_secondary_thread()
testing.SetName( "TestBacktrace" );
testing.Create( TestBacktraceThread, NULL );
while( g_ThreadId == (uint64_t) -1 )
while( g_ThreadId == (std::uint64_t) -1 )
;
if( !test_thread_backtrace( g_ThreadId, (void *) TestBacktraceThread, (void *) TestBacktraceThreadLoop ) )
{
printf( "test_backtracing_secondary_thread failed\n" );
@@ -189,16 +190,16 @@ void test_backtracing_secondary_thread()
g_Finish = true;
testing.Wait();
g_Finish = false;
g_ThreadId = (uint64_t) -1;
g_ThreadId = (std::uint64_t) -1;
}
int TestBacktraceMainThread( void *p )
{
printf("Test thread started\n");
while( g_ThreadId == (uint64_t) -1 )
while( g_ThreadId == (std::uint64_t) -1 )
;
if( !test_thread_backtrace( g_ThreadId, (void *) TestBacktraceThread, (void *) TestBacktraceThreadLoop ) )
{
printf( "test_backtracing_main_thread failed\n" );
@@ -213,7 +214,7 @@ int TestBacktraceMainThread( void *p )
void test_backtracing_main_thread()
{
ASSERT( !g_Finish );
ASSERT( g_ThreadId == (uint64_t) -1 );
ASSERT( g_ThreadId == (std::uint64_t) -1 );
RageThread testing;
testing.SetName( "TestBacktrace" );
@@ -223,7 +224,7 @@ void test_backtracing_main_thread()
testing.Wait();
g_Finish = false;
g_ThreadId = (uint64_t) -1;
g_ThreadId = (std::uint64_t) -1;
}
static RageMutex g_Mutex("test");
@@ -247,13 +248,13 @@ int TestLocksThread( void *p )
void test_locks()
{
ASSERT( !g_Finish );
ASSERT( g_ThreadId == (uint64_t) -1 );
ASSERT( g_ThreadId == (std::uint64_t) -1 );
RageThread testing;
testing.SetName( "TestLocks" );
testing.Create( TestLocksThread, NULL );
while( g_ThreadId == (uint64_t) -1 )
while( g_ThreadId == (std::uint64_t) -1 )
;
/* Stop the thread. */
@@ -276,7 +277,7 @@ void test_locks()
g_Finish = true;
testing.Wait();
g_Finish = false;
g_ThreadId = (uint64_t) -1;
g_ThreadId = (std::uint64_t) -1;
}
void go()
@@ -284,7 +285,7 @@ void go()
/* Test the main thread suspending a secondary thread, and vice versa. */
test_suspend_secondary_thread();
test_suspend_main_thread();
/* Test the main thread backtracing a secondary thread, and vice versa. */
test_backtracing_secondary_thread();
test_backtracing_main_thread();
+9 -8
View File
@@ -1,9 +1,10 @@
#define _XOPEN_SOURCE 600
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <archutils/Darwin/VectorHelper.h>
@@ -36,7 +37,7 @@ static void ScalarWrite( float *pDestBuf, const float *pSrcBuf, std::size_t iSiz
}
#if 0
static void ScalarRead( int16_t *pDestBuf, const int32_t *pSrcBuf, unsigned iSize )
static void ScalarRead( std::int16_t *pDestBuf, const std::int32_t *pSrcBuf, unsigned iSize )
{
for( unsigned iPos = 0; iPos < iSize; ++iPos )
pDestBuf[iPos] = std::max( -32768, std::min(pSrcBuf[iPos]/256, 32767) );
@@ -197,7 +198,7 @@ static bool CheckMisalignedBothWrite()
return ret;
}
static bool cmp( const int16_t *p1, const int16_t *p2, std::size_t size )
static bool cmp( const std::int16_t *p1, const std::int16_t *p2, std::size_t size )
{
return !memcmp( p1, p2, size * 2 );
}
@@ -216,7 +217,7 @@ template<typename T>
static bool CheckAlignedRead()
{
const std::size_t size = 1024;
int32_t *pSrcBuf = NEW( int32_t, size );
std::int32_t *pSrcBuf = NEW( std::int32_t, size );
T *pDestBuf = NEW( T, size );
T *pRefBuf = NEW( T, size );
bool ret = true;
@@ -245,7 +246,7 @@ template<typename T>
static bool CheckMisalignedRead()
{
const std::size_t size = 1024;
int32_t *pSrcBuf = NEW( int32_t, size );
std::int32_t *pSrcBuf = NEW( std::int32_t, size );
T *pDestBuf = NEW( T, size );
T *pRefBuf = NEW( T, size );
bool ret = true;
@@ -303,7 +304,7 @@ int main()
return 1;
}
#if 0
if( !CheckAlignedRead<int16_t>() )
if( !CheckAlignedRead<std::int16_t>() )
{
fputs( "Failed aligned read.\n", stderr );
return 1;
@@ -313,7 +314,7 @@ int main()
fputs( "Failed aligned float read.\n", stderr );
return 1;
}
if( !CheckMisalignedRead<int16_t>() )
if( !CheckMisalignedRead<std::int16_t>() )
{
fputs( "Failed misaligned read.\n", stderr );
return 1;