Make library work on unix again
This commit is contained in:
parent
540deb4774
commit
6fcf111d2d
@ -47,7 +47,7 @@ enum class Status
|
|||||||
Error
|
Error
|
||||||
};
|
};
|
||||||
|
|
||||||
void Log(Status status, char *fmt, va_list argList)
|
void Log(Status status, char const *fmt, va_list argList)
|
||||||
{
|
{
|
||||||
DQN_ASSERT(globalIndent >= 0);
|
DQN_ASSERT(globalIndent >= 0);
|
||||||
LOCAL_PERSIST i32 lineLen = 0;
|
LOCAL_PERSIST i32 lineLen = 0;
|
||||||
@ -56,7 +56,7 @@ void Log(Status status, char *fmt, va_list argList)
|
|||||||
i32 bufLen = 0;
|
i32 bufLen = 0;
|
||||||
{
|
{
|
||||||
bufLen = Dqn_vsprintf(buf, fmt, argList);
|
bufLen = Dqn_vsprintf(buf, fmt, argList);
|
||||||
DQN_ASSERT(bufLen < DQN_ARRAY_COUNT(buf));
|
DQN_ASSERT(bufLen < (i32)DQN_ARRAY_COUNT(buf));
|
||||||
lineLen += bufLen;
|
lineLen += bufLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ void Log(Status status, char *fmt, va_list argList)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log(Status status, char *fmt, ...)
|
void Log(Status status, char const *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list argList;
|
va_list argList;
|
||||||
va_start(argList, fmt);
|
va_start(argList, fmt);
|
||||||
@ -121,7 +121,7 @@ void Log(Status status, char *fmt, ...)
|
|||||||
va_end(argList);
|
va_end(argList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log(char *fmt, ...)
|
void Log(char const *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list argList;
|
va_list argList;
|
||||||
va_start(argList, fmt);
|
va_start(argList, fmt);
|
||||||
@ -129,7 +129,7 @@ void Log(char *fmt, ...)
|
|||||||
va_end(argList);
|
va_end(argList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogHeader(char *funcName)
|
void LogHeader(char const *funcName)
|
||||||
{
|
{
|
||||||
globalIndent--;
|
globalIndent--;
|
||||||
Log("\n[%s]", funcName);
|
Log("\n[%s]", funcName);
|
||||||
@ -707,17 +707,6 @@ void DqnString_Test()
|
|||||||
str.Free();
|
str.Free();
|
||||||
Log(Status::Ok, "Check expand on append");
|
Log(Status::Ok, "Check expand on append");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try init literal no alloc
|
|
||||||
if (1)
|
|
||||||
{
|
|
||||||
char *literal = "this is a literal string";
|
|
||||||
DqnString str = {};
|
|
||||||
DQN_ASSERT(str.InitLiteralNoAlloc(literal));
|
|
||||||
DQN_ASSERT(str.Append(", hello again") == false);
|
|
||||||
str.Free();
|
|
||||||
Log(Status::Ok, "Try init literal no alloc, can't expand");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DqnTimer_Test()
|
void DqnTimer_Test()
|
||||||
@ -726,13 +715,14 @@ void DqnTimer_Test()
|
|||||||
|
|
||||||
if (1)
|
if (1)
|
||||||
{
|
{
|
||||||
|
|
||||||
#if defined(DQN_UNIX_PLATFORM)
|
#if defined(DQN_UNIX_PLATFORM)
|
||||||
f64 startInS = DqnTimer_NowInS();
|
f64 startInMs = DqnTimer_NowInMs();
|
||||||
u32 sleepTimeInS = 1;
|
u32 sleepTimeInMs = 1;
|
||||||
sleep(sleepTimeInS);
|
sleep(sleepTimeInMs);
|
||||||
f64 endInS = DqnTimer_NowInS();
|
f64 endInMs = DqnTimer_NowInMs();
|
||||||
Log("start: %f, end: %f", startInS, endInS);
|
Log("start: %f, end: %f", startInMs, endInMs);
|
||||||
DQN_ASSERT((startInS + sleepTimeInS) <= endInS);
|
DQN_ASSERT((startInMs + sleepTimeInMs) <= endInMs);
|
||||||
|
|
||||||
#elif defined(DQN_WIN32_PLATFORM)
|
#elif defined(DQN_WIN32_PLATFORM)
|
||||||
f64 startInMs = DqnTimer_NowInMs();
|
f64 startInMs = DqnTimer_NowInMs();
|
||||||
@ -1577,7 +1567,7 @@ void DqnArray_TestRealDataInternal(DqnArray<char> *array)
|
|||||||
u8 *buf = DqnFile::ReadEntireFile("tests/google-10000-english.txt", &bufSize);
|
u8 *buf = DqnFile::ReadEntireFile("tests/google-10000-english.txt", &bufSize);
|
||||||
DQN_ASSERT(buf);
|
DQN_ASSERT(buf);
|
||||||
|
|
||||||
for (auto i = 0; i < bufSize; i++)
|
for (usize i = 0; i < bufSize; i++)
|
||||||
array->Push(buf[i]);
|
array->Push(buf[i]);
|
||||||
|
|
||||||
DQN_ASSERT((size_t)array->count == bufSize);
|
DQN_ASSERT((size_t)array->count == bufSize);
|
||||||
@ -1631,7 +1621,6 @@ void DqnArray_Test()
|
|||||||
if (1)
|
if (1)
|
||||||
{
|
{
|
||||||
DqnMemStack stack = {}; stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard);
|
DqnMemStack stack = {}; stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard);
|
||||||
DqnMemAPI memAPI = DqnMemAPI::StackAllocator(&stack);
|
|
||||||
|
|
||||||
if (1)
|
if (1)
|
||||||
{
|
{
|
||||||
@ -1681,7 +1670,7 @@ void DqnFile_Test()
|
|||||||
// should give us zero, but we fall back to manual byte checking
|
// should give us zero, but we fall back to manual byte checking
|
||||||
// which should give us the proper size.
|
// which should give us the proper size.
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
DQN_ASSERT(DqnFile_GetFileSize("/proc/cpuinfo", &size));
|
DQN_ASSERT(DqnFile::GetFileSize("/proc/cpuinfo", &size));
|
||||||
DQN_ASSERT(size > 0);
|
DQN_ASSERT(size > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1866,8 +1855,7 @@ void DqnFile_Test()
|
|||||||
FILE_SCOPE u32 volatile globalDebugCounter;
|
FILE_SCOPE u32 volatile globalDebugCounter;
|
||||||
FILE_SCOPE DqnLock globalJobQueueLock;
|
FILE_SCOPE DqnLock globalJobQueueLock;
|
||||||
const u32 QUEUE_SIZE = 256;
|
const u32 QUEUE_SIZE = 256;
|
||||||
FILE_SCOPE void JobQueueDebugCallbackIncrementCounter(DqnJobQueue *const queue,
|
FILE_SCOPE void JobQueueDebugCallbackIncrementCounter(DqnJobQueue *const queue, void *const userData)
|
||||||
void *const userData)
|
|
||||||
{
|
{
|
||||||
(void)userData;
|
(void)userData;
|
||||||
DQN_ASSERT(queue->size == QUEUE_SIZE);
|
DQN_ASSERT(queue->size == QUEUE_SIZE);
|
||||||
@ -1875,15 +1863,11 @@ FILE_SCOPE void JobQueueDebugCallbackIncrementCounter(DqnJobQueue *const queue,
|
|||||||
DqnLockGuard guard = globalJobQueueLock.LockGuard();
|
DqnLockGuard guard = globalJobQueueLock.LockGuard();
|
||||||
globalDebugCounter++;
|
globalDebugCounter++;
|
||||||
|
|
||||||
#if 0
|
|
||||||
u32 number = globalDebugCounter;
|
u32 number = globalDebugCounter;
|
||||||
#if defined(DQN_WIN32_IMPLEMENTATION)
|
#if defined(DQN_WIN32_IMPLEMENTATION)
|
||||||
Log("JobQueueDebugCallbackIncrementCounter(): Thread %d: Incrementing Number: %d\n",
|
Log("JobQueueDebugCallbackIncrementCounter(): Thread %d: Incrementing Number: %d", GetCurrentThreadId(), number);
|
||||||
GetCurrentThreadId(), number);
|
|
||||||
#elif defined(DQN_UNIX_IMPLEMENTATION)
|
#elif defined(DQN_UNIX_IMPLEMENTATION)
|
||||||
Log("JobQueueDebugCallbackIncrementCounter(): Thread unix: Incrementing Number: %d\n",
|
Log("JobQueueDebugCallbackIncrementCounter(): Thread unix: Incrementing Number: %d", number);
|
||||||
number);
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2314,16 +2298,18 @@ void DqnMemSet_Test()
|
|||||||
for (auto testIndex = 0; testIndex < size; testIndex++)
|
for (auto testIndex = 0; testIndex < size; testIndex++)
|
||||||
{
|
{
|
||||||
DQN_ASSERT(((u8 *)buffers[0])[testIndex] == ((u8 *)buffers[1])[testIndex]);
|
DQN_ASSERT(((u8 *)buffers[0])[testIndex] == ((u8 *)buffers[1])[testIndex]);
|
||||||
|
#if defined(DQN_WIN32_IMPLEMENTATION)
|
||||||
DQN_ASSERT(((u8 *)buffers[1])[testIndex] == ((u8 *)buffers[2])[testIndex]);
|
DQN_ASSERT(((u8 *)buffers[1])[testIndex] == ((u8 *)buffers[2])[testIndex]);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto bufferIndex = 0; bufferIndex < DQN_ARRAY_COUNT(buffers); bufferIndex++)
|
for (usize bufferIndex = 0; bufferIndex < DQN_ARRAY_COUNT(buffers); bufferIndex++)
|
||||||
{
|
{
|
||||||
free(buffers[bufferIndex]);
|
free(buffers[bufferIndex]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto timingsIndex = 0; timingsIndex < DQN_ARRAY_COUNT(timings); timingsIndex++)
|
for (usize timingsIndex = 0; timingsIndex < DQN_ARRAY_COUNT(timings); timingsIndex++)
|
||||||
{
|
{
|
||||||
f64 totalTime = 0;
|
f64 totalTime = 0;
|
||||||
for (auto iterationIndex = 0; iterationIndex < NUM_ITERATIONS; iterationIndex++)
|
for (auto iterationIndex = 0; iterationIndex < NUM_ITERATIONS; iterationIndex++)
|
||||||
@ -2897,15 +2883,14 @@ int main(void)
|
|||||||
{
|
{
|
||||||
globalIndent = 1;
|
globalIndent = 1;
|
||||||
globalNewLine = true;
|
globalNewLine = true;
|
||||||
|
|
||||||
DqnString_Test();
|
DqnString_Test();
|
||||||
|
DqnMemStack_Test();
|
||||||
DqnChar_Test();
|
DqnChar_Test();
|
||||||
DqnRnd_Test();
|
DqnRnd_Test();
|
||||||
DqnMath_Test();
|
DqnMath_Test();
|
||||||
DqnVX_Test();
|
DqnVX_Test();
|
||||||
DqnRect_Test();
|
DqnRect_Test();
|
||||||
DqnArray_Test();
|
DqnArray_Test();
|
||||||
DqnMemStack_Test();
|
|
||||||
DqnQuickSort_Test();
|
DqnQuickSort_Test();
|
||||||
DqnHashTable_Test();
|
DqnHashTable_Test();
|
||||||
Dqn_BSearch_Test();
|
Dqn_BSearch_Test();
|
||||||
|
Loading…
Reference in New Issue
Block a user