Changeset 51 in libcf for trunk/test/test.c


Ignore:
Timestamp:
04/02/13 10:23:52 (11 years ago)
Author:
cheese
Message:

#1 change the debugging utiltity to support single context with mutex

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/test.c

    r49 r51  
    2222#define PORT        1234
    2323
    24 CF_Debug_Ctx        gDebugCtx;
    25 CF_Debug_CallStack  gDebugCallstack;
    2624CF_Mutex            globalMutex;
    2725
     
    6361    CF_Thread   tid[10];
    6462
    65     CF_DEBUG_CALLSTACK_PUSH (gDebugCtx);
     63    CF_DEBUG_BEGIN_FUNCTION;
    6664
    6765    /* initialize */
     
    125123    /* finalize */
    126124    CF_Log_Finalize ();
     125
     126    CF_DEBUG_END_FUNCTION;
    127127}
    128128
     
    132132    char    buffer[128] = {0x00,};
    133133
    134     CF_DEBUG_CALLSTACK_PUSH (gDebugCtx);
     134    CF_DEBUG_BEGIN_FUNCTION;
    135135
    136136    fd = CF_File_Open (file, CF_FILE_RO);
    137137    if (fd < 0)
    138         CF_DEBUG_TRACE (gDebugCtx, "what the ... file open ?\n");
     138        CF_DEBUG_PRINT (stderr, "what the ... file open ?\n");
    139139
    140140    if (CF_File_Read (fd, buffer, sizeof (buffer)) < 0)
    141         CF_DEBUG_TRACE (gDebugCtx, "what the ... file read ?\n");
     141        CF_DEBUG_PRINT (stderr, "what the ... file read ?\n");
    142142    else
    143         CF_DEBUG_TRACE_BIN (gDebugCtx, (unsigned char *)buffer,
    144                                         sizeof (buffer),
    145                                         "-- %d bytes of %d bytes\n",
    146                                         sizeof (buffer),
    147                                         CF_File_GetSize (fd));
     143        CF_DEBUG_PRINT_BIN (stdout, (unsigned char *)buffer,
     144                                    sizeof (buffer),
     145                                    "-- %d bytes of %d bytes\n",
     146                                    sizeof (buffer),
     147                                    CF_File_GetSize (fd));
    148148
    149149    CF_File_Close (fd);
    150150
    151     CF_DEBUG_CALLSTACK_POP (gDebugCtx, NULL);
     151    CF_DEBUG_END_FUNCTION;
    152152}
    153153
    154154void test_callstack3 (void)
    155155{
    156     CF_DEBUG_CALLSTACK_PUSH (gDebugCtx);
    157     while (CF_DEBUG_CALLSTACK_POP (gDebugCtx, &gDebugCallstack) == CF_OK)
    158     {
    159         CF_DEBUG_TRACE (gDebugCtx, "print callstack [file:%s line:%d func:%s]\n",
    160                                     gDebugCallstack.file,
    161                                     gDebugCallstack.line,
    162                                     gDebugCallstack.function);
    163     }
    164     CF_DEBUG_CALLSTACK_POP (gDebugCtx, NULL);
     156    CF_DEBUG_BEGIN_FUNCTION;
     157    CF_Debug_PrintCallStack (stdout);
     158    CF_DEBUG_END_FUNCTION;
    165159}
    166160void test_callstack2 (void)
    167161{
    168     CF_DEBUG_CALLSTACK_PUSH (gDebugCtx);
     162    CF_DEBUG_BEGIN_FUNCTION;
    169163    test_callstack3 ();
    170     CF_DEBUG_CALLSTACK_POP (gDebugCtx, NULL);
     164    CF_DEBUG_END_FUNCTION;
    171165}
    172166void test_callstack1 (void)
    173167{
    174     CF_DEBUG_CALLSTACK_PUSH (gDebugCtx);
     168    CF_DEBUG_BEGIN_FUNCTION;
    175169    test_callstack2 ();
    176     CF_DEBUG_CALLSTACK_POP (gDebugCtx, NULL);
     170    CF_DEBUG_END_FUNCTION;
    177171}
    178172
     
    333327int main (int argc, char ** argv)
    334328{
    335     gDebugCtx = CF_Debug_CreateCtx ();
    336 
    337     CF_DEBUG_CALLSTACK_PUSH (gDebugCtx);
     329    CF_DEBUG_BEGIN_FUNCTION;
    338330
    339331    // 1
     
    353345    test_socket ();
    354346
    355     CF_DEBUG_CALLSTACK_POP (gDebugCtx, &gDebugCallstack);
    356 
    357347    CF_DEBUG_PRINT (stderr, " == END OF TEST ==\n");
    358     CF_DEBUG_TRACE (gDebugCtx, "here is the end of function [file:%s line:%d func:%s]\n",
    359                                 gDebugCallstack.file,
    360                                 gDebugCallstack.line,
    361                                 gDebugCallstack.function);
    362 
    363     CF_Debug_DestroyCtx (gDebugCtx);
     348
     349    CF_DEBUG_END_FUNCTION;
    364350
    365351    return 0;
Note: See TracChangeset for help on using the changeset viewer.