Changeset 39

Show
Ignore:
Timestamp:
06/04/08 16:36:44 (6 months ago)
Author:
jtang
Message:

Added chunked mqueue test.
Valgrind reports no errors now.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libsipc/tests/mqueue.c

    r37 r39  
    11/* Author: David Windsor <dwindsor@tresys.com> 
    22* 
    3 * Copyright (C) 2006, 2007 Tresys Technology, LLC 
     3* Copyright (C) 2006 - 2008 Tresys Technology, LLC 
    44* Developed Under US JFCOM Sponsorship 
    55* 
     
    3232 
    3333#define SIPC_MQ_KEY "mq_ipc_test" 
     34#define SIPC_BIG_MQ_KEY "mq2_ipc_test" 
    3435 
    3536#define CREATOR_APP "ipc_creator" 
     
    3738#define IN_FILE "data" 
    3839#define DATA_LEN 8192 
     40#define BIG_DATA_LEN (1024 * 32) 
    3941#define XMIT_END "0xDEADBEEF" 
    4042 
    41 static sipc_t *writer_ipc
    42 static sipc_t *reader_ipc; 
     43static sipc_t *writer_ipc, *reader_ipc
     44static sipc_t *writer2_ipc, *reader2_ipc; 
    4345static int send_end_xmit(sipc_t *ipc); 
    4446static void do_parent(void); 
    4547static void do_child(void); 
     48static void do_parent_chunked(void); 
     49static void do_child_chunked(void); 
    4650static int verify_data(char *filename, char *recv_data); 
    4751static inline int is_end_xmit(char *data); 
     
    7478        } 
    7579        wait(&status); 
     80        helper_argv[1] = SIPC_BIG_MQ_KEY; 
     81        switch ((pid = fork())) { 
     82        case -1: 
     83                fprintf(stderr, "fork(): %s\n", strerror(errno)); 
     84                return -1; 
     85        case 0: 
     86                execve(CREATOR_APP, helper_argv, NULL); 
     87                break; 
     88        default: 
     89                break; 
     90        } 
     91        wait(&status); 
    7692 
    7793        /* Open IPCs */ 
     
    87103        } 
    88104 
     105        writer2_ipc = sipc_open(SIPC_BIG_MQ_KEY, SIPC_SENDER, SIPC_SYSV_MQUEUES, BIG_DATA_LEN); 
     106        if (writer2_ipc == NULL) { 
     107                fprintf(stderr, "Unable to initialize big IPC resource\n"); 
     108                return -1; 
     109        } 
     110        reader2_ipc = sipc_open(SIPC_BIG_MQ_KEY, SIPC_RECEIVER, SIPC_SYSV_MQUEUES, BIG_DATA_LEN); 
     111        if (reader2_ipc == NULL) { 
     112                fprintf(stderr, "Error initializing big IPC resource\n"); 
     113                return -1; 
     114        } 
    89115        return 0; 
    90116} 
     
    96122        char ipc_type_str[128]; 
    97123 
    98         /* Cleanup handle here */ 
     124        /* Cleanup handles here */ 
    99125        sipc_close(reader_ipc); 
    100126        sipc_close(writer_ipc); 
     127        sipc_close(reader2_ipc); 
     128        sipc_close(writer2_ipc); 
    101129 
    102130        /* Build the destroyer app's argv */ 
     
    123151        wait(&status); 
    124152 
     153        helper_argv[1] = SIPC_BIG_MQ_KEY; 
     154        switch ((pid = fork())) { 
     155        case -1: 
     156                fprintf(stderr, "fork(): %s\n", strerror(errno)); 
     157                return -1; 
     158        case 0: 
     159                execve(DESTROYER_APP, helper_argv, NULL); 
     160                break; 
     161        default: 
     162                break; 
     163        } 
     164        wait(&status); 
     165 
    125166        return 0; 
    126167} 
     
    142183        CU_ASSERT(memcmp(recv_data, message, message_len) == 0); 
    143184        free(recv_data); 
    144         CU_ASSERT(sipc_shm_recv_done(reader_ipc) == 0); 
    145185} 
    146186 
     
    161201        default: 
    162202                do_parent(); 
     203                break; 
     204        } 
     205 
     206        wait(&status); 
     207} 
     208 
     209static void test_chunked_mqueue(void) 
     210{ 
     211        pid_t pid; 
     212        int status = 0; 
     213 
     214        switch ((pid = fork())) { 
     215        case -1: 
     216                fprintf(stderr, "fork: %s\n", strerror(errno)); 
     217                return; 
     218        case 0: 
     219                sipc_close(reader2_ipc); 
     220                do_child_chunked(); 
     221                exit(0); 
     222                break; 
     223        default: 
     224                do_parent_chunked(); 
    163225                break; 
    164226        } 
     
    172234        {"forked mqueue", test_mqueue} 
    173235        , 
     236        {"forked chunked mqueue", test_chunked_mqueue} 
     237        , 
    174238        CU_TEST_INFO_NULL 
    175239}; 
    176240 
    177241/* Read a message from mqueue */ 
    178 static void do_parent(
     242static void do_parent(void
    179243{ 
    180244        char *data = NULL; 
     
    196260} 
    197261 
    198 static void do_child(
     262static void do_child(void
    199263{ 
    200264        int rbytes = 0; 
     
    227291} 
    228292 
     293static void do_parent_chunked(void) 
     294{ 
     295        char *data = NULL; 
     296        int len = 0; 
     297 
     298        size_t total_read = 0, j = 0; 
     299        while (!sipc_recv_data(reader2_ipc, &data, &len)) { 
     300                CU_ASSERT_PTR_NOT_NULL_FATAL(data); 
     301                CU_ASSERT_FATAL(len > 0); 
     302 
     303                size_t i; 
     304                for (i = 0; i < len; i++) { 
     305                        if (total_read % 512 == 0) { 
     306                                j++; 
     307                        } 
     308                        CU_ASSERT(data[i] == j); 
     309                        total_read++; 
     310                } 
     311 
     312                free(data); 
     313                if (total_read >= BIG_DATA_LEN) { 
     314                        return; 
     315                } 
     316        } 
     317        CU_FAIL("Did not receive as much data as expected."); 
     318} 
     319 
     320static void do_child_chunked(void) 
     321{ 
     322        char *data = NULL; 
     323 
     324        /* Get pointer to IPC's data member */ 
     325        data = sipc_get_data_ptr(writer2_ipc); 
     326        CU_ASSERT_PTR_NOT_NULL(data); 
     327 
     328        size_t i, j = 0; 
     329        for (i = 0; i < BIG_DATA_LEN; i++) { 
     330                if (i % 512 == 0) { 
     331                        j++; 
     332                } 
     333                data[i] = j; 
     334        } 
     335 
     336        /* Send data, then end of xmit */ 
     337        CU_ASSERT(sipc_send_data(writer2_ipc, i) == 0); 
     338 
     339        /* Cleanup handle here */ 
     340        sipc_close(writer2_ipc); 
     341} 
     342 
    229343static int send_end_xmit(sipc_t *ipc) 
    230344{ 
  • trunk/libsipc/tests/mqueue.h

    r33 r39  
    11/* Author: David Windsor <dwindsor@tresys.com> 
    22* 
    3 * Copyright (C) 2006, 2007 Tresys Technology, LLC 
     3* Copyright (C) 2006 - 2008 Tresys Technology, LLC 
    44* Developed Under US JFCOM Sponsorship 
    55* 
  • trunk/libsipc/tests/run_tests.sh

    r1 r39  
    33touch shm_ipc_test 
    44touch mq_ipc_test 
     5touch mq2_ipc_test 
    56./test_ipc 
    67rm -f shm_ipc_test 
    78rm -f mq_ipc_test 
     9rm -f mq2_ipc_test 
  • trunk/libsipc/tests/shm.c

    r37 r39  
    11/* Author: David Windsor <dwindsor@tresys.com> 
    22* 
    3 * Copyright (C) 2006, 2007 Tresys Technology, LLC 
     3* Copyright (C) 2006 - 2008 Tresys Technology, LLC 
    44* Developed Under US JFCOM Sponsorship 
    55* 
     
    129129} 
    130130 
    131 static void test_unforked_shm(void) 
    132 { 
    133         static char message[] = "HELLO,"; 
    134         size_t message_len = sizeof(message); 
    135         char *shm_data = sipc_get_data_ptr(writer_ipc); 
    136         int recv_len; 
    137         char *recv_data; 
    138  
    139         CU_ASSERT_PTR_NOT_NULL_FATAL(shm_data); 
    140         strcpy(shm_data, message); 
    141         CU_ASSERT(sipc_send_data(writer_ipc, message_len) == 0); 
    142         CU_ASSERT(sipc_recv_data(reader_ipc, &recv_data, &recv_len) == 0); 
    143         CU_ASSERT(recv_len >= message_len); 
    144         CU_ASSERT(memcmp(recv_data, message, message_len) == 0); 
    145         CU_ASSERT(sipc_shm_recv_done(reader_ipc) == 0); 
    146 } 
    147  
    148131static void test_shm(void) 
    149132{ 
     
    193176 
    194177CU_TestInfo shm_tests[] = { 
    195         {"unforked shm", test_unforked_shm} 
    196         , 
    197178        {"forked shm", test_shm} 
    198179        , 
     
    305286        while (!sipc_recv_data(reader_ipc, &data, &len)) { 
    306287                if (END_XMIT(data)) { 
    307                         sipc_shm_recv_done(reader_ipc); 
    308288                        break; 
    309289                } 
     
    315295        CU_PASS("Successfully read a message via SYSV shared memory"); 
    316296 
     297        /* until sipc_shm_recv_done() is called, further reading of 
     298           data will cause a non-recoverable state */ 
     299        /* 
     300           CU_ASSERT(sipc_recv_data(reader_ipc, &data, &len) < 0); 
     301         */ 
     302        sipc_shm_recv_done(reader_ipc); 
     303 
    317304        for (i = 0; i < DATA_LEN; i++) { 
    318305                if (recv_data[i] != i % 256) { 
  • trunk/libsipc/tests/shm.h

    r33 r39  
    11/* Author: David Windsor <dwindsor@tresys.com> 
    22* 
    3 * Copyright (C) 2006, 2007 Tresys Technology, LLC 
     3* Copyright (C) 2006 - 2008 Tresys Technology, LLC 
    44* Developed Under US JFCOM Sponsorship 
    55* 
  • trunk/libsipc/tests/test_ipc.c

    r35 r39  
    11/* Author: David Windsor <dwindsor@tresys.com> 
    22* 
    3 * Copyright (C) 2006, 2007 Tresys Technology, LLC 
     3* Copyright (C) 2006 - 2008 Tresys Technology, LLC 
    44* Developed Under US JFCOM Sponsorship 
    55*