Changeset 105 in libcf


Ignore:
Timestamp:
05/29/13 14:10:04 (11 years ago)
Author:
cheese
Message:

#1 remove integrated test code

Location:
trunk
Files:
1 added
3 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/cf_base.h

    r82 r105  
    55 *
    66 * @remarks 기본 정의
    7  *
    8  * @example test.c
    97 *
    108 * @mainpage
  • trunk/test/log.c

    r103 r105  
    44 */
    55#include "cf_log.h"
     6#include "cf_thread.h"
     7#include "cf_debug.h"
     8
    69#include <stdio.h>
     10
     11CF_Mutex globalMutex;
     12
     13#define LOG_MT      1
     14
     15int test_log_mt (void * arg)
     16{
     17    static int cnt = 0;
     18    int i = 0;
     19    int th = 0;
     20   
     21    if (CF_Mutex_Lock (&globalMutex) < 0) { // for critical section
     22        // error
     23    }
     24    th = cnt++;
     25    if (CF_Mutex_Unlock (&globalMutex) < 0) { // for critical section
     26        // error
     27    }
     28
     29    CF_DEBUG_PRINT (stderr, "created %dth thread\n", th);
     30
     31    for (i = 0 ; i < 100000 ; i++)
     32    {
     33        CF_Log_Write (LOG_MT, "LOG_MT", "[%d] multi-threadedlogging test %d\n", th, i);
     34    }
     35
     36    CF_DEBUG_PRINT (stderr, "end %dth thread\n", th);
     37
     38    return 0;
     39}
    740
    841int main (void)
    942{
    1043    int         i, j;
    11     char        logname[16] = {0x00,};
     44    char        idname[16] = {0x00,};
     45    CF_Thread   tid[10];
    1246
    13     if (CF_Log_Initialize (10, CF_LOG_NO_LEVEL) < 0)
     47    /* initialize */
     48    if (CF_Log_Initialize (10, 2) < 0)
    1449    {
    1550        fprintf (stderr, "failed to init. log\n");
     
    1954    for (i = 0 ; i < 10 ; i++)
    2055    {
    21         sprintf (logname, "logid%d.txt", i);
    22         if (CF_Log_Open (i, logname, CF_LOG_NO_BUFFER) < 0)
     56        sprintf (idname, "logid%d.txt", i);
     57        if (CF_Log_Open (i, idname, CF_LOG_NO_BUFFER) < 0)
    2358            fprintf (stderr, "failed to open log\n");
    2459    }
     
    3772    }
    3873
     74    /* mt {{{ */
     75    if (CF_Log_Open (LOG_MT, "log_mt.txt", CF_LOG_DEFAULT_BUFFER) < 0)
     76        CF_DEBUG_PRINT (stderr, "create log ctx error\n");
     77
     78    if (CF_Log_SetMT (LOG_MT, CF_TRUE) < 0)
     79        CF_DEBUG_PRINT (stderr, "set multi-threading mode error\n");
     80
     81    if (CF_Mutex_Create (&globalMutex) < 0) {
     82        // error
     83    }
     84
     85    for (i = 0 ; i < 10 ; i++)
     86    {
     87        if (CF_Thread_Create (&tid[i], test_log_mt, &i) < 0)
     88        {
     89            CF_DEBUG_PRINT (stderr, "failed to create %dth thread\n", i);
     90            return -2;
     91        }
     92    }
     93
     94    for (i = 0 ; i < 10 ; i++)
     95    {
     96        if (CF_Thread_Join (&tid[i]) < 0)
     97            CF_DEBUG_PRINT (stderr, "failed to join %dth thread\n", i);
     98        if (CF_Thread_Release (&tid[i]) < 0)
     99            CF_DEBUG_PRINT (stderr, "failed to release %dth thread\n", i);
     100    }
     101
     102    if (CF_Mutex_Destory (&globalMutex) < 0) {
     103        // error
     104    }
     105    /* }}} mt */
     106
     107    /* finalize */
    39108    CF_Log_Finalize ();
    40109
  • trunk/test/makefile

    r84 r105  
    88# env
    99#----------------------------------------------------------
    10 FILES           =   \
    11                     test            \
    12 
    13 TARGET_NAME     = test
    14 
    1510TARGET_PATH     = ../_build
    1611OBJ_PATH        = ../_obj
    17 TARGET          = $(TARGET_PATH)/$(TARGET_NAME).$(EXT_EXECUTE)
    18 SRCS            = $(addsuffix .$(SOURCE_TYPE),$(FILES))
    19 OBJS            = $(addprefix $(OBJ_PATH)/,$(addsuffix .o,$(FILES)))
    2012
    2113INCLUDES        = -I../include
     
    2719# label
    2820#----------------------------------------------------------
    29 all: dep $(TARGET)
     21all: dep
    3022    @echo ========== Complete CHEROXY compilation ==========
    3123dep: $(OBJ_PATH) $(TARGET_PATH) $(LIB_CF)
     
    3729$(LIB_CF): dummy
    3830    cd ../src; make all;
     31
     32test:
     33    make $(shell ls *.c | awk -F. '{ print $$1 }')
    3934
    4035%: %.c
  • trunk/windows/test/test.vcproj

    r14 r105  
    174174            >
    175175            <File
    176                 RelativePath="..\..\test\test.c"
     176                RelativePath="..\..\test\codec.c"
     177                >
     178            </File>
     179            <File
     180                RelativePath="..\..\test\debug.c"
     181                >
     182            </File>
     183            <File
     184                RelativePath="..\..\test\file.c"
     185                >
     186            </File>
     187            <File
     188                RelativePath="..\..\test\log.c"
     189                >
     190            </File>
     191            <File
     192                RelativePath="..\..\test\socket.c"
     193                >
     194            </File>
     195            <File
     196                RelativePath="..\..\test\thread.c"
    177197                >
    178198            </File>
Note: See TracChangeset for help on using the changeset viewer.