Browse Source

Remove namespace from internal error simulator

Kajetan Johannes Hammerle 9 months ago
parent
commit
1b47dc0d67
6 changed files with 39 additions and 40 deletions
  1. 6 6
      src/ErrorSimulator.c
  2. 18 18
      src/ErrorSimulator.h
  3. 4 5
      src/ReadLine.c
  4. 1 1
      src/Utility.c
  5. 8 8
      test/modules/ReadLineTests.c
  6. 2 2
      test/modules/UtilityTests.c

+ 6 - 6
src/ErrorSimulator.c

@@ -2,11 +2,11 @@
 
 #include "ErrorSimulator.h"
 
-bool coreFailFileClose = false;
-bool coreFailTimeGet = false;
-bool coreFailThreadInit = false;
-bool coreFailMutexInit = false;
-bool coreFailMutexLock = false;
-bool coreFailMutexUnlock = false;
+bool failFileClose = false;
+bool failTimeGet = false;
+bool failThreadInit = false;
+bool failMutexInit = false;
+bool failMutexLock = false;
+bool failMutexUnlock = false;
 
 #endif

+ 18 - 18
src/ErrorSimulator.h

@@ -2,25 +2,25 @@
 #define CORE_ERROR_SIMULATOR_H
 
 #ifdef ERROR_SIMULATOR
-extern bool coreFailFileClose;
-extern bool coreFailTimeGet;
-extern bool coreFailThreadInit;
-extern bool coreFailMutexInit;
-extern bool coreFailMutexLock;
-extern bool coreFailMutexUnlock;
-#define CORE_FILE_CLOSE_FAIL coreFailFile
-#define CORE_TIME_GET_FAIL coreFailTimeGet
-#define CORE_THREAD_INIT_FAIL coreFailThreadInit
-#define CORE_MUTEX_INIT_FAIL coreFailMutexInit
-#define CORE_MUTEX_LOCK_FAIL coreFailMutexLock
-#define CORE_MUTEX_UNLOCK_FAIL coreFailMutexUnlock
+extern bool failFileClose;
+extern bool failTimeGet;
+extern bool failThreadInit;
+extern bool failMutexInit;
+extern bool failMutexLock;
+extern bool failMutexUnlock;
+#define FILE_CLOSE_FAIL failFile
+#define TIME_GET_FAIL failTimeGet
+#define THREAD_INIT_FAIL failThreadInit
+#define MUTEX_INIT_FAIL failMutexInit
+#define MUTEX_LOCK_FAIL failMutexLock
+#define MUTEX_UNLOCK_FAIL failMutexUnlock
 #else
-#define CORE_FILE_CLOSE_FAIL false
-#define CORE_TIME_GET_FAIL false
-#define CORE_THREAD_INIT_FAIL false
-#define CORE_MUTEX_INIT_FAIL false
-#define CORE_MUTEX_LOCK_FAIL false
-#define CORE_MUTEX_UNLOCK_FAIL false
+#define FILE_CLOSE_FAIL false
+#define TIME_GET_FAIL false
+#define THREAD_INIT_FAIL false
+#define MUTEX_INIT_FAIL false
+#define MUTEX_LOCK_FAIL false
+#define MUTEX_UNLOCK_FAIL false
 #endif
 
 #endif

+ 4 - 5
src/ReadLine.c

@@ -102,13 +102,13 @@ static void addToHistory() {
 }
 
 static void lock() {
-    if(mtx_lock(&bufferMutex) != thrd_success || CORE_MUTEX_LOCK_FAIL) {
+    if(mtx_lock(&bufferMutex) != thrd_success || MUTEX_LOCK_FAIL) {
         CORE_LOG_WARNING("could not lock buffer mutex");
     }
 }
 
 static void unlock() {
-    if(mtx_unlock(&bufferMutex) != thrd_success || CORE_MUTEX_UNLOCK_FAIL) {
+    if(mtx_unlock(&bufferMutex) != thrd_success || MUTEX_UNLOCK_FAIL) {
         CORE_LOG_WARNING("could not unlock buffer mutex");
     }
 }
@@ -262,12 +262,11 @@ bool coreStartReadLine(void) {
 
     buffer = CORE_RING_BUFFER(10, sizeof(ConsoleLine));
     atomic_store(&running, true);
-    if(CORE_MUTEX_INIT_FAIL ||
-       mtx_init(&bufferMutex, mtx_plain) != thrd_success) {
+    if(MUTEX_INIT_FAIL || mtx_init(&bufferMutex, mtx_plain) != thrd_success) {
         CORE_LOG_ERROR("cannot init buffer mutex");
         coreStopReadLine();
         return true;
-    } else if(CORE_THREAD_INIT_FAIL ||
+    } else if(THREAD_INIT_FAIL ||
               thrd_create(&readThread, loop, nullptr) != thrd_success) {
         CORE_LOG_ERROR("cannot start read thread");
         coreStopReadLine();

+ 1 - 1
src/Utility.c

@@ -241,7 +241,7 @@ bool sleepNanos(i64 nanos) {
 
 i64 getNanos(void) {
     struct timespec ts;
-    if(timespec_get(&ts, TIME_UTC) == 0 || CORE_TIME_GET_FAIL) {
+    if(timespec_get(&ts, TIME_UTC) == 0 || TIME_GET_FAIL) {
         return -1;
     }
     return (i64)ts.tv_sec * 1'000'000'000L + (i64)ts.tv_nsec;

+ 8 - 8
test/modules/ReadLineTests.c

@@ -38,26 +38,26 @@ static void testString(int line, const char* s) {
 
 void testReadLine(void) {
 #ifdef ERROR_SIMULATOR
-    coreFailMutexInit = true;
+    failMutexInit = true;
     if(!CORE_TEST_TRUE(coreStartReadLine())) {
         return;
     }
-    coreFailMutexInit = false;
-    coreFailThreadInit = true;
+    failMutexInit = false;
+    failThreadInit = true;
     if(!CORE_TEST_TRUE(coreStartReadLine())) {
         return;
     }
-    coreFailThreadInit = false;
-    coreFailMutexLock = true;
-    coreFailMutexUnlock = true;
+    failThreadInit = false;
+    failMutexLock = true;
+    failMutexUnlock = true;
 #endif
     if(!CORE_TEST_FALSE(coreStartReadLine())) {
         return;
     }
     testString(__LINE__, "wusi");
 #ifdef ERROR_SIMULATOR
-    coreFailMutexLock = false;
-    coreFailMutexUnlock = false;
+    failMutexLock = false;
+    failMutexUnlock = false;
 #endif
     testString(__LINE__, "gusi");
     testString(__LINE__, "abc");

+ 2 - 2
test/modules/UtilityTests.c

@@ -65,9 +65,9 @@ static void testSleep(i64 nanos) {
 
 static void testFail() {
 #ifdef ERROR_SIMULATOR
-    coreFailTimeGet = true;
+    failTimeGet = true;
     TEST_I64(-1, getNanos());
-    coreFailTimeGet = false;
+    failTimeGet = false;
 #endif
 }